P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::TypeUnification Class Referencefinal

#include <typeUnification.h>

Public Member Functions

 TypeUnification (TypeConstraints *constraints, const P4::TypeMap *typeMap)
 
bool unify (const BinaryConstraint *constraint)
 

Detailed Description

Hindley-Milner type unification algorithm (See for example, http://cs.brown.edu/~sk/Publications/Books/ProgLangs/2007-04-26/plai-2007-04-26.pdf, page 280.) Attempts to unify two types. As a consequence it generates constraints on other sub-types. Constraints are solved at the end. Solving a constraint generates type-variable substitutions (where a type variable is replaced with another type - which could still contain type variables inside). All substitutions are composed together. Constraint solving can fail, which means that the program does not type-check.

Member Function Documentation

◆ unify()

bool P4::TypeUnification::unify ( const BinaryConstraint * constraint)

Return false if unification fails right away. Generates a set of type constraints. If it returns true unification could still fail later.

Returns
False if unification fails immediately.