[tint][core] Fix return type of HashCode()
This must be size_t, which can be 32-bit depending on target architecture.
Fixes warnings about losing precision.
Change-Id: I874969043d00ce0f85e91260061c323cd0dbb92f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/160560
Auto-Submit: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/tint/lang/core/ir/transform/direct_variable_access.cc b/src/tint/lang/core/ir/transform/direct_variable_access.cc
index a13d1b9..6a264b9 100644
--- a/src/tint/lang/core/ir/transform/direct_variable_access.cc
+++ b/src/tint/lang/core/ir/transform/direct_variable_access.cc
@@ -53,7 +53,7 @@
Var* var = nullptr;
/// @return a hash value for this object
- uint64_t HashCode() const { return Hash(var); }
+ size_t HashCode() const { return Hash(var); }
/// Inequality operator
bool operator!=(const RootModuleScopeVar& other) const { return var != other.var; }
@@ -66,7 +66,7 @@
const type::Pointer* type = nullptr;
/// @return a hash value for this object
- uint64_t HashCode() const { return Hash(type); }
+ size_t HashCode() const { return Hash(type); }
/// Inequality operator
bool operator!=(const RootPtrParameter& other) const { return type != other.type; }
@@ -81,7 +81,7 @@
const type::StructMember* member;
/// @return a hash member for this object
- uint64_t HashCode() const { return Hash(member); }
+ size_t HashCode() const { return Hash(member); }
/// Inequality operator
bool operator!=(const MemberAccess& other) const { return member != other.member; }
@@ -91,7 +91,7 @@
/// The ordered list of indices is passed by parameter.
struct IndexAccess {
/// @return a hash value for this object
- uint64_t HashCode() const { return 42; }
+ size_t HashCode() const { return 42; }
/// Inequality operator
bool operator!=(const IndexAccess&) const { return false; }
@@ -166,7 +166,7 @@
}
/// @return a hash value for this object
- uint64_t HashCode() const { return Hash(root, ops); }
+ size_t HashCode() const { return Hash(root, ops); }
/// Inequality operator
bool operator!=(const AccessShape& other) const {
diff --git a/src/tint/utils/math/hash.h b/src/tint/utils/math/hash.h
index ac6bce9..e143d07 100644
--- a/src/tint/utils/math/hash.h
+++ b/src/tint/utils/math/hash.h
@@ -103,7 +103,10 @@
/// @returns a hash of the value
size_t operator()(const T& value) const {
if constexpr (detail::HasHashCodeMember<T>::value) {
- return value.HashCode();
+ auto hash = value.HashCode();
+ static_assert(std::is_same_v<decltype(hash), size_t>,
+ "T::HashCode() must return size_t");
+ return hash;
} else {
return std::hash<T>()(value);
}