diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2021-12-14 12:27:04 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-14 12:27:04 -0800 |
commit | e5594bbde36ac96b6f2a41259d8a8d66e5d0a7cc (patch) | |
tree | e1b9c6b9dc53b4b6560eb376db47a97f29ce264b /src | |
parent | de3847140bce792a75a2f167b9c4e2aa107719c5 (diff) | |
download | binaryen-e5594bbde36ac96b6f2a41259d8a8d66e5d0a7cc.tar.gz binaryen-e5594bbde36ac96b6f2a41259d8a8d66e5d0a7cc.tar.bz2 binaryen-e5594bbde36ac96b6f2a41259d8a8d66e5d0a7cc.zip |
[NFC] Simplify HeapTypeInfo hashing and comparison (#4394)
Now that caching of "canonical" nominal signatures is handled at a separate
layer, we can remove the separate code paths for hashing and comparing
HeapTypeInfos based on their structure even in nominal mode. Now hashing and
comparing of HeapTypeInfos is uniformly handled by FiniteShapeHasher and
FiniteShapeEquator.
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm/wasm-type.cpp | 51 |
1 files changed, 4 insertions, 47 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index f0c444da9..b2f50bfbf 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -630,32 +630,7 @@ HeapTypeInfo& HeapTypeInfo::operator=(const HeapTypeInfo& other) { } bool HeapTypeInfo::operator==(const HeapTypeInfo& other) const { - if (isNominal != other.isNominal) { - return false; - } - - // Structural HeapTypeInfos with the same shape are considered equivalent. - // This is important during global canonicalization, when newly created - // canonically-shaped graphs are checked against the existing globally - // canonical graphs. - if (!isNominal && typeSystem == TypeSystem::Equirecursive) { - return FiniteShapeEquator().eq(*this, other); - } - - if (kind != other.kind) { - return false; - } - switch (kind) { - case wasm::HeapTypeInfo::BasicKind: - return basic == other.basic; - case wasm::HeapTypeInfo::SignatureKind: - return signature == other.signature; - case wasm::HeapTypeInfo::StructKind: - return struct_ == other.struct_; - case wasm::HeapTypeInfo::ArrayKind: - return array == other.array; - } - WASM_UNREACHABLE("unexpected kind"); + return FiniteShapeEquator().eq(*this, other); } template<typename Info> struct Store { @@ -1976,7 +1951,7 @@ size_t FiniteShapeHasher::hash(const TypeInfo& info) { size_t FiniteShapeHasher::hash(const HeapTypeInfo& info) { size_t digest = wasm::hash(info.isNominal); - if (info.isNominal) { + if (info.isNominal || getTypeSystem() == TypeSystem::Nominal) { rehash(digest, uintptr_t(&info)); return digest; } @@ -2100,7 +2075,7 @@ bool FiniteShapeEquator::eq(const TypeInfo& a, const TypeInfo& b) { bool FiniteShapeEquator::eq(const HeapTypeInfo& a, const HeapTypeInfo& b) { if (a.isNominal != b.isNominal) { return false; - } else if (a.isNominal) { + } else if (a.isNominal || getTypeSystem() == TypeSystem::Nominal) { return &a == &b; } if (a.isFinalized != b.isFinalized) { @@ -3367,25 +3342,7 @@ size_t hash<wasm::TypeInfo>::operator()(const wasm::TypeInfo& info) const { size_t hash<wasm::HeapTypeInfo>::operator()(const wasm::HeapTypeInfo& info) const { - if (wasm::typeSystem == wasm::TypeSystem::Equirecursive) { - return wasm::FiniteShapeHasher().hash(info); - } - - auto digest = wasm::hash(info.kind); - switch (info.kind) { - case wasm::HeapTypeInfo::BasicKind: - WASM_UNREACHABLE("Basic HeapTypeInfo should have been canonicalized"); - case wasm::HeapTypeInfo::SignatureKind: - wasm::rehash(digest, info.signature); - return digest; - case wasm::HeapTypeInfo::StructKind: - wasm::rehash(digest, info.struct_); - return digest; - case wasm::HeapTypeInfo::ArrayKind: - wasm::rehash(digest, info.array); - return digest; - } - WASM_UNREACHABLE("unexpected kind"); + return wasm::FiniteShapeHasher().hash(info); } } // namespace std |