Skip to content

Commit 5bfb192

Browse files
authored
Parse non-nullable tuple elements without special handling (#5910)
In the binary parser, when creating a scratch local to hold multivalue results as tuples, we previously ensured that the scratch local did not contain any non-nullable by modifying its type and inserting ref.as_non_null as necessary. Now that we properly support non-nullable elements in tuple locals, however, this parser behavior is no longer necessary. Remove it.
1 parent e8adbdd commit 5bfb192

2 files changed

Lines changed: 8 additions & 28 deletions

File tree

src/wasm/wasm-binary.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,32 +3006,14 @@ void WasmBinaryReader::skipUnreachableCode() {
30063006
void WasmBinaryReader::pushExpression(Expression* curr) {
30073007
auto type = curr->type;
30083008
if (type.isTuple()) {
3009-
// Store tuple to local and push individual extracted values
3009+
// Store tuple to local and push individual extracted values.
30103010
Builder builder(wasm);
3011-
// Non-nullable types require special handling as they cannot be stored to
3012-
// a local, so we may need to use a different local type than the original.
3013-
auto localType = type;
3014-
if (!wasm.features.hasGCNNLocals()) {
3015-
std::vector<Type> finalTypes;
3016-
for (auto t : type) {
3017-
if (t.isNonNullable()) {
3018-
t = Type(t.getHeapType(), Nullable);
3019-
}
3020-
finalTypes.push_back(t);
3021-
}
3022-
localType = Type(Tuple(finalTypes));
3023-
}
30243011
requireFunctionContext("pushExpression-tuple");
3025-
Index tuple = builder.addVar(currFunction, localType);
3012+
Index tuple = builder.addVar(currFunction, type);
30263013
expressionStack.push_back(builder.makeLocalSet(tuple, curr));
3027-
for (Index i = 0; i < localType.size(); ++i) {
3028-
Expression* value =
3029-
builder.makeTupleExtract(builder.makeLocalGet(tuple, localType), i);
3030-
if (localType[i] != type[i]) {
3031-
// We modified this to be nullable; undo that.
3032-
value = builder.makeRefAs(RefAsNonNull, value);
3033-
}
3034-
expressionStack.push_back(value);
3014+
for (Index i = 0; i < type.size(); ++i) {
3015+
expressionStack.push_back(
3016+
builder.makeTupleExtract(builder.makeLocalGet(tuple, type), i));
30353017
}
30363018
} else {
30373019
expressionStack.push_back(curr);

test/lit/passes/roundtrip.wast

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
;; CHECK: (type $none (func))
66
(type $none (func))
77
;; CHECK: (func $foo (type $none)
8-
;; CHECK-NEXT: (local $0 (funcref (ref null $none)))
8+
;; CHECK-NEXT: (local $0 (funcref (ref $none)))
99
;; CHECK-NEXT: (local $1 funcref)
1010
;; CHECK-NEXT: (local.set $0
1111
;; CHECK-NEXT: (block $label$1 (result funcref (ref $none))
@@ -23,10 +23,8 @@
2323
;; CHECK-NEXT: )
2424
;; CHECK-NEXT: )
2525
;; CHECK-NEXT: (drop
26-
;; CHECK-NEXT: (ref.as_non_null
27-
;; CHECK-NEXT: (tuple.extract 1
28-
;; CHECK-NEXT: (local.get $0)
29-
;; CHECK-NEXT: )
26+
;; CHECK-NEXT: (tuple.extract 1
27+
;; CHECK-NEXT: (local.get $0)
3028
;; CHECK-NEXT: )
3129
;; CHECK-NEXT: )
3230
;; CHECK-NEXT: (local.get $1)

0 commit comments

Comments
 (0)