Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve diagnostics when encountering TypeRef in metadata #2742

Open
MarijnS95 opened this issue Dec 12, 2023 · 4 comments
Open

Improve diagnostics when encountering TypeRef in metadata #2742

MarijnS95 opened this issue Dec 12, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@MarijnS95
Copy link
Contributor

Note that code gen from TypeRef is not a good idea as it implies the TypeDef is not available and thus you have no idea what kind of type you're actually generating code for. Usually this implies you're missing metadata. I should have better diagnostics for this in riddle soon.

TypeRef currently raises an unimplemented!() assuming this i something that could be implemented at some point:

rest => unimplemented!("{rest:?}"),

This is showing when generating (custom) metadata on (top of) win32metadata main (currently at microsoft/win32metadata@3d65d37):

     Running `target\debug\riddle.exe --etc crates/tools/windows/bindings.txt`
thread '<unnamed>' panicked at crates\libs\bindgen\src\rust\writer.rs:173:21:
not implemented: TypeRef(TypeName { namespace: "Windows.UI.Composition", name: "ICompositionTexture" })

This is caused by an upstream issue, where metadata is missing for a type that is used by other functions (microsoft/win32metadata#1760). riddle needs to understand the type here, and for that the generator should emit a more descriptive diagnostic upon encountering TypeRef.

Originally posted by @MarijnS95 in #2539 (comment)

@kennykerr kennykerr added the enhancement New feature or request label Dec 13, 2023
@kennykerr
Copy link
Collaborator

I'm working on some winmd validation. It will be some time before this is available, but its goal is to catch stuff like this.

@MarijnS95
Copy link
Contributor Author

As it turns out the proper fix for microsoft/win32metadata#1760 was simply that the new Win32 winmd I was generating was referencing newer types from the "API contracts" that windows-rs was using. Updating them here (#2745) allows me to once again regenerate windows-rs from newer Win32 winmd.

This means somewhere TypeRef gets replaced with TypeDef when multiple winmds are loaded, maybe the diagnostics could build off of that process and report any unresolved TypeRefs (where required)?

@kennykerr
Copy link
Collaborator

Yes, I intentionally use TypeRefs in this case so that the panic message gives you a clue of what's missing.

@MarijnS95
Copy link
Contributor Author

Clarifying that precedent in the panic message might be useful, then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants