mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 05:34:11 +03:00
Ad some docs to tag union layouts
This commit is contained in:
parent
7771b2090c
commit
c9f06a9172
@ -276,6 +276,12 @@ pub enum UnionLayout<'a> {
|
||||
/// It has more than one other variant, so they need tag IDs (payloads are "wrapped")
|
||||
/// e.g. `FingerTree a : [ Empty, Single a, More (Some a) (FingerTree (Tuple a)) (Some a) ]`
|
||||
/// see also: https://youtu.be/ip92VMpf_-A?t=164
|
||||
///
|
||||
/// nullable_id refers to the index of the tag that is represented at runtime as NULL.
|
||||
/// For example, in `FingerTree a : [ Empty, Single a, More (Some a) (FingerTree (Tuple a)) (Some a) ]`,
|
||||
/// the ids would be Empty = 0, More = 1, Single = 2, because that's how those tags are
|
||||
/// ordered alphabetically. Since the Empty tag will be represented at runtime as NULL,
|
||||
/// and since Empty's tag id is 0, here nullable_id would be 0.
|
||||
NullableWrapped {
|
||||
nullable_id: u16,
|
||||
other_tags: &'a [&'a [Layout<'a>]],
|
||||
@ -283,6 +289,14 @@ pub enum UnionLayout<'a> {
|
||||
/// A recursive tag union with only two variants, where one is empty.
|
||||
/// Optimizations: Use null for the empty variant AND don't store a tag ID for the other variant.
|
||||
/// e.g. `ConsList a : [ Nil, Cons a (ConsList a) ]`
|
||||
///
|
||||
/// nullable_id is a bool because it's only ever 0 or 1, but (as with the NullableWrapped
|
||||
/// variant), it reprsents the index of the tag that will be represented at runtime as NULL.
|
||||
///
|
||||
/// So for example, in `ConsList a : [ Nil, Cons a (ConsList a) ]`, Nil is tag id 1 and
|
||||
/// Cons is tag id 0 because Nil comes alphabetically after Cons. Here, Nil will be
|
||||
/// represented as NULL at runtime, so nullable_id is 1 - which is to say, `true`, because
|
||||
/// `(1 as bool)` is `true`.
|
||||
NullableUnwrapped {
|
||||
nullable_id: bool,
|
||||
other_fields: &'a [Layout<'a>],
|
||||
|
Loading…
Reference in New Issue
Block a user