-
Notifications
You must be signed in to change notification settings - Fork 464
Emit tags as strings. #6088
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
Emit tags as strings. #6088
Conversation
eb3577a
to
ec10b76
Compare
f9633a1
to
6e033c9
Compare
Compile is_tag to `!== "object"` instead of `=== "string"`.
Also the comment is not emitted anymore, since there's always a tag. Not special casing means that the representation is uniform, and does not change when the type is extended. This is important with zero cost ffi, where the runtime representation is exposed to the user, to reduce possible surprises.
6e4a73a
to
2524fca
Compare
Will there be a way to turn this off and go back to the old behaviour? |
No |
Some engines struggle with switching over a large amount of strings (hermes). Recently, React removed a few instances of these big string switch cases for that reason It'd be a shame if there was no escape hatch when you know you have performance critical code |
Please send your perf measurements. |
I’ll write myself a note to do that after upgrading |
@jacobp100, looks like you can use the @tag("state")
type loadingState = | @as(1) Loading({ready: bool}) | @as(2) Error({message: string}) | @as(3) Done({data: bool})
let state = Error({message: "Something went wrong!"}) |
Correct, use tagged variants, e.g. in my case, I needed interop with TypeScript enum and this chapter in the blog post goes to the point. I then used coercion instead of the methods generated by The only drawback is that the conversion from JS -> Variant is missing, you cannot coerce e.g. |
Emit tags as strings.
Currently does not have support for
@deriving(jsConverter)
and the relevant tests have been removed.