Skip to content

Commit 4ffd9fe

Browse files
authored
Skip continuation types in SignatureRefining (#8449)
1 parent 1b9b280 commit 4ffd9fe

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

src/passes/SignaturePruning.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ struct SignaturePruning : public Pass {
199199
allInfo[tag->type].optimizable = false;
200200
}
201201

202+
// Continuations must not have params refined, because we do not update
203+
// their users (e.g. cont.bind, resume) with new types.
204+
// TODO: support refining continuations
205+
if (module->features.hasStackSwitching()) {
206+
for (auto type : ModuleUtils::collectHeapTypes(*module)) {
207+
if (type.isContinuation()) {
208+
allInfo[type.getContinuation().type].optimizable = false;
209+
}
210+
}
211+
}
212+
202213
// Signature-called functions must also not be modified.
203214
// TODO: Explore whether removing parameters from the end could be
204215
// beneficial (check if it does not regress call performance with JS).

test/lit/passes/signature-pruning.wast

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,3 +1269,84 @@
12691269
)
12701270
)
12711271
)
1272+
1273+
(module
1274+
;; If a signature is used in a continuation, we cannot refine its parameters,
1275+
;; as we do not yet support updating continuation instructions with new types.
1276+
(rec
1277+
;; CHECK: (rec
1278+
;; CHECK-NEXT: (type $cont (cont $sig))
1279+
1280+
;; CHECK: (type $1 (func))
1281+
1282+
;; CHECK: (type $other (func))
1283+
1284+
;; CHECK: (type $sig (func (param anyref)))
1285+
(type $sig (func (param anyref)))
1286+
(type $other (func (param anyref)))
1287+
(type $cont (cont $sig))
1288+
)
1289+
;; CHECK: (elem declare func $cont $not-cont $other)
1290+
1291+
;; CHECK: (func $cont (type $sig) (param $0 anyref)
1292+
;; CHECK-NEXT: (nop)
1293+
;; CHECK-NEXT: )
1294+
(func $cont (type $sig) (param anyref)
1295+
;; The param is unused here, and in all functions below, so we want to
1296+
;; remove it where possible.
1297+
(nop)
1298+
)
1299+
1300+
;; CHECK: (func $not-cont (type $sig) (param $0 anyref)
1301+
;; CHECK-NEXT: (nop)
1302+
;; CHECK-NEXT: )
1303+
(func $not-cont (type $sig) (param anyref)
1304+
;; This function cannot be optimized even though it is not used in a
1305+
;; continuation. It is enough that it shares a type with a continuation
1306+
;; function.
1307+
(nop)
1308+
)
1309+
1310+
;; CHECK: (func $other (type $other)
1311+
;; CHECK-NEXT: (local $0 anyref)
1312+
;; CHECK-NEXT: (local.set $0
1313+
;; CHECK-NEXT: (ref.null none)
1314+
;; CHECK-NEXT: )
1315+
;; CHECK-NEXT: (nop)
1316+
;; CHECK-NEXT: )
1317+
(func $other (type $other) (param anyref)
1318+
;; This function uses a different type, so it can be optimized.
1319+
(nop)
1320+
)
1321+
1322+
1323+
;; CHECK: (func $test (type $1)
1324+
;; CHECK-NEXT: (drop
1325+
;; CHECK-NEXT: (cont.new $cont
1326+
;; CHECK-NEXT: (ref.func $cont)
1327+
;; CHECK-NEXT: )
1328+
;; CHECK-NEXT: )
1329+
;; CHECK-NEXT: (call_ref $sig
1330+
;; CHECK-NEXT: (ref.null none)
1331+
;; CHECK-NEXT: (ref.func $not-cont)
1332+
;; CHECK-NEXT: )
1333+
;; CHECK-NEXT: (call_ref $other
1334+
;; CHECK-NEXT: (ref.func $other)
1335+
;; CHECK-NEXT: )
1336+
;; CHECK-NEXT: )
1337+
(func $test
1338+
(drop
1339+
(cont.new $cont
1340+
(ref.func $cont)
1341+
)
1342+
)
1343+
(call_ref $sig
1344+
(ref.null none)
1345+
(ref.func $not-cont)
1346+
)
1347+
(call_ref $other
1348+
(ref.null none)
1349+
(ref.func $other)
1350+
)
1351+
)
1352+
)

test/lit/passes/signature-refining.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@
12121212
(func $not-cont (type $sig) (param anyref)
12131213
;; This function cannot be optimized even though it is not used in a
12141214
;; continuation. It is enough that it shares a type with a continuation
1215-
;;function.
1215+
;; function.
12161216
(nop)
12171217
)
12181218

0 commit comments

Comments
 (0)