Skip to content

windows-clang dependency-resolution cleanup - #4912

Closed
Kenny Kerr (kennykerr) wants to merge 3 commits into
masterfrom
clang-unified
Closed

Kenny Kerr (kennykerr) wants to merge 3 commits into
masterfrom
clang-unified

Conversation

@kennykerr

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

Copy link
Copy Markdown
Collaborator

This fixes several related windows-clang dependency-resolution gaps in namespaced scrapes.

Referenced typedefs, records, and enums now flow through a shared declaration worklist. This preserves definitions from included headers, retains types referenced only by typed constants, and follows chained aliases. Genuinely incomplete records are emitted as opaque records only when used through pointers or references; using one by value now reports an error instead of producing missing or incorrect metadata.

Included enum definitions retain their variants and declared backing types. Forward-only enums use the exact representation reported by libclang rather than guessing i32. This also fixes existing generated metadata for several SDK enums whose headers declare u8 or u32 backing types, with the corresponding windows and windows-sys bindings regenerated.

The dependency closure starts from retained API items, so unused forward declarations are no longer emitted. Tests cover direct and typedef-backed incomplete records, const and mutable pointers, invalid by-value use, included and forward enums, typedef-backed enum representations, typed constants, and chained dependencies.

Fixes items 10, 11, and 13 in #4902.

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

Declaration validation mishandles multiple translation units and omits incomplete C++ class declarations.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Cleans up windows-clang dependency resolution for namespaced scrapes.

Changes:

  • Adds a shared declaration worklist and incomplete-record validation.
  • Preserves enum definitions and backing types.
  • Regenerates affected metadata and Rust bindings with expanded tests.
File summaries
File Description
metadata/win32/wincrypt.rdl Corrects enum representation.
metadata/win32/dxcore_interface.rdl Corrects enum representations.
metadata/win32/dwrite_3.rdl Corrects enum representation.
metadata/win32/d3dkmdt.rdl Corrects enum representations.
docs/crates/windows-clang.md Documents dependency handling.
crates/tests/libs/clang/tests/clang.rs Adds dependency-resolution tests.
crates/tests/libs/clang/input/incomplete_record_dependency.hpp Adds pointer dependency fixture.
crates/tests/libs/clang/input/incomplete_record_dependency_inc.inl Adds incomplete record declarations.
crates/tests/libs/clang/input/incomplete_record_by_value.hpp Adds invalid by-value fixture.
crates/tests/libs/clang/input/enum_dependency.hpp Adds enum dependency fixture.
crates/tests/libs/clang/input/enum_dependency_inc.inl Adds included enum definitions.
crates/tests/libs/clang/input/const_dependency.hpp Adds typed constant fixture.
crates/tests/libs/clang/input/const_dependency_inc.inl Adds constant type aliases.
crates/tests/libs/clang/expected/midl_proxy_stub.rdl Removes an unused opaque declaration.
crates/libs/windows/src/Windows/Win32/wincrypt/mod.rs Regenerates corrected binding type.
crates/libs/windows/src/Windows/Win32/dxcore_interface/mod.rs Regenerates corrected enum wrappers.
crates/libs/windows/src/Windows/Win32/dwrite/mod.rs Regenerates corrected binding type.
crates/libs/windows/src/Windows/Win32/d3dkmdt/mod.rs Regenerates corrected binding types.
crates/libs/sys/src/Windows/Win32/wincrypt/mod.rs Regenerates corrected sys type.
crates/libs/sys/src/Windows/Win32/dxcore_interface/mod.rs Regenerates corrected sys wrappers.
crates/libs/sys/src/Windows/Win32/dwrite/mod.rs Regenerates corrected sys type.
crates/libs/sys/src/Windows/Win32/d3dkmdt/mod.rs Regenerates corrected sys types.
crates/libs/clang/src/typedef.rs Pulls enum dependencies through typedefs.
crates/libs/clang/src/scope.rs Tracks layout-required references.
crates/libs/clang/src/naming.rs Builds the declaration index.
crates/libs/clang/src/lib.rs Processes and validates dependency closure.
crates/libs/clang/src/enum.rs Resolves exact enum representations.
crates/libs/clang/src/cx.rs Queues declarations and opaque records.
crates/libs/clang/src/canon.rs Uses the unified declaration worklist.
Review details
  • Files reviewed: 29/30 changed files
  • Comments generated: 2
  • 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
Comment thread crates/libs/clang/src/naming.rs

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

Cross-TU pointer and enum definitions can still be lost, and batch-evaluated typed constants bypass dependency resolution.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 33/34 changed files
  • Comments generated: 4
  • Review effort level: Balanced

Comment on lines +1545 to +1548
let is_complete = match collector.get(name) {
Some(Item::Struct(item)) => !item.is_opaque,
Some(_) => true,
None => false,
Comment on lines +80 to +85
let tag = child.name();
let name = if is_anonymous_name(&tag) {
tag_rename.get(&child.location_id()).cloned().unwrap_or(tag)
} else {
tag_rename.get(&tag).cloned().unwrap_or(tag)
};
Comment on lines +181 to +185
metadata::Type::Array(_)
| metadata::Type::RefMut(_)
| metadata::Type::RefConst(_)
| metadata::Type::PtrMut(_, _)
| metadata::Type::PtrConst(_, _)
Comment on lines +1561 to +1566
// Constants have no type cursor, so seed their named dependencies from the TU index.
let mut referenced = HashSet::new();
for item in collector.values() {
if matches!(item, Item::Const(_) | Item::PropertyKeyConst(_)) {
item_refs(item, &mut referenced);
}
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