diff options
author | Alon Zakai <azakai@google.com> | 2021-03-23 14:23:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-23 14:23:43 -0700 |
commit | f2abcbc8d1659d3e6506b1d4128646b892ebc218 (patch) | |
tree | 30bb82cc27bc26df7cb32b889176605c54b9a0b3 /src/wasm/wasm-s-parser.cpp | |
parent | 5ef255154172504385a8218f9712a48d98a47689 (diff) | |
download | binaryen-f2abcbc8d1659d3e6506b1d4128646b892ebc218.tar.gz binaryen-f2abcbc8d1659d3e6506b1d4128646b892ebc218.tar.bz2 binaryen-f2abcbc8d1659d3e6506b1d4128646b892ebc218.zip |
[Wasm GC] Add support for non-nullable types, all except for locals (#3710)
After this PR we still do not support non-nullable locals. But we no longer
turn all types into nullable upon load. In particular, we support non-nullable
types on function parameters and struct fields, etc. This should be enough to
experiment with optimizations in both binaryen and in VMs regarding non-
nullability (since we expect that optimizing VMs can do well inside functions
anyhow; it's non-nullability across calls and from data that the VM can't be
expected to think about).
Let is handled as before, by lowering it into gets and sets. In addition, we
turn non-nullable locals into nullable ones, and add a ref.as_non_null on
all their gets (to keep the type identical there). This is used not just for
loading code with a let but also is needed after inlining.
Most of the code changes here are removing FIXMEs for allowing
non-nullable types. But there is also code to handle the issues mentioned
above.
Most of the test updates are removing extra nulls that we added before
when we turned all types nullable. A few tests had actual issues, though,
and also some new tests are added to cover the code changes here.
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 91ed5056f..45c7c9161 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -686,22 +686,20 @@ void SExpressionWasmBuilder::preParseHeapTypes(Element& module) { auto parseRefType = [&](Element& elem) -> Type { // '(' 'ref' 'null'? ht ')' - bool nullable = elem[1]->isStr() && *elem[1] == NULL_; + auto nullable = + elem[1]->isStr() && *elem[1] == NULL_ ? Nullable : NonNullable; auto& referent = nullable ? *elem[2] : *elem[1]; const char* name = referent.c_str(); if (referent.dollared()) { - // TODO: Support non-nullable types - return builder.getTempRefType(typeIndices[name], Nullable); + return builder.getTempRefType(typeIndices[name], nullable); } else if (String::isNumber(name)) { - // TODO: Support non-nullable types size_t index = atoi(name); if (index >= numTypes) { throw ParseException("invalid type index", elem.line, elem.col); } - return builder.getTempRefType(index, Nullable); + return builder.getTempRefType(index, nullable); } else { - // TODO: Support non-nullable types - return Type(stringToHeapType(name), Nullable); + return Type(stringToHeapType(name), nullable); } }; @@ -1091,12 +1089,10 @@ Type SExpressionWasmBuilder::stringToType(const char* str, return Type::eqref; } if (strncmp(str, "i31ref", 6) == 0 && (prefix || str[6] == 0)) { - // FIXME: for now, force all inputs to be nullable - return Type(HeapType::BasicHeapType::i31, Nullable); + return Type::i31ref; } if (strncmp(str, "dataref", 7) == 0 && (prefix || str[7] == 0)) { - // FIXME: for now, force all inputs to be nullable - return Type(HeapType::BasicHeapType::data, Nullable); + return Type::dataref; } if (allowError) { return Type::none; @@ -1161,8 +1157,7 @@ Type SExpressionWasmBuilder::elementToType(Element& s) { throw ParseException( std::string("invalid reference type qualifier"), s.line, s.col); } - // FIXME: for now, force all inputs to be nullable - Nullability nullable = Nullable; + Nullability nullable = NonNullable; size_t i = 1; if (size == 3) { nullable = Nullable; @@ -2385,7 +2380,7 @@ Expression* SExpressionWasmBuilder::makeRefFunc(Element& s) { ret->func = func; // To support typed function refs, we give the reference not just a general // funcref, but a specific subtype with the actual signature. - ret->finalize(Type(HeapType(functionSignatures[func]), Nullable)); + ret->finalize(Type(HeapType(functionSignatures[func]), NonNullable)); return ret; } |