-
Notifications
You must be signed in to change notification settings - Fork 82
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
Canonical abi: union-type
#325
Comments
I haven't digested the whole idea, but two initial thoughts:
|
For context, options of options usually come up when composing things. For example, you have some domain of values that is represented by an option (say, because it contains an "empty" element), and then you need to put those in some kind of map where the lookup function returns an optional result to indicate lookup failure. Conflating the two then becomes a fatal composability failure. |
FWIW, you could do types inside a rec group to prevent |
Oh right, good point! Thinking about which is better from a perf POV, I would guess that for low number of cases, the difference is negligible, but for high numbers of cases, the nice thing about a (dense) discriminant is that you can |
Motivation
Runtime Reinterpretation
Many languages have the ability to reinterpret a piece of data at runtime, and this ability can be constrained by the type system.
For example, in C language:
Or in typescript:
Interface merging (interface subtype)
In some type systems, identical types or subtypes can be merged:
This is completely different from variants (sum types) in algebraic data types.
ABI change
Add a new union option, which does not take effect by default
This option will require variants to pass data directly without adding additional enumeration parameters.
Changes to
reference-type
When
reference-type
andunion-type
are enabled at the same time, the following changes will occurrt
+ut
rt
+ut
option<bool>
(i32, i32)
(ref null i31)
option<option<bool>>
(i32, i32)
(ref null i31)
option<char>
(i32, i32)
(ref null i32)
option<i8>
(i32, i32)
(ref null i31)
option<i32>
(i32, i32)
(ref null i32)
option<i64>
(i32, i64)
(ref null i64)
option<T>
(heap type)(i32, SIZE_OF_T)
(ref null $t)
option<option<T>>
(heap type)(i32, SIZE_OF_T)
(ref null $t)
result<A, B>
(i32, MAX_SIZE_A_B)
anyref
variants
(i32, MAX_SIZE)
anyref
Each variant item will have an independent type id, which is used for type conversion and distinguishing variant items with the same name.
This helps to implement features such as abstract classes, interface inheritance,
?.
(non-null call),??
(null merge), etc.The text was updated successfully, but these errors were encountered: