-
Notifications
You must be signed in to change notification settings - Fork 455
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
Support @as("foo") to customize the representation of tags. #6095
Conversation
cristianoc
commented
Mar 23, 2023
•
edited
Loading
edited
6e4a73a
to
2524fca
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.
null and undefined can only be applied to cases with no payloads unboxed can only be applied when there is exactly one case with payloads, and that case takes exactly one argument Some of those checks are possible statically. Not all of them are implemented. Some checks cannot if one wants to have user-level nullable, null, undefined types with pattern matching. E.g. null type could take null as an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few places where one needs to make sure assert false is not triggered.
| AsInt i -> small_int i | ||
| AsNull -> nil | ||
| AsUndefined -> undefined | ||
| AsUnboxed -> assert false (* Should not emit tags for unboxed *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: put restriction on the variant definitions allowed, to make sure this never happens.
expression_desc cxt ~level f (Object objs) | ||
let exp = match objs with | ||
| [(_, e)] when as_value = Some AsUnboxed -> e.expression_desc | ||
| _ when as_value = Some AsUnboxed -> assert false (* should not happen *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: put restriction on the variant definitions allowed, to make sure this never happens.
WOW, it seems this fully resolves the #5207 |
I think so. Would you have a try and report back? |