Skip to content

Conversation

@Sergio0694
Copy link
Member

Title. Removes ~1230 manual Import calls. I'll do a follow up to clean the (now unnecessary) leftover parameters.

Original attempt: #2140

Copy link

Copilot AI left a 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 updates cswinrtgen (WinRT.Interop.Generator) to rely on AsmResolver’s auto-import behavior instead of performing explicit manual Import(module) calls, significantly reducing boilerplate across the IL rewriting and type/method definition factories.

Changes:

  • Removed a large number of explicit .Import(module) calls when emitting IL, signatures, and metadata references.
  • Simplified ImportExtensions by removing most import helpers (now largely unnecessary with auto-import), retaining only assembly reference importing.
  • Updated many factory/builder/rewriter sites to pass AsmResolver reference objects directly (types, members, signatures) and let import happen automatically.

Reviewed changes

Copilot reviewed 66 out of 66 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/WinRT.Interop.Generator/Rewriters/InteropMethodRewriter.ReturnValue.cs Remove explicit imports for return-value marshalling callsites.
src/WinRT.Interop.Generator/Rewriters/InteropMethodRewriter.RetVal.cs Remove explicit imports for retval marshalling and ABI stores.
src/WinRT.Interop.Generator/Rewriters/InteropMethodRewriter.RawRetVal.cs Remove explicit imports for raw retval marshalling calls.
src/WinRT.Interop.Generator/Rewriters/InteropMethodRewriter.NativeParameter.cs Remove explicit imports across native-parameter marshalling paths.
src/WinRT.Interop.Generator/Rewriters/InteropMethodRewriter.ManagedValue.cs Remove explicit imports for managed-value marshalling calls.
src/WinRT.Interop.Generator/Rewriters/InteropMethodRewriter.ManagedParameter.cs Remove explicit imports for managed-parameter marshalling calls.
src/WinRT.Interop.Generator/Rewriters/InteropMethodRewriter.Dispose.cs Remove explicit imports for disposal/free paths.
src/WinRT.Interop.Generator/Resolvers/InteropInterfaceEntriesResolver.cs Remove explicit imports when emitting IID/vtable loads.
src/WinRT.Interop.Generator/Factories/WellKnownTypeDefinitionFactory.IgnoreAccessChecksToAttribute.cs Remove explicit imports for attribute base type and ctor calls.
src/WinRT.Interop.Generator/Factories/WellKnownMemberDefinitionFactory.cs Remove explicit imports for IID property signatures/attributes.
src/WinRT.Interop.Generator/Factories/WellKnownCilMethodBodyFactory.cs Remove explicit imports in emitted helper IL bodies.
src/WinRT.Interop.Generator/Factories/InteropTypeDefinitionFactory.SzArrayMarshaller.cs Remove explicit imports in generated SZ-array marshaller APIs.
src/WinRT.Interop.Generator/Factories/InteropTypeDefinitionFactory.SzArrayElementMarshaller.cs Remove explicit imports in generated element marshaller implementations.
src/WinRT.Interop.Generator/Factories/InteropTypeDefinitionFactory.IReadOnlyCollectionKeyValuePair2.cs Remove explicit imports for forwarder attribute base type and methods.
src/WinRT.Interop.Generator/Factories/InteropTypeDefinitionFactory.IEnumeratorElementMarshaller.cs Remove explicit imports in enumerator element marshaller definitions.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.KeyValuePairMethods.cs Remove explicit imports for ABI locals and callsites.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IVectorViewMethods.cs Remove explicit imports in vector view method bodies/signatures.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IVectorMethods.cs Remove explicit imports in vector method bodies/signatures.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IReadOnlyList1Impl.cs Remove explicit imports in IReadOnlyList ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IReadOnlyDictionary2Impl.cs Remove explicit imports in IReadOnlyDictionary ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IObservableVector1Impl.cs Remove explicit imports in observable vector ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IObservableMap2Impl.cs Remove explicit imports in observable map ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IMapViewMethods.cs Remove explicit imports in map view method bodies/signatures.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IMapMethods.cs Remove explicit imports in map method bodies/signatures.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IMapChangedEventArgs1Methods.cs Remove explicit imports in map-changed args helper methods.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IMapChangedEventArgs1Impl.cs Remove explicit imports in map-changed args ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IKeyValuePair2Impl.cs Remove explicit imports in KeyValuePair ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IEnumerator1Impl.cs Remove explicit imports in IEnumerator ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IEnumerable1Impl.cs Remove explicit imports in IEnumerable ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IDictionary2Impl.cs Remove explicit imports in IDictionary ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.ICollectionKeyValuePair2InterfaceImpl.cs Remove explicit imports in ICollection interface impl.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncOperation1Impl.cs Remove explicit imports in async operation ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncInfoMethods.cs Remove explicit imports in async info helper methods.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncInfoImpl.cs Remove explicit imports in async info ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMethodDefinitionFactory.IAsyncActionWithProgress1Impl.cs Remove explicit imports in async action-with-progress ABI impl generation.
src/WinRT.Interop.Generator/Factories/InteropMemberDefinitionFactory.cs Remove explicit imports for generated members (fields/methods/ctors).
src/WinRT.Interop.Generator/Factories/InteropCustomAttributeFactory.cs Remove explicit imports in emitted custom attributes/signatures.
src/WinRT.Interop.Generator/Extensions/MethodDefinitionExtensions.cs Remove explicit imports when emitting base ctor calls.
src/WinRT.Interop.Generator/Extensions/ImportExtensions.cs Remove most custom import helpers; keep assembly ref import only.
src/WinRT.Interop.Generator/Extensions/CilInstructionExtensions.cs Remove explicit imports when emitting Ldobj/Stobj operands.
src/WinRT.Interop.Generator/Builders/WindowsRuntimeTypeHierarchyBuilder.cs Remove explicit imports for ValueType base and span ctor refs.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.cs Remove explicit imports across generated types, methods, and attributes.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.UserDefinedType.cs Remove explicit imports in user-defined type marshalling pieces.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.SzArray.cs Remove explicit imports in SZ-array builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.KeyValuePair.cs Remove explicit imports in KeyValuePair builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IReadOnlyList1.cs Remove explicit imports in IReadOnlyList builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IReadOnlyDictionary2.cs Remove explicit imports in IReadOnlyDictionary builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IReadOnlyCollectionKeyValuePair2.cs Remove explicit imports in IReadOnlyCollection builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IObservableVector1.cs Remove explicit imports in observable vector builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IObservableMap2.cs Remove explicit imports in observable map builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IMapChangedEventArgs1.cs Remove explicit imports in map-changed args builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IEnumerator1.cs Remove explicit imports in enumerator builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IEnumerable1.cs Remove explicit imports in enumerable builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.ICollectionKeyValuePair2.cs Remove explicit imports in collection builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncOperationWithProgress2.cs Remove explicit imports in async op w/ progress builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncOperation1.cs Remove explicit imports in async operation builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.IAsyncActionWithProgress1.cs Remove explicit imports in async action w/ progress builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.EventSource.cs Remove explicit imports in event source builder output.
src/WinRT.Interop.Generator/Builders/InteropTypeDefinitionBuilder.Delegate.cs Remove explicit imports in delegate builder output.
src/WinRT.Interop.Generator/Builders/DynamicCustomMappedTypeMapEntriesBuilder.INotifyPropertyChanged.cs Remove explicit imports in dynamic mapped interface impl output.
src/WinRT.Interop.Generator/Builders/DynamicCustomMappedTypeMapEntriesBuilder.INotifyCollectionChanged.cs Remove explicit imports in dynamic mapped interface impl output.
src/WinRT.Interop.Generator/Builders/DynamicCustomMappedTypeMapEntriesBuilder.ICommand.cs Remove explicit imports in dynamic mapped interface impl output.
Comments suppressed due to low confidence (1)

