-
Notifications
You must be signed in to change notification settings - Fork 121
Add exclusion list for types in 'cswinrtgen #2157
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?
Add exclusion list for types in 'cswinrtgen #2157
Conversation
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.
Applied the [WindowsRuntimeManagedOnlyType] attribute to the WindowsRuntimeObjectReference class to indicate it is intended for managed use only.
Introduces a TypeExclusions helper class to centralize logic for excluding specific types, such as Task<T>, from the interop API surface. Also adds a Task1 reference to InteropReferences to support this exclusion logic.
Introduced checks in InteropTypeDiscovery to skip types explicitly excluded via TypeExclusions, including support for SZ arrays. This prevents processing of types that should not be considered for interop marshalling, improving filtering and correctness.
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 introduces an exclusion list mechanism for the 'cswinrtgen' tool to filter out specific types from the interop API surface, with the initial exclusion being Task<T> instantiations.
Key Changes:
- Created a new
TypeExclusionshelper class with extensible exclusion logic - Added
Task<T>reference toInteropReferencesfor use in exclusion checks - Integrated exclusion checks into three type discovery methods to prevent tracking of excluded types
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/WinRT.Runtime2/InteropServices/ObjectReference/WindowsRuntimeObjectReference.cs | Added [WindowsRuntimeManagedOnlyType] attribute to mark the class as managed-only |
| src/WinRT.Interop.Generator/References/InteropReferences.cs | Added Task1 property to provide reference to Task<TResult> generic type definition |
| src/WinRT.Interop.Generator/Helpers/TypeExclusions.cs | Created new helper class containing exclusion logic for types that should be filtered from interop API surface |
| src/WinRT.Interop.Generator/Discovery/InteropTypeDiscovery.cs | Added exclusion check in TryTrackExposedUserDefinedType to filter excluded types |
| src/WinRT.Interop.Generator/Discovery/InteropTypeDiscovery.Generics.cs | Added exclusion checks in TryTrackGenericTypeInstance and TryTrackSzArrayType to filter excluded types |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ecc4d6d to
54cf730
Compare
Applied the [WindowsRuntimeManagedOnlyType] attribute to various Windows Runtime collection and async types in the WinRT.Runtime2 project. This change clarifies that these types are managed-only implementations, improving code clarity and maintainability.
| } | ||
|
|
||
| // Check if the input type matches any of our exclusions | ||
| foreach (TypeReference excludedType in (ReadOnlySpan<TypeReference>)[interopReferences.Task1]) |
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.
Should this be in a separate global variable or so if we are planning on adding to it or is it just this?
This PR adds an extensible way to special-case types to exclude in 'cswinrtgen', such as
Task<T>instantiations.