tipc
A TIP to LLVM compiler
Public Member Functions | Static Public Member Functions | List of all members
Unifier Class Reference

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< TipTypeinferred (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)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Unifier() [1/2]

Unifier::Unifier ( )

◆ Unifier() [2/2]

Unifier::Unifier ( std::vector< TypeConstraint constrs)
explicit

Construct a Unifier with seeded with constraints.

Useful for when one is collecting and then unifying constraints.

◆ ~Unifier()

Unifier::~Unifier ( )
default

Construct an empty Unifier.

Useful for when unifying on the fly.

Member Function Documentation

◆ add()

void Unifier::add ( std::vector< TypeConstraint constrs)

Add constraints to this unifier.

◆ inferred()

std::shared_ptr< TipType > Unifier::inferred ( std::shared_ptr< TipType v)

Returns the inferred type for a given type.

Looks up the inferred type in the type solution.

Precondition
The unifier has computed a solution. This will close the type by replacing any variables that are bound to proper types in the inferred solution with that proper type.

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.

◆ isAlpha()

bool Unifier::isAlpha ( std::shared_ptr< TipType type)
static

◆ isCons()

bool Unifier::isCons ( std::shared_ptr< TipType type)
static

◆ isMu()

bool Unifier::isMu ( std::shared_ptr< TipType type)
static

◆ isProperType()

bool Unifier::isProperType ( std::shared_ptr< TipType type)
static

◆ isVar()

bool Unifier::isVar ( std::shared_ptr< TipType type)
static

◆ solve()

void Unifier::solve ( )

Solve the system of constraints that have presented to this unifier.

Precondition
The unifier has been constructed with seed values. Incremental solving can be achieved by adding constraints, via the add method, after solving. This will cause the new constraints to be unified with the currently unified constraints.

◆ unify()

void Unifier::unify ( std::shared_ptr< TipType t1,
std::shared_ptr< TipType t2 
)

Attempt to unify the two types.

Exceptions
UnificationErrorwhen constraints cannot be unifierd.

The documentation for this class was generated from the following files: