Add #[overload("Name")] pseudo-attribute for WinRT method overloads in RDL#4184
Open
Add #[overload("Name")] pseudo-attribute for WinRT method overloads in RDL#4184
#[overload("Name")] pseudo-attribute for WinRT method overloads in RDL#4184Conversation
Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/98790d2a-1199-4b5c-9110-e2fb5c7512d0 Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
kennykerr
April 14, 2026 14:37
View session
kennykerr
reviewed
Apr 14, 2026
Comment on lines
+4
to
+11
| #[overload("Method")] | ||
| fn MethodOne(&self) -> i32; | ||
| #[overload("Method")] | ||
| fn MethodTwo(&self, a: i32) -> i32; | ||
| #[overload("Other")] | ||
| fn OtherVariantA(&self, x: f32, y: f32) -> bool; | ||
| #[overload("Other")] | ||
| fn OtherVariantB(&self, x: f32, y: f32, z: f32) -> bool; |
Collaborator
There was a problem hiding this comment.
@copilot this .rdl looks right but the .winmd representation is such that the MethodDef name stores the common name while the attribute stores the unique name. So keep this .rdl representation but make sure the metadata is actually encoded correctly.
Contributor
Author
There was a problem hiding this comment.
Fixed in 912ca1a. The WINMD encoding is now correct:
MethodDef.Name= common/logical name (e.g."Method") — taken from the#[overload("...")]argOverloadAttribute.value= unique vtable name (e.g."MethodOne") — taken from thefnidentifier
Added overload_encoding.rs which directly reads the produced WINMD and asserts this layout.
…bute.value = unique name Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/9c771f77-258b-4888-82d6-2b4c3277c389 Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
Collaborator
|
@copilot fmt code |
Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/a637526a-a754-4904-b3a3-95c59e4129b6 Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
Contributor
Author
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.
WinRT's
OverloadAttributeidentifies the logical shared name for a group of uniquely-named vtable methods. RDL previously emitted this as a verbose qualified form (#[Windows::Foundation::Metadata::Overload("Method")]), which is awkward and requiresWindows.Foundation.Metadatato be loaded as a reference to round-trip.This introduces a first-class
#[overload("Name")]pseudo-attribute—following the same pattern as#[typedef],#[special], and#[no_guid]—that cleanly expresses the overload grouping using the actual WINMD method names:In RDL the
fnidentifier is the unique vtable name and#[overload("...")]carries the common logical name. This matches the WinRT metadata binary layout whereMethodDef.Namestores the common name andOverloadAttribute.valuestores the unique name.Changes:
crates/libs/rdl/src/writer/interface.rs):write_methoddetectsOverloadAttribute, uses its value as thefnname (unique vtable name), and emits#[overload("common")]fromMethodDef.Name.OverloadAttributeis excluded from the general custom-attributes path.crates/libs/rdl/src/reader/interface.rs):encode_interfacedetects#[overload("common")], uses the arg asMethodDef.Name, and emitsOverloadAttributewith thefnidentifier (unique name) as its value. GUID derivation usesMethodDef.Namefor consistency.crates/tests/libs/rdl/tests/roundtrip/overload-method.rdl): Golden exercising the full RDL → WINMD → RDL cycle.crates/tests/libs/rdl/tests/overload_encoding.rs): Directly reads the produced WINMD and asserts thatMethodDef.Name= common name andOverloadAttribute.value= unique name.crates/libs/rdl/rdl.md): Documents#[overload]under the Interfaces section.