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

Improved string enum typing try 2 #4180

Merged
merged 8 commits into from
Oct 12, 2024

Conversation

RunDevelopment
Copy link
Contributor

Alright, let's try again. This PR reverts most of #4174 and restores most of #4147. I just made 2 changes:

  1. String enum types are only generated when used.
  2. String enum types are never exported.

This ensures that we don't repeat #4163 and puts us in a good position to make a fix for #2153, because we just have to decide when to export the generated type (but this will be its own PR).

Code-wise, not much is different from #4147. The only new part is how usage is detected. I hocked into the function that generates function signatures to keep track of which string enums are referenced. Since we always generate the type definition for exported functions before the type definitions for string enums, this works out beautifully and ensures that we know exactly which string enums are used.


If possible, please merge #4179 before this PR, so I can update this PR and have tests to ensure that #4163 isn't repeated.

Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

Nice work!
Missing a changelog entry.

Gonna wait for those tests as well like you said!

crates/cli-support/src/js/binding.rs Outdated Show resolved Hide resolved
@daxpedda daxpedda added the waiting for author Waiting for author to respond label Oct 12, 2024
@daxpedda
Copy link
Collaborator

Also reverts #4175.

CHANGELOG.md Outdated Show resolved Hide resolved
@@ -83,6 +83,10 @@ export const ImplicitDiscriminant = Object.freeze({ A:0,"0":"A",B:1,"1":"B",C:42

const __wbindgen_enum_ColorName = ["green", "yellow", "red"];

const __wbindgen_enum_FooBar = ["foo", "bar"];
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't used so it should not be generated as well.
I don't believe this is an issue this PR caused though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is a side effect of #4147 (point 3), though I also only noticed this yesterday. I'll make a PR fixing this tomorrow. I just wanted for this PR to be in, because I'll need to implement a similar usage analysis. Nothing complex, I just wanted to see would be acceptable in the first place.

@daxpedda daxpedda merged commit 4c2e923 into rustwasm:main Oct 12, 2024
39 checks passed
@RunDevelopment RunDevelopment deleted the string-enum-types-try-2 branch October 12, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for author Waiting for author to respond
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants