Skip to main content

Decision

Enum Decision 

Source
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.

Fields

§scrutinee: Occurrence
§outcome: Outcome
§matched: Box<Decision<'a>>
§default: Box<Decision<'a>>
§

Leaf

A branch matched: its bindings, each already named and given the occurrence to read it from, and its body.

Fields

§bindings: Vec<Binding>
§body: &'a TypedTerm
§

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: Name

The 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.

Trait Implementations§

Source§

impl<'a> Clone for Decision<'a>

Source§

fn clone(&self) -> Decision<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Decision<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Decision<'_>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Decision<'a>

§

impl<'a> RefUnwindSafe for Decision<'a>

§

impl<'a> Send for Decision<'a>

§

impl<'a> Sync for Decision<'a>

§

impl<'a> Unpin for Decision<'a>

§

impl<'a> UnsafeUnpin for Decision<'a>

§

impl<'a> UnwindSafe for Decision<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.