Skip to content

Commit f64f57d

Browse files
committed
[Parser] Use unreachables to fulfill tuple requirements
When we need to pop a tuple and the top value on the stack is unreachable, just pop the unreachable rather than producing a tuple.make. This always produces valid IR since an unreachable is always valid where a tuple would otherwise be expected. It also avoids bloating the parsed IR, since we would previously parse a `tuple.make` where all the children were unreachable in this case.
1 parent e30f3be commit f64f57d

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

src/wasm/wasm-ir-builder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ Result<Expression*> IRBuilder::pop(size_t size) {
175175
CHECK_ERR(packageHoistedValue(*hoisted, size));
176176

177177
auto* ret = scope.exprStack.back();
178-
if (ret->type.size() == size) {
178+
if (ret->type.size() == size || ret->type == Type::unreachable) {
179179
scope.exprStack.pop_back();
180180
return ret;
181181
}

test/lit/wat-kitchen-sink.wast

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3652,10 +3652,7 @@
36523652
;; CHECK-NEXT: (local.get $0)
36533653
;; CHECK-NEXT: )
36543654
;; CHECK-NEXT: (return
3655-
;; CHECK-NEXT: (tuple.make 2
3656-
;; CHECK-NEXT: (unreachable)
3657-
;; CHECK-NEXT: (unreachable)
3658-
;; CHECK-NEXT: )
3655+
;; CHECK-NEXT: (unreachable)
36593656
;; CHECK-NEXT: )
36603657
;; CHECK-NEXT: )
36613658
(func $return-two-second-unreachable (param i32) (result i32 i64)

0 commit comments

Comments
 (0)