Skip to content

[Wasm GC] Add support for non-nullable locals in binary reading #3955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,9 @@ void WasmBinaryBuilder::readFunctions() {
}
}

TypeUpdating::handleNonDefaultableLocals(func, wasm);
if (!wasm.features.hasGCNNLocals()) {
TypeUpdating::handleNonDefaultableLocals(func, wasm);
}

std::swap(func->epilogLocation, debugLocation);
currFunction = nullptr;
Expand Down Expand Up @@ -2560,14 +2562,16 @@ void WasmBinaryBuilder::pushExpression(Expression* curr) {
Builder builder(wasm);
// Non-nullable types require special handling as they cannot be stored to
// a local.
std::vector<Type> nullableTypes;
for (auto t : type) {
if (t.isRef() && !t.isNullable()) {
t = Type(t.getHeapType(), Nullable);
std::vector<Type> finalTypes;
if (!wasm.features.hasGCNNLocals()) {
for (auto t : type) {
if (t.isRef() && !t.isNullable()) {
t = Type(t.getHeapType(), Nullable);
}
finalTypes.push_back(t);
}
nullableTypes.push_back(t);
}
auto nullableType = Type(Tuple(nullableTypes));
auto nullableType = Type(Tuple(finalTypes));
Index tuple = builder.addVar(currFunction, nullableType);
expressionStack.push_back(builder.makeLocalSet(tuple, curr));
for (Index i = 0; i < nullableType.size(); ++i) {
Expand Down
4 changes: 3 additions & 1 deletion test/lit/passes/ssa-gc-nn-locals.wast
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
;; RUN: wasm-opt %s -all --ssa --enable-gc-nn-locals -S -o - | filecheck %s
;; -g --roundtrip are added to show that we properly handle non-nullable locals
;; through the binary format as well (-g is for the function names).
;; RUN: wasm-opt %s -all --ssa --enable-gc-nn-locals -g --roundtrip -S -o - | filecheck %s

(module
;; CHECK: (func $nn-locals
Expand Down