Skip to content

Use TYPE_SWITCH macro for types (NFC) #2579

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

Closed
wants to merge 2 commits into from

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Jan 8, 2020

This adds TYPE_SWITCH macro that makes sure the given type is
converted to enum Type::ValueType. Using this over the regular
switch-case when switch-casing over types has an advantage that when new
types are added and not handled, they will generate compile time errors.

This is another attempt at solving #2572. We have #2577, and while I'm
OK with that, and this is just to see what other people might think.

This PR is at this stage to see what people think, and I only converted
a handful of switch-cases into TYPE_SWITCH for now for demonstration.

This adds `TYPE_SWITCH` macro that makes sure the given type is
converted to `enum Type::ValueType`. Using this over the regular
switch-case when switch-casing over types has an advantage that when new
types are added and not handled, they will generate compile time errors.

This is another attempt at solving WebAssembly#2572. We have WebAssembly#2577, and while I'm
OK with that, and this is just to see what other people might think.

This PR is at this stage to see what people think, and I only converted
a handful of switch-cases into `TYPE_SWITCH` for now for demonstration.
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

One footgun I am concerned about here is that it there are no checks that you're not attempting to cast a multivalue type to ValueType. It would be good to add an assertion checking this. With that change, I think this would be similar to #2577 modulo syntax. Another potential footgun is that without removing the implicit conversion operator from Type to uint32_t, it is still possible to switch on a bare type, which would not get the helpful checks from the compiler.

@aheejin
Copy link
Member Author

aheejin commented Jan 8, 2020

Closing in favor of #2577.

@aheejin aheejin closed this Jan 8, 2020
@aheejin aheejin deleted the type_switch branch January 8, 2020 21:54
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