37# include <gtest/gtest.h>
44TEST(CompilerTypes, BuiltinsAreStableAndPrettyPrinted)
58TEST(CompilerTypes, BuildsTuplesFunctionsAndTypeVariables)
70 EXPECT_EQ(ctx.
to_string(tuple),
"(Int, Bool, Elem)");
71 EXPECT_EQ(ctx.
to_string(fn),
"fn((Int, Bool, Elem), T0) -> Char");
75TEST(CompilerTypes, ClearKeepsBuiltinsAndResetsFreshVariables)
84 EXPECT_EQ(ctx.
size(), 6u);
90TEST(CompilerTypes, BuildsNominalStructsAndEnums)
112 EXPECT_EQ(ctx.
to_string(point),
"Point");
Stable type graph for the compiler-support MVP.
Context owning all compiler type nodes.
bool is_type_variable(const Compiler_Type_Id id) const
Returns whether id names a type variable.
Compiler_Type_Id string_type() const noexcept
Returns the preloaded String type id.
size_t builtin_count() const noexcept
Returns the number of eager built-in types.
void set_struct_fields(const Compiler_Type_Id id, const DynArray< std::string > &field_names, const DynArray< Compiler_Type_Id > &field_types)
Assigns field metadata to a previously created struct type.
size_t size() const noexcept
Returns the total number of stored types.
std::string to_string(const Compiler_Type_Id id) const
Renders one type to a deterministic human-readable string.
bool is_struct(const Compiler_Type_Id id) const
Returns whether id names a nominal struct type.
Compiler_Type_Id make_enum_type(std::string name)
Creates a nominal enum type placeholder.
void set_enum_variants(const Compiler_Type_Id id, const DynArray< std::string > &variant_names)
Assigns variant metadata to a previously created enum type.
const Compiler_Type & type(const Compiler_Type_Id id) const
Returns type id.
Compiler_Type_Id invalid_type() const noexcept
Returns the preloaded Invalid type id.
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 character_type() const noexcept
Returns the preloaded Char type id.
void clear() noexcept
Drops user-created types and keeps the built-ins.
Compiler_Type_Id unit_type() const noexcept
Returns the preloaded Unit type id.
bool is_enum(const Compiler_Type_Id id) const
Returns whether id names a nominal enum 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.
Compiler_Type_Id make_struct_type(std::string name)
Creates a nominal struct type placeholder.
size_t size() const noexcept
Return the current dimension of array.
T & access(const size_t i) noexcept
Fast access without checking allocation and bound_min_clock checking.
T & append()
Allocate a new entry to the end of array.
Main namespace for Aleph-w library functions.
static long & color(typename GT::Node *p)
DynArray< Compiler_Type_Id > components
Tuple members, function parameters, or struct field types.
DynArray< std::string > member_names
Struct field names or enum variant names.