Book

Struct Book 

Source
pub struct Book {
    pub defs: Definitions,
    pub hvm_defs: HvmDefinitions,
    pub adts: Adts,
    pub ctrs: Constructors,
    pub entrypoint: Option<Name>,
    pub imports: Vec<Import>,
}
Expand description

The representation of a program.

Fields§

§defs: Definitions

Function definitions.

§hvm_defs: HvmDefinitions

HVM native function definitions.

§adts: Adts

Algebraic datatype definitions.

§ctrs: Constructors

Map of constructor name to type name.

§entrypoint: Option<Name>

A custom or default “main” entrypoint.

§imports: Vec<Import>

Imports declared in the program.

Implementations§

Source§

impl Book

Source

pub fn encode_builtins(&mut self)

Source§

impl Book

Source

pub fn display_pretty(&self) -> impl Display + '_

Source§

impl Book

Source

pub fn merge_definitions(&mut self)

Merges definitions that have the same structure into one definition. Expects variables to be linear.

Some of the origins of the rules will be lost in this stage, Should not be preceded by passes that cares about the origins.

Source§

impl Book

Source

pub fn desugar_use(&mut self)

Inline copies of the declared bind in the use expression.

Example:

use id = λx x
(id id id)

// Transforms to:
(λx x λx x λx x)
Source

pub fn desugar_ctr_use(&mut self)

Inline copies of the declared bind in Fold, Mat and Open inside use expressions.

Source§

impl Book

Source

pub fn encode_adts(&mut self, adt_encoding: AdtEncoding)

Defines a function for each constructor in each ADT in the book.

Source§

impl Book

Source

pub fn encode_matches(&mut self, adt_encoding: AdtEncoding)

Encodes pattern matching expressions in the book into their core form. Must be run after [Ctr::fix_match_terms].

ADT matches are encoded based on adt_encoding.

Num matches are encoded as a sequence of native num matches (on 0 and 1+).

Source§

impl Book

Source§

impl Book

Source

pub fn expand_main(&mut self)

Expands the main function so that it is not just a reference. While technically correct, directly returning a reference is never what users want.

Source§

impl Book

Source

pub fn float_combinators(&mut self, max_size: usize)

Extracts combinator terms into new definitions.

Precondition: Variables must have been sanitized.

The floating algorithm follows these rules: For each child of the term:

  • Recursively float every grandchild term.
  • If the child is a combinator:
    • If the child is not “safe”, extract it.
    • If the term is a combinator and it’s “safe”:
      • If the term is currently larger than max_size, extract the child.
    • Otherwise, always extract the child to a new definition.
  • If the child is not a combinator, we can’t extract it since it would generate an invalid term.

Terms are considered combinators if they have no free vars, no unmatched unscoped binds/vars and are not references (to avoid infinite recursion).

See Term::is_safe for what is considered safe here.

See Term::size for the measurement of size. It should more or less correspond to the compiled inet size.

Source§

impl Book

Source

pub fn lift_local_defs(&mut self)

Source§

impl Book

Source

pub fn linearize_match_binds(&mut self)

Linearization of binds preceding match/switch terms, up to the first bind used in either the scrutinee or the bind.

Example:

@a @b @c let d = (b c); switch a {
  0: (A b c d)
  _: (B a-1 b c d)
}
// Since `b`, `c` and `d` would be eta-reducible if linearized,
// they get pushed inside the match.
@a switch a {
  0: @b @c let d = (b c); (A b c d)
  _: @b @c let d = (b c); (B a-1 b c d)
}
Source§

impl Book

Source

pub fn linearize_matches(&mut self)

Linearizes all variables used in a matches’ arms.

Source§

impl Book

Source

pub fn linearize_match_with(&mut self)

Linearizes all variables specified in the with clauses of match terms.

Source§

impl Book

Erases variables that weren’t used, dups the ones that were used more than once. Substitutes lets into their variable use. In details: For all var declarations: If they’re used 0 times: erase the declaration If they’re used 1 time: leave them as-is If they’re used more times: insert dups to make var use affine For all let vars: If they’re used 0 times: Discard the let If they’re used 1 time: substitute the body in the var use If they’re use more times: add dups for all the uses, put the let body at the root dup. Precondition: All variables are bound and have unique names within each definition.

Source

pub fn linearize_vars(&mut self)

Source§

impl Book

Source

pub fn make_var_names_unique(&mut self)

Makes all variables in each definition have a new unique name. Skips unbound variables. Precondition: Definition references have been resolved.

Source§

impl Book

Source

pub fn hvm_entrypoint(&self) -> &str

Trait Implementations§

Source§

impl Clone for Book

Source§

fn clone(&self) -> Book

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Book

Source§

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

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

impl Default for Book

Source§

fn default() -> Book

Returns the “default value” for a type. Read more
Source§

impl Display for Book

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Book

§

impl RefUnwindSafe for Book

§

impl Send for Book

§

impl Sync for Book

§

impl Unpin for Book

§

impl UnwindSafe for Book

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'t, T> Place<'t, T> for T

Source§

fn place(loaned: LoanedMut<'t, T>, place: &'t mut T)

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.