Skip to content

feat(rdl): add #[nested(OuterTypeName)] attribute for roundtripping nested types#4185

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/understand-windows-rdl-un-nesting
Draft

feat(rdl): add #[nested(OuterTypeName)] attribute for roundtripping nested types#4185
Copilot wants to merge 4 commits intomasterfrom
copilot/understand-windows-rdl-un-nesting

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

Windows metadata uses nested types (anonymous inner structs/unions) that windows-rdl flattens when writing RDL, but previously had no mechanism to reconstruct the nesting relationship when reading back. This adds a #[nested(OuterTypeName)] pseudo-attribute that roundtrips the NestedPublic flag and NestedClass metadata records.

Writer (writer/struct.rs)

collect_nested now emits #[nested(OuterFlatName)] on every un-nested helper type:

#[packed(1)]
struct BTH_INFO_RSP { result: u16, dataLen: u8, Anonymous: BTH_INFO_RSP_0, }
#[packed(1)]
#[nested(BTH_INFO_RSP)]
union BTH_INFO_RSP_0 { connectionlessMTU: u16, data: [u8; 44], }

Reader (reader/)

  • mod.rs: Added typedef_ids: HashMap<String, TypeDef> to Encoder tracking TypeDef row IDs in encoding order. Added read_nested helper parsing #[nested(Ident)].
  • struct.rs: encode_struct reads #[nested], sets NestedPublic flag (instead of Public) with empty namespace on the TypeDef, emits a NestedClass record linking inner→outer using the tracked ID map, and excludes "nested" from encode_attrs. Errors if the outer type hasn't been encoded yet.
  • union.rs: Same treatment for encode_union.

Tests

  • Updated golden files nested-packing.rdl and nested-arches.rdl to include the new #[nested] attributes.
  • New roundtrip test nested-flat.rdl covering single and double nesting levels.
  • Two new panic tests: malformed #[nested] (no argument) and out-of-order outer type declaration.

Formatting

  • Ran cargo fmt across the entire workspace.

@kennykerr
Copy link
Copy Markdown
Collaborator

@copilot fmt failed

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot fmt failed

Fixed in eb9b8e2cargo fmt reformatted the ternary if in reader/struct.rs.

Copilot AI requested a review from kennykerr April 14, 2026 20:14
@kennykerr
Copy link
Copy Markdown
Collaborator

@copilot please run cargo fmt on all the code.

Agent-Logs-Url: https://github.com/microsoft/windows-rs/sessions/28c8e21b-ac8b-4e6b-80ad-7844954a8b35

Co-authored-by: kennykerr <9845234+kennykerr@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot please run cargo fmt on all the code.

Done in 0d8f1b9cargo fmt on the full workspace reformatted the #[should_panic] attribute in tests/libs/rdl/tests/panic.rs.

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