Struct Evaluator

Source
pub struct Evaluator<'a> { /* private fields */ }
Expand description

The context used in evaluation, quoting, and conversion checking

We bundle this all together because conversion checking and quoting sometimes need to evaluate terms. For instance, quoting a lambda involves evaluating the body of the lambda in the context of a freshly introduced variable; even though we don’t have lambdas, a similar thing applies to dependent records.

Implementations§

Source§

impl<'a> Evaluator<'a>

Source

pub fn new(toplevel: &'a Toplevel, env: Env, scope_length: usize) -> Self

Constructor for Evaluator

Source

pub fn with_env(&self, env: Env) -> Self

Return a new Evaluator with environment env

Source

pub fn eval_ty(&self, ty: &TyS) -> TyV

Evaluate type syntax to produce a type value

Assumes that the type syntax is well-formed and well-scoped with respect to self.env

Source

pub fn eval_tm(&self, tm: &TmS) -> TmV

Evaluate term syntax to produce a term value

Assumes that the term syntax is well-formed and well-scoped with respect to self.env

Source

pub fn proj( &self, tm: &TmV, field_name: FieldName, field_label: LabelSegment, ) -> TmV

Compute the projection of a field from a term value

Source

pub fn field_ty(&self, ty: &TyV, val: &TmV, field_name: FieldName) -> TyV

Evaluate the type of the field field_name of val : ty.

Source

pub fn bind_neu( &self, name: VarName, label: LabelSegment, ty: TyV, ) -> (TmN, Self)

Bind a new neutral of type ty

Source

pub fn bind_self(&self, ty: TyV) -> (TmN, Self)

Bind a variable called “self” to ty

Source

pub fn quote_ty(&self, ty: &TyV) -> TyS

Produce type syntax from a type value.

This is a section of eval, in that self.eval_ty(self.quote_ty(ty_v)) == ty_v but it is not necessarily true that self.quote_ty(self.eval_ty(ty_s)) == ty_v.

This is used for displaying TyV to the user in type errors, and for creating syntax that can be re-evaluated in other contexts. In theory this could be used for conversion checking, but it’s more efficient to implement that directly, and it’s better to not do eta-expansion for user-facing messages or for syntax that is meant to be re-evaluated.

Source

pub fn quote_neu(&self, n: &TmN) -> TmS

Produce term syntax from a term neutral.

The documentation for Evaluator::quote_ty is also applicable here.

Source

pub fn quote_tm(&self, tm: &TmV) -> TmS

Produce term syntax from a term value.

The documentation for Evaluator::quote_ty is also applicable here.

Source

pub fn subtype<'b>(&self, ty1: &TyV, ty2: &TyV) -> Result<(), D<'b>>

Check if ty1 is a subtype of ty2.

This is true iff ty1 is convertable with ty2, and an eta-expanded neutral of type ty1 is an element of ty2.

Source

pub fn element_of<'b>(&self, tm: &TmV, ty: &TyV) -> Result<(), D<'b>>

Check if tm is an element of ty, accounting for specializations of ty.

Precondition: the type of tm must be convertable with ty, and tm is eta-expanded.

Example: if a : Entity and b : Entity are neutrals, then a is not an element of @sing b, but a is an element of @sing a.

Source

pub fn convertable_ty<'b>(&self, ty1: &TyV, ty2: &TyV) -> Result<(), D<'b>>

Check if two types are convertable.

Ignores specializations: specializations are handled in Evaluator::subtype

On failure, returns a doc which describes the obstruction to convertability.

Source

pub fn eta_neu(&self, n: &TmN, ty: &TyV) -> TmV

Performs eta-expansion of the neutral n at type ty.

Source

pub fn eta(&self, v: &TmV, ty: &TyV) -> TmV

Performs eta-expansion of the term n at type ty

Source

pub fn equal_tm<'b>(&self, tm1: &TmV, tm2: &TmV) -> Result<(), D<'b>>

Check if two terms are definitionally equal.

On failure, returns a doc which describes the obstruction to convertability.

Assumes that the base type of tm1 is convertable with the base type of tm2. First attempts to do conversion checking without eta-expansion (strict mode), and if that fails, does conversion checking with eta-expansion.

Source

pub fn try_specialize( &self, ty: &TyV, path: &[(FieldName, LabelSegment)], field_ty: TyV, ) -> Result<TyV, String>

Try to specialize the record r with the subtype ty at path

Precondition: path is non-empty.

Trait Implementations§

Source§

impl<'a> Clone for Evaluator<'a>

Source§

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

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

Auto Trait Implementations§

§

impl<'a> Freeze for Evaluator<'a>

§

impl<'a> !RefUnwindSafe for Evaluator<'a>

§

impl<'a> !Send for Evaluator<'a>

§

impl<'a> !Sync for Evaluator<'a>

§

impl<'a> Unpin for Evaluator<'a>

§

impl<'a> !UnwindSafe for Evaluator<'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> 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> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V