Skip to content

windows-clang type value collisions - #4957

Merged
Kenny Kerr (kennykerr) merged 5 commits into
masterfrom
clang-type-value-collision
Sep 17, 2026
Merged

Kenny Kerr (kennykerr) merged 5 commits into
masterfrom
clang-type-value-collision

Conversation

@kennykerr

@kennykerr Kenny Kerr (kennykerr) commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Fixes #4941.

C permits a type and an object-like macro to share the same spelling. windows-clang previously selected the type and discarded the constant because planning and emission treated every projected name as globally unique. Preserve both output categories while continuing to reject duplicate values and incompatible translation-unit dependency graphs explicitly.

Add focused test_clang and test_rdl fixtures for supported type/value and type/function names. Full SDK regeneration surfaces the canonical HTTP_VERSION case as both a struct and an ANSI string constant, and tool-package projects both declarations into the same Rust module for windows and windows-sys.

This PR is intentionally scoped to object-like macro constants. GUID, property-key, and coclass facts also emit values but currently participate in type-root planning and have separate exclusion and UM/KM ownership behavior. A follow-up will separate those facts throughout planning and apply metadata exclusions consistently; full generation shows that work will remove redundant UM-owned GUIDs from the additive WDK RDL while leaving the merged WinMD unchanged.

Validation:

  • cargo test -p windows-clang -p test_clang -p test_rdl
  • cargo clippy -p windows-clang --all-targets
  • cargo check -p windows --features http
  • cargo check -p windows-sys --features http
  • cargo run -p tool-roundtrip --quiet
  • cargo run -p tool-package --quiet
  • cargo run -p tool-features --quiet
  • Two complete tool-win32 runs produced identical output in 470.66s and 455.12s.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Root planning can still discard constants during type exclusions and function collisions.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR preserves colliding C type/value names through RDL and Rust projection.

Changes:

  • Separates type and value output-name tracking.
  • Adds collision fixtures and dependency-planning tests.
  • Regenerates HTTP bindings with both HTTP_VERSION declarations.
File summaries
File Description
metadata/win32/http.rdl Adds the HTTP_VERSION constant.
docs/crates/windows-clang.md Documents collision handling.
crates/tests/libs/rdl/input/type_value_name_collision.rdl Tests type/constant collisions.
crates/tests/libs/rdl/input/type_function_name_collision.rdl Tests type/function collisions.
crates/tests/libs/clang/input/type_value_name_collision.h Adds the Clang fixture input.
crates/tests/libs/clang/expected/type_value_name_collision.rdl Defines expected extraction output.
crates/libs/windows/src/Windows/Win32/http/mod.rs Projects the Windows HTTP constant.
crates/libs/sys/src/Windows/Win32/http/mod.rs Projects the windows-sys HTTP constant.
crates/libs/clang/tests/checkpoint3.rs Updates dependency-collision expectations.
crates/libs/clang/src/lib.rs Separates output namespaces and revises planning.
Review details
  • Files reviewed: 10/11 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/libs/clang/src/lib.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Planning still rejects collisions between real types and value-emitting GUID, property-key, or class facts.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

crates/libs/clang/src/lib.rs:520

  • The category split happens only after planning. plan() still puts FactData::Guid, PropertyKey, and Class in Roots.types, so a real type with the same projected name reaches choose_type_root_cached as an incompatible pair and fails with ambiguous type root before this classification runs. For example, valid C containing struct Shared { ... }; DEFINE_GUID(Shared, ...) should produce a struct and GUID constant. Please separate these value-emitting facts during planning as well, while continuing to reject collisions with other values, and cover this case with a fixture.
  • Files reviewed: 10/11 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new value-fact path ignores constant exclusions and can re-emit values already present in referenced metadata.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 12/13 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread crates/libs/clang/src/lib.rs Outdated
@kennykerr
Kenny Kerr (kennykerr) merged commit 4479a78 into master Sep 17, 2026
37 checks passed
@kennykerr
Kenny Kerr (kennykerr) deleted the clang-type-value-collision branch September 17, 2026 20:35
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.

[win32metadata] Preserve colliding C type and value names

2 participants