[][src]Struct rusttyc::TypeChecker

pub struct TypeChecker<AbsTy: Abstract, Var: TcVar> { /* fields omitted */ }

The TypeChecker is the main interaction point for the type checking procedure.

The TypeChecker is the main interaction point for the type checking procedure. It provides functionality to obtain TcKeys, manage variables, impose constraints, and generate a type table.

Related Data Structures

  • TcKey represent different entities during the type checking procedure such as variables or terms.
  • TcVar represent variables in the external structure, e.g. in the AST that is type checked. A variable has exactly one associated key, even if it occurs several times in the external data structure. The type checker manages keys for variables.
  • Constraints represent dependencies between keys and types. They can only be created using TcKey.
  • Abstract is an external data type that constitutes a potentially unresolved type.
  • TcErr is a wrapper for Abstract::Err that contains additional information on what went wrong.
  • AbstractTypeTable maps keys to abstract types.

Process

In the first step after creation, the TypeChecker generates keys and collects information. It may already resolve some constraints and reveal contradictions. This prompts it to return a negative result with a TcErr. When all information is collected, it resolves them and generates a type table that contains the least restrictive abstract type for each registered key.

Note:

The absence of errors does not entail that a constraint can be satisfied. Only the successful generation of a type table indicates that all constraints can be satisfied.

Example

See crate documentation.

Implementations

impl<AbsTy: Abstract, Var: TcVar> TypeChecker<AbsTy, Var>[src]

pub fn new() -> Self[src]

Creates a new, empty TypeChecker.

pub fn new_term_key(&mut self) -> TcKey[src]

Generates a new key representing a term.

pub fn get_var_key(&mut self, var: &Var) -> TcKey[src]

Manages keys for variables. It checks if var already has an associated key. If so, it returns the key. Otherwise, it generates a new one.

pub fn get_child_key(
    &mut self,
    parent: TcKey,
    nth: usize
) -> Result<TcKey, TcErr<AbsTy>>
[src]

Provides a key to the nth child of the type behind parent. This imposes the restriction that parent resolves to a type that has at least nth dependent sub-types. If this imposition immediately leads to a contradiction, an TcErr is returned. Contradictions due to this constraint may only occur later when resolving further constraints. Calling this function several times on a parent with the same nth results in the same key.

pub fn impose(&mut self, constr: Constraint<AbsTy>) -> Result<(), TcErr<AbsTy>>[src]

Imposes a constraint on keys. They can be obtained by using the associated functions of TcKey. Returns a TcErr if the constraint immediately reveals a contradiction.

pub fn all_keys(&self) -> impl Iterator<Item = &TcKey>[src]

Returns an iterator over all keys currently present in the type checking procedure.

pub fn type_check(self) -> Result<AbstractTypeTable<AbsTy>, TcErr<AbsTy>>[src]

Finalizes the type check procedure. Calling this function indicates that all relevant information was passed on to the type checker. It will attempt to resolve all constraints and return a type table mapping each registered key to its minimally constrained abstract type.
If any constrained caused a contradiction, it will return a TcErr: ./TcErr.html containing information about it.

Trait Implementations

impl<AbsTy: Clone + Abstract, Var: Clone + TcVar> Clone for TypeChecker<AbsTy, Var>[src]

impl<AbsTy: Debug + Abstract, Var: Debug + TcVar> Debug for TypeChecker<AbsTy, Var>[src]

impl<AbsTy: Abstract, Var: TcVar> Default for TypeChecker<AbsTy, Var>[src]

Auto Trait Implementations

impl<AbsTy, Var> RefUnwindSafe for TypeChecker<AbsTy, Var> where
    AbsTy: RefUnwindSafe,
    Var: RefUnwindSafe

impl<AbsTy, Var> Send for TypeChecker<AbsTy, Var> where
    AbsTy: Send,
    Var: Send

impl<AbsTy, Var> Sync for TypeChecker<AbsTy, Var> where
    AbsTy: Sync,
    Var: Sync

impl<AbsTy, Var> Unpin for TypeChecker<AbsTy, Var> where
    AbsTy: Unpin,
    Var: Unpin

impl<AbsTy, Var> UnwindSafe for TypeChecker<AbsTy, Var> where
    AbsTy: UnwindSafe,
    Var: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.