tint: Replace type::UniqueNode::Hash() virtual with field
Virtual methods are expensive to call, and hashes are frequently tested.
The hash must be immutable, so just calculate it once in the constructor and store it as an immutable field.
Change-Id: I9d29fb3fc074e57e7af91367768a47193baa40f1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/114780
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/resolver/intrinsic_table.cc b/src/tint/resolver/intrinsic_table.cc
index a8d3f47..54c851d 100644
--- a/src/tint/resolver/intrinsic_table.cc
+++ b/src/tint/resolver/intrinsic_table.cc
@@ -57,11 +57,10 @@
/// A special type that matches all TypeMatchers
class Any final : public Castable<Any, type::Type> {
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 "<any>"; }
};
diff --git a/src/tint/sem/array_count.cc b/src/tint/sem/array_count.cc
index 1999877..a324ea5 100644
--- a/src/tint/sem/array_count.cc
+++ b/src/tint/sem/array_count.cc
@@ -20,13 +20,10 @@
namespace tint::sem {
NamedOverrideArrayCount::NamedOverrideArrayCount(const GlobalVariable* var)
- : Base(), variable(var) {}
+ : Base(static_cast<size_t>(TypeInfo::Of<NamedOverrideArrayCount>().full_hashcode)),
+ variable(var) {}
NamedOverrideArrayCount::~NamedOverrideArrayCount() = default;
-size_t NamedOverrideArrayCount::Hash() const {
- return static_cast<size_t>(TypeInfo::Of<NamedOverrideArrayCount>().full_hashcode);
-}
-
bool NamedOverrideArrayCount::Equals(const UniqueNode& other) const {
if (auto* v = other.As<NamedOverrideArrayCount>()) {
return variable == v->variable;
@@ -38,13 +35,10 @@
return symbols.NameFor(variable->Declaration()->symbol);
}
-UnnamedOverrideArrayCount::UnnamedOverrideArrayCount(const Expression* e) : Base(), expr(e) {}
+UnnamedOverrideArrayCount::UnnamedOverrideArrayCount(const Expression* e)
+ : Base(static_cast<size_t>(TypeInfo::Of<UnnamedOverrideArrayCount>().full_hashcode)), expr(e) {}
UnnamedOverrideArrayCount::~UnnamedOverrideArrayCount() = default;
-size_t UnnamedOverrideArrayCount::Hash() const {
- return static_cast<size_t>(TypeInfo::Of<UnnamedOverrideArrayCount>().full_hashcode);
-}
-
bool UnnamedOverrideArrayCount::Equals(const UniqueNode& other) const {
if (auto* v = other.As<UnnamedOverrideArrayCount>()) {
return expr == v->expr;
diff --git a/src/tint/sem/array_count.h b/src/tint/sem/array_count.h
index b30ab38..fd441e8 100644
--- a/src/tint/sem/array_count.h
+++ b/src/tint/sem/array_count.h
@@ -36,9 +36,6 @@
explicit NamedOverrideArrayCount(const GlobalVariable* var);
~NamedOverrideArrayCount() override;
- /// @returns a hash of the array count.
- size_t Hash() const override;
-
/// @param other the other node
/// @returns true if this array count is equal @p other
bool Equals(const type::UniqueNode& other) const override;
@@ -65,9 +62,6 @@
explicit UnnamedOverrideArrayCount(const Expression* e);
~UnnamedOverrideArrayCount() override;
- /// @returns a hash of the array count.
- size_t Hash() const override;
-
/// @param other the other node
/// @returns true if this array count is equal @p other
bool Equals(const type::UniqueNode& other) const override;
diff --git a/src/tint/type/abstract_float.cc b/src/tint/type/abstract_float.cc
index 2b01c27..443bb21 100644
--- a/src/tint/type/abstract_float.cc
+++ b/src/tint/type/abstract_float.cc
@@ -21,14 +21,9 @@
namespace tint::type {
-AbstractFloat::AbstractFloat() = default;
-AbstractFloat::AbstractFloat(AbstractFloat&&) = default;
+AbstractFloat::AbstractFloat() : Base(utils::Hash(TypeInfo::Of<AbstractFloat>().full_hashcode)) {}
AbstractFloat::~AbstractFloat() = default;
-size_t AbstractFloat::Hash() const {
- return utils::Hash(TypeInfo::Of<AbstractFloat>().full_hashcode);
-}
-
bool AbstractFloat::Equals(const UniqueNode& other) const {
return other.Is<AbstractFloat>();
}
diff --git a/src/tint/type/abstract_float.h b/src/tint/type/abstract_float.h
index d45ec73..9a7d4a8 100644
--- a/src/tint/type/abstract_float.h
+++ b/src/tint/type/abstract_float.h
@@ -28,13 +28,9 @@
/// 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 439c291..990d4e6 100644
--- a/src/tint/type/abstract_int.cc
+++ b/src/tint/type/abstract_int.cc
@@ -21,13 +21,9 @@
namespace tint::type {
-AbstractInt::AbstractInt() = default;
-AbstractInt::AbstractInt(AbstractInt&&) = default;
-AbstractInt::~AbstractInt() = default;
+AbstractInt::AbstractInt() : Base(utils::Hash(TypeInfo::Of<AbstractInt>().full_hashcode)) {}
-size_t AbstractInt::Hash() const {
- return utils::Hash(TypeInfo::Of<AbstractInt>().full_hashcode);
-}
+AbstractInt::~AbstractInt() = default;
bool AbstractInt::Equals(const UniqueNode& other) const {
return other.Is<AbstractInt>();
diff --git a/src/tint/type/abstract_int.h b/src/tint/type/abstract_int.h
index 98d878f..2df6328 100644
--- a/src/tint/type/abstract_int.h
+++ b/src/tint/type/abstract_int.h
@@ -28,13 +28,9 @@
/// 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 390488e..838aa61 100644
--- a/src/tint/type/abstract_numeric.cc
+++ b/src/tint/type/abstract_numeric.cc
@@ -18,13 +18,13 @@
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 33cdac8..5b6b9f4 100644
--- a/src/tint/type/abstract_numeric.h
+++ b/src/tint/type/abstract_numeric.h
@@ -26,10 +26,10 @@
class AbstractNumeric : public Castable<AbstractNumeric, Type> {
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 28f41d3..6df6cdc 100644
--- a/src/tint/type/array.cc
+++ b/src/tint/type/array.cc
@@ -58,7 +58,8 @@
uint32_t size,
uint32_t stride,
uint32_t implicit_stride)
- : Base(FlagsFrom(element, count)),
+ : Base(utils::Hash(TypeInfo::Of<Array>().full_hashcode, count, align, size, stride),
+ FlagsFrom(element, count)),
element_(element),
count_(count),
align_(align),
@@ -68,10 +69,6 @@
TINT_ASSERT(Type, element_);
}
-size_t Array::Hash() const {
- return utils::Hash(TypeInfo::Of<Array>().full_hashcode, count_, align_, size_, stride_);
-}
-
bool Array::Equals(const UniqueNode& other) const {
if (auto* o = other.As<Array>()) {
// 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 e77d2d9..18882a4 100644
--- a/src/tint/type/array.h
+++ b/src/tint/type/array.h
@@ -52,9 +52,6 @@
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 9c6d4f6..bebe896 100644
--- a/src/tint/type/array_count.cc
+++ b/src/tint/type/array_count.cc
@@ -20,16 +20,13 @@
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<size_t>(TypeInfo::Of<ConstantArrayCount>().full_hashcode)), value(val) {}
ConstantArrayCount::~ConstantArrayCount() = default;
-size_t ConstantArrayCount::Hash() const {
- return static_cast<size_t>(TypeInfo::Of<ConstantArrayCount>().full_hashcode);
-}
-
bool ConstantArrayCount::Equals(const UniqueNode& other) const {
if (auto* v = other.As<ConstantArrayCount>()) {
return value == v->value;
@@ -41,13 +38,10 @@
return std::to_string(value);
}
-RuntimeArrayCount::RuntimeArrayCount() : Base() {}
+RuntimeArrayCount::RuntimeArrayCount()
+ : Base(static_cast<size_t>(TypeInfo::Of<RuntimeArrayCount>().full_hashcode)) {}
RuntimeArrayCount::~RuntimeArrayCount() = default;
-size_t RuntimeArrayCount::Hash() const {
- return static_cast<size_t>(TypeInfo::Of<RuntimeArrayCount>().full_hashcode);
-}
-
bool RuntimeArrayCount::Equals(const UniqueNode& other) const {
return other.Is<RuntimeArrayCount>();
}
diff --git a/src/tint/type/array_count.h b/src/tint/type/array_count.h
index c3e59cb..aa2c182 100644
--- a/src/tint/type/array_count.h
+++ b/src/tint/type/array_count.h
@@ -33,7 +33,9 @@
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 @@
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 @@
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 @@
} // namespace tint::type
-namespace std {
-
-/// std::hash specialization for tint::type::ArrayCount
-template <>
-struct hash<tint::type::ArrayCount> {
- /// @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<tint::type::ArrayCount> {
- /// @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 cd4d5f1..089b12e 100644
--- a/src/tint/type/array_test.cc
+++ b/src/tint/type/array_test.cc
@@ -75,7 +75,7 @@
auto* a = create<Array>(create<U32>(), create<ConstantArrayCount>(2u), 4u, 8u, 32u, 16u);
auto* b = create<Array>(create<U32>(), create<ConstantArrayCount>(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 5070dd9..91efcd4 100644
--- a/src/tint/type/atomic.cc
+++ b/src/tint/type/atomic.cc
@@ -23,18 +23,15 @@
namespace tint::type {
Atomic::Atomic(const type::Type* subtype)
- : Base(type::Flags{
- Flag::kCreationFixedFootprint,
- Flag::kFixedFootprint,
- }),
+ : Base(utils::Hash(TypeInfo::Of<Atomic>().full_hashcode, subtype),
+ type::Flags{
+ Flag::kCreationFixedFootprint,
+ Flag::kFixedFootprint,
+ }),
subtype_(subtype) {
TINT_ASSERT(AST, !subtype->Is<Reference>());
}
-size_t Atomic::Hash() const {
- return utils::Hash(TypeInfo::Of<Atomic>().full_hashcode, subtype_);
-}
-
bool Atomic::Equals(const type::UniqueNode& other) const {
if (auto* o = other.As<Atomic>()) {
return o->subtype_ == subtype_;
@@ -56,8 +53,6 @@
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 fefc791..31d1c5b 100644
--- a/src/tint/type/atomic.h
+++ b/src/tint/type/atomic.h
@@ -28,13 +28,9 @@
/// @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 740ce79..ed0bdec 100644
--- a/src/tint/type/atomic_test.cc
+++ b/src/tint/type/atomic_test.cc
@@ -33,7 +33,7 @@
TEST_F(AtomicTest, Hash) {
auto* a = create<Atomic>(create<I32>());
auto* b = create<Atomic>(create<I32>());
- 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 8c80c52..89c55a1 100644
--- a/src/tint/type/bool.cc
+++ b/src/tint/type/bool.cc
@@ -21,20 +21,15 @@
namespace tint::type {
Bool::Bool()
- : Base(type::Flags{
- Flag::kConstructable,
- Flag::kCreationFixedFootprint,
- Flag::kFixedFootprint,
- }) {}
-
-Bool::Bool(Bool&&) = default;
+ : Base(static_cast<size_t>(TypeInfo::Of<Bool>().full_hashcode),
+ type::Flags{
+ Flag::kConstructable,
+ Flag::kCreationFixedFootprint,
+ Flag::kFixedFootprint,
+ }) {}
Bool::~Bool() = default;
-size_t Bool::Hash() const {
- return static_cast<size_t>(TypeInfo::Of<Bool>().full_hashcode);
-}
-
bool Bool::Equals(const UniqueNode& other) const {
return other.Is<Bool>();
}
diff --git a/src/tint/type/bool.h b/src/tint/type/bool.h
index b14ec0a..a33a352 100644
--- a/src/tint/type/bool.h
+++ b/src/tint/type/bool.h
@@ -32,12 +32,9 @@
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 24b3014..d9b9d7a 100644
--- a/src/tint/type/bool_test.cc
+++ b/src/tint/type/bool_test.cc
@@ -29,7 +29,7 @@
TEST_F(BoolTest, Hash) {
auto* a = create<Bool>();
auto* b = create<Bool>();
- 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 271544c..1313d70 100644
--- a/src/tint/type/depth_multisampled_texture.cc
+++ b/src/tint/type/depth_multisampled_texture.cc
@@ -28,18 +28,13 @@
} // namespace
-DepthMultisampledTexture::DepthMultisampledTexture(ast::TextureDimension dim) : Base(dim) {
+DepthMultisampledTexture::DepthMultisampledTexture(ast::TextureDimension dim)
+ : Base(utils::Hash(TypeInfo::Of<DepthMultisampledTexture>().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<DepthMultisampledTexture>().full_hashcode, dim());
-}
-
bool DepthMultisampledTexture::Equals(const UniqueNode& other) const {
if (auto* o = other.As<DepthMultisampledTexture>()) {
return o->dim() == dim();
diff --git a/src/tint/type/depth_multisampled_texture.h b/src/tint/type/depth_multisampled_texture.h
index b54f506..f92a00d 100644
--- a/src/tint/type/depth_multisampled_texture.h
+++ b/src/tint/type/depth_multisampled_texture.h
@@ -27,12 +27,9 @@
/// Constructor
/// @param dim the dimensionality of the texture
explicit DepthMultisampledTexture(ast::TextureDimension dim);
- /// Move constructor
- DepthMultisampledTexture(DepthMultisampledTexture&&);
- ~DepthMultisampledTexture() override;
- /// @returns a hash of the type.
- size_t Hash() const override;
+ /// Destructor
+ ~DepthMultisampledTexture() 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_multisampled_texture_test.cc b/src/tint/type/depth_multisampled_texture_test.cc
index 1a01e54..46897e5 100644
--- a/src/tint/type/depth_multisampled_texture_test.cc
+++ b/src/tint/type/depth_multisampled_texture_test.cc
@@ -35,7 +35,7 @@
auto* a = create<DepthMultisampledTexture>(ast::TextureDimension::k2d);
auto* b = create<DepthMultisampledTexture>(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 ab2f028..c5d5aae 100644
--- a/src/tint/type/depth_texture.cc
+++ b/src/tint/type/depth_texture.cc
@@ -29,18 +29,13 @@
} // namespace
-DepthTexture::DepthTexture(ast::TextureDimension dim) : Base(dim) {
+DepthTexture::DepthTexture(ast::TextureDimension dim)
+ : Base(utils::Hash(TypeInfo::Of<DepthTexture>().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<DepthTexture>().full_hashcode, dim());
-}
-
bool DepthTexture::Equals(const UniqueNode& other) const {
if (auto* o = other.As<DepthTexture>()) {
return o->dim() == dim();
diff --git a/src/tint/type/depth_texture.h b/src/tint/type/depth_texture.h
index db687c5..0e5bef3 100644
--- a/src/tint/type/depth_texture.h
+++ b/src/tint/type/depth_texture.h
@@ -27,12 +27,9 @@
/// 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 3b73af4..eab9ba8 100644
--- a/src/tint/type/depth_texture_test.cc
+++ b/src/tint/type/depth_texture_test.cc
@@ -37,7 +37,7 @@
auto* a = create<DepthTexture>(ast::TextureDimension::k2d);
auto* b = create<DepthTexture>(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 298f6b5..9bc319c 100644
--- a/src/tint/type/external_texture.cc
+++ b/src/tint/type/external_texture.cc
@@ -20,16 +20,12 @@
namespace tint::type {
-ExternalTexture::ExternalTexture() : Base(ast::TextureDimension::k2d) {}
-
-ExternalTexture::ExternalTexture(ExternalTexture&&) = default;
+ExternalTexture::ExternalTexture()
+ : Base(static_cast<size_t>(TypeInfo::Of<ExternalTexture>().full_hashcode),
+ ast::TextureDimension::k2d) {}
ExternalTexture::~ExternalTexture() = default;
-size_t ExternalTexture::Hash() const {
- return static_cast<size_t>(TypeInfo::Of<ExternalTexture>().full_hashcode);
-}
-
bool ExternalTexture::Equals(const UniqueNode& other) const {
return other.Is<ExternalTexture>();
}
diff --git a/src/tint/type/external_texture.h b/src/tint/type/external_texture.h
index 3afe9f6..a60eddc 100644
--- a/src/tint/type/external_texture.h
+++ b/src/tint/type/external_texture.h
@@ -27,13 +27,9 @@
/// 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 5f54015..d04b973 100644
--- a/src/tint/type/external_texture_test.cc
+++ b/src/tint/type/external_texture_test.cc
@@ -34,7 +34,7 @@
TEST_F(ExternalTextureTest, Hash) {
auto* a = create<ExternalTexture>();
auto* b = create<ExternalTexture>();
- 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 0cea348..94849e5 100644
--- a/src/tint/type/f16.cc
+++ b/src/tint/type/f16.cc
@@ -21,20 +21,15 @@
namespace tint::type {
F16::F16()
- : Base(type::Flags{
- Flag::kConstructable,
- Flag::kCreationFixedFootprint,
- Flag::kFixedFootprint,
- }) {}
-
-F16::F16(F16&&) = default;
+ : Base(static_cast<size_t>(TypeInfo::Of<F16>().full_hashcode),
+ type::Flags{
+ Flag::kConstructable,
+ Flag::kCreationFixedFootprint,
+ Flag::kFixedFootprint,
+ }) {}
F16::~F16() = default;
-size_t F16::Hash() const {
- return static_cast<size_t>(TypeInfo::Of<F16>().full_hashcode);
-}
-
bool F16::Equals(const UniqueNode& other) const {
return other.Is<F16>();
}
diff --git a/src/tint/type/f16.h b/src/tint/type/f16.h
index 71071e0..9cac21b 100644
--- a/src/tint/type/f16.h
+++ b/src/tint/type/f16.h
@@ -26,12 +26,9 @@
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 4bd0529..e486380 100644
--- a/src/tint/type/f16_test.cc
+++ b/src/tint/type/f16_test.cc
@@ -29,7 +29,7 @@
TEST_F(F16Test, Hash) {
auto* a = create<F16>();
auto* b = create<F16>();
- 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 5c70139..4ccd13a 100644
--- a/src/tint/type/f32.cc
+++ b/src/tint/type/f32.cc
@@ -21,20 +21,15 @@
namespace tint::type {
F32::F32()
- : Base(type::Flags{
- Flag::kConstructable,
- Flag::kCreationFixedFootprint,
- Flag::kFixedFootprint,
- }) {}
-
-F32::F32(F32&&) = default;
+ : Base(static_cast<size_t>(TypeInfo::Of<F32>().full_hashcode),
+ type::Flags{
+ Flag::kConstructable,
+ Flag::kCreationFixedFootprint,
+ Flag::kFixedFootprint,
+ }) {}
F32::~F32() = default;
-size_t F32::Hash() const {
- return static_cast<size_t>(TypeInfo::Of<F32>().full_hashcode);
-}
-
bool F32::Equals(const UniqueNode& other) const {
return other.Is<F32>();
}
diff --git a/src/tint/type/f32.h b/src/tint/type/f32.h
index 962beec..7a1e864 100644
--- a/src/tint/type/f32.h
+++ b/src/tint/type/f32.h
@@ -26,12 +26,9 @@
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 127a34b..8ecbdbd 100644
--- a/src/tint/type/f32_test.cc
+++ b/src/tint/type/f32_test.cc
@@ -29,7 +29,7 @@
TEST_F(F32Test, Hash) {
auto* a = create<F32>();
auto* b = create<F32>();
- 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 80d7d8e..c616d14 100644
--- a/src/tint/type/i32.cc
+++ b/src/tint/type/i32.cc
@@ -21,20 +21,15 @@
namespace tint::type {
I32::I32()
- : Base(type::Flags{
- Flag::kConstructable,
- Flag::kCreationFixedFootprint,
- Flag::kFixedFootprint,
- }) {}
-
-I32::I32(I32&&) = default;
+ : Base(static_cast<size_t>(TypeInfo::Of<I32>().full_hashcode),
+ type::Flags{
+ Flag::kConstructable,
+ Flag::kCreationFixedFootprint,
+ Flag::kFixedFootprint,
+ }) {}
I32::~I32() = default;
-size_t I32::Hash() const {
- return static_cast<size_t>(TypeInfo::Of<I32>().full_hashcode);
-}
-
bool I32::Equals(const UniqueNode& other) const {
return other.Is<I32>();
}
diff --git a/src/tint/type/i32.h b/src/tint/type/i32.h
index 6cf9bef..2160c3a 100644
--- a/src/tint/type/i32.h
+++ b/src/tint/type/i32.h
@@ -26,12 +26,9 @@
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 7b45a03e..bdcbf8e 100644
--- a/src/tint/type/i32_test.cc
+++ b/src/tint/type/i32_test.cc
@@ -29,7 +29,7 @@
TEST_F(I32Test, Hash) {
auto* a = create<I32>();
auto* b = create<I32>();
- 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 db5380a..0d7571f 100644
--- a/src/tint/type/matrix.cc
+++ b/src/tint/type/matrix.cc
@@ -23,11 +23,12 @@
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<Vector>().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 @@
TINT_ASSERT(AST, columns_ < 5);
}
-Matrix::Matrix(Matrix&&) = default;
-
Matrix::~Matrix() = default;
-size_t Matrix::Hash() const {
- return utils::Hash(TypeInfo::Of<Vector>().full_hashcode, rows_, columns_, column_type_);
-}
-
bool Matrix::Equals(const UniqueNode& other) const {
if (auto* v = other.As<Matrix>()) {
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 c4df065..70555ea 100644
--- a/src/tint/type/matrix.h
+++ b/src/tint/type/matrix.h
@@ -33,12 +33,9 @@
/// @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 7d88c6a..3a74741 100644
--- a/src/tint/type/matrix_test.cc
+++ b/src/tint/type/matrix_test.cc
@@ -41,7 +41,7 @@
auto* a = create<Matrix>(create<Vector>(create<I32>(), 3u), 4u);
auto* b = create<Matrix>(create<Vector>(create<I32>(), 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 ab1356a..16588f4 100644
--- a/src/tint/type/multisampled_texture.cc
+++ b/src/tint/type/multisampled_texture.cc
@@ -22,18 +22,13 @@
namespace tint::type {
MultisampledTexture::MultisampledTexture(ast::TextureDimension dim, const Type* type)
- : Base(dim), type_(type) {
+ : Base(utils::Hash(TypeInfo::Of<MultisampledTexture>().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<MultisampledTexture>().full_hashcode, dim(), type_);
-}
-
bool MultisampledTexture::Equals(const UniqueNode& other) const {
if (auto* o = other.As<MultisampledTexture>()) {
return o->dim() == dim() && o->type_ == type_;
diff --git a/src/tint/type/multisampled_texture.h b/src/tint/type/multisampled_texture.h
index 410ecf4..f78d40b 100644
--- a/src/tint/type/multisampled_texture.h
+++ b/src/tint/type/multisampled_texture.h
@@ -28,12 +28,9 @@
/// @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 8eac7c6..e919ccf 100644
--- a/src/tint/type/multisampled_texture_test.cc
+++ b/src/tint/type/multisampled_texture_test.cc
@@ -38,7 +38,7 @@
TEST_F(MultisampledTextureTest, Hash) {
auto* a = create<MultisampledTexture>(ast::TextureDimension::k2d, create<F32>());
auto* b = create<MultisampledTexture>(ast::TextureDimension::k2d, create<F32>());
- 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 00c3d22..0ae8e0a 100644
--- a/src/tint/type/pointer.cc
+++ b/src/tint/type/pointer.cc
@@ -23,15 +23,15 @@
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<Pointer>().full_hashcode, address_space, subtype, access),
+ type::Flags{}),
+ subtype_(subtype),
+ address_space_(address_space),
+ access_(access) {
TINT_ASSERT(Type, !subtype->Is<Reference>());
TINT_ASSERT(Type, access != ast::Access::kUndefined);
}
-size_t Pointer::Hash() const {
- return utils::Hash(TypeInfo::Of<Pointer>().full_hashcode, address_space_, subtype_, access_);
-}
-
bool Pointer::Equals(const UniqueNode& other) const {
if (auto* o = other.As<Pointer>()) {
return o->address_space_ == address_space_ && o->subtype_ == subtype_ &&
@@ -51,8 +51,6 @@
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 c7a7ef8..3f7ff01 100644
--- a/src/tint/type/pointer.h
+++ b/src/tint/type/pointer.h
@@ -32,13 +32,9 @@
/// @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 ab51f7c..af3587a 100644
--- a/src/tint/type/pointer_test.cc
+++ b/src/tint/type/pointer_test.cc
@@ -41,7 +41,7 @@
auto* a = create<Pointer>(create<I32>(), ast::AddressSpace::kStorage, ast::Access::kReadWrite);
auto* b = create<Pointer>(create<I32>(), 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 a825bb7..f811b28 100644
--- a/src/tint/type/reference.cc
+++ b/src/tint/type/reference.cc
@@ -22,15 +22,15 @@
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<Reference>().full_hashcode, address_space, subtype, access),
+ type::Flags{}),
+ subtype_(subtype),
+ address_space_(address_space),
+ access_(access) {
TINT_ASSERT(Type, !subtype->Is<Reference>());
TINT_ASSERT(Type, access != ast::Access::kUndefined);
}
-size_t Reference::Hash() const {
- return utils::Hash(TypeInfo::Of<Reference>().full_hashcode, address_space_, subtype_, access_);
-}
-
bool Reference::Equals(const UniqueNode& other) const {
if (auto* o = other.As<Reference>()) {
return o->address_space_ == address_space_ && o->subtype_ == subtype_ &&
@@ -50,8 +50,6 @@
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 848c95d..e13b3cf 100644
--- a/src/tint/type/reference.h
+++ b/src/tint/type/reference.h
@@ -32,13 +32,9 @@
/// @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 094770e..e9f6128 100644
--- a/src/tint/type/reference_test.cc
+++ b/src/tint/type/reference_test.cc
@@ -47,7 +47,7 @@
auto* b =
create<Reference>(create<I32>(), 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 b723d3a..a8bdce6 100644
--- a/src/tint/type/sampled_texture.cc
+++ b/src/tint/type/sampled_texture.cc
@@ -22,18 +22,12 @@
namespace tint::type {
SampledTexture::SampledTexture(ast::TextureDimension dim, const Type* type)
- : Base(dim), type_(type) {
+ : Base(utils::Hash(TypeInfo::Of<SampledTexture>().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<SampledTexture>().full_hashcode, dim(), type_);
-}
-
bool SampledTexture::Equals(const UniqueNode& other) const {
if (auto* o = other.As<SampledTexture>()) {
return o->dim() == dim() && o->type_ == type_;
diff --git a/src/tint/type/sampled_texture.h b/src/tint/type/sampled_texture.h
index d4f5fcc..5272102 100644
--- a/src/tint/type/sampled_texture.h
+++ b/src/tint/type/sampled_texture.h
@@ -28,12 +28,9 @@
/// @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 f9cb5be..772629f 100644
--- a/src/tint/type/sampled_texture_test.cc
+++ b/src/tint/type/sampled_texture_test.cc
@@ -42,7 +42,7 @@
auto* a = create<SampledTexture>(ast::TextureDimension::kCube, create<F32>());
auto* b = create<SampledTexture>(ast::TextureDimension::kCube, create<F32>());
- 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 5a3c945..9de1ea8 100644
--- a/src/tint/type/sampler.cc
+++ b/src/tint/type/sampler.cc
@@ -21,16 +21,11 @@
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<Sampler>().full_hashcode, kind), type::Flags{}), kind_(kind) {}
Sampler::~Sampler() = default;
-size_t Sampler::Hash() const {
- return utils::Hash(TypeInfo::Of<Sampler>().full_hashcode, kind_);
-}
-
bool Sampler::Equals(const UniqueNode& other) const {
if (auto* o = other.As<Sampler>()) {
return o->kind_ == kind_;
diff --git a/src/tint/type/sampler.h b/src/tint/type/sampler.h
index 949d359..7778dcd 100644
--- a/src/tint/type/sampler.h
+++ b/src/tint/type/sampler.h
@@ -28,12 +28,9 @@
/// 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 ba30541..262dd18 100644
--- a/src/tint/type/sampler_test.cc
+++ b/src/tint/type/sampler_test.cc
@@ -40,7 +40,7 @@
auto* a = create<Sampler>(ast::SamplerKind::kSampler);
auto* b = create<Sampler>(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 b899deb..ae574f1 100644
--- a/src/tint/type/storage_texture.cc
+++ b/src/tint/type/storage_texture.cc
@@ -25,16 +25,13 @@
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<StorageTexture>().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<StorageTexture>().full_hashcode, dim(), texel_format_, access_);
-}
-
bool StorageTexture::Equals(const UniqueNode& other) const {
if (auto* o = other.As<StorageTexture>()) {
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 2ff2d3b..25b452b 100644
--- a/src/tint/type/storage_texture.h
+++ b/src/tint/type/storage_texture.h
@@ -41,13 +41,9 @@
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 0c86d89..30293ee 100644
--- a/src/tint/type/storage_texture_test.cc
+++ b/src/tint/type/storage_texture_test.cc
@@ -56,7 +56,7 @@
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 d179eb9..f54f21f 100644
--- a/src/tint/type/struct.cc
+++ b/src/tint/type/struct.cc
@@ -56,7 +56,7 @@
uint32_t align,
uint32_t size,
uint32_t size_no_padding)
- : Base(FlagsFrom(members)),
+ : Base(utils::Hash(TypeInfo::Of<Struct>().full_hashcode, name), FlagsFrom(members)),
source_(source),
name_(name),
members_(std::move(members)),
@@ -66,10 +66,6 @@
Struct::~Struct() = default;
-size_t Struct::Hash() const {
- return utils::Hash(TypeInfo::Of<Struct>().full_hashcode, name_);
-}
-
bool Struct::Equals(const UniqueNode& other) const {
if (auto* o = other.As<Struct>()) {
return o->name_ == name_;
diff --git a/src/tint/type/struct.h b/src/tint/type/struct.h
index aff433e..ff23a89 100644
--- a/src/tint/type/struct.h
+++ b/src/tint/type/struct.h
@@ -65,9 +65,6 @@
/// 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 0aa8549..57ce265 100644
--- a/src/tint/type/texture.cc
+++ b/src/tint/type/texture.cc
@@ -18,9 +18,7 @@
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 4ce0120..fc0f72d 100644
--- a/src/tint/type/texture.h
+++ b/src/tint/type/texture.h
@@ -24,10 +24,10 @@
class Texture : public Castable<Texture, Type> {
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 d7bccc0..6163a9a 100644
--- a/src/tint/type/type.cc
+++ b/src/tint/type/type.cc
@@ -34,14 +34,12 @@
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 74cd61f..ccd0fe5 100644
--- a/src/tint/type/type.h
+++ b/src/tint/type/type.h
@@ -48,8 +48,7 @@
/// Base class for a type in the system
class Type : public Castable<Type, UniqueNode> {
public:
- /// Move constructor
- Type(Type&&);
+ /// Destructor
~Type() override;
/// @param symbols the program's symbol table
@@ -187,8 +186,9 @@
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 @@
struct hash<tint::type::Type> {
/// @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 e9ae75d..34ae027 100644
--- a/src/tint/type/u32.cc
+++ b/src/tint/type/u32.cc
@@ -21,20 +21,15 @@
namespace tint::type {
U32::U32()
- : Base(type::Flags{
- Flag::kConstructable,
- Flag::kCreationFixedFootprint,
- Flag::kFixedFootprint,
- }) {}
+ : Base(static_cast<size_t>(TypeInfo::Of<U32>().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<size_t>(TypeInfo::Of<U32>().full_hashcode);
-}
-
bool U32::Equals(const UniqueNode& other) const {
return other.Is<U32>();
}
diff --git a/src/tint/type/u32.h b/src/tint/type/u32.h
index 59b288b..222a387 100644
--- a/src/tint/type/u32.h
+++ b/src/tint/type/u32.h
@@ -26,12 +26,9 @@
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 784b6d6..5ec5502 100644
--- a/src/tint/type/u32_test.cc
+++ b/src/tint/type/u32_test.cc
@@ -29,7 +29,7 @@
TEST_F(U32Test, Hash) {
auto* a = create<U32>();
auto* b = create<U32>();
- 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 d52a6af..280c98b 100644
--- a/src/tint/type/unique_node.cc
+++ b/src/tint/type/unique_node.cc
@@ -18,10 +18,6 @@
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 84b22ce..1fd6011 100644
--- a/src/tint/type/unique_node.h
+++ b/src/tint/type/unique_node.h
@@ -28,20 +28,18 @@
class UniqueNode : public Castable<UniqueNode, Node> {
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 @@
struct hash<tint::type::UniqueNode> {
/// @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 5e7a5c0..a1f964e 100644
--- a/src/tint/type/vector.cc
+++ b/src/tint/type/vector.cc
@@ -22,25 +22,20 @@
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<Vector>().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<Vector>().full_hashcode, width_, subtype_);
-}
-
bool Vector::Equals(const UniqueNode& other) const {
if (auto* v = other.As<Vector>()) {
return v->width_ == width_ && v->subtype_ == subtype_;
diff --git a/src/tint/type/vector.h b/src/tint/type/vector.h
index 6d171d7..86f6f95 100644
--- a/src/tint/type/vector.h
+++ b/src/tint/type/vector.h
@@ -28,12 +28,9 @@
/// @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 65d7b1b..2bd144e 100644
--- a/src/tint/type/vector_test.cc
+++ b/src/tint/type/vector_test.cc
@@ -38,7 +38,7 @@
auto* a = create<Vector>(create<I32>(), 2u);
auto* b = create<Vector>(create<I32>(), 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 4f21f5c..3522607 100644
--- a/src/tint/type/void.cc
+++ b/src/tint/type/void.cc
@@ -20,16 +20,10 @@
namespace tint::type {
-Void::Void() : Base(type::Flags{}) {}
-
-Void::Void(Void&&) = default;
+Void::Void() : Base(static_cast<size_t>(TypeInfo::Of<Void>().full_hashcode), type::Flags{}) {}
Void::~Void() = default;
-size_t Void::Hash() const {
- return static_cast<size_t>(TypeInfo::Of<Void>().full_hashcode);
-}
-
bool Void::Equals(const UniqueNode& other) const {
return other.Is<Void>();
}
diff --git a/src/tint/type/void.h b/src/tint/type/void.h
index 4fc0b98..801a671 100644
--- a/src/tint/type/void.h
+++ b/src/tint/type/void.h
@@ -26,12 +26,9 @@
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