37# include <gtest/gtest.h>
44TEST(CompilerConstraints, UnifiesTypeVariableWithBuiltinAndAppliesSubstitution)
52 ASSERT_TRUE(result.ok());
58TEST(CompilerConstraints, UnifiesStructuredFunctionTypesTransitively)
68 const auto result = unifier.
unify(lhs, rhs);
70 ASSERT_TRUE(result.ok());
73 EXPECT_EQ(ctx.
to_string(unifier.
apply(lhs)),
"fn(Int, Bool) -> Int");
77TEST(CompilerConstraints, OccursCheckRejectsRecursiveBinding)
84 const auto result = unifier.
unify(alpha, recursive);
86 EXPECT_EQ(result.kind, Compiler_Unify_Result_Kind::Occurs_Check_Failed);
90TEST(CompilerConstraints, RigidVariablesCannotBeBound)
98 EXPECT_EQ(result.kind, Compiler_Unify_Result_Kind::Rigid_Variable);
102TEST(CompilerConstraints, SolvesConstraintSetsInInsertionOrder)
117 const auto result = unifier.
solve(constraints);
119 ASSERT_TRUE(result.ok());
125TEST(CompilerConstraints, SolveShortCircuitsOnFirstFailure)
137 const auto result = unifier.
solve(constraints);
139 EXPECT_FALSE(result.ok());
141 EXPECT_EQ(unifier.
apply(beta), beta);
Context owning all compiler type nodes.
Compiler_Type_Id string_type() const noexcept
Returns the preloaded String type id.
std::string to_string(const Compiler_Type_Id id) const
Renders one type to a deterministic human-readable string.
Compiler_Type_Id make_type_variable(std::string label="", const bool rigid=false)
Creates a fresh type variable.
Compiler_Type_Id make_tuple_type(const DynArray< Compiler_Type_Id > &members)
Creates a tuple type.
Compiler_Type_Id make_function_type(const DynArray< Compiler_Type_Id > ¶meters, const Compiler_Type_Id result)
Creates a function type.
Compiler_Type_Id bool_type() const noexcept
Returns the preloaded Bool type id.
Compiler_Type_Id integer_type() const noexcept
Returns the preloaded Int type id.
Structural unifier for compiler types.
std::string dump_substitution()
Dumps the current substitution in a deterministic format.
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.
Compiler_Type_Id apply(const Compiler_Type_Id id)
Applies the current substitution to id.
Ordered collection of equality constraints.
size_t add(const T &lhs, const T &rhs, const Source_Span &span={}, const std::string &message="")
Appends an equality constraint.
Main namespace for Aleph-w library functions.
Equality constraints and type unification helpers for compiler work.