summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-09-30 16:57:55 -0700
committerGitHub <noreply@github.com>2022-09-30 23:57:55 +0000
commita697046975cb2f952d7cc1e67474f7cd000ed027 (patch)
tree854ef0dd8ac21123821503e37d0931d220e9187e /src/wasm
parent2055ea3fd0391c1abb92cdec54f32274dc7fd971 (diff)
downloadbinaryen-a697046975cb2f952d7cc1e67474f7cd000ed027.tar.gz
binaryen-a697046975cb2f952d7cc1e67474f7cd000ed027.tar.bz2
binaryen-a697046975cb2f952d7cc1e67474f7cd000ed027.zip
[Wasm GC] Fix .depth() and add testing (#5102)
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-type.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index c77099a1d..d24e42acb 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -1392,6 +1392,36 @@ size_t HeapType::getDepth() const {
for (auto curr = *this; (super = curr.getSuperType()); curr = *super) {
++depth;
}
+ // In addition to the explicit supertypes we just traversed over, there is
+ // implicit supertyping wrt basic types. A signature type always has one more
+ // super, HeapType::func, etc.
+ if (!isBasic()) {
+ if (isFunction()) {
+ depth++;
+ } else if (isData()) {
+ // specific struct types <: data <: eq <: any
+ depth += 3;
+ }
+ } else {
+ // Some basic types have supers.
+ switch (getBasic()) {
+ case HeapType::ext:
+ case HeapType::func:
+ case HeapType::any:
+ break;
+ case HeapType::eq:
+ depth++;
+ break;
+ case HeapType::i31:
+ case HeapType::data:
+ case HeapType::string:
+ case HeapType::stringview_wtf8:
+ case HeapType::stringview_wtf16:
+ case HeapType::stringview_iter:
+ depth += 2;
+ break;
+ }
+ }
return depth;
}