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

convert to valid identifier before checking for collision #942

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

primoly
Copy link
Contributor

@primoly primoly commented Apr 28, 2024

Because the current to_*_ident functions check for collisions with keywords before converting to snake/camel case some edge cases are missed. For example with the following type in Wit:

record weird {
    CONST: u32,
    BREAK: u32,
}

wit-bindgen currently generates fields, attributes and parameters named const and break.

This commit also resolves the //TODO: Repace with actual keywords in the C# bindings generator.

primoly added 5 commits April 28, 2024 10:20
Convert to snake case *before* checking for keyword collisions, so C and C++ keywords with underscores will be “escaped” as well.
@jsturtevant jsturtevant mentioned this pull request Apr 29, 2024
@jsturtevant
Copy link
Collaborator

Copy link
Collaborator

@jsturtevant jsturtevant left a comment

Choose a reason for hiding this comment

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

LGTM

@jsturtevant
Copy link
Collaborator

@primoly looks like a few tests are failing with this change

@Mossaka
Copy link
Member

Mossaka commented Apr 30, 2024

It seems like the Go bindgen was broken for this change

@primoly
Copy link
Contributor Author

primoly commented May 1, 2024

The name generation for Go is quite a bit more involved due to the conversions and collision checks being done in different functions and files and handled differently on a case-by-case basis (keyword escapes/name mangling, snake/camel, Go/C). Because #784 (comment) might supersede the bindgen here (?) I’m unsure if fixing this now would be worth the effort.

Also, the current camel case conversion, for example, turns serve-HTTP into ServeHttp (Rust convention) instead of ServeHTTP (Go convention).

Maybe it makes sense to just drop that test since it is very unlikely that all caps keywords will appear in Wit names since they are usually not acronyms. On the other hand I believe automated binding generators should generally be able to handle edge cases since these kinds of issues, while rare, are really difficult to debug when they do occur.

@jsturtevant
Copy link
Collaborator

On the other hand I believe automated binding generators should generally be able to handle edge cases since these kinds of issues, while rare, are really difficult to debug when they do occur.

I generally agree but lets get some input from @alexcrichton

@alexcrichton
Copy link
Member

I definitely think this is a good test to add, thanks! Feel free to add ignores for other generators and maintainers can get around to supporting them after this PR lands.

@Mossaka
Copy link
Member

Mossaka commented May 2, 2024

Yeah feel free to ignore the tests for Go at the moment. I will take a step to fix them as soon as I got some time. (might be a good idea to create an issue to track since I sometimes forgot things)

The name generation for Go is quite a bit more involved due to the conversions and collision checks being done in different functions and files and handled differently on a case-by-case basis (keyword escapes/name mangling, snake/camel, Go/C).

I am hoping to do some refactoring work to make this centralized and easier to change.

Because #784 (comment) might supersede the bindgen here (?) I’m unsure if fixing this now would be worth the effort.

I intend to still maintain this project to pass all the test cases since it's been used in several other projects, while waiting for the new wit-bindgen-go to land.

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.

4 participants