Skip to content

Commit 9795fc1

Browse files
authored
Do not optimize tag types in SignaturePruning (#7231)
Now that we preserve tag heap types in the IR, it was possible for SignaturePruning to optimize heap types used by tags in such a way that the tag uses would no longer be valid. An ideal fix would be to have SignaturePruning analyze and optimize tag usage as well as calls, but for now just skip optimizing any heap type used in a tag.
1 parent 8e7fa99 commit 9795fc1

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/passes/SignaturePruning.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ struct SignaturePruning : public Pass {
169169
}
170170
}
171171

172+
// Similarly, we cannot yet modify types used in exception handling or stack
173+
// switching tags. TODO.
174+
for (auto& tag : module->tags) {
175+
allInfo[tag->type].optimizable = false;
176+
}
177+
172178
// A type must have the same number of parameters and results as its
173179
// supertypes and subtypes, so we only attempt to modify types without
174180
// supertypes or subtypes.

test/lit/passes/signature-pruning.wast

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,3 +1239,34 @@
12391239
)
12401240
)
12411241

1242+
;; Test that we do not prune parameters from types used in tags.
1243+
(module
1244+
;; CHECK: (type $sig (func (param anyref)))
1245+
(type $sig (func (param anyref)))
1246+
1247+
;; CHECK: (type $1 (func))
1248+
1249+
;; CHECK: (tag $e (type $sig) (param anyref))
1250+
(tag $e (type $sig))
1251+
1252+
;; CHECK: (func $unused-param (type $sig) (param $0 anyref)
1253+
;; CHECK-NEXT: (nop)
1254+
;; CHECK-NEXT: )
1255+
(func $unused-param (type $sig) (param anyref)
1256+
(nop)
1257+
)
1258+
1259+
;; CHECK: (func $throw (type $1)
1260+
;; CHECK-NEXT: (local $0 anyref)
1261+
;; CHECK-NEXT: (throw $e
1262+
;; CHECK-NEXT: (local.get $0)
1263+
;; CHECK-NEXT: )
1264+
;; CHECK-NEXT: )
1265+
(func $throw
1266+
(local anyref)
1267+
;; This would be invalid if we optimized $sig.
1268+
(throw $e
1269+
(local.get 0)
1270+
)
1271+
)
1272+
)

0 commit comments

Comments
 (0)