Skip to content

rdl reader: drop TypeAttributes::Public for ExclusiveTo interfaces#4162

Closed
Copilot wants to merge 8 commits intomasterfrom
copilot/compare-metadata-roundtrip-rdl
Closed

rdl reader: drop TypeAttributes::Public for ExclusiveTo interfaces#4162
Copilot wants to merge 8 commits intomasterfrom
copilot/compare-metadata-roundtrip-rdl

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

WinRT interfaces marked with Windows.Foundation.Metadata.ExclusiveToAttribute are NotPublic in Windows SDK metadata — they're implementation details bound to a specific class. The RDL reader was unconditionally setting TypeAttributes::Public on all encoded interfaces, causing a flag mismatch when roundtripping.

  • reader/attribute_ref.rs: Added is_exclusive_to_attribute helper using find_attribute_type — same pattern as is_guid_attribute. This correctly handles use glob imports so both #[Windows::Foundation::Metadata::ExclusiveTo(Foo)] and a use-shortened #[ExclusiveTo(Foo)] are detected.
  • reader/interface.rs: encode_interface omits TypeAttributes::Public when is_exclusive_to_attribute matches any attribute on the interface.
  • Tests: Roundtrip test (exclusive-to.rdl) for the full-qualified form; exclusive_to_with_use test in use-declarations.rs uses reader().input_str(...) with a use Windows::Foundation::Metadata::* glob import and #[ExclusiveTo(Foo)], then reads back the winmd via windows_metadata::reader::TypeIndex to assert that the class carries TypeAttributes::Public while the exclusive interface does not.
  • Checked-in winmd files: All six checked-in winmd files that contain ExclusiveTo interfaces have been regenerated to reflect the updated TypeAttributestests/winrt/reference/metadata.winmd, tests/winrt/events/metadata.winmd, tests/misc/component/component.winmd, samples/robot/component/robot.winmd, samples/robot/component_cpp/robot.winmd, and samples/json/json_validator_winrt/sample.winmd.


#[test]
pub fn exclusive_to_with_use() {
reader()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot the only thing this needs to be testing is that the resulting TypeDef in the winmd is not public.

  1. Use reader().input_str("class ... interface ... ") ... to write a winmd with an exclusive interface.
  2. Use windows-metadata reader to check the interface TypeAttributes::Public flag is present on the class but not present on the interface.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 8d61cb6. The test now:

  1. Uses reader().input_str(...) with use Windows::Foundation::Metadata::* + #[ExclusiveTo(Foo)]
  2. Reads back the winmd via windows_metadata::reader::TypeIndex and asserts Foo has TypeAttributes::Public while IFoo does not.

Copilot AI requested a review from kennykerr April 9, 2026 00:06
@kennykerr
Copy link
Copy Markdown
Collaborator

@copilot fmt failed

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 9, 2026

@copilot fmt failed

Fixed in 95590b5 — the import ordering in use-declarations.rs is now correct per cargo fmt.

@kennykerr
Copy link
Copy Markdown
Collaborator

@copilot - check the build - this change means the winmd files that are checked in will have to be commited as they would have changed.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 9, 2026

@copilot - check the build - this change means the winmd files that are checked in will have to be commited as they would have changed.

Done in bad108a. All 6 checked-in winmd files that contain ExclusiveTo interfaces have been regenerated with the updated TypeAttributes (sans Public on exclusive interfaces): reference/metadata.winmd, events/metadata.winmd, robot/component/robot.winmd, robot/component_cpp/robot.winmd, misc/component/component.winmd, and json_validator_winrt/sample.winmd.

@kennykerr
Copy link
Copy Markdown
Collaborator

@copilot more diff winmd files

@kennykerr kennykerr closed this Apr 9, 2026
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