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

Add support for enums with negative discriminants #4204

Merged
merged 12 commits into from
Nov 9, 2024

Conversation

RunDevelopment
Copy link
Contributor

@RunDevelopment RunDevelopment commented Oct 16, 2024

fixes #2313

This adds support for enums with negative discriminants and slightly improves error messages.

Honestly, implementing this was pretty simple. I don't have too much to say about this, just a few notes on implementation details:

  1. Within the serialized data for ASTs and descriptors, variants are still passed around as u32. Instead of representing the actual value, they now represent the bits of the i32 or u32 value. Which one it is depends on the new signed: bool field. I wanted to use i64, but this doesn't work well with inform or other serialization, so I opted to "decode" the variant values to i64 on the CLI side just before JS code gen.
  2. Holes. The parser will only search for non-negative holes. This means that a signed enum with 2^31 variants will fail to find a hole, but I think that's okay. Not having to worry about the sign of a hole also makes the downstream code handling holes simpler.

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.

Thank you for doing this!

crates/backend/src/codegen.rs Show resolved Hide resolved
crates/backend/src/codegen.rs Show resolved Hide resolved
crates/macro-support/src/parser.rs Outdated Show resolved Hide resolved
crates/macro-support/src/parser.rs Show resolved Hide resolved
Co-authored-by: daxpedda <daxpedda@gmail.com>
@daxpedda daxpedda added the waiting for author Waiting for author to respond label Oct 31, 2024
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!

@daxpedda daxpedda merged commit a8b1a09 into rustwasm:main Nov 9, 2024
41 checks passed
@RunDevelopment RunDevelopment deleted the negative-enum-values branch November 9, 2024 21:42
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.

A negative custom discriminant in a fieldless number enumeration seems unsupported
2 participants