tipc
A TIP to LLVM compiler
|
Class used to solve type constraints and establish typability. More...
#include <Unifier.h>
Public Member Functions | |
Unifier () | |
Unifier (std::vector< TypeConstraint >) | |
Construct a Unifier with seeded with constraints. More... | |
~Unifier ()=default | |
Construct an empty Unifier. More... | |
void | unify (std::shared_ptr< TipType > t1, std::shared_ptr< TipType > t2) |
Attempt to unify the two types. More... | |
void | add (std::vector< TypeConstraint >) |
Add constraints to this unifier. More... | |
void | solve () |
Solve the system of constraints that have presented to this unifier. More... | |
std::shared_ptr< TipType > | inferred (std::shared_ptr< TipType > t) |
Returns the inferred type for a given type. More... | |
Static Public Member Functions | |
static bool | isCons (std::shared_ptr< TipType > type) |
static bool | isMu (std::shared_ptr< TipType > type) |
static bool | isVar (std::shared_ptr< TipType > type) |
static bool | isAlpha (std::shared_ptr< TipType > type) |
static bool | isProperType (std::shared_ptr< TipType > type) |
Class used to solve type constraints and establish typability.
Make uses of a union-find data structure. This class will throw a UnificationError anytime two terms cannot be unified, either because their constructor or arity mismatch.
Unifier::Unifier | ( | ) |
|
explicit |
Construct a Unifier with seeded with constraints.
Useful for when one is collecting and then unifying constraints.
|
default |
Construct an empty Unifier.
Useful for when unifying on the fly.
void Unifier::add | ( | std::vector< TypeConstraint > | constrs | ) |
Add constraints to this unifier.
Returns the inferred type for a given type.
Looks up the inferred type in the type solution.
Here we want to produce an inferred type that is "closed" in the sense that all variables in the type definition are replaced with their base types. The close() function may update the unionFind structure, by generating new types, and this is essential for the staged nature of polymorphic type inference.
|
static |
|
static |
|
static |
|
static |
|
static |
void Unifier::solve | ( | ) |
Solve the system of constraints that have presented to this unifier.
Attempt to unify the two types.
UnificationError | when constraints cannot be unifierd. |