Struct rusttyc::TypeChecker[][src]

pub struct TypeChecker<V: ContextSensitiveVariant, Var: TcVar> { /* fields omitted */ }
Expand description

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.

  • 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 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

Instantiates a new, empty type checker that does not require variables.

Creates a new, empty type checker.

Creates a new, empty type checker with the given context.

Generates a new key representing a term.

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.

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.

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.

Lifts a collection of keys as children into a certain recursive variant.

Lifts a collection of keys as subset of children into a certain recursive variant.

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

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.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.