diff --git a/src/tint/resolver/intrinsic_table.cc b/src/tint/resolver/intrinsic_table.cc index a8d3f478fb..54c851d4f2 100644 --- a/src/tint/resolver/intrinsic_table.cc +++ b/src/tint/resolver/intrinsic_table.cc @@ -57,11 +57,10 @@ constexpr static const size_t kNumFixedCandidates = 8; /// A special type that matches all TypeMatchers class Any final : public Castable { public: - Any() : Base(type::Flags{}) {} + Any() : Base(0u, type::Flags{}) {} ~Any() override = default; // Stub implementations for type::Type conformance. - size_t Hash() const override { return 0; } bool Equals(const type::UniqueNode&) const override { return false; } std::string FriendlyName(const SymbolTable&) const override { return ""; } }; diff --git a/src/tint/sem/array_count.cc b/src/tint/sem/array_count.cc index 1999877454..a324ea58e8 100644 --- a/src/tint/sem/array_count.cc +++ b/src/tint/sem/array_count.cc @@ -20,13 +20,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::UnnamedOverrideArrayCount); namespace tint::sem { NamedOverrideArrayCount::NamedOverrideArrayCount(const GlobalVariable* var) - : Base(), variable(var) {} + : Base(static_cast(TypeInfo::Of().full_hashcode)), + variable(var) {} NamedOverrideArrayCount::~NamedOverrideArrayCount() = default; -size_t NamedOverrideArrayCount::Hash() const { - return static_cast(TypeInfo::Of().full_hashcode); -} - bool NamedOverrideArrayCount::Equals(const UniqueNode& other) const { if (auto* v = other.As()) { return variable == v->variable; @@ -38,13 +35,10 @@ std::string NamedOverrideArrayCount::FriendlyName(const SymbolTable& symbols) co return symbols.NameFor(variable->Declaration()->symbol); } -UnnamedOverrideArrayCount::UnnamedOverrideArrayCount(const Expression* e) : Base(), expr(e) {} +UnnamedOverrideArrayCount::UnnamedOverrideArrayCount(const Expression* e) + : Base(static_cast(TypeInfo::Of().full_hashcode)), expr(e) {} UnnamedOverrideArrayCount::~UnnamedOverrideArrayCount() = default; -size_t UnnamedOverrideArrayCount::Hash() const { - return static_cast(TypeInfo::Of().full_hashcode); -} - bool UnnamedOverrideArrayCount::Equals(const UniqueNode& other) const { if (auto* v = other.As()) { return expr == v->expr; diff --git a/src/tint/sem/array_count.h b/src/tint/sem/array_count.h index b30ab38aad..fd441e8959 100644 --- a/src/tint/sem/array_count.h +++ b/src/tint/sem/array_count.h @@ -36,9 +36,6 @@ class NamedOverrideArrayCount final : public Castable().full_hashcode)) {} AbstractFloat::~AbstractFloat() = default; -size_t AbstractFloat::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode); -} - bool AbstractFloat::Equals(const UniqueNode& other) const { return other.Is(); } diff --git a/src/tint/type/abstract_float.h b/src/tint/type/abstract_float.h index d45ec73450..9a7d4a8bb1 100644 --- a/src/tint/type/abstract_float.h +++ b/src/tint/type/abstract_float.h @@ -28,13 +28,9 @@ class AbstractFloat final : public Castable { /// Constructor AbstractFloat(); - /// Move constructor - AbstractFloat(AbstractFloat&&); + /// Destructor ~AbstractFloat() override; - /// @returns a hash of the type. - size_t Hash() const override; - /// @param other the other type to compare against /// @returns true if this type is equal to the given type bool Equals(const UniqueNode& other) const override; diff --git a/src/tint/type/abstract_int.cc b/src/tint/type/abstract_int.cc index 439c291ba2..990d4e6264 100644 --- a/src/tint/type/abstract_int.cc +++ b/src/tint/type/abstract_int.cc @@ -21,13 +21,9 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::AbstractInt); namespace tint::type { -AbstractInt::AbstractInt() = default; -AbstractInt::AbstractInt(AbstractInt&&) = default; -AbstractInt::~AbstractInt() = default; +AbstractInt::AbstractInt() : Base(utils::Hash(TypeInfo::Of().full_hashcode)) {} -size_t AbstractInt::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode); -} +AbstractInt::~AbstractInt() = default; bool AbstractInt::Equals(const UniqueNode& other) const { return other.Is(); diff --git a/src/tint/type/abstract_int.h b/src/tint/type/abstract_int.h index 98d878ffc3..2df6328d41 100644 --- a/src/tint/type/abstract_int.h +++ b/src/tint/type/abstract_int.h @@ -28,13 +28,9 @@ class AbstractInt final : public Castable { /// Constructor AbstractInt(); - /// Move constructor - AbstractInt(AbstractInt&&); + /// Destructor ~AbstractInt() override; - /// @returns a hash of the type. - size_t Hash() const override; - /// @param other the other node to compare against /// @returns true if the this type is equal to @p other bool Equals(const UniqueNode& other) const override; diff --git a/src/tint/type/abstract_numeric.cc b/src/tint/type/abstract_numeric.cc index 390488e252..838aa619a2 100644 --- a/src/tint/type/abstract_numeric.cc +++ b/src/tint/type/abstract_numeric.cc @@ -18,13 +18,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::AbstractNumeric); namespace tint::type { -AbstractNumeric::AbstractNumeric() - : Base(type::Flags{ - Flag::kConstructable, - Flag::kCreationFixedFootprint, - Flag::kFixedFootprint, - }) {} -AbstractNumeric::AbstractNumeric(AbstractNumeric&&) = default; +AbstractNumeric::AbstractNumeric(size_t hash) + : Base(hash, + type::Flags{ + Flag::kConstructable, + Flag::kCreationFixedFootprint, + Flag::kFixedFootprint, + }) {} AbstractNumeric::~AbstractNumeric() = default; uint32_t AbstractNumeric::Size() const { diff --git a/src/tint/type/abstract_numeric.h b/src/tint/type/abstract_numeric.h index 33cdac8f82..5b6b9f4dbf 100644 --- a/src/tint/type/abstract_numeric.h +++ b/src/tint/type/abstract_numeric.h @@ -26,10 +26,10 @@ namespace tint::type { class AbstractNumeric : public Castable { public: /// Constructor - AbstractNumeric(); + /// @param hash the unique hash of the node + explicit AbstractNumeric(size_t hash); - /// Move constructor - AbstractNumeric(AbstractNumeric&&); + /// Destructor ~AbstractNumeric() override; /// @returns 0, as the type is abstract. diff --git a/src/tint/type/array.cc b/src/tint/type/array.cc index 28f41d39f8..6df6cdc81f 100644 --- a/src/tint/type/array.cc +++ b/src/tint/type/array.cc @@ -58,7 +58,8 @@ Array::Array(const Type* element, uint32_t size, uint32_t stride, uint32_t implicit_stride) - : Base(FlagsFrom(element, count)), + : Base(utils::Hash(TypeInfo::Of().full_hashcode, count, align, size, stride), + FlagsFrom(element, count)), element_(element), count_(count), align_(align), @@ -68,10 +69,6 @@ Array::Array(const Type* element, TINT_ASSERT(Type, element_); } -size_t Array::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, count_, align_, size_, stride_); -} - bool Array::Equals(const UniqueNode& other) const { if (auto* o = other.As()) { // Note: implicit_stride is not part of the type_name string as this is diff --git a/src/tint/type/array.h b/src/tint/type/array.h index e77d2d99fc..18882a41f5 100644 --- a/src/tint/type/array.h +++ b/src/tint/type/array.h @@ -52,9 +52,6 @@ class Array final : public Castable { uint32_t stride, uint32_t implicit_stride); - /// @returns a hash of the type. - size_t Hash() const override; - /// @param other the other node to compare against /// @returns true if the this type is equal to @p other bool Equals(const UniqueNode& other) const override; diff --git a/src/tint/type/array_count.cc b/src/tint/type/array_count.cc index 9c6d4f6503..bebe8969cc 100644 --- a/src/tint/type/array_count.cc +++ b/src/tint/type/array_count.cc @@ -20,16 +20,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::RuntimeArrayCount); namespace tint::type { -ArrayCount::ArrayCount() : Base() {} +ArrayCount::ArrayCount(size_t hash) : Base(hash) {} ArrayCount::~ArrayCount() = default; -ConstantArrayCount::ConstantArrayCount(uint32_t val) : Base(), value(val) {} +ConstantArrayCount::ConstantArrayCount(uint32_t val) + : Base(static_cast(TypeInfo::Of().full_hashcode)), value(val) {} ConstantArrayCount::~ConstantArrayCount() = default; -size_t ConstantArrayCount::Hash() const { - return static_cast(TypeInfo::Of().full_hashcode); -} - bool ConstantArrayCount::Equals(const UniqueNode& other) const { if (auto* v = other.As()) { return value == v->value; @@ -41,13 +38,10 @@ std::string ConstantArrayCount::FriendlyName(const SymbolTable&) const { return std::to_string(value); } -RuntimeArrayCount::RuntimeArrayCount() : Base() {} +RuntimeArrayCount::RuntimeArrayCount() + : Base(static_cast(TypeInfo::Of().full_hashcode)) {} RuntimeArrayCount::~RuntimeArrayCount() = default; -size_t RuntimeArrayCount::Hash() const { - return static_cast(TypeInfo::Of().full_hashcode); -} - bool RuntimeArrayCount::Equals(const UniqueNode& other) const { return other.Is(); } diff --git a/src/tint/type/array_count.h b/src/tint/type/array_count.h index c3e59cbc1f..aa2c18201a 100644 --- a/src/tint/type/array_count.h +++ b/src/tint/type/array_count.h @@ -33,7 +33,9 @@ class ArrayCount : public Castable { virtual std::string FriendlyName(const SymbolTable& symbols) const = 0; protected: - ArrayCount(); + /// Constructor + /// @param hash the unique hash of the node + explicit ArrayCount(size_t hash); }; /// The variant of an ArrayCount when the array is a const-expression. @@ -49,9 +51,6 @@ class ConstantArrayCount final : public Castable explicit ConstantArrayCount(uint32_t val); ~ConstantArrayCount() override; - /// @returns a hash of the array count. - size_t Hash() const override; - /// @param other the other object /// @returns true if this array count is equal to other bool Equals(const UniqueNode& other) const override; @@ -75,9 +74,6 @@ class RuntimeArrayCount final : public Castable { RuntimeArrayCount(); ~RuntimeArrayCount() override; - /// @returns a hash of the array count. - size_t Hash() const override; - /// @param other the other object /// @returns true if this array count is equal to other bool Equals(const UniqueNode& other) const override; @@ -89,27 +85,4 @@ class RuntimeArrayCount final : public Castable { } // namespace tint::type -namespace std { - -/// std::hash specialization for tint::type::ArrayCount -template <> -struct hash { - /// @param a the array count to obtain a hash from - /// @returns the hash of the array count - size_t operator()(const tint::type::ArrayCount& a) const { return a.Hash(); } -}; - -/// std::equal_to specialization for tint::type::ArrayCount -template <> -struct equal_to { - /// @param a the first array count to compare - /// @param b the second array count to compare - /// @returns true if the two array counts are equal - bool operator()(const tint::type::ArrayCount& a, const tint::type::ArrayCount& b) const { - return a.Equals(b); - } -}; - -} // namespace std - #endif // SRC_TINT_TYPE_ARRAY_COUNT_H_ diff --git a/src/tint/type/array_test.cc b/src/tint/type/array_test.cc index cd4d5f137a..089b12ebad 100644 --- a/src/tint/type/array_test.cc +++ b/src/tint/type/array_test.cc @@ -75,7 +75,7 @@ TEST_F(ArrayTest, Hash) { auto* a = create(create(), create(2u), 4u, 8u, 32u, 16u); auto* b = create(create(), create(2u), 4u, 8u, 32u, 16u); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(ArrayTest, Equals) { diff --git a/src/tint/type/atomic.cc b/src/tint/type/atomic.cc index 5070dd9ae1..91efcd4150 100644 --- a/src/tint/type/atomic.cc +++ b/src/tint/type/atomic.cc @@ -23,18 +23,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Atomic); namespace tint::type { Atomic::Atomic(const type::Type* subtype) - : Base(type::Flags{ - Flag::kCreationFixedFootprint, - Flag::kFixedFootprint, - }), + : Base(utils::Hash(TypeInfo::Of().full_hashcode, subtype), + type::Flags{ + Flag::kCreationFixedFootprint, + Flag::kFixedFootprint, + }), subtype_(subtype) { TINT_ASSERT(AST, !subtype->Is()); } -size_t Atomic::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, subtype_); -} - bool Atomic::Equals(const type::UniqueNode& other) const { if (auto* o = other.As()) { return o->subtype_ == subtype_; @@ -56,8 +53,6 @@ uint32_t Atomic::Align() const { return subtype_->Align(); } -Atomic::Atomic(Atomic&&) = default; - Atomic::~Atomic() = default; } // namespace tint::type diff --git a/src/tint/type/atomic.h b/src/tint/type/atomic.h index fefc791177..31d1c5bbc8 100644 --- a/src/tint/type/atomic.h +++ b/src/tint/type/atomic.h @@ -28,13 +28,9 @@ class Atomic final : public Castable { /// @param subtype the atomic type explicit Atomic(const type::Type* subtype); - /// Move constructor - Atomic(Atomic&&); + /// Destructor ~Atomic() override; - /// @returns a hash of the type. - size_t Hash() const override; - /// @param other the other node to compare against /// @returns true if the this type is equal to @p other bool Equals(const type::UniqueNode& other) const override; diff --git a/src/tint/type/atomic_test.cc b/src/tint/type/atomic_test.cc index 740ce791b0..ed0bdecfa1 100644 --- a/src/tint/type/atomic_test.cc +++ b/src/tint/type/atomic_test.cc @@ -33,7 +33,7 @@ TEST_F(AtomicTest, Creation) { TEST_F(AtomicTest, Hash) { auto* a = create(create()); auto* b = create(create()); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(AtomicTest, Equals) { diff --git a/src/tint/type/bool.cc b/src/tint/type/bool.cc index 8c80c522d4..89c55a1835 100644 --- a/src/tint/type/bool.cc +++ b/src/tint/type/bool.cc @@ -21,20 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Bool); namespace tint::type { Bool::Bool() - : Base(type::Flags{ - Flag::kConstructable, - Flag::kCreationFixedFootprint, - Flag::kFixedFootprint, - }) {} - -Bool::Bool(Bool&&) = default; + : Base(static_cast(TypeInfo::Of().full_hashcode), + type::Flags{ + Flag::kConstructable, + Flag::kCreationFixedFootprint, + Flag::kFixedFootprint, + }) {} Bool::~Bool() = default; -size_t Bool::Hash() const { - return static_cast(TypeInfo::Of().full_hashcode); -} - bool Bool::Equals(const UniqueNode& other) const { return other.Is(); } diff --git a/src/tint/type/bool.h b/src/tint/type/bool.h index b14ec0a729..a33a352982 100644 --- a/src/tint/type/bool.h +++ b/src/tint/type/bool.h @@ -32,12 +32,9 @@ class Bool final : public Castable { public: /// Constructor Bool(); - /// Move constructor - Bool(Bool&&); - ~Bool() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~Bool() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other diff --git a/src/tint/type/bool_test.cc b/src/tint/type/bool_test.cc index 24b30140f4..d9b9d7a757 100644 --- a/src/tint/type/bool_test.cc +++ b/src/tint/type/bool_test.cc @@ -29,7 +29,7 @@ TEST_F(BoolTest, Creation) { TEST_F(BoolTest, Hash) { auto* a = create(); auto* b = create(); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(BoolTest, Equals) { diff --git a/src/tint/type/depth_multisampled_texture.cc b/src/tint/type/depth_multisampled_texture.cc index 271544c720..1313d70cff 100644 --- a/src/tint/type/depth_multisampled_texture.cc +++ b/src/tint/type/depth_multisampled_texture.cc @@ -28,18 +28,13 @@ bool IsValidDepthDimension(ast::TextureDimension dim) { } // namespace -DepthMultisampledTexture::DepthMultisampledTexture(ast::TextureDimension dim) : Base(dim) { +DepthMultisampledTexture::DepthMultisampledTexture(ast::TextureDimension dim) + : Base(utils::Hash(TypeInfo::Of().full_hashcode, dim), dim) { TINT_ASSERT(Type, IsValidDepthDimension(dim)); } -DepthMultisampledTexture::DepthMultisampledTexture(DepthMultisampledTexture&&) = default; - DepthMultisampledTexture::~DepthMultisampledTexture() = default; -size_t DepthMultisampledTexture::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, dim()); -} - bool DepthMultisampledTexture::Equals(const UniqueNode& other) const { if (auto* o = other.As()) { return o->dim() == dim(); diff --git a/src/tint/type/depth_multisampled_texture.h b/src/tint/type/depth_multisampled_texture.h index b54f5061af..f92a00da61 100644 --- a/src/tint/type/depth_multisampled_texture.h +++ b/src/tint/type/depth_multisampled_texture.h @@ -27,12 +27,9 @@ class DepthMultisampledTexture final : public Castable(ast::TextureDimension::k2d); auto* b = create(ast::TextureDimension::k2d); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(DepthMultisampledTextureTest, Equals) { diff --git a/src/tint/type/depth_texture.cc b/src/tint/type/depth_texture.cc index ab2f0285b9..c5d5aaeb37 100644 --- a/src/tint/type/depth_texture.cc +++ b/src/tint/type/depth_texture.cc @@ -29,18 +29,13 @@ bool IsValidDepthDimension(ast::TextureDimension dim) { } // namespace -DepthTexture::DepthTexture(ast::TextureDimension dim) : Base(dim) { +DepthTexture::DepthTexture(ast::TextureDimension dim) + : Base(utils::Hash(TypeInfo::Of().full_hashcode, dim), dim) { TINT_ASSERT(Type, IsValidDepthDimension(dim)); } -DepthTexture::DepthTexture(DepthTexture&&) = default; - DepthTexture::~DepthTexture() = default; -size_t DepthTexture::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, dim()); -} - bool DepthTexture::Equals(const UniqueNode& other) const { if (auto* o = other.As()) { return o->dim() == dim(); diff --git a/src/tint/type/depth_texture.h b/src/tint/type/depth_texture.h index db687c5d73..0e5bef396c 100644 --- a/src/tint/type/depth_texture.h +++ b/src/tint/type/depth_texture.h @@ -27,12 +27,9 @@ class DepthTexture final : public Castable { /// Constructor /// @param dim the dimensionality of the texture explicit DepthTexture(ast::TextureDimension dim); - /// Move constructor - DepthTexture(DepthTexture&&); - ~DepthTexture() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~DepthTexture() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other diff --git a/src/tint/type/depth_texture_test.cc b/src/tint/type/depth_texture_test.cc index 3b73af46c6..eab9ba891a 100644 --- a/src/tint/type/depth_texture_test.cc +++ b/src/tint/type/depth_texture_test.cc @@ -37,7 +37,7 @@ TEST_F(DepthTextureTest, Hash) { auto* a = create(ast::TextureDimension::k2d); auto* b = create(ast::TextureDimension::k2d); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(DepthTextureTest, Equals) { diff --git a/src/tint/type/external_texture.cc b/src/tint/type/external_texture.cc index 298f6b5008..9bc319c95b 100644 --- a/src/tint/type/external_texture.cc +++ b/src/tint/type/external_texture.cc @@ -20,16 +20,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::ExternalTexture); namespace tint::type { -ExternalTexture::ExternalTexture() : Base(ast::TextureDimension::k2d) {} - -ExternalTexture::ExternalTexture(ExternalTexture&&) = default; +ExternalTexture::ExternalTexture() + : Base(static_cast(TypeInfo::Of().full_hashcode), + ast::TextureDimension::k2d) {} ExternalTexture::~ExternalTexture() = default; -size_t ExternalTexture::Hash() const { - return static_cast(TypeInfo::Of().full_hashcode); -} - bool ExternalTexture::Equals(const UniqueNode& other) const { return other.Is(); } diff --git a/src/tint/type/external_texture.h b/src/tint/type/external_texture.h index 3afe9f643d..a60eddcae7 100644 --- a/src/tint/type/external_texture.h +++ b/src/tint/type/external_texture.h @@ -27,13 +27,9 @@ class ExternalTexture final : public Castable { /// Constructor ExternalTexture(); - /// Move constructor - ExternalTexture(ExternalTexture&&); + /// Destructor ~ExternalTexture() override; - /// @returns a hash of the type. - size_t Hash() const override; - /// @param other the other node to compare against /// @returns true if the this type is equal to @p other bool Equals(const UniqueNode& other) const override; diff --git a/src/tint/type/external_texture_test.cc b/src/tint/type/external_texture_test.cc index 5f54015f1d..d04b973b5a 100644 --- a/src/tint/type/external_texture_test.cc +++ b/src/tint/type/external_texture_test.cc @@ -34,7 +34,7 @@ TEST_F(ExternalTextureTest, Creation) { TEST_F(ExternalTextureTest, Hash) { auto* a = create(); auto* b = create(); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(ExternalTextureTest, Equals) { diff --git a/src/tint/type/f16.cc b/src/tint/type/f16.cc index 0cea348b8f..94849e5940 100644 --- a/src/tint/type/f16.cc +++ b/src/tint/type/f16.cc @@ -21,20 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::F16); namespace tint::type { F16::F16() - : Base(type::Flags{ - Flag::kConstructable, - Flag::kCreationFixedFootprint, - Flag::kFixedFootprint, - }) {} - -F16::F16(F16&&) = default; + : Base(static_cast(TypeInfo::Of().full_hashcode), + type::Flags{ + Flag::kConstructable, + Flag::kCreationFixedFootprint, + Flag::kFixedFootprint, + }) {} F16::~F16() = default; -size_t F16::Hash() const { - return static_cast(TypeInfo::Of().full_hashcode); -} - bool F16::Equals(const UniqueNode& other) const { return other.Is(); } diff --git a/src/tint/type/f16.h b/src/tint/type/f16.h index 71071e0df3..9cac21b86c 100644 --- a/src/tint/type/f16.h +++ b/src/tint/type/f16.h @@ -26,12 +26,9 @@ class F16 final : public Castable { public: /// Constructor F16(); - /// Move constructor - F16(F16&&); - ~F16() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~F16() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other diff --git a/src/tint/type/f16_test.cc b/src/tint/type/f16_test.cc index 4bd0529635..e4863805e0 100644 --- a/src/tint/type/f16_test.cc +++ b/src/tint/type/f16_test.cc @@ -29,7 +29,7 @@ TEST_F(F16Test, Creation) { TEST_F(F16Test, Hash) { auto* a = create(); auto* b = create(); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(F16Test, Equals) { diff --git a/src/tint/type/f32.cc b/src/tint/type/f32.cc index 5c7013996d..4ccd13a05a 100644 --- a/src/tint/type/f32.cc +++ b/src/tint/type/f32.cc @@ -21,20 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::F32); namespace tint::type { F32::F32() - : Base(type::Flags{ - Flag::kConstructable, - Flag::kCreationFixedFootprint, - Flag::kFixedFootprint, - }) {} - -F32::F32(F32&&) = default; + : Base(static_cast(TypeInfo::Of().full_hashcode), + type::Flags{ + Flag::kConstructable, + Flag::kCreationFixedFootprint, + Flag::kFixedFootprint, + }) {} F32::~F32() = default; -size_t F32::Hash() const { - return static_cast(TypeInfo::Of().full_hashcode); -} - bool F32::Equals(const UniqueNode& other) const { return other.Is(); } diff --git a/src/tint/type/f32.h b/src/tint/type/f32.h index 962beec117..7a1e864e3f 100644 --- a/src/tint/type/f32.h +++ b/src/tint/type/f32.h @@ -26,12 +26,9 @@ class F32 final : public Castable { public: /// Constructor F32(); - /// Move constructor - F32(F32&&); - ~F32() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~F32() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other diff --git a/src/tint/type/f32_test.cc b/src/tint/type/f32_test.cc index 127a34bb40..8ecbdbdcc7 100644 --- a/src/tint/type/f32_test.cc +++ b/src/tint/type/f32_test.cc @@ -29,7 +29,7 @@ TEST_F(F32Test, Creation) { TEST_F(F32Test, Hash) { auto* a = create(); auto* b = create(); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(F32Test, Equals) { diff --git a/src/tint/type/i32.cc b/src/tint/type/i32.cc index 80d7d8ee7b..c616d14a3e 100644 --- a/src/tint/type/i32.cc +++ b/src/tint/type/i32.cc @@ -21,20 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::I32); namespace tint::type { I32::I32() - : Base(type::Flags{ - Flag::kConstructable, - Flag::kCreationFixedFootprint, - Flag::kFixedFootprint, - }) {} - -I32::I32(I32&&) = default; + : Base(static_cast(TypeInfo::Of().full_hashcode), + type::Flags{ + Flag::kConstructable, + Flag::kCreationFixedFootprint, + Flag::kFixedFootprint, + }) {} I32::~I32() = default; -size_t I32::Hash() const { - return static_cast(TypeInfo::Of().full_hashcode); -} - bool I32::Equals(const UniqueNode& other) const { return other.Is(); } diff --git a/src/tint/type/i32.h b/src/tint/type/i32.h index 6cf9befacd..2160c3a48b 100644 --- a/src/tint/type/i32.h +++ b/src/tint/type/i32.h @@ -26,12 +26,9 @@ class I32 final : public Castable { public: /// Constructor I32(); - /// Move constructor - I32(I32&&); - ~I32() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~I32() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other diff --git a/src/tint/type/i32_test.cc b/src/tint/type/i32_test.cc index 7b45a03ec9..bdcbf8ed69 100644 --- a/src/tint/type/i32_test.cc +++ b/src/tint/type/i32_test.cc @@ -29,7 +29,7 @@ TEST_F(I32Test, Creation) { TEST_F(I32Test, Hash) { auto* a = create(); auto* b = create(); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(I32Test, Equals) { diff --git a/src/tint/type/matrix.cc b/src/tint/type/matrix.cc index db5380a624..0d7571fe6b 100644 --- a/src/tint/type/matrix.cc +++ b/src/tint/type/matrix.cc @@ -23,11 +23,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Matrix); namespace tint::type { Matrix::Matrix(const Vector* column_type, uint32_t columns) - : Base(type::Flags{ - Flag::kConstructable, - Flag::kCreationFixedFootprint, - Flag::kFixedFootprint, - }), + : Base(utils::Hash(TypeInfo::Of().full_hashcode, columns, column_type), + type::Flags{ + Flag::kConstructable, + Flag::kCreationFixedFootprint, + Flag::kFixedFootprint, + }), subtype_(column_type->type()), column_type_(column_type), rows_(column_type->Width()), @@ -38,14 +39,8 @@ Matrix::Matrix(const Vector* column_type, uint32_t columns) TINT_ASSERT(AST, columns_ < 5); } -Matrix::Matrix(Matrix&&) = default; - Matrix::~Matrix() = default; -size_t Matrix::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, rows_, columns_, column_type_); -} - bool Matrix::Equals(const UniqueNode& other) const { if (auto* v = other.As()) { return v->rows_ == rows_ && v->columns_ == columns_ && v->column_type_ == column_type_; diff --git a/src/tint/type/matrix.h b/src/tint/type/matrix.h index c4df065aa4..70555ea699 100644 --- a/src/tint/type/matrix.h +++ b/src/tint/type/matrix.h @@ -33,12 +33,9 @@ class Matrix final : public Castable { /// @param column_type the type of a column of the matrix /// @param columns the number of columns in the matrix Matrix(const Vector* column_type, uint32_t columns); - /// Move constructor - Matrix(Matrix&&); - ~Matrix() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~Matrix() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other diff --git a/src/tint/type/matrix_test.cc b/src/tint/type/matrix_test.cc index 7d88c6a1f2..3a7474128b 100644 --- a/src/tint/type/matrix_test.cc +++ b/src/tint/type/matrix_test.cc @@ -41,7 +41,7 @@ TEST_F(MatrixTest, Hash) { auto* a = create(create(create(), 3u), 4u); auto* b = create(create(create(), 3u), 4u); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(MatrixTest, Equals) { diff --git a/src/tint/type/multisampled_texture.cc b/src/tint/type/multisampled_texture.cc index ab1356a381..16588f4b14 100644 --- a/src/tint/type/multisampled_texture.cc +++ b/src/tint/type/multisampled_texture.cc @@ -22,18 +22,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::MultisampledTexture); namespace tint::type { MultisampledTexture::MultisampledTexture(ast::TextureDimension dim, const Type* type) - : Base(dim), type_(type) { + : Base(utils::Hash(TypeInfo::Of().full_hashcode, dim, type), dim), + type_(type) { TINT_ASSERT(Type, type_); } -MultisampledTexture::MultisampledTexture(MultisampledTexture&&) = default; - MultisampledTexture::~MultisampledTexture() = default; -size_t MultisampledTexture::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, dim(), type_); -} - bool MultisampledTexture::Equals(const UniqueNode& other) const { if (auto* o = other.As()) { return o->dim() == dim() && o->type_ == type_; diff --git a/src/tint/type/multisampled_texture.h b/src/tint/type/multisampled_texture.h index 410ecf42b3..f78d40b12f 100644 --- a/src/tint/type/multisampled_texture.h +++ b/src/tint/type/multisampled_texture.h @@ -28,12 +28,9 @@ class MultisampledTexture final : public Castable /// @param dim the dimensionality of the texture /// @param type the data type of the multisampled texture MultisampledTexture(ast::TextureDimension dim, const Type* type); - /// Move constructor - MultisampledTexture(MultisampledTexture&&); - ~MultisampledTexture() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~MultisampledTexture() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other diff --git a/src/tint/type/multisampled_texture_test.cc b/src/tint/type/multisampled_texture_test.cc index 8eac7c636a..e919ccf27b 100644 --- a/src/tint/type/multisampled_texture_test.cc +++ b/src/tint/type/multisampled_texture_test.cc @@ -38,7 +38,7 @@ TEST_F(MultisampledTextureTest, Creation) { TEST_F(MultisampledTextureTest, Hash) { auto* a = create(ast::TextureDimension::k2d, create()); auto* b = create(ast::TextureDimension::k2d, create()); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(MultisampledTextureTest, Equals) { diff --git a/src/tint/type/pointer.cc b/src/tint/type/pointer.cc index 00c3d225f7..0ae8e0ad41 100644 --- a/src/tint/type/pointer.cc +++ b/src/tint/type/pointer.cc @@ -23,15 +23,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Pointer); namespace tint::type { Pointer::Pointer(const Type* subtype, ast::AddressSpace address_space, ast::Access access) - : Base(type::Flags{}), subtype_(subtype), address_space_(address_space), access_(access) { + : Base(utils::Hash(TypeInfo::Of().full_hashcode, address_space, subtype, access), + type::Flags{}), + subtype_(subtype), + address_space_(address_space), + access_(access) { TINT_ASSERT(Type, !subtype->Is()); TINT_ASSERT(Type, access != ast::Access::kUndefined); } -size_t Pointer::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, address_space_, subtype_, access_); -} - bool Pointer::Equals(const UniqueNode& other) const { if (auto* o = other.As()) { return o->address_space_ == address_space_ && o->subtype_ == subtype_ && @@ -51,8 +51,6 @@ std::string Pointer::FriendlyName(const SymbolTable& symbols) const { return out.str(); } -Pointer::Pointer(Pointer&&) = default; - Pointer::~Pointer() = default; } // namespace tint::type diff --git a/src/tint/type/pointer.h b/src/tint/type/pointer.h index c7a7ef8034..3f7ff0191f 100644 --- a/src/tint/type/pointer.h +++ b/src/tint/type/pointer.h @@ -32,13 +32,9 @@ class Pointer final : public Castable { /// @param access the resolved access control of the reference Pointer(const Type* subtype, ast::AddressSpace address_space, ast::Access access); - /// Move constructor - Pointer(Pointer&&); + /// Destructor ~Pointer() override; - /// @returns a hash of the type. - size_t Hash() const override; - /// @param other the other node to compare against /// @returns true if the this type is equal to @p other bool Equals(const UniqueNode& other) const override; diff --git a/src/tint/type/pointer_test.cc b/src/tint/type/pointer_test.cc index ab51f7c02d..af3587a93d 100644 --- a/src/tint/type/pointer_test.cc +++ b/src/tint/type/pointer_test.cc @@ -41,7 +41,7 @@ TEST_F(PointerTest, Hash) { auto* a = create(create(), ast::AddressSpace::kStorage, ast::Access::kReadWrite); auto* b = create(create(), ast::AddressSpace::kStorage, ast::Access::kReadWrite); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(PointerTest, Equals) { diff --git a/src/tint/type/reference.cc b/src/tint/type/reference.cc index a825bb7914..f811b28a1b 100644 --- a/src/tint/type/reference.cc +++ b/src/tint/type/reference.cc @@ -22,15 +22,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Reference); namespace tint::type { Reference::Reference(const Type* subtype, ast::AddressSpace address_space, ast::Access access) - : Base(type::Flags{}), subtype_(subtype), address_space_(address_space), access_(access) { + : Base(utils::Hash(TypeInfo::Of().full_hashcode, address_space, subtype, access), + type::Flags{}), + subtype_(subtype), + address_space_(address_space), + access_(access) { TINT_ASSERT(Type, !subtype->Is()); TINT_ASSERT(Type, access != ast::Access::kUndefined); } -size_t Reference::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, address_space_, subtype_, access_); -} - bool Reference::Equals(const UniqueNode& other) const { if (auto* o = other.As()) { return o->address_space_ == address_space_ && o->subtype_ == subtype_ && @@ -50,8 +50,6 @@ std::string Reference::FriendlyName(const SymbolTable& symbols) const { return out.str(); } -Reference::Reference(Reference&&) = default; - Reference::~Reference() = default; } // namespace tint::type diff --git a/src/tint/type/reference.h b/src/tint/type/reference.h index 848c95d441..e13b3cf84a 100644 --- a/src/tint/type/reference.h +++ b/src/tint/type/reference.h @@ -32,13 +32,9 @@ class Reference final : public Castable { /// @param access the resolved access control of the reference Reference(const Type* subtype, ast::AddressSpace address_space, ast::Access access); - /// Move constructor - Reference(Reference&&); + /// Destructor ~Reference() override; - /// @returns a hash of the type. - size_t Hash() const override; - /// @param other the other node to compare against /// @returns true if the this type is equal to @p other bool Equals(const UniqueNode& other) const override; diff --git a/src/tint/type/reference_test.cc b/src/tint/type/reference_test.cc index 094770e37b..e9f61289a1 100644 --- a/src/tint/type/reference_test.cc +++ b/src/tint/type/reference_test.cc @@ -47,7 +47,7 @@ TEST_F(ReferenceTest, Hash) { auto* b = create(create(), ast::AddressSpace::kStorage, ast::Access::kReadWrite); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(ReferenceTest, Equals) { diff --git a/src/tint/type/sampled_texture.cc b/src/tint/type/sampled_texture.cc index b723d3afd6..a8bdce6929 100644 --- a/src/tint/type/sampled_texture.cc +++ b/src/tint/type/sampled_texture.cc @@ -22,18 +22,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::SampledTexture); namespace tint::type { SampledTexture::SampledTexture(ast::TextureDimension dim, const Type* type) - : Base(dim), type_(type) { + : Base(utils::Hash(TypeInfo::Of().full_hashcode, dim, type), dim), type_(type) { TINT_ASSERT(Type, type_); } -SampledTexture::SampledTexture(SampledTexture&&) = default; - SampledTexture::~SampledTexture() = default; -size_t SampledTexture::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, dim(), type_); -} - bool SampledTexture::Equals(const UniqueNode& other) const { if (auto* o = other.As()) { return o->dim() == dim() && o->type_ == type_; diff --git a/src/tint/type/sampled_texture.h b/src/tint/type/sampled_texture.h index d4f5fcce9a..527210218f 100644 --- a/src/tint/type/sampled_texture.h +++ b/src/tint/type/sampled_texture.h @@ -28,12 +28,9 @@ class SampledTexture final : public Castable { /// @param dim the dimensionality of the texture /// @param type the data type of the sampled texture SampledTexture(ast::TextureDimension dim, const Type* type); - /// Move constructor - SampledTexture(SampledTexture&&); - ~SampledTexture() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~SampledTexture() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other diff --git a/src/tint/type/sampled_texture_test.cc b/src/tint/type/sampled_texture_test.cc index f9cb5be900..772629f626 100644 --- a/src/tint/type/sampled_texture_test.cc +++ b/src/tint/type/sampled_texture_test.cc @@ -42,7 +42,7 @@ TEST_F(SampledTextureTest, Hash) { auto* a = create(ast::TextureDimension::kCube, create()); auto* b = create(ast::TextureDimension::kCube, create()); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(SampledTextureTest, Equals) { diff --git a/src/tint/type/sampler.cc b/src/tint/type/sampler.cc index 5a3c94549c..9de1ea83e9 100644 --- a/src/tint/type/sampler.cc +++ b/src/tint/type/sampler.cc @@ -21,16 +21,11 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Sampler); namespace tint::type { -Sampler::Sampler(ast::SamplerKind kind) : Base(type::Flags{}), kind_(kind) {} - -Sampler::Sampler(Sampler&&) = default; +Sampler::Sampler(ast::SamplerKind kind) + : Base(utils::Hash(TypeInfo::Of().full_hashcode, kind), type::Flags{}), kind_(kind) {} Sampler::~Sampler() = default; -size_t Sampler::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, kind_); -} - bool Sampler::Equals(const UniqueNode& other) const { if (auto* o = other.As()) { return o->kind_ == kind_; diff --git a/src/tint/type/sampler.h b/src/tint/type/sampler.h index 949d359702..7778dcd7a4 100644 --- a/src/tint/type/sampler.h +++ b/src/tint/type/sampler.h @@ -28,12 +28,9 @@ class Sampler final : public Castable { /// Constructor /// @param kind the kind of sampler explicit Sampler(ast::SamplerKind kind); - /// Move constructor - Sampler(Sampler&&); - ~Sampler() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~Sampler() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other diff --git a/src/tint/type/sampler_test.cc b/src/tint/type/sampler_test.cc index ba30541b12..262dd18de5 100644 --- a/src/tint/type/sampler_test.cc +++ b/src/tint/type/sampler_test.cc @@ -40,7 +40,7 @@ TEST_F(SamplerTest, Hash) { auto* a = create(ast::SamplerKind::kSampler); auto* b = create(ast::SamplerKind::kSampler); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(SamplerTest, Equals) { diff --git a/src/tint/type/storage_texture.cc b/src/tint/type/storage_texture.cc index b899deb3d2..ae574f19f2 100644 --- a/src/tint/type/storage_texture.cc +++ b/src/tint/type/storage_texture.cc @@ -25,16 +25,13 @@ StorageTexture::StorageTexture(ast::TextureDimension dim, ast::TexelFormat format, ast::Access access, Type* subtype) - : Base(dim), texel_format_(format), access_(access), subtype_(subtype) {} - -StorageTexture::StorageTexture(StorageTexture&&) = default; + : Base(utils::Hash(TypeInfo::Of().full_hashcode, dim, format, access), dim), + texel_format_(format), + access_(access), + subtype_(subtype) {} StorageTexture::~StorageTexture() = default; -size_t StorageTexture::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, dim(), texel_format_, access_); -} - bool StorageTexture::Equals(const UniqueNode& other) const { if (auto* o = other.As()) { return o->dim() == dim() && o->texel_format_ == texel_format_ && o->access_ == access_; diff --git a/src/tint/type/storage_texture.h b/src/tint/type/storage_texture.h index 2ff2d3b54c..25b452b2a8 100644 --- a/src/tint/type/storage_texture.h +++ b/src/tint/type/storage_texture.h @@ -41,13 +41,9 @@ class StorageTexture final : public Castable { ast::Access access, Type* subtype); - /// Move constructor - StorageTexture(StorageTexture&&); + /// Destructor ~StorageTexture() override; - /// @returns a hash of the type. - size_t Hash() const override; - /// @param other the other node to compare against /// @returns true if the this type is equal to @p other bool Equals(const UniqueNode& other) const override; diff --git a/src/tint/type/storage_texture_test.cc b/src/tint/type/storage_texture_test.cc index 0c86d890d6..30293ee3dd 100644 --- a/src/tint/type/storage_texture_test.cc +++ b/src/tint/type/storage_texture_test.cc @@ -56,7 +56,7 @@ TEST_F(StorageTextureTest, Hash) { auto* b = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(StorageTextureTest, Equals) { diff --git a/src/tint/type/struct.cc b/src/tint/type/struct.cc index d179eb9efc..f54f21f68b 100644 --- a/src/tint/type/struct.cc +++ b/src/tint/type/struct.cc @@ -56,7 +56,7 @@ Struct::Struct(tint::Source source, uint32_t align, uint32_t size, uint32_t size_no_padding) - : Base(FlagsFrom(members)), + : Base(utils::Hash(TypeInfo::Of().full_hashcode, name), FlagsFrom(members)), source_(source), name_(name), members_(std::move(members)), @@ -66,10 +66,6 @@ Struct::Struct(tint::Source source, Struct::~Struct() = default; -size_t Struct::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, name_); -} - bool Struct::Equals(const UniqueNode& other) const { if (auto* o = other.As()) { return o->name_ == name_; diff --git a/src/tint/type/struct.h b/src/tint/type/struct.h index aff433efda..ff23a89e2b 100644 --- a/src/tint/type/struct.h +++ b/src/tint/type/struct.h @@ -65,9 +65,6 @@ class Struct : public Castable { /// Destructor ~Struct() override; - /// @returns a hash of the type. - size_t Hash() const override; - /// @param other the other node to compare against /// @returns true if the this type is equal to @p other bool Equals(const UniqueNode& other) const override; diff --git a/src/tint/type/texture.cc b/src/tint/type/texture.cc index 0aa8549eee..57ce2650cf 100644 --- a/src/tint/type/texture.cc +++ b/src/tint/type/texture.cc @@ -18,9 +18,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Texture); namespace tint::type { -Texture::Texture(ast::TextureDimension dim) : Base(type::Flags{}), dim_(dim) {} - -Texture::Texture(Texture&&) = default; +Texture::Texture(size_t hash, ast::TextureDimension dim) : Base(hash, type::Flags{}), dim_(dim) {} Texture::~Texture() = default; diff --git a/src/tint/type/texture.h b/src/tint/type/texture.h index 4ce0120e0f..fc0f72da54 100644 --- a/src/tint/type/texture.h +++ b/src/tint/type/texture.h @@ -24,10 +24,10 @@ namespace tint::type { class Texture : public Castable { public: /// Constructor + /// @param hash the unique hash of the node /// @param dim the dimensionality of the texture - explicit Texture(ast::TextureDimension dim); - /// Move constructor - Texture(Texture&&); + Texture(size_t hash, ast::TextureDimension dim); + /// Destructor ~Texture() override; /// @returns the texture dimension diff --git a/src/tint/type/type.cc b/src/tint/type/type.cc index d7bccc0105..6163a9ab0c 100644 --- a/src/tint/type/type.cc +++ b/src/tint/type/type.cc @@ -34,14 +34,12 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Type); namespace tint::type { -Type::Type(type::Flags flags) : flags_(flags) { +Type::Type(size_t hash, type::Flags flags) : Base(hash), flags_(flags) { if (IsConstructible()) { TINT_ASSERT(Type, HasCreationFixedFootprint()); } } -Type::Type(Type&&) = default; - Type::~Type() = default; const Type* Type::UnwrapPtr() const { diff --git a/src/tint/type/type.h b/src/tint/type/type.h index 74cd61fac5..ccd0fe5b91 100644 --- a/src/tint/type/type.h +++ b/src/tint/type/type.h @@ -48,8 +48,7 @@ using Flags = utils::EnumSet; /// Base class for a type in the system class Type : public Castable { public: - /// Move constructor - Type(Type&&); + /// Destructor ~Type() override; /// @param symbols the program's symbol table @@ -187,8 +186,9 @@ class Type : public Castable { protected: /// Constructor + /// @param hash the immutable hash for the node /// @param flags the flags of this type - explicit Type(type::Flags flags); + Type(size_t hash, type::Flags flags); /// The flags of this type. const type::Flags flags_; @@ -203,7 +203,7 @@ template <> struct hash { /// @param type the type to obtain a hash from /// @returns the hash of the type - size_t operator()(const tint::type::Type& type) const { return type.Hash(); } + size_t operator()(const tint::type::Type& type) const { return type.unique_hash; } }; /// std::equal_to specialization for tint::type::Type diff --git a/src/tint/type/u32.cc b/src/tint/type/u32.cc index e9ae75de2d..34ae02763b 100644 --- a/src/tint/type/u32.cc +++ b/src/tint/type/u32.cc @@ -21,20 +21,15 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::U32); namespace tint::type { U32::U32() - : Base(type::Flags{ - Flag::kConstructable, - Flag::kCreationFixedFootprint, - Flag::kFixedFootprint, - }) {} + : Base(static_cast(TypeInfo::Of().full_hashcode), + type::Flags{ + Flag::kConstructable, + Flag::kCreationFixedFootprint, + Flag::kFixedFootprint, + }) {} U32::~U32() = default; -U32::U32(U32&&) = default; - -size_t U32::Hash() const { - return static_cast(TypeInfo::Of().full_hashcode); -} - bool U32::Equals(const UniqueNode& other) const { return other.Is(); } diff --git a/src/tint/type/u32.h b/src/tint/type/u32.h index 59b288b355..222a387463 100644 --- a/src/tint/type/u32.h +++ b/src/tint/type/u32.h @@ -26,12 +26,9 @@ class U32 final : public Castable { public: /// Constructor U32(); - /// Move constructor - U32(U32&&); - ~U32() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~U32() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other diff --git a/src/tint/type/u32_test.cc b/src/tint/type/u32_test.cc index 784b6d6c61..5ec5502298 100644 --- a/src/tint/type/u32_test.cc +++ b/src/tint/type/u32_test.cc @@ -29,7 +29,7 @@ TEST_F(U32Test, Creation) { TEST_F(U32Test, Hash) { auto* a = create(); auto* b = create(); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(U32Test, Equals) { diff --git a/src/tint/type/unique_node.cc b/src/tint/type/unique_node.cc index d52a6afe6a..280c98b442 100644 --- a/src/tint/type/unique_node.cc +++ b/src/tint/type/unique_node.cc @@ -18,10 +18,6 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::UniqueNode); namespace tint::type { -UniqueNode::UniqueNode() = default; - -UniqueNode::UniqueNode(const UniqueNode&) = default; - UniqueNode::~UniqueNode() = default; } // namespace tint::type diff --git a/src/tint/type/unique_node.h b/src/tint/type/unique_node.h index 84b22ce4b1..1fd6011240 100644 --- a/src/tint/type/unique_node.h +++ b/src/tint/type/unique_node.h @@ -28,20 +28,18 @@ namespace tint::type { class UniqueNode : public Castable { public: /// Constructor - UniqueNode(); - - /// Copy constructor - UniqueNode(const UniqueNode&); + /// @param hash the immutable hash for the node + inline explicit UniqueNode(size_t hash) : unique_hash(hash) {} /// Destructor ~UniqueNode() override; - /// @returns a hash of the node. - virtual size_t Hash() const = 0; - /// @param other the other node to compare this node against /// @returns true if the this node is equal to @p other virtual bool Equals(const UniqueNode& other) const = 0; + + /// the immutable hash for the node + const size_t unique_hash; }; } // namespace tint::type @@ -53,7 +51,7 @@ template <> struct hash { /// @param node the unique node to obtain a hash from /// @returns the hash of the node - size_t operator()(const tint::type::UniqueNode& node) const { return node.Hash(); } + size_t operator()(const tint::type::UniqueNode& node) const { return node.unique_hash; } }; /// std::equal_to specialization for tint::type::UniqueNode diff --git a/src/tint/type/vector.cc b/src/tint/type/vector.cc index 5e7a5c0fdc..a1f964e819 100644 --- a/src/tint/type/vector.cc +++ b/src/tint/type/vector.cc @@ -22,25 +22,20 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Vector); namespace tint::type { Vector::Vector(Type const* subtype, uint32_t width) - : Base(type::Flags{ - Flag::kConstructable, - Flag::kCreationFixedFootprint, - Flag::kFixedFootprint, - }), + : Base(utils::Hash(TypeInfo::Of().full_hashcode, width, subtype), + type::Flags{ + Flag::kConstructable, + Flag::kCreationFixedFootprint, + Flag::kFixedFootprint, + }), subtype_(subtype), width_(width) { TINT_ASSERT(Type, width_ > 1); TINT_ASSERT(Type, width_ < 5); } -Vector::Vector(Vector&&) = default; - Vector::~Vector() = default; -size_t Vector::Hash() const { - return utils::Hash(TypeInfo::Of().full_hashcode, width_, subtype_); -} - bool Vector::Equals(const UniqueNode& other) const { if (auto* v = other.As()) { return v->width_ == width_ && v->subtype_ == subtype_; diff --git a/src/tint/type/vector.h b/src/tint/type/vector.h index 6d171d7634..86f6f95613 100644 --- a/src/tint/type/vector.h +++ b/src/tint/type/vector.h @@ -28,12 +28,9 @@ class Vector final : public Castable { /// @param subtype the vector element type /// @param size the number of elements in the vector Vector(Type const* subtype, uint32_t size); - /// Move constructor - Vector(Vector&&); - ~Vector() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~Vector() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other diff --git a/src/tint/type/vector_test.cc b/src/tint/type/vector_test.cc index 65d7b1b420..2bd144e74f 100644 --- a/src/tint/type/vector_test.cc +++ b/src/tint/type/vector_test.cc @@ -38,7 +38,7 @@ TEST_F(VectorTest, Hash) { auto* a = create(create(), 2u); auto* b = create(create(), 2u); - EXPECT_EQ(a->Hash(), b->Hash()); + EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(VectorTest, Equals) { diff --git a/src/tint/type/void.cc b/src/tint/type/void.cc index 4f21f5cac5..352260719e 100644 --- a/src/tint/type/void.cc +++ b/src/tint/type/void.cc @@ -20,16 +20,10 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Void); namespace tint::type { -Void::Void() : Base(type::Flags{}) {} - -Void::Void(Void&&) = default; +Void::Void() : Base(static_cast(TypeInfo::Of().full_hashcode), type::Flags{}) {} Void::~Void() = default; -size_t Void::Hash() const { - return static_cast(TypeInfo::Of().full_hashcode); -} - bool Void::Equals(const UniqueNode& other) const { return other.Is(); } diff --git a/src/tint/type/void.h b/src/tint/type/void.h index 4fc0b98c3c..801a671ee3 100644 --- a/src/tint/type/void.h +++ b/src/tint/type/void.h @@ -26,12 +26,9 @@ class Void final : public Castable { public: /// Constructor Void(); - /// Move constructor - Void(Void&&); - ~Void() override; - /// @returns a hash of the type. - size_t Hash() const override; + /// Destructor + ~Void() override; /// @param other the other node to compare against /// @returns true if the this type is equal to @p other