-
Notifications
You must be signed in to change notification settings - Fork 12
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
Efficient (unboxed) tagged unions #388
Comments
I think something like this would need to ride on the back of the "fat pointers"-related changes that need to happen, as both relate to keeping type information as part of the use site of the runtime value (rather than in pointed-to memory). In other words, I think what you're describing is mostly just a "fat value" (no pointer). |
Not sure if this is related to fat-pointers...This could also be just another built-in type A valid use-case is enum MessagePackToken {
Nil,
Bool(bool),
UInt(u64),
Int(i64),
Float(f64),
BinaryAhead {len: u32},
StringAhead {len: u32},
ArrayAhead {nelems: u32},
MapAhead {nitems: u32},
ExtAhead {type: u8, len: u32}
} And the sizeof |
The approach I'm thinking of that piggybacks on "fat pointers", could be thought of as "fat values", but the result is the same as what you wrote here:
The difference is that with the approach I'm suggesting we should be able to use anonymous type unions (like The advantage is that you need not declare all the cases ahead of time in a |
That sounds good! So If I want: enum Expr {
Add(u32, u32),
Sub(u32, u32)
} We would just write in Savi:
And If I would want a
|
Yes, that's the idea. |
:enum
with some payload.U64 | I64 | F64 | Pair(U64, U64)
will be boxed or not.Union(A | B | C)
that would enforce un-boxing.Would be nice to write code like this:
The text was updated successfully, but these errors were encountered: