diff options
author | Alon Zakai <azakai@google.com> | 2020-11-14 15:27:47 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-14 15:27:47 -0800 |
commit | c91c519cbb0a32e39e9a324cae611c5db0b66325 (patch) | |
tree | 80781651910f626968208653e970248e8ac3b537 | |
parent | 54612e4f28bc1c68606713b1a5483dcde02047b5 (diff) | |
download | binaryen-c91c519cbb0a32e39e9a324cae611c5db0b66325.tar.gz binaryen-c91c519cbb0a32e39e9a324cae611c5db0b66325.tar.bz2 binaryen-c91c519cbb0a32e39e9a324cae611c5db0b66325.zip |
[TypedFunctionReferences] Identify subtyping between funcref and all typed function references (#3357)
-rw-r--r-- | src/wasm/wasm-type.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp index cf68d92e9..f98077961 100644 --- a/src/wasm/wasm-type.cpp +++ b/src/wasm/wasm-type.cpp @@ -521,8 +521,21 @@ bool Type::isSubType(Type left, Type right) { return true; } if (left.isRef() && right.isRef()) { - return right == Type::anyref || - (left == Type::i31ref && right == Type::eqref); + // Everything is a subtype of anyref. + if (right == Type::anyref) { + return true; + } + // Various things are subtypes of eqref. + if ((left == Type::i31ref || left.getHeapType().isArray() || + left.getHeapType().isStruct()) && + right == Type::eqref) { + return true; + } + // All typed function signatures are subtypes of funcref. + if (left.getHeapType().isSignature() && right == Type::funcref) { + return true; + } + return false; } if (left.isTuple() && right.isTuple()) { if (left.size() != right.size()) { |