-
Notifications
You must be signed in to change notification settings - Fork 124
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
Avoiding duplicate type names #1501
Comments
@AArnott @timsneath @marler8997 what are your thoughts on this? |
I'm not a big fan of this. My primary rationale is that this metadata file should IMHO be as close as possible to a faithful structured documentation of the Win32 API. Most of us are using it for language projections, but there are many other useful potential purposes for this, including research and documentation. If the struct is called (This is also my rationale why I want to see inline macros and constants embedded in the metadata -- I should have confidence that the metadata is an exhaustive representation of the API.) I'm curious though, @kennykerr: what does your proposed syntax give you that the current syntax doesn't? Can't you infer exactly the same Rust binding from either syntax? |
I'm not merely interested in generating Rust bindings, but completely roundtripping metadata so I need to also merge and generate metadata and I'm finding that while you can technically get away with duplicate names in the |
Apologies if this was already answered in the referenced issues/links. I haven't seen any issues yet with the status quo because every platform-specific type exists in it's own "universe", as if each definition is in it's own mutually exclusive "ifdef" sections. Is there ever a time where you would need access to multiple platform-specific definitions in the same compilation? If so then this seems like a good solution. |
This is a good thing, since otherwise a type that is only defined once in the metadata, but references another type that is defined twice in the metadata, would have to just arbitrarily pick one.
Not by type name alone, that's true. What Cswin32 has to do is consider the architecture of the source of the reference to disambiguate the target, when there are multiple possible targets.
I remember this came up before. But it just compounds the problem that everyone else who references the type within the metadata now has to reference a specific one when they don't care to. How would a field whose type is CONTEXT reference it once there are 3 distinctly named definitions of it? To be fair, the way the metadata expresses all this was very hard to get right in CsWin32, but it works. So I'm selfishly hoping it doesn't change. |
The fact that such types have the same name doesn't really help if you end up ignoring the
That's not practical in C/C++/Rust since we don't know what that is until compile time and long after code is generated.
That isn't reasonable since you cannot surely be content with "whatever" definition you happen to find. |
Data point: If we move forward with removing type name ambiguity, we can trivially fix CONTEXT #1044 by excluding it from the scraper and manually define per-architecture types. |
I don't understand this point. If the win32 headers define struct B to reference struct A, B doesn't have to know in that header or in the win32metadata which architecture A is defined in. As a result, B can be defined without |
I decided to move in a different direction, so I'll just close this issue - sorry for the distraction. |
Duplicate type names are used today to let the same struct or function have distinct per-architecture definitions. The canonical example is the
CONTEXT
struct. One of the reasons that it is so hard to fix "the CONTEXT problem" (#1044) is that it is very difficult to manipulate the individual per-architecture definitions since their names are ambiguous. As I started working on metadata processing and generation I've also discovered this on the Rust side where it makes it very difficult to uniquely refer to a type since the ECMA-335TypeRef
table is meant to identify type references but it only lets you specify an assembly/namespace/name tuple so there's no way to reliably identify a specific definition across assemblies.I suggest we switch to a model where we have strictly unique type names and add an optional "Overload" field to the
SupportedArchitecture
attribute that lets languages find the "good name" for a type if it has been overloaded.So instead of this:
We would have something like this:
Language bindings can hide the mangled name and only show overloaded names as before, but tools can quickly and efficiently identify and process unique definitions.
The text was updated successfully, but these errors were encountered: