Repository navigation
Support TypeDefinition handles for struct-typed constants in nesting and extension blocks - #1846
Austin (AustinAviv) wants to merge 1 commit into
Conversation
7307a49 to
a292593
Compare
Jevan Saks (jevansaks)
left a comment
There was a problem hiding this comment.
The core TypeDefinition nesting change looks directionally correct, and the nesting test covers the metadata-default-value path. I am requesting changes because the extension regression test bypasses the production validation path and currently accepts generated code that does not compile, while the new ConstantAttribute/TypeDefinition branch is not exercised.
Non-blocking: CreateConstant can reuse the existing TryGetTypeDefHandle(EntityHandle, out QualifiedTypeDefinitionHandle) helper rather than duplicating its TypeReference/TypeDefinition switch, while retaining the Guid fallback for unresolved type references.
I don't see any responses to the comments or pushes to the PR. Please take a look at the comments I left. |
|
Could you share the practical, real-world repro that led to #1845? In particular, is there an actual WinMD/package or metadata-generation tool that emits a typedef struct and a constant of that type using a The regression fixture in this PR is hand-authored IL, and the current Windows SDK metadata does not appear to contain this encoding for constants. A representative WinMD (or the producer and exact declaration) would help establish the impact and confirm that the fixture matches the real metadata shape. If this is anticipatory support rather than a reported real-world failure, please confirm that as well. |
Thanks for the review, Jevan Saks (@jevansaks)! Sorry, I missed your comments when I checked GitHub around midnight. I'll fix the tests so they properly check the generated code and try to find a real-world WinMD example that reproduces the issue. If I can't find one, I'll mention that this is anticipatory support. Thanks for taking the time to review my PR! |
…and extension blocks
a292593 to
a706e75
Compare
|
Thanks for the detailed review Jevan Saks (@jevansaks)! I pushed an update addressing all points:
|
|
Got it. And so was the metadata you ran into this problem with generated by the winmdgenerator tooling? Or the windows-rs tooling? Or something else custom? |
Summary
Fixes #1845. Struct constant nesting and extension block resolution now support constants whose type is encoded as a TypeDefinitionHandle in metadata signatures.
Details
In
Generator.Constant.cs, constant signatures typed as typedef structs were only inspected ifhandleInfo.Handle.Kind == HandleKind.TypeReference. For metadata modules where types in the same assembly are referenced directly viaHandleKind.TypeDefinition:fieldTypewas left null, so constants were not injected into the struct declaration.extensionStructNamewas left null, so forwarders underextensionReceiverdid not attach to the struct extension block.CreateConstantassumedTypeReferenceHandle, failing if invoked with aTypeDefinitionHandle.This change:
HandleKind.TypeDefinitionandHandleKind.TypeReferencewhen extracting the type name, namespace, and definition handle for constant nesting.EntityHandleinCreateConstantto support both handle kinds when instantiating target types.TypeDefConstant.il/TypeDefConstant.winmdand test coverage inMultiMetadataTestsverifying struct nesting and extension block binding.