Emit full "Impl" types for IList<T> in 'cswinrtgen'#2170
Merged
manodasanW merged 23 commits intostaging/3.0from Jan 16, 2026
Merged
Emit full "Impl" types for IList<T> in 'cswinrtgen'#2170manodasanW merged 23 commits intostaging/3.0from
IList<T> in 'cswinrtgen'#2170manodasanW merged 23 commits intostaging/3.0from
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for emitting full implementation types for IList<T> in 'cswinrtgen'. The implementation involves creating adapter types for marshalling IList<T> instances to/from Windows Runtime interfaces, along with the necessary infrastructure for code generation.
Key changes:
- Added
IListAdapter<T>andIListAdapterExtensionsfor marshallingIList<T>instances - Implemented factory methods for generating interop method definitions for
IList<T>implementations - Added support for tracking and rewriting managed values during IL generation
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/WinRT.Runtime2/InteropServices/Collections/IListAdapter{T}.cs |
New adapter providing stateless marshalling methods for IList<T> to Windows Runtime IVector<T> |
src/WinRT.Runtime2/InteropServices/Collections/IListAdapterExtensions.cs |
Extension methods for IListAdapter<T>, specifically for string handling |
src/WinRT.Interop.Generator/References/InteropReferences.cs |
Added type and method references for IListAdapter<T> and moved existing references |
src/WinRT.Interop.Generator/Models/MethodRewriteInfo/MethodRewriteInfo.ManagedValue.cs |
New model for tracking method rewrites involving managed values |
src/WinRT.Interop.Generator/Generation/InteropGeneratorEmitState.cs |
Added tracking support for managed value method rewrites |
src/WinRT.Interop.Generator/Generation/InteropGeneratorDiscoveryState.cs |
Added support for marking user-defined types to prevent duplicate processing |
src/WinRT.Interop.Generator/Generation/InteropGenerator.Emit.cs |
Added case handling for managed value method rewrites |
src/WinRT.Interop.Generator/Factories/InteropMethodRewriteFactory.ManagedValue.cs |
New factory for rewriting methods to marshal managed values |
src/WinRT.Interop.Generator/Factories/InteropMethodRewriteFactory.ManagedParameter.cs |
Removed duplicate comments and consolidated marshalling logic |
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IReadOnlyList1Impl.cs |
Refactored to support both IReadOnlyList<T> and IList<T> implementations |
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IList1Impl.cs |
New factory for creating method definitions for IList<T> implementations |
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IEnumerator1Impl.cs |
Updated comment for accuracy |
src/WinRT.Interop.Generator/Extensions/CilInstructionExtensions.cs |
Added CreateLdind method for loading values indirectly |
src/WinRT.Interop.Generator/Discovery/InteropTypeDiscovery.cs |
Added early exit to prevent infinite recursion when discovering user-defined types |
src/WinRT.Interop.Generator/Discovery/InteropTypeDiscovery.Generics.cs |
Added tracking of IReadOnlyList<T> and ReadOnlyCollection<T> when discovering IList<T> |
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IReadOnlyList1.cs |
Updated to pass method references to factory methods |
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IList1.cs |
Implemented full vtable methods for IList<T> implementations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/WinRT.Runtime2/InteropServices/Collections/IListAdapter{T}.cs
Outdated
Show resolved
Hide resolved
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IReadOnlyList1Impl.cs
Outdated
Show resolved
Hide resolved
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IReadOnlyList1Impl.cs
Outdated
Show resolved
Hide resolved
manodasanW
approved these changes
Jan 10, 2026
5be243f to
13f4fdd
Compare
Base automatically changed from
user/sergiopedri/read-only-list-impl
to
staging/3.0
January 16, 2026 20:15
Updated GetAt and get_Size methods in InteropMethodDefinitionFactory.IReadOnlyList1Impl to accept explicit MemberReference parameters for the interface methods to invoke. Adjusted InteropTypeDefinitionBuilder to pass the correct references. This improves flexibility and clarity in method invocation for interop scenarios.
Introduces IListAdapter<T> as a stateless adapter for IList<T> to expose vector-like operations, including GetAt, Size, IndexOf, and GetMany. Adds IListAdapterExtensions with an IndexOf overload for IList<string> supporting ReadOnlySpan<char> comparisons. Both are marked obsolete for internal use.
Introduces methods for 'GetAt' and 'Size' using IListAdapter<T> in InteropTypeDefinitionBuilder.IList1. Adds new type and member references for IListAdapter<T> and IListAdapterExtensions in InteropReferences, enabling more complete IList1 interop support.
Introduced the GetView method to return an immutable view of the IList<T> as IReadOnlyList<T>. This improves performance by avoiding unnecessary allocations when possible and aligns with the expected behavior for vector views in interop scenarios.
Introduces a new GetView method for IList<T> interop types, including its method factory and reference resolution. Updates type discovery to track IReadOnlyList<T> when IList<T> is found, ensuring correct marshaling for IVector<T>.GetView. This enables proper support for projecting IList<T> to IReadOnlyList<T> in generated interop code.
Adds a check to avoid reprocessing user-defined types during interop type discovery, preventing stack overflows from infinite recursion. Also tracks ReadOnlyCollection<T> when IList<T> is discovered to ensure correct marshaling, and introduces supporting fields and methods for marking user-defined types.
Introduces methods and references to support IListAdapter1<T>.IndexOf in the interop generator. Updates method factories and type builders to correctly handle IndexOf for both IList<T> and IReadOnlyList<T> scenarios, including string specialization.
Implements the SetAt method for IList<T> interop, including method definition generation, reference resolution, and adapter implementation. This enables setting values at a specific index in generated COM interop for IList<T>.
Eliminated an unused variable in InteropMethodDefinitionFactory.IList1Impl.cs and moved the IListAdapter1SetAt method in InteropReferences.cs for better code organization.
Introduces the InsertAt method for IList<T> interop, including its definition in IListAdapter<T>, method generation in InteropMethodDefinitionFactory, and reference handling in InteropReferences. This enables correct handling of the IVector<T>.InsertAt method in generated interop code.
Relocated the IndexOf method and its documentation within IListAdapter<T> to improve code organization and maintain logical grouping of related methods. No functional changes were made.
Implemented the RemoveAt method for IList<T> interop, including its definition in the generator, method factory, and interop references. Also added the actual RemoveAt implementation in IListAdapter<T> to handle item removal and error translation.
Introduces the 'Append' method for IList<T> in the interop generator. Adds method definition, reference, and implementation logic to support exporting the Append method for COM interop scenarios.
Implements the RemoveAtEnd method for IList<T> interop scenarios, including generator, factory, references, and adapter logic. This enables proper handling of the IVector<T>.RemoveAtEnd operation in Windows Runtime interop, with error handling for empty collections.
Implemented the 'Clear' method for IList<T> interop by defining a new method in InteropMethodDefinitionFactory.IList1Impl and wiring it up in InteropTypeDefinitionBuilder. This enables COM interop consumers to call the Clear method on IList<T> implementations.
Introduces the GetMany method to IList<T> interop type definitions, aligning its implementation with IReadOnlyList<T>. Updates method signatures and calls to pass the appropriate getAtMethod reference, enabling consistent method generation for both IList<T> and IReadOnlyList<T> interfaces.
Introduces the ManagedValue method rewrite type, including its model, factory logic, and emit state tracking. Updates the interop generator to handle marshalling of managed values, enabling more flexible and accurate IL generation for managed parameters.
Introduces the CreateLdind method for generating instructions to load values indirectly based on the type signature. This complements the existing CreateStind method and improves support for indirect value loading in IL code generation.
Introduces a new ReplaceAll method for IList1 interop, including its definition, method body, and integration into the type builder. Also updates method calls to use ICollection1.Add instead of IList1.Append and removes the unused IList1Append reference.
Replaces usage of 'elementType' with explicit 'GenericParameterSignature(GenericParameterType.Type, 0)' in IList1 and IReadOnlyList1 generic reference type creation for method signatures. This ensures consistent and correct handling of generic parameters in interop reference methods.
3064471 to
b4c923a
Compare
Corrected minor spelling errors in comments and XML documentation across InteropTypeDiscovery, InteropMethodDefinitionFactory.IReadOnlyList1Impl, and IListAdapter<T> to improve clarity and accuracy.
Added #pragma warning disable CS8620 to temporarily suppress warnings caused by a Roslyn bug. This will be removed once the bug is fixed.
Corrected the XML comment to reference TryMarkUserDefinedType instead of MarkUserDefinedType for clarity and accuracy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title.
GetManyis an empty stub for now, will implement in a follow up PR.Examples of codegen:

Note
Draft because there's some commits to move and this branch also needs to be rebased.