-
Notifications
You must be signed in to change notification settings - Fork 122
Track CCW info for '[ReadOnly]Dictionary[Key|Value]Collection<TKey, TValue>' typs in 'cswinrtgen' #2159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: user/sergiopedri/generic-ccw2
Are you sure you want to change the base?
Track CCW info for '[ReadOnly]Dictionary[Key|Value]Collection<TKey, TValue>' typs in 'cswinrtgen' #2159
Conversation
Replaces the use of _corLibTypeFactory.CorLibScope with SystemObjectModel for creating the TypeReference for System.Windows.Input.ICommand. This change may improve consistency or correctness in type reference creation.
Added support for mapping the IVectorChangedEventArgs interface to its well-known IID string in WellKnownInterfaceIIDs. This improves interface recognition for Windows.Foundation.Collections.IVectorChangedEventArgs.
Relocated the IID mappings for IDisposable and IServiceProvider to an earlier position in the switch statement within WellKnownInterfaceIIDs.cs. This change ensures these interfaces are matched before others, likely to address precedence or matching issues.
Updated GuidGenerator and WellKnownInterfaceIIDs to support resolving interface IIDs based on the useWindowsUIXamlProjections flag. This enables correct GUID selection for interfaces that differ between Windows.UI.Xaml and Microsoft.UI.Xaml projections, improving compatibility and correctness in generated interop signatures.
Added [Guid] attributes to several Windows.Foundation and Windows.Foundation.Collections interface definitions to specify their interface IDs. This change improves COM interop and aligns the interfaces with their corresponding WinRT specifications.
Introduces EnumerateAllInterfaces to TypeSignatureExtensions, allowing traversal of all interfaces implemented by a type, including those from base types. This method handles generic types and ensures robust traversal even with incomplete type hierarchies.
Updated the logic to yield base interfaces directly without re-instantiating their generic types, as they are already instantiated when returned. This prevents unnecessary operations and improves code clarity.
Added a call to emitState.TrackTypeDefinition for implType and vectorType in the InteropTypeDefinitionBuilder.IObservableVector1 implementation. This ensures the type is tracked, which may be required for COM interface entries involving user-defined types.
Renamed and updated warning methods in WellKnownInteropExceptions for improved clarity regarding interface and base type resolution failures. Refactored InteropGenerator.Discover.cs to use the new warning methods, streamline interface discovery, and ensure correct handling of generic interface instantiations.
Deleted the EnumerateAllInterfaces method, which enumerated all interface implementations for a type and its base types. This cleanup may be due to redundancy, lack of use, or a refactor in interface enumeration logic.
Introduced HasBaseType extension to encapsulate base type checks and refactored related logic in TypeDefinitionExtensions and InteropGenerator.Discover. This improves code clarity and reduces duplication when handling type hierarchies and base type resolution.
Moved the logic for tracking exposed user-defined types from InteropGenerator.Discover.cs into a new InteropTypeDiscovery helper class. This improves code organization and reusability by encapsulating the discovery process in a dedicated static method.
Moved logic for tracking constructed generic types from InteropGenerator.Discover.cs into a new InteropTypeDiscovery.Generics.cs file. This refactoring centralizes and organizes generic type discovery, improving maintainability and separation of concerns.
Extended the EnumerateTypeSignatures method to process 'newobj' and 'newarr' CIL instructions, ensuring that object and array instantiations are included in the signature enumeration. This improves coverage of type signatures encountered in method bodies.
Moved SZ array and type hierarchy tracking logic from InteropGenerator.Discover.cs into dedicated helper methods in InteropTypeDiscovery. This improves code reuse and maintainability by centralizing the logic for type analysis and tracking.
Updated InteropTypeDiscovery tracking methods to return void instead of bool, as their return values were not used. Adjusted all call sites and removed related comments and unreachable code for clarity.
Added checks to skip unconstructed generic type definitions during interop type discovery and generation. This ensures only constructed generic types are considered for marshalling code, improving accuracy and avoiding unnecessary processing of generic definitions.
Introduced new test cases to validate activation and interface QueryInterface (QI) for constructed generic types and their derived types. Refactored QI logic into a reusable ComHelpers.EnsureQueryInterface method. Added several generic and derived classes to exercise interface exposure and activation scenarios.
Introduces tests for IAsyncActionWithProgress<int> and IAsyncOperation<TimeSpan> using AsyncInfo.Run with explicit and transitive type arguments. Ensures correct COM interface querying and memory management for these async operations.
Added XML documentation remarks to the Keys and Values properties in WindowsRuntimeDictionary, WindowsRuntimeObservableMap, and WindowsRuntimeReadOnlyDictionary classes to clarify the concrete collection types returned. This improves API documentation and developer understanding of the property return types.
Replaces direct calls to TrackGenericInterfaceType with a new TryTrackWindowsRuntimeGenericInterfaceTypeInstance method. This centralizes and extends the logic for tracking constructed generic Windows Runtime interface types, ensuring all necessary related types and delegates are also tracked for code generation.
Deleted the InteropGeneratorDiscoveryStateExtensions.cs file, which contained extension methods for tracking generic interface and delegate types in the interop generator discovery process. This may be part of a refactor or cleanup to simplify or relocate this logic.
Updated generic type discovery logic to explicitly track constructed DictionaryKeyCollection, DictionaryValueCollection, ReadOnlyDictionaryKeyCollection, and ReadOnlyDictionaryValueCollection types when discovering IDictionary<TKey, TValue> and IReadOnlyDictionary<TKey, TValue> instantiations. This ensures correct marshaling of these types, which may not be present in input assemblies but are generated during emit. Also refactored method signatures to consistently pass the current module and args where needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the WinRT interop generator to track CCW (COM Callable Wrapper) information for dictionary collection types (DictionaryKeyCollection, DictionaryValueCollection, ReadOnlyDictionaryKeyCollection, and ReadOnlyDictionaryValueCollection). The changes ensure these collection types are properly instantiated in WinRT.Interop.dll when their parent dictionary types are discovered, enabling correct marshalling to native code.
Key changes:
- Refactored generic interface type tracking from extension methods to a dedicated method in
InteropTypeDiscovery.Generics.cs - Added automatic tracking of dictionary key/value collection types when discovering
IDictionary<TKey, TValue>andIReadOnlyDictionary<TKey, TValue>instantiations - Enhanced documentation in dictionary collection classes to clarify the concrete types returned by
KeysandValuesproperties
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
WindowsRuntimeReadOnlyDictionary{TKey, TValue}.cs |
Added XML documentation remarks clarifying the concrete types returned by Keys and Values properties |
WindowsRuntimeObservableMap{TKey, TValue}.cs |
Added XML documentation remarks for dictionary collection properties with inherited documentation for interface implementations |
WindowsRuntimeDictionary{TKey, TValue}.cs |
Added XML documentation remarks for dictionary collection properties with inherited documentation for interface implementations |
InteropGenerator.Discover.cs |
Added module parameter to TryTrackExposedUserDefinedType call to support enhanced type discovery |
InteropGeneratorDiscoveryStateExtensions.cs |
Deleted file - functionality moved to InteropTypeDiscovery.Generics.cs |
InteropTypeDiscovery.cs |
Added module parameter to TryTrackExposedUserDefinedType method signature |
InteropTypeDiscovery.Generics.cs |
Refactored generic interface tracking into dedicated method with automatic tracking of dictionary collection types when parent dictionary types are discovered |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/WinRT.Runtime2/Collections/WindowsRuntimeObservableMap{TKey, TValue}.cs
Show resolved
Hide resolved
src/WinRT.Runtime2/Collections/WindowsRuntimeObservableMap{TKey, TValue}.cs
Show resolved
Hide resolved
src/WinRT.Runtime2/Collections/WindowsRuntimeDictionary{TKey, TValue}.cs
Show resolved
Hide resolved
src/WinRT.Runtime2/Collections/WindowsRuntimeDictionary{TKey, TValue}.cs
Show resolved
Hide resolved
4147e26 to
10baca1
Compare
Title. This results in the following additional instantiations in
WinRT.Interop.dll(there's more):