diff options
Diffstat (limited to 'src/passes')
-rw-r--r-- | src/passes/TypeMerging.cpp | 51 | ||||
-rw-r--r-- | src/passes/TypeSSA.cpp | 17 | ||||
-rw-r--r-- | src/passes/Unsubtyping.cpp | 38 |
3 files changed, 67 insertions, 39 deletions
diff --git a/src/passes/TypeMerging.cpp b/src/passes/TypeMerging.cpp index e5ac7888b..1cac7732f 100644 --- a/src/passes/TypeMerging.cpp +++ b/src/passes/TypeMerging.cpp @@ -544,14 +544,22 @@ bool shapeEq(HeapType a, HeapType b) { if (a.isShared() != b.isShared()) { return false; } - if (a.isStruct() && b.isStruct()) { - return shapeEq(a.getStruct(), b.getStruct()); - } - if (a.isArray() && b.isArray()) { - return shapeEq(a.getArray(), b.getArray()); + auto aKind = a.getKind(); + auto bKind = b.getKind(); + if (aKind != bKind) { + return false; } - if (a.isSignature() && b.isSignature()) { - return shapeEq(a.getSignature(), b.getSignature()); + switch (aKind) { + case HeapTypeKind::Func: + return shapeEq(a.getSignature(), b.getSignature()); + case HeapTypeKind::Struct: + return shapeEq(a.getStruct(), b.getStruct()); + case HeapTypeKind::Array: + return shapeEq(a.getArray(), b.getArray()); + case HeapTypeKind::Cont: + WASM_UNREACHABLE("TODO: cont"); + case HeapTypeKind::Basic: + WASM_UNREACHABLE("unexpected kind"); } return false; } @@ -559,19 +567,24 @@ bool shapeEq(HeapType a, HeapType b) { size_t shapeHash(HeapType a) { size_t digest = hash(a.isOpen()); rehash(digest, a.isShared()); - if (a.isStruct()) { - rehash(digest, 0); - hash_combine(digest, shapeHash(a.getStruct())); - } else if (a.isArray()) { - rehash(digest, 1); - hash_combine(digest, shapeHash(a.getArray())); - } else if (a.isSignature()) { - rehash(digest, 2); - hash_combine(digest, shapeHash(a.getSignature())); - } else { - WASM_UNREACHABLE("unexpected kind"); + auto kind = a.getKind(); + rehash(digest, kind); + switch (kind) { + case HeapTypeKind::Func: + hash_combine(digest, shapeHash(a.getSignature())); + return digest; + case HeapTypeKind::Struct: + hash_combine(digest, shapeHash(a.getStruct())); + return digest; + case HeapTypeKind::Array: + hash_combine(digest, shapeHash(a.getArray())); + return digest; + case HeapTypeKind::Cont: + WASM_UNREACHABLE("TODO: cont"); + case HeapTypeKind::Basic: + break; } - return digest; + WASM_UNREACHABLE("unexpected kind"); } bool shapeEq(const Struct& a, const Struct& b) { diff --git a/src/passes/TypeSSA.cpp b/src/passes/TypeSSA.cpp index 1355b113e..8ba6c10c4 100644 --- a/src/passes/TypeSSA.cpp +++ b/src/passes/TypeSSA.cpp @@ -237,12 +237,17 @@ struct TypeSSA : public Pass { for (Index i = 0; i < num; i++) { auto* curr = newsToModify[i]; auto oldType = curr->type.getHeapType(); - if (oldType.isStruct()) { - builder[i] = oldType.getStruct(); - } else if (oldType.isArray()) { - builder[i] = oldType.getArray(); - } else { - WASM_UNREACHABLE("unexpected type kind"); + switch (oldType.getKind()) { + case HeapTypeKind::Struct: + builder[i] = oldType.getStruct(); + break; + case HeapTypeKind::Array: + builder[i] = oldType.getArray(); + break; + case HeapTypeKind::Func: + case HeapTypeKind::Cont: + case HeapTypeKind::Basic: + WASM_UNREACHABLE("unexpected kind"); } builder[i].subTypeOf(oldType); builder[i].setShared(oldType.getShared()); diff --git a/src/passes/Unsubtyping.cpp b/src/passes/Unsubtyping.cpp index ccad4ed3d..8d76f348a 100644 --- a/src/passes/Unsubtyping.cpp +++ b/src/passes/Unsubtyping.cpp @@ -264,21 +264,31 @@ struct Unsubtyping if (super.isBasic()) { continue; } - if (type.isStruct()) { - const auto& fields = type.getStruct().fields; - const auto& superFields = super.getStruct().fields; - for (size_t i = 0, size = superFields.size(); i < size; ++i) { - noteSubtype(fields[i].type, superFields[i].type); + switch (type.getKind()) { + case HeapTypeKind::Func: { + auto sig = type.getSignature(); + auto superSig = super.getSignature(); + noteSubtype(superSig.params, sig.params); + noteSubtype(sig.results, superSig.results); + break; } - } else if (type.isArray()) { - auto elem = type.getArray().element; - noteSubtype(elem.type, super.getArray().element.type); - } else { - assert(type.isSignature()); - auto sig = type.getSignature(); - auto superSig = super.getSignature(); - noteSubtype(superSig.params, sig.params); - noteSubtype(sig.results, superSig.results); + case HeapTypeKind::Struct: { + const auto& fields = type.getStruct().fields; + const auto& superFields = super.getStruct().fields; + for (size_t i = 0, size = superFields.size(); i < size; ++i) { + noteSubtype(fields[i].type, superFields[i].type); + } + break; + } + case HeapTypeKind::Array: { + auto elem = type.getArray().element; + noteSubtype(elem.type, super.getArray().element.type); + break; + } + case HeapTypeKind::Cont: + WASM_UNREACHABLE("TODO: cont"); + case HeapTypeKind::Basic: + WASM_UNREACHABLE("unexpected kind"); } } |