Add ImplParam GAT: use primitive types directly in _Impl trait methods#4155
Add ImplParam GAT: use primitive types directly in _Impl trait methods#4155
Conversation
…l trait methods Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/205ca06b-cbb1-41ee-8d46-dd1379661f73 Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
|
@copilot check the build failures |
… directly (no Ref) Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/b7ddf051-5172-4d8e-ac1c-6bec9857a693 Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
Fixed in 70debcf. The CI failures were in |
|
@copilot fmt failed |
|
@copilot more test failures |
Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/e17f3e4f-e89f-40a1-93ba-b1effc4a8e8b Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
…th param Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/5f5476f1-8cf0-4922-9151-336f8d1fdca0 Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
|
@copilot clippy failure |
Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/e72d00b1-ca13-4ea1-b79f-5ac1e2840a0f Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
|
@copilot build failures |
… with ImplParam Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/347294e7-f5c5-4215-b0ce-f6f3bf474d8f Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
Fixed in 7e3ed76. The "Tests changed code in the repo" check was failing because |
Resolves the TODO in
crates/tests/libs/implement/tests/map.rsthat said// TODO: shouldn't requireReffor primitive.Problem
When implementing
IMap_Impl<i32, f32>, users had to write:even though
i32is a primitive copy type whereRef<T>adds no semantic value. The same issue affected event handler closures —EventHandler::<i32>::new(move |_, args: Ref<i32>| { assert_eq!(*args, 2); ... })required unnecessary wrapping and dereferencing.Solution
Added a
Param<'a>generic associated type (GAT) to theType<T, C>trait inwindows-core:CopyType(primitives, GUID, enums, etc.):Param<'a> = T— the type itself, noRefwrapperCloneType(HSTRING, etc.):Param<'a> = Ref<'a, T>— same as beforeInterfaceType(COM interfaces):Param<'a> = Ref<'a, T>— same as beforeTwo helpers are added to
Type<T, C>:abi_to_param(abi: &Self::Abi) -> Self::Param<'_>— used in generated vtable code to convert from raw ABI parameter to impl param typeparam_as_default(param: &Self::Param<'_>) -> &Self::Default— used in generic impl method bodies to get&K::Defaultfrom eitherK(copy) orRef<K>(others)A public type alias is exported:
The bindgen code generator is updated to:
windows_core::ImplParam<'_, K>instead ofwindows_core::Ref<K>for generic type parameters in_Impltrait method signatures<K as windows_core::Type<K>>::abi_to_param(&key)instead oftransmute_copy(&key)in vtable upcall code for generic parametersAll affected bindings are regenerated (
windows-collections,windows-future,Windows/Foundation, test bindgen files,reference_custom/src/bindings.rs,reference_no_deps/src/bindings.rs). Hand-written impls (map_view.rs,vector_view.rs, test files) are updated to use the new API. Test files using event handler closures (events_client/src/lib.rs,event_core/tests/tests.rs) are updated to use primitive values directly instead ofRef<primitive>/*args. Twoclippy::explicit_auto_dereflints in theparam_as_defaultimplementations are resolved by returningparamdirectly instead of&**param. Thedelegates.rstest is updated to remove the now-resolved*portdereference of a primitivei32.Result
Users can now write:
Event handler closures over primitive types are also simplified:
For non-primitive types like
HSTRINGand COM interfaces,Ref<T>is still used as before (which remains the correct approach for borrowed, non-owned types).