Add support for custom overload names to the WinMD generator#2454
Open
Sergio0694 wants to merge 3 commits into
Open
Add support for custom overload names to the WinMD generator#2454Sergio0694 wants to merge 3 commits into
Sergio0694 wants to merge 3 commits into
Conversation
Port custom overload name support from PR #2275 (CsWinRT 2.x) to the CsWinRT 3.0 WinMD generator (cswinrtwinmdgen). When an authored method carries [Windows.Foundation.Metadata.Overload("Name")], emit that name in the generated .winmd instead of an auto-generated sequential one. windows-rs consumers require explicit overload names because Rust has no method overloading. - Record author-specified overload names while emitting interface methods and honor them in AddOverloadAttributesForType; stop copying the [Overload] attribute verbatim so it is never duplicated. - Select the default overload (which keeps the original name) from the [DefaultOverload] attribute rather than metadata order, so an author-specified name is not dropped when the default is not declared first. - Auto-generated names skip any name already used by another method or an author-specified overload, avoiding collisions. - Emit [Overload] only on interfaces (authored and synthesized), matching the Windows Runtime metadata convention; runtime classes expose their ABI through interfaces (consistent with CsWinRT 2.x). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add the ICustomOverloadNames interface and CustomOverloadNamesClass authoring types, and the CustomOverloadNames consumption test. The test validates that author-specified [Overload] names (LookupByIndex, LookupByFlag, TransformNumber) appear in the generated projection's ABI vtables, on both an authored interface and a class's synthesized interface. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…lt selection
Extend the overload-name tests to cover behaviors beyond the original PR:
- Verify the auto-generated ABI name (Transform2) coexists with an author-
specified one (TransformNumber) in the same overload group.
- OverloadCollisionClass: an author-specified overload name matching the auto
pattern ("M2") forces the auto-generated name of the remaining overload to
skip it ("M3").
- DefaultOverloadNotFirstClass / IDefaultOverloadNotFirst: [DefaultOverload] on
a non-first overload keeps the original ABI name, while the author-specified
name ("GetByIndex") on the first overload is still honored.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 18, 2026
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.
Summary
Honor an author-applied
[Windows.Foundation.Metadata.Overload("Name")]attribute when generating a component's.winmd, emitting that name instead of an auto-generated sequential one. This ports #2275 (which targeted CsWinRT 2.x) to the CsWinRT 3.0 WinMD generator.Motivation
Rust (windows-rs) and some other Windows Runtime consumers cannot represent overloaded methods, so they rely on the
[Overload]attribute to give each overload a distinct, ergonomic ABI name. Previously, author-specified names were ignored and the generator always auto-generated sequential suffixes (Method2,Method3, …). PR #2275 added support for honoring them in CsWinRT 2.x. CsWinRT 3.0 produces the.winmdwith a different, post-build tool (cswinrtwinmdgen, which analyzes the compiled.dllwith AsmResolver rather than running a Roslyn source generator), so the behavior had to be re-implemented there.Changes
Generator (
src/WinRT.WinMD.Generator/):Writers/WinMDWriter.Finalization.cs:AddOverloadAttributesForTypenow honors an author-specified[Overload("...")]name when present (otherwise it keeps auto-generating a sequential name). It also selects the default overload (the one that keeps the original ABI name) from the[DefaultOverload]attribute rather than from metadata order, so an author-specified name is not dropped when the default is not declared first, and auto-generated names skip any name already used by another member or overload to avoid collisions. Adds theRecordUserSpecifiedOverloadNameandHasDefaultOverloadAttributehelpers.Writers/WinMDWriter.Members.cs: records the author-specified overload name while emitting interface methods (authored and synthesized), so finalization can honor it.Writers/WinMDWriter.Attributes.cs:ShouldCopyAttributeno longer copies[Overload]verbatim; it is emitted exactly once by the overload phase as the single source of truth, preventing duplicates.Writers/WinMDWriter.cs: adds the_userSpecifiedOverloadNamesmap.[Overload]is emitted only on interfaces (authored and synthesized), not on runtime classes, matching the Windows Runtime metadata convention and CsWinRT 2.x (a runtime class exposes its ABI through interfaces).Tests:
src/Tests/AuthoringTest/Program.cs: theICustomOverloadNamesinterface andCustomOverloadNamesClassfrom PR Add support for custom overload names to CsWinMD #2275, plus types covering additional behaviors (OverloadCollisionClass,IDefaultOverloadNotFirst/DefaultOverloadNotFirstClass).src/Tests/AuthoringConsumptionTest/test.cpp: the portedCustomOverloadNamesconsumption test, plus new tests for an auto-generated name coexisting with an author-specified one, collision avoidance, and[DefaultOverload]on a non-first overload.src/Tests/AuthoringConsumptionTest/AuthoringConsumptionTest.exe.manifest:activatableClassentries for the newly activatable test classes (includingCustomOverloadNamesClass, whose entry the original PR omitted).