pub enum Decision<'a> {
Test {
scrutinee: Occurrence,
outcome: Outcome,
matched: Box<Decision<'a>>,
default: Box<Decision<'a>>,
},
Leaf {
bindings: Vec<Binding>,
body: &'a TypedTerm,
},
Fail {
declaration: Name,
},
}Expand description
The tree a case’s branches lower to: what test distinguishes which branch, in what
order they are tried, and the names each leaf binds.
'a is the lifetime of the TypedTerm the branches were built from: a leaf
borrows its branch’s body rather than cloning it, since TypedTerm carries no
Clone impl. A body can appear in more than one leaf once a fallback tree is copied
(see this module’s doc comment), which a borrow makes free in the IR; a backend that
writes each leaf out writes the body once per leaf (GEN-26).
Two trees are equal when they have the same shape and each pair of leaves borrows
the same body — compared by address, since TypedTerm has no PartialEq. That
is the equality a test wants: the leaf is the one built from this branch.
Variants§
Test
Check the value at scrutinee against outcome: matched if it is that value,
default if it is not.
Leaf
A branch matched: its bindings, each already named and given the occurrence to read it from, and its body.
Fail
No branch matches.
Coverage is checked, so no such case
compiles — but nothing
checks it yet (LANG-19), so a case missing a branch compiles today and
reaches this leaf at runtime. It is not deleted the day LANG-19 lands: an
unreachable leaf still has to
abort rather
than fall through to whatever follows it, and this is that leaf — merely one
exhaustiveness will have made unreachable, rather than one still worth reaching
for.
Fields
declaration: NameThe declaration the case was written in: what the description $abort
takes (runtime/js/zelkova.mjs, added by GEN-8) is built from.
This is whatever build’s caller passed, not something the tree finds:
nothing in a case’s branches says which declaration they sit in, so naming
it is the caller’s contract — a backend walking a declaration’s body has
that declaration’s name at hand. Neither the $abort call nor the
description’s exact wording is this pass’s to write; walking a Decision
to build them is zelkova_js::emit’s.