Split out an Enum type from the Variant type#211
Merged
alexcrichton merged 2 commits intobytecodealliance:mainfrom May 3, 2022
Merged
Split out an Enum type from the Variant type#211alexcrichton merged 2 commits intobytecodealliance:mainfrom
Enum type from the Variant type#211alexcrichton merged 2 commits intobytecodealliance:mainfrom
Conversation
21 tasks
This was not 100% straightforward as the lowering of an enum wants to be `the_value as i32` in the Rust-to-wasm generator, but that's not working because sometimes `the_value` has type `&T` instead of `T` which can't be cast to `i32`. This means that lowerings in Rust are now always producing a `match` statement which should optimize to the same thing but won't be as easy on the eyes. Additionally a small change was made to the C code generator that `expected<_, _>` is now represented as a struct-of-union instead of special-cased to be an `enum`. The only reason it was special cased prior was that it was accidentally interpreted as an `enum` due to the `Variant::is_enum` check (which is now removed).
peterhuene
approved these changes
May 2, 2022
Member
peterhuene
left a comment
There was a problem hiding this comment.
Looks great, just the tiny nit regarding a test case name now that enum and variant are distinct types.
willemneal
pushed a commit
to theahaco/wit-bindgen
that referenced
this pull request
May 31, 2022
* Split out an `Enum` type from the `Variant` type This was not 100% straightforward as the lowering of an enum wants to be `the_value as i32` in the Rust-to-wasm generator, but that's not working because sometimes `the_value` has type `&T` instead of `T` which can't be cast to `i32`. This means that lowerings in Rust are now always producing a `match` statement which should optimize to the same thing but won't be as easy on the eyes. Additionally a small change was made to the C code generator that `expected<_, _>` is now represented as a struct-of-union instead of special-cased to be an `enum`. The only reason it was special cased prior was that it was accidentally interpreted as an `enum` due to the `Variant::is_enum` check (which is now removed). * Move a test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This was not 100% straightforward as the lowering of an enum wants to be
the_value as i32in the Rust-to-wasm generator, but that's not workingbecause sometimes
the_valuehas type&Tinstead ofTwhich can'tbe cast to
i32. This means that lowerings in Rust are now alwaysproducing a
matchstatement which should optimize to the same thingbut won't be as easy on the eyes.
Additionally a small change was made to the C code generator that
expected<_, _>is now represented as a struct-of-union instead ofspecial-cased to be an
enum. The only reason it was special casedprior was that it was accidentally interpreted as an
enumdue to theVariant::is_enumcheck (which is now removed).