windows-clang dependency-resolution cleanup - #4912
Closed
Kenny Kerr (kennykerr) wants to merge 3 commits into
Closed
Kenny Kerr (kennykerr) wants to merge 3 commits into
Kenny Kerr (kennykerr) wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 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.
Contributor
There was a problem hiding this comment.
🟡 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); | ||
| } |
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.
This fixes several related
windows-clangdependency-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 declareu8oru32backing types, with the correspondingwindowsandwindows-sysbindings 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.