Evaluator

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 point applies to dependent records.

Implementations§

Source§

impl<'a> Evaluator<'a>

Source

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

Source§

impl<'a> Evaluator<'a>

Source

pub fn empty(toplevel: &'a Toplevel) -> Self

Constructs a new Evaluator with empty environment.

Source

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

Return a new Evaluator with environment env.

Source

pub fn eval_ty(&self, ty: &BaseTyS) -> BaseTyV

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: &BaseTmS) -> BaseTmV

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: &BaseTmV, field_name: FieldName, field_label: LabelSegment, ) -> BaseTmV

Compute the projection of a field from a term value.

Source

pub fn field_ty( &self, ty: &BaseTyV, val: &BaseTmV, field_name: FieldName, ) -> BaseTyV

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

Source

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

Bind a new neutral of type ty.

Source

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

Bind a variable called “self” to ty.

Source

pub fn quote_ty(&self, ty: &BaseTyV) -> BaseTyS

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 BaseTyV 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) -> BaseTmS

Produce term syntax from a neutral term.

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

Source

pub fn quote_tm(&self, tm: &BaseTmV) -> BaseTmS

Produce term syntax from a term value.

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

Source

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

Check if ty1 is a subtype of ty2.

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

Source

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

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

Precondition: the type of tm must be convertible 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 convertible_ty<'b>( &self, ty1: &BaseTyV, ty2: &BaseTyV, ) -> Result<(), D<'b>>

Check if two types are convertible.

Ignores specializations: specializations are handled in Evaluator::subtype.

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

Source

pub fn eta_neu(&self, n: &TmN, ty: &BaseTyV) -> BaseTmV

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

Source

pub fn eta(&self, v: &BaseTmV, ty: Option<&BaseTyV>) -> BaseTmV

Performs eta-expansion of the term v at type ty.

Source

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

Check if two terms are definitionally equal.

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

Assumes that the type of tm1 is convertible with the 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 path_ty( &self, ty: &BaseTyV, val: &BaseTmV, path: &[(FieldName, LabelSegment)], ) -> Result<BaseTyV, String>

Walk path from the value val of record type ty, returning the type of the field at the end of the path.

An empty path returns ty unchanged. Each segment requires the current type to be a record containing the named field.

Source

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

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

Precondition: path is non-empty.

Source

pub fn fiber_field_ty( &self, ty: &FiberTyV, field: FieldName, ) -> Option<FiberTyV>

The fiber type of field field of a fiber record type, if present.

Only Over generator fields are ever projected (as we.e); their types are closed, so this is a plain lookup with no environment.

Source

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

Check that two fiber types are convertible.

Source

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

Check that two fiber terms are equal. Fiber terms are all neutral, so this is structural.

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more