|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Structural unifier for compiler types. More...
#include <tpl_constraints.H>
Public Member Functions | |
| Compiler_Type_Unifier (Compiler_Type_Context &ctx) noexcept | |
Constructs a unifier operating over ctx. | |
| void | clear () noexcept |
| Clears substitutions and the last stored result. | |
| const Compiler_Unify_Result & | last_result () const noexcept |
Returns the last result produced by unify() or solve(). | |
| const Compiler_Type_Substitution & | substitution () const noexcept |
| Returns the accumulated substitution. | |
| Compiler_Type_Id | apply (const Compiler_Type_Id id) |
Applies the current substitution to id. | |
| Compiler_Unify_Result | unify (const Compiler_Type_Id lhs, const Compiler_Type_Id rhs) |
Attempts to unify lhs and rhs. | |
| Compiler_Unify_Result | solve (const Compiler_Type_Constraint_Set &constraints) |
| Solves a whole ordered set of type constraints. | |
| std::string | dump_substitution () |
| Dumps the current substitution in a deterministic format. | |
Private Member Functions | |
| Compiler_Unify_Result | fail (const Compiler_Unify_Result_Kind kind, const Compiler_Type_Id lhs, const Compiler_Type_Id rhs, const std::string &message, const Source_Span &span={}) noexcept |
| Compiler_Type_Id | resolve (const Compiler_Type_Id id) const |
| bool | occurs_in (const Compiler_Type_Id variable, const Compiler_Type_Id candidate) |
| Compiler_Unify_Result | bind_variable (const Compiler_Type_Id variable, const Compiler_Type_Id replacement) |
Static Private Member Functions | |
| static Compiler_Unify_Result | success () noexcept |
Private Attributes | |
| Compiler_Type_Context * | context = nullptr |
| Compiler_Type_Substitution | subst |
| Compiler_Unify_Result | last |
Structural unifier for compiler types.
Definition at line 378 of file tpl_constraints.H.
|
inlineexplicitnoexcept |
Constructs a unifier operating over ctx.
Definition at line 493 of file tpl_constraints.H.
|
inline |
Applies the current substitution to id.
| id | Type to normalize. |
Definition at line 521 of file tpl_constraints.H.
References Aleph::Compiler_Type_Substitution::apply(), context, and subst.
Referenced by Aleph::Compiler_Typed_Semantic_Analyzer::collect_free_type_variables(), Aleph::Compiler_Typed_Semantic_Analyzer::instantiate_binding(), Aleph::Compiler_Typed_Semantic_Analyzer::instantiate_type(), main(), Aleph::Compiler_Typed_Semantic_Analyzer::normalize_recorded_types(), TEST(), TEST(), TEST(), and TEST().
|
inlineprivate |
Definition at line 464 of file tpl_constraints.H.
References Aleph::Compiler_Type_Substitution::bind(), Aleph::blossom_maximum_cardinality_matching(), context, fail(), Aleph::Occurs_Check_Failed, occurs_in(), resolve(), Aleph::Rigid_Variable, subst, success(), Aleph::Compiler_Type_Context::to_string(), and Aleph::Compiler_Type_Context::type().
Referenced by unify().
|
inlinenoexcept |
Clears substitutions and the last stored result.
Definition at line 498 of file tpl_constraints.H.
References Aleph::Compiler_Type_Substitution::clear(), last, and subst.
Referenced by Aleph::Compiler_Typed_Semantic_Analyzer::clear().
|
inline |
Dumps the current substitution in a deterministic format.
Definition at line 653 of file tpl_constraints.H.
References context, subst, and Aleph::Compiler_Type_Substitution::to_string().
|
inlineprivatenoexcept |
Definition at line 391 of file tpl_constraints.H.
Referenced by bind_variable(), and unify().
|
inlinenoexcept |
Returns the last result produced by unify() or solve().
Definition at line 505 of file tpl_constraints.H.
References last.
|
inlineprivate |
Definition at line 425 of file tpl_constraints.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::Builtin, context, Aleph::Enum, Aleph::Function, occurs_in(), resolve(), Aleph::Struct, Aleph::Tuple, Aleph::Compiler_Type_Context::type(), and Aleph::Type_Variable.
Referenced by bind_variable(), and occurs_in().
|
inlineprivate |
Definition at line 407 of file tpl_constraints.H.
References ah_logic_error_if, Aleph::Compiler_Type_Substitution::lookup(), Aleph::Compiler_Type_Substitution::size(), and subst.
Referenced by bind_variable(), occurs_in(), and unify().
|
inline |
Solves a whole ordered set of type constraints.
Constraints are solved in insertion order and the first failing result is returned with the corresponding span.
| constraints | Ordered equality constraints. |
Definition at line 632 of file tpl_constraints.H.
References Aleph::blossom_maximum_cardinality_matching(), Aleph::Constraint_Set< T >::constraint(), last, Aleph::Equality_Constraint< T >::lhs, Aleph::Equality_Constraint< T >::message, Aleph::Equality_Constraint< T >::rhs, Aleph::Constraint_Set< T >::size(), Aleph::Equality_Constraint< T >::span, success(), and unify().
|
inlinenoexcept |
Returns the accumulated substitution.
Definition at line 511 of file tpl_constraints.H.
References subst.
|
inlinestaticprivatenoexcept |
Definition at line 385 of file tpl_constraints.H.
Referenced by bind_variable(), solve(), and unify().
|
inline |
Attempts to unify lhs and rhs.
On success, the internal substitution is updated.
| lhs | Left-hand type. |
| rhs | Right-hand type. |
Definition at line 534 of file tpl_constraints.H.
References Aleph::Arity_Mismatch, bind_variable(), Aleph::blossom_maximum_cardinality_matching(), Aleph::Builtin, context, Aleph::Enum, fail(), Aleph::Function, Aleph::Invalid_Type, Aleph::Kind_Mismatch, last, resolve(), Aleph::Struct, success(), Aleph::Compiler_Type_Context::to_string(), Aleph::Tuple, Aleph::Compiler_Type_Context::type(), Aleph::Type_Variable, and unify().
Referenced by Aleph::Compiler_Typed_Semantic_Analyzer::require_unify(), solve(), TEST(), TEST(), TEST(), TEST(), and unify().
|
private |
Definition at line 380 of file tpl_constraints.H.
Referenced by apply(), bind_variable(), dump_substitution(), occurs_in(), and unify().
|
private |
Definition at line 382 of file tpl_constraints.H.
Referenced by clear(), last_result(), solve(), and unify().
|
private |
Definition at line 381 of file tpl_constraints.H.
Referenced by apply(), bind_variable(), clear(), dump_substitution(), resolve(), and substitution().