Skip to content

Split out an Enum type from the Variant type#211

Merged
alexcrichton merged 2 commits intobytecodealliance:mainfrom
alexcrichton:enum-type
May 3, 2022
Merged

Split out an Enum type from the Variant type#211
alexcrichton merged 2 commits intobytecodealliance:mainfrom
alexcrichton:enum-type

Conversation

@alexcrichton
Copy link
Member

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).

@alexcrichton alexcrichton mentioned this pull request Apr 29, 2022
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).
Copy link
Member

@peterhuene peterhuene left a comment

Choose a reason for hiding this comment

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

Looks great, just the tiny nit regarding a test case name now that enum and variant are distinct types.

@alexcrichton alexcrichton merged commit d218845 into bytecodealliance:main May 3, 2022
@alexcrichton alexcrichton deleted the enum-type branch May 3, 2022 15:07
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
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.

2 participants