Skip to content
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
7 changes: 6 additions & 1 deletion src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
// Print out text in s-expression format
//

#include <algorithm>

#include <ir/iteration.h>
#include <ir/module-utils.h>
#include <ir/table-utils.h>
Expand Down Expand Up @@ -2016,7 +2018,10 @@ struct PrintExpressionContents
}
void visitTupleExtract(TupleExtract* curr) {
printMedium(o, "tuple.extract ");
o << curr->tuple->type.size() << " ";
// If the tuple is unreachable, its size will be reported as 1, but that's
// not a valid tuple size. The size we print mostly doesn't matter if the
// tuple is unreachable, but it does have to be valid.
o << std::max(curr->tuple->type.size(), size_t(2)) << " ";
o << curr->index;
}
void visitRefI31(RefI31* curr) { printMedium(o, "ref.i31"); }
Expand Down
2 changes: 1 addition & 1 deletion test/lit/passes/optimize-instructions-multivalue.wast
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
)

;; CHECK: (func $extract-make-unreachable (param $x i32) (param $y i32) (result i32)
;; CHECK-NEXT: (tuple.extract 1 0
;; CHECK-NEXT: (tuple.extract 2 0
;; CHECK-NEXT: (tuple.make 2
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: (local.get $y)
Expand Down
4 changes: 2 additions & 2 deletions test/lit/passes/tuple-optimization.wast
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,12 @@
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (tuple.extract 1 0
;; CHECK-NEXT: (tuple.extract 2 0
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (tuple.extract 1 1
;; CHECK-NEXT: (tuple.extract 2 1
;; CHECK-NEXT: (local.tee $tuple
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this depend on the type of $tuple, which happens to be of size 2? That is, if line 571 changed to have 17 items in the tuple, would this still validate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would still validate because we do not store the expected arity of TupleExtract in the IR, so the validator would not know what the expected arity is, just that the tuple value is unreachable.

;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
Expand Down