Struct rusttyc::TypeChecker [−][src]
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.
Constraint
s represent dependencies between keys and types. They can only be created using TcKeys.- Variant is an external data type that constitutes a potentially unresolved type.
- TcErr is a wrapper for Variant::Err that contains additional information on what went wrong.
- TypeTable maps keys to Constructable::Type if Variant implements Constructable.
- PreliminaryTypeTable maps keys to Preliminary. This is only useful if Variant does not implement Constructable
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 Variant 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<V: Variant> TypeChecker<V, NoVars>
[src]
pub fn without_vars() -> VarlessTypeChecker<V>
[src]
Instantiates a new, empty type checker that does not require variables.
impl<V: Variant, Var: TcVar> TypeChecker<V, Var>
[src]
impl<V: ContextSensitiveVariant, Var: TcVar> TypeChecker<V, Var>
[src]
pub fn with_context(context: V::Context) -> Self
[src]
Creates a new, empty type checker with the given context.
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<V>>
[src]
&mut self,
parent: TcKey,
nth: usize
) -> Result<TcKey, TcErr<V>>
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 an arity of nth
.
If this imposition immediately leads to a contradiction, a 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<V>) -> Result<(), TcErr<V>>
[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 lift_into(&mut self, variant: V, sub_types: Vec<TcKey>) -> TcKey
[src]
Lifts a collection of keys as children into a certain recursive variant.
pub fn lift_partially(
&mut self,
variant: V,
sub_types: Vec<Option<TcKey>>
) -> TcKey
[src]
&mut self,
variant: V,
sub_types: Vec<Option<TcKey>>
) -> TcKey
Lifts a collection of keys as subset of children into a certain recursive variant.
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 update_context<F>(&mut self, update: F) where
F: FnOnce(&mut V::Context),
[src]
F: FnOnce(&mut V::Context),
Updates the current context.
Applies the update
function to the context of the current typechecker.
The function may mutate the context.
Warning
This will not change any call retroactively, i.e. it only applies to future meet and equate calls. Proceed with caution.
pub fn type_check_preliminary(self) -> Result<PreliminaryTypeTable<V>, TcErr<V>>
[src]
Finalizes the type check procedure without constructing a full type table. Refer to TypeChecker::type_check if Variant implements Constructable. 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 Variants. For recursive types, the respective Preliminary provides access to crate::TcKeys refering to their children. If any constrained caused a contradiction, it will return a TcErr containing information about it.
impl<V, Var: TcVar> TypeChecker<V, Var> where
V: Constructable,
[src]
V: Constructable,
pub fn type_check(self) -> Result<TypeTable<V>, TcErr<V>>
[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, constructed type, i.e. Constructable::Type. Refer to TypeChecker::type_check_preliminary() if Variant does not implement Constructable. If any constrained caused a contradiction, it will return a TcErr containing information about it.
Trait Implementations
impl<V: Clone + ContextSensitiveVariant, Var: Clone + TcVar> Clone for TypeChecker<V, Var> where
V::Context: Clone,
[src]
V::Context: Clone,
fn clone(&self) -> TypeChecker<V, Var>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<V: Debug + ContextSensitiveVariant, Var: Debug + TcVar> Debug for TypeChecker<V, Var> where
V::Context: Debug,
[src]
V::Context: Debug,
impl<V: Variant, Var: TcVar> Default for TypeChecker<V, Var>
[src]
Auto Trait Implementations
impl<V, Var> RefUnwindSafe for TypeChecker<V, Var> where
V: RefUnwindSafe,
Var: RefUnwindSafe,
<V as ContextSensitiveVariant>::Context: RefUnwindSafe,
[src]
V: RefUnwindSafe,
Var: RefUnwindSafe,
<V as ContextSensitiveVariant>::Context: RefUnwindSafe,
impl<V, Var> Send for TypeChecker<V, Var> where
V: Send,
Var: Send,
<V as ContextSensitiveVariant>::Context: Send,
[src]
V: Send,
Var: Send,
<V as ContextSensitiveVariant>::Context: Send,
impl<V, Var> Sync for TypeChecker<V, Var> where
V: Sync,
Var: Sync,
<V as ContextSensitiveVariant>::Context: Sync,
[src]
V: Sync,
Var: Sync,
<V as ContextSensitiveVariant>::Context: Sync,
impl<V, Var> Unpin for TypeChecker<V, Var> where
V: Unpin,
Var: Unpin,
<V as ContextSensitiveVariant>::Context: Unpin,
[src]
V: Unpin,
Var: Unpin,
<V as ContextSensitiveVariant>::Context: Unpin,
impl<V, Var> UnwindSafe for TypeChecker<V, Var> where
V: UnwindSafe,
Var: UnwindSafe,
<V as ContextSensitiveVariant>::Context: UnwindSafe,
[src]
V: UnwindSafe,
Var: UnwindSafe,
<V as ContextSensitiveVariant>::Context: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,