src/WinRT.Interop.Generator/Extensions/ImportExtensions.cs:22

  • The XML docs here refer to importing a “member reference”, but the method actually imports an AssemblyReference. This is misleading now that the other Import overloads have been removed; please update the summary/param docs to match the actual API (assembly reference import).
    /// <summary>
    /// Imports a member reference into a module using the default reference importer.
    /// </summary>
    /// <param name="assemblyReference">The <see cref="AssemblyReference"/> instance to import.</param>
    /// <param name="module">The module to import into.</param>
    /// <returns>The imported <see cref="AssemblyReference"/>.</returns>
    public static AssemblyReference Import(this AssemblyReference assemblyReference, ModuleDefinition module)
    {
        return assemblyReference.ImportWith(module.DefaultImporter);
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Replace numerous usages of .Import(module) (and .Import(module).ToTypeDefOrRef() / .Import(module).ToReferenceTypeSignature()) with direct interopReferences types/methods or their ToTypeDefOrRef()/ToReferenceTypeSignature() variants across the WinRT.Interop.Generator codebase. This simplifies and standardizes how interop type and method descriptors are consumed by builders, factories and rewriters (e.g. InteropTypeDefinitionBuilder, DynamicCustomMappedTypeMapEntriesBuilder and related files), avoiding redundant module imports and clarifying signatures for marshalling and explicit interface implementations.
Remove several thin Import extension methods that forwarded various AsmResolver types to module.DefaultImporter. Deleted overloads for ITypeDefOrRef, IMethodDefOrRef, IMethodDescriptor, TypeSignature, GenericInstanceTypeSignature, MethodSignature, MemberReference (module-based) and MethodSpecification, and also removed the unused AsmResolver.DotNet.Signatures using. Keeps the AssemblyReference importer; simplifies ImportExtensions by reducing redundant API surface.
Clean up interop reference callsites and formatting across multiple builders and rewriters. Replaced unnecessary .ToTypeDefOrRef() conversions where interopReferences already provided the proper TypeRef (e.g. IEnumerable, AbiType, AbiException), removed stray line breaks in chained calls for readability, and removed an unnecessary null-forgiving operator on GetConstructor. Also adjusted a member reference creation chain. These changes are purely cleanup/refactoring to improve clarity and correct use of existing reference objects.
Remove unused local temporary variables (e.g. delegateType2, typeSignature2) in InteropTypeDefinitionBuilder and related partial builders. Updated method signatures, Castclass operands, and parameter lists to reference the original TypeSignature variables directly. This is a cleanup change with no behavioral impact — it eliminates unnecessary locals and simplifies the code.
@Sergio0694 Sergio0694 force-pushed the user/sergiopedri/asmresolver-auto-import branch from 49df5b6 to 0916289 Compare February 11, 2026 07:37
@Sergio0694 Sergio0694 merged commit dc7d274 into staging/3.0 Feb 11, 2026
11 checks passed
@Sergio0694 Sergio0694 deleted the user/sergiopedri/asmresolver-auto-import branch February 11, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants