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

Implement type_name() for TypeRef #2539

Closed
wants to merge 1 commit into from

Conversation

MarijnS95
Copy link
Contributor

When running tool_windows on the latest .winmd generated with microsoft/win32metadata#1591 to test the results of that metadata change, no implementation exists for TypeRef. This implementation is rather trivial/straightforward based on TypeDef.

Going forward, also print the failed value when a match statement ends up in _ => unimplemented!() so that it is quicker to immediately debug what enum variant needs to be implemented.

When running `tool_windows` on the latest `.winmd` generated with
microsoft/win32metadata#1591 to test the results
of that metadata change, no implementation exists for `TypeRef`.  This
implementation is rather trivial/straightforward based on `TypeDef`.

Going forward, also print the failed value when a `match` statement ends
up in `_ => unimplemented!()` so that it is quicker to immediately debug
what enum variant needs to be implemented.
@MarijnS95
Copy link
Contributor Author

MarijnS95 commented Jun 14, 2023

Note that while tool_windows succeeds, all Foundation things are gone, and running tool_core still runs into:

thread 'main' panicked at 'Windows.Foundation.IReference not found', crates\libs\bindgen\src\standalone.rs:97:9

These seem to come from Windows.winmd. I've downloaded the latest 10.0.22621.755 version and regenerated it, and now it is fine. Noticed only later that this file - supposedly - was already generated from that exact same version of Microsoft.Windows.SDK.Contracts? Did the format for mdmerge change?

EDIT: Regen branch at https://github.com/MarijnS95/windows-rs/compare/regen

@kennykerr
Copy link
Collaborator

I haven't taken the last few releases of the Win32 metadata as there are a number of problematic changes that block Rust adoption. I also have some major changes coming to metadata and code generation and I'd like to land those before dealing with the metadata breaking changes.

@MarijnS95
Copy link
Contributor Author

@kennykerr ah that's unfortunate, I'd love to have the updated metadata in windows-rs at some point for these small improvements, but makes sense to delay that until getting those major changes in. Will sit tight, thanks!

@kennykerr kennykerr closed this Jun 17, 2023
@MarijnS95
Copy link
Contributor Author

MarijnS95 commented Jun 21, 2023

@kennykerr that doesn't make this PR invalid though? It is still very much necessary to compile with the latest win32metadata and it still rebases nicely on top of master even after riddle made its way in.

Since that's in it sounds like we're unblocked here now to look into "dealing with the metadata breaking changes", this can be reopened?

@kennykerr
Copy link
Collaborator

There are just a bunch of incompatibilities that were introduced by the Win32/Wdk metadata in the last few releases that need to be dealt with. I've worked on, among other things, making the error reporting through riddle far more helpful for this sort of thing. Anyway, I'll take a look at the latest metadata when I have a sec and see if it's something we can now easily handle or whether it needs a bit more thought and engineering.

@@ -156,13 +179,14 @@ impl<'a> Gen<'a> {
Type::WinrtArray(ty) => self.type_name(ty),
Type::WinrtArrayRef(ty) => self.type_name(ty),
Type::ConstRef(ty) => self.type_name(ty),
_ => unimplemented!(),
Type::TypeRef(TypeDefOrRef::TypeRef(ref_)) => self.type_ref_name(*ref_),
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Throwing in my experiences from last night smoke testing riddle. I ran into this too; I was missing base Win32 Metadata winmd in the riddle input folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kennykerr ah, thanks, so you're basically saying that I fixed this in the wrong way. Which might match the observation of Foundation having vanished.

Improved diagnostics (even something simple as a format-string in an unimplemented!() call) are definitely welcome!

@riverar note that this PR was from before riddle and might be caused by the Win32metadata updates instead.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I checked the latest Win32/Wdk metadata and riddle can parse it just fine - there are however other complications that will need to be addressed, changes to type and attributes, that go beyond merely parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@kennykerr are you still planning on improving the diagnostics here? A similar issue is appearing again because of incomplete metadata: microsoft/win32metadata#1760

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please open a new issue and include a repro. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reported at #2742. The repro is generating new metadata with win32metadata main (relevant commit hash is linked in case this is fixed upstream), followed by running tool_windows.

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.

3 participants