Skip to content

Commit 8e7fa99

Browse files
authored
Do not optimize tag types in SignatureRefining (#7230)
Now that we preserve tag heap types in the IR, it was possible for SignatureRefining to refine 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 SignatureRefining analyze and optimize tag usage as well as calls, but for now just skip optimizing any heap type used in a tag.
1 parent e984c89 commit 8e7fa99

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/passes/SignatureRefining.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ struct SignatureRefining : public Pass {
154154
}
155155
}
156156

157+
// Also skip modifying types used in tags, even private tags, since we don't
158+
// analyze exception handling or stack switching instructions. TODO: Analyze
159+
// and optimize exception handling and stack switching instructions.
160+
for (auto& tag : module->tags) {
161+
allInfo[tag->type].canModify = false;
162+
}
163+
157164
// For now, do not optimize types that have subtypes. When we modify such a
158165
// type we need to modify subtypes as well, similar to the analysis in
159166
// TypeRefining, and perhaps we can unify this pass with that. TODO

test/lit/passes/signature-refining.wast

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,7 @@
11261126

11271127
;; CHECK: (func $func (type $sig) (param $x anyref)
11281128
;; CHECK-NEXT: )
1129-
(func $func (type $sig) (param $x anyref)
1130-
)
1129+
(func $func (type $sig) (param $x anyref))
11311130

11321131
;; CHECK: (func $caller (type $2)
11331132
;; CHECK-NEXT: (call $func
@@ -1141,3 +1140,43 @@
11411140
)
11421141
)
11431142

1143+
;; Tags: The type we'd like to refine, $sig, is used by a tag, so do not
1144+
;; optimize.
1145+
(module
1146+
;; CHECK: (type $sig (func (param anyref)))
1147+
(type $sig (func (param anyref)))
1148+
1149+
;; CHECK: (type $1 (func))
1150+
1151+
;; CHECK: (tag $e (type $sig) (param anyref))
1152+
(tag $e (type $sig))
1153+
1154+
;; CHECK: (func $optimizable (type $sig) (param $0 anyref)
1155+
;; CHECK-NEXT: (call $optimizable
1156+
;; CHECK-NEXT: (ref.cast eqref
1157+
;; CHECK-NEXT: (local.get $0)
1158+
;; CHECK-NEXT: )
1159+
;; CHECK-NEXT: )
1160+
;; CHECK-NEXT: )
1161+
(func $optimizable (type $sig) (param anyref)
1162+
(call $optimizable
1163+
(ref.cast eqref
1164+
(local.get 0)
1165+
)
1166+
)
1167+
)
1168+
1169+
;; CHECK: (func $throw (type $1)
1170+
;; CHECK-NEXT: (local $0 anyref)
1171+
;; CHECK-NEXT: (throw $e
1172+
;; CHECK-NEXT: (local.get $0)
1173+
;; CHECK-NEXT: )
1174+
;; CHECK-NEXT: )
1175+
(func $throw
1176+
(local anyref)
1177+
;; This would be invalid if we optimized $sig.
1178+
(throw $e
1179+
(local.get 0)
1180+
)
1181+
)
1182+
)

0 commit comments

Comments
 (0)