rustwasm / wasm-bindgen

Facilitating high-level interactions between Wasm modules and JavaScript
https://rustwasm.github.io/docs/wasm-bindgen/
Apache License 2.0
7.84k stars 1.08k forks source link

Add support for enums with negative discriminants #4204

Closed RunDevelopment closed 2 weeks ago

RunDevelopment commented 1 month ago

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.