diff --git a/common/constants.h b/common/constants.h index 23a504f5..5569eec9 100644 --- a/common/constants.h +++ b/common/constants.h @@ -112,7 +112,6 @@ struct PointerType : Type { private: friend Type; - friend struct TypeSystem; friend PointerType Ptr(Type t); explicit PointerType() = default; @@ -131,7 +130,6 @@ struct BufferPointerType : Type { private: friend Type; - friend struct TypeSystem; friend BufferPointerType BufPtr(Type t); explicit BufferPointerType() = default; @@ -151,7 +149,6 @@ struct SliceType : Type { private: friend Type; - friend struct TypeSystem; friend SliceType Slice(Type t); explicit SliceType() = default; @@ -222,7 +219,6 @@ struct ParametersType : Type { private: friend Type; friend struct FunctionType; - friend struct TypeSystem; friend ParametersType Parameters(std::span); explicit constexpr ParametersType(uint32_t n) : Type(Type::Kind::Parameters, n) {} @@ -266,7 +262,6 @@ struct FunctionType : Type { private: friend Type; - friend struct TypeSystem; friend FunctionType Function(ParametersType, std::span, Evaluation); diff --git a/ir/deserialize.h b/ir/deserialize.h index 6b96ed6b..2f063404 100644 --- a/ir/deserialize.h +++ b/ir/deserialize.h @@ -52,7 +52,6 @@ struct ModuleDeserializer : R { type::Type t; co_await nth::io::deserialize(d, t); std::vector values; - t = d.reindexing_(t); switch (t.kind()) { case type::Type::Kind::Primitive: { auto p = t.AsPrimitive(); @@ -197,13 +196,11 @@ struct ModuleDeserializer : R { StringLiteral name; type::Type t; co_await nth::io::deserialize(d, name, t); - f = ForeignFunction(name, d.reindexing_(t).AsFunction()); + f = ForeignFunction(name, t.AsFunction()); co_return Result::success(); } friend Result NthDeserialize(ModuleDeserializer& d, Module& m) { - d.reindexing_.clear(); - co_await nth::io::deserialize(d, GlobalConstantTable()); co_await nth::io::deserialize(d, d.context_.foreign); co_await nth::io::deserialize(d, m.program()); @@ -217,7 +214,6 @@ struct ModuleDeserializer : R { return context_.registry; } private: - type::TypeSystem::ReindexTable reindexing_; SharedContext& context_; Result read_as_string(std::string& content) { diff --git a/ir/emit.h b/ir/emit.h index c1bd6971..44f746ad 100644 --- a/ir/emit.h +++ b/ir/emit.h @@ -9,6 +9,7 @@ #include "absl/container/flat_hash_map.h" #include "common/identifier.h" #include "common/module_id.h" +#include "common/type.h" #include "ir/dependent_modules.h" #include "ir/lexical_scope.h" #include "ir/local_storage.h" @@ -20,7 +21,6 @@ #include "parse/declaration.h" #include "parse/node_index.h" #include "parse/tree.h" -#include "type/type.h" namespace ic { diff --git a/ir/ir.cc b/ir/ir.cc index 34a0a535..a433cb46 100644 --- a/ir/ir.cc +++ b/ir/ir.cc @@ -10,6 +10,7 @@ #include "common/module_id.h" #include "common/resources.h" #include "common/string.h" +#include "common/type.h" #include "ir/lexical_scope.h" #include "ir/type_stack.h" #include "jasmin/core/function.h" @@ -19,7 +20,6 @@ #include "parse/node_index.h" #include "parse/tree.h" #include "type/cast.h" -#include "type/type.h" namespace ic { namespace { diff --git a/ir/lexical_scope.h b/ir/lexical_scope.h index c0992d71..93accb4c 100644 --- a/ir/lexical_scope.h +++ b/ir/lexical_scope.h @@ -9,7 +9,6 @@ #include "nth/debug/debug.h" #include "nth/utility/iterator_range.h" #include "parse/node_index.h" -#include "type/type.h" namespace ic { diff --git a/ir/local_storage.h b/ir/local_storage.h index ec44e298..411606f6 100644 --- a/ir/local_storage.h +++ b/ir/local_storage.h @@ -2,11 +2,11 @@ #define ICARUS_IR_LOCAL_STORAGE_H #include "absl/container/flat_hash_map.h" +#include "common/type.h" #include "nth/container/interval.h" #include "nth/debug/debug.h" #include "parse/node_index.h" #include "type/byte_width.h" -#include "type/type.h" namespace ic { diff --git a/ir/module.h b/ir/module.h index bd96b73a..1bf6fd37 100644 --- a/ir/module.h +++ b/ir/module.h @@ -11,7 +11,6 @@ #include "ir/function.h" #include "ir/scope.h" #include "jasmin/core/value.h" -#include "type/type.h" namespace ic { diff --git a/ir/type_stack.h b/ir/type_stack.h index 59216c9b..d02b1289 100644 --- a/ir/type_stack.h +++ b/ir/type_stack.h @@ -6,7 +6,8 @@ #include #include -#include "type/type.h" +#include "common/type.h" +#include "type/basic.h" namespace ic { diff --git a/toolchain/builtin/module.cc b/toolchain/builtin/module.cc index bf32ab6d..8f0ce861 100644 --- a/toolchain/builtin/module.cc +++ b/toolchain/builtin/module.cc @@ -5,7 +5,7 @@ #include "common/any_value.h" #include "common/identifier.h" #include "common/pattern.h" -#include "type/type.h" +#include "common/type.h" namespace ic::builtin { namespace { diff --git a/type/BUILD b/type/BUILD index c08b99d4..438e846e 100644 --- a/type/BUILD +++ b/type/BUILD @@ -173,10 +173,10 @@ cc_library( cc_library( name = "type", - hdrs = ["type.h"], srcs = ["type.cc"], deps = [ - ":type_system", + ":dependent", + ":type_contour", "//common:constants", "@nth_cc//nth/container:flyweight_set", "@nth_cc//nth/debug", @@ -201,28 +201,3 @@ cc_test( "@nth_cc//nth/test:main", ] ) - -cc_library( - name = "type_system", - hdrs = ["type_system.h"], - srcs = ["type_system.cc"], - deps = [ - ":alignment", - ":basic", - ":byte_width", - ":dependent", - ":function", - ":opaque", - ":parameters", - ":pattern", - ":pointer", - ":primitive", - ":refinement", - ":type_contour", - "//common/language:type_kind", - "//common:pattern", - "@nth_cc//nth/container:flyweight_set", - "@nth_cc//nth/debug", - "@nth_cc//nth/utility:no_destructor", - ], -) diff --git a/type/cast.h b/type/cast.h index 5858d8a1..baa00a07 100644 --- a/type/cast.h +++ b/type/cast.h @@ -1,8 +1,8 @@ #ifndef ICARUS_TYPE_CAST_H #define ICARUS_TYPE_CAST_H -#include "type/type.h" #include "common/any_value.h" +#include "common/type.h" namespace ic::type { diff --git a/type/dependent_test.cc b/type/dependent_test.cc index fb1c9272..35fe6977 100644 --- a/type/dependent_test.cc +++ b/type/dependent_test.cc @@ -1,13 +1,14 @@ #include "type/dependent.h" #include "common/any_value.h" +#include "common/type.h" #include "jasmin/instructions/arithmetic.h" #include "jasmin/instructions/common.h" #include "nth/test/test.h" +#include "type/basic.h" #include "type/function.h" #include "type/parameters.h" #include "type/primitive.h" -#include "type/type.h" namespace ic::type { namespace { diff --git a/type/type.cc b/type/type.cc index 19554a73..9514da3b 100644 --- a/type/type.cc +++ b/type/type.cc @@ -1,4 +1,4 @@ -#include "type/type.h" +#include "common/type.h" #include #include @@ -9,12 +9,12 @@ #include "common/pattern.h" #include "nth/debug/debug.h" #include "nth/utility/no_destructor.h" +#include "type/dependent.h" +#include "type/type_contour.h" namespace ic::type { namespace { -nth::NoDestructor type_system; - uint64_t opaque_count = 0; } // namespace diff --git a/type/type.h b/type/type.h deleted file mode 100644 index eb4eeeb5..00000000 --- a/type/type.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef ICARUS_TYPE_TYPE_H -#define ICARUS_TYPE_TYPE_H - -#include -#include -#include -#include - -#include "type/type_system.h" - -#endif // ICARUS_TYPE_TYPE_H diff --git a/type/type_system.cc b/type/type_system.cc deleted file mode 100644 index a4a8c988..00000000 --- a/type/type_system.cc +++ /dev/null @@ -1,32 +0,0 @@ -#include "type/type_system.h" - -#include "common/identifier.h" -#include "nth/debug/debug.h" - -namespace ic::type { - -ParametersType TypeSystem::parameter_type( - std::vector&& p) { - return ParametersType( - parameters.index(parameters.insert(std::move(p)).first)); -} - -ParametersType TypeSystem::parameter_type( - std::vector const& p) { - return ParametersType(parameters.index(parameters.insert(p).first)); -} - -FunctionType TypeSystem::function(ParametersType p, std::vector r, - Evaluation e) { - uint64_t rt = returns.index(returns.insert(std::move(r)).first); - return FunctionType(functions.index(functions.insert({p, rt, e}).first)); -} - -Type TypeSystem::ReindexTable::operator()(Type t) const { - if (t.kind() == Type::Kind::Primitive) { return t; } - auto iter = mapping_.find(t); - NTH_REQUIRE((v.debug), iter != mapping_.end()); - return iter->second; -} - -} // namespace ic::type diff --git a/type/type_system.h b/type/type_system.h deleted file mode 100644 index ad71b9cf..00000000 --- a/type/type_system.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef ICARUS_TYPE_TYPE_SYSTEM_H -#define ICARUS_TYPE_TYPE_SYSTEM_H - -#include -#include -#include -#include - -#include "common/pattern.h" -#include "nth/container/flyweight_set.h" -#include "type/basic.h" -#include "type/dependent.h" -#include "type/function.h" -#include "type/opaque.h" -#include "type/parameters.h" -#include "type/pattern.h" -#include "type/pointer.h" -#include "type/primitive.h" -#include "type/refinement.h" -#include "type/type_contour.h" - -namespace ic::type { - -struct TypeSystem { - ParametersType parameter_type( - std::vector const& p); - ParametersType parameter_type(std::vector&& p); - FunctionType function(ParametersType p, std::vector r, Evaluation e); - - nth::flyweight_set> parameters; - nth::flyweight_set> returns; - - nth::flyweight_set> - functions; - nth::flyweight_set dependent_terms; - nth::flyweight_set dependent_mapping; - nth::flyweight_set> dependent_term_mapping_pairs; - nth::flyweight_set> refinements; - nth::flyweight_set pattern_match_types; - - struct ReindexTable { - Type operator()(Type t) const; - void clear() { - returns_.clear(); - mapping_.clear(); - } - - private: - friend TypeSystem; - std::vector returns_; - absl::flat_hash_map mapping_; - }; -}; - -} // namespace ic::type - -#endif // ICARUS_TYPE_TYPE_SYSTEM_H diff --git a/type/type_test.cc b/type/type_test.cc deleted file mode 100644 index 9d76bfc3..00000000 --- a/type/type_test.cc +++ /dev/null @@ -1,97 +0,0 @@ -#include "type/type.h" - -#include "nth/test/test.h" - -namespace ic::type { -namespace { - -NTH_TEST("type/construction") { - Type t = PrimitiveType(PrimitiveType::Kind::Bool); - NTH_EXPECT(t == Bool); - NTH_EXPECT(t.kind() == Type::Kind::Primitive); - - t = PrimitiveType(PrimitiveType::Kind::Module); - NTH_EXPECT(t == Module); - NTH_EXPECT(t.kind() == Type::Kind::Primitive); - - t = PrimitiveType(PrimitiveType::Kind::Type); - NTH_EXPECT(t == Type_); - NTH_EXPECT(t.kind() == Type::Kind::Primitive); -} - -NTH_TEST("type/parameters/construction") { - Type t0 = Parameters({}); - Type t1 = Parameters( - {ParametersType::Parameter{.name = Identifier("a"), .type = Bool}}); - Type t2 = Parameters( - {ParametersType::Parameter{.name = Identifier("b"), .type = Bool}}); - Type t3 = Parameters( - {ParametersType::Parameter{.name = Identifier("b"), .type = Char}}); - - NTH_EXPECT(t0 == t0); - NTH_EXPECT(t0 != t1); - NTH_EXPECT(t0 != t2); - NTH_EXPECT(t0 != t3); - NTH_EXPECT(t1 != t0); - NTH_EXPECT(t1 == t1); - NTH_EXPECT(t1 != t2); - NTH_EXPECT(t1 != t3); - NTH_EXPECT(t2 != t1); - NTH_EXPECT(t2 != t0); - NTH_EXPECT(t2 == t2); - NTH_EXPECT(t2 != t3); - NTH_EXPECT(t3 != t0); - NTH_EXPECT(t3 != t1); - NTH_EXPECT(t3 != t2); - NTH_EXPECT(t3 == t3); - - NTH_EXPECT(t0.kind() == Type::Kind::Parameters); - NTH_EXPECT(t1.kind() == Type::Kind::Parameters); - NTH_EXPECT(t2.kind() == Type::Kind::Parameters); - NTH_EXPECT(t3.kind() == Type::Kind::Parameters); - - NTH_EXPECT(t0 != Error); - NTH_EXPECT(t0 != Bool); - - NTH_EXPECT(t3 == Parameters({ParametersType::Parameter{ - .name = Identifier("b"), .type = Char}})); -} - -NTH_TEST("type/pointer") { - NTH_EXPECT(Ptr(Char) == Ptr(Char)); - NTH_EXPECT(Ptr(Ptr(Char)) != Ptr(Char)); - NTH_EXPECT(Ptr(Ptr(Char)).pointee() == Ptr(Char)); - NTH_EXPECT(Ptr(Ptr(Char)).pointee().AsPointer().pointee() == Char); -} - -NTH_TEST("type/buffer-pointer") { - NTH_EXPECT(BufPtr(Char) == BufPtr(Char)); - NTH_EXPECT(BufPtr(Ptr(Char)) != Ptr(Char)); - NTH_EXPECT(BufPtr(Ptr(Char)).pointee() == Ptr(Char)); - NTH_EXPECT(BufPtr(Ptr(Char)).pointee().AsPointer().pointee() == Char); - NTH_EXPECT(BufPtr(BufPtr(Char)) != BufPtr(Char)); - NTH_EXPECT(BufPtr(BufPtr(Char)).pointee() == BufPtr(Char)); - NTH_EXPECT(BufPtr(BufPtr(Char)).pointee().AsBufferPointer().pointee() == - Char); -} - -NTH_TEST("type/slice") { - NTH_EXPECT(Slice(Char) == Slice(Char)); - NTH_EXPECT(Slice(Slice(Char)) != Slice(Char)); - NTH_EXPECT(Slice(Slice(Char)).element_type() == Slice(Char)); - NTH_EXPECT(Slice(Slice(Char)).element_type().AsSlice().element_type() == - Char); -} - -NTH_TEST("qualified-type/construction") { - NTH_EXPECT(QualifiedType(Qualifier::Constant(), Bool).type() == Bool); - NTH_EXPECT(QualifiedType(Qualifier::Constant(), Bool).qualifier() == - Qualifier::Constant()); - - NTH_EXPECT(QualifiedType(Qualifier::Constant(), Bool).type() == Bool); - NTH_EXPECT(QualifiedType(Qualifier::Unqualified(), Bool).qualifier() == - Qualifier::Unqualified()); -} - -} // namespace -} // namespace ic::type