Skip to content

Commit 90182d0

Browse files
committed
SILGen: Add missing FormalEvaluationScope when evaluating consumed noncopyable switch subjects.
After #83959, we expect noncopyable OpenExistential evaluations to have an outer FormalEvaluationScope to forward to. However, there was no such FormalEvaluationScope while emitting a consuming switch subject, causing an assertion failure to trip. Add a FormalEvaluationScope tightly scoped around the evaluation in this case, fixing rdar://160080337.
1 parent 96900f9 commit 90182d0

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/SILGen/SILGenPattern.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3500,7 +3500,7 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
35003500
// exits out of the switch.
35013501
//
35023502
// When we break out of a case block, we take the subject's remnants with us
3503-
// in the former case, but not the latter.q
3503+
// in the former case, but not the latter.
35043504
CleanupsDepth subjectDepth = Cleanups.getCleanupsDepth();
35053505
LexicalScope switchScope(*this, CleanupLocation(S));
35063506
std::optional<FormalEvaluationScope> switchFormalAccess;
@@ -3563,6 +3563,10 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
35633563
}
35643564
case ValueOwnership::Owned: {
35653565
// A consuming pattern match. Emit as a +1 rvalue.
3566+
// Create a tight evaluation scope for temporary borrows emitted during the
3567+
// evaluation.
3568+
FormalEvaluationScope limitedScope(*this);
3569+
35663570
subjectMV = emitRValueAsSingleValue(S->getSubjectExpr());
35673571
break;
35683572
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-emit-silgen -verify %s
2+
3+
func fooify(p: any P) {
4+
switch p.foo() {
5+
case .success:
6+
break
7+
}
8+
}
9+
10+
enum Resoult: ~Copyable {
11+
case success
12+
}
13+
14+
protocol P {
15+
func foo() -> Resoult
16+
}
17+

0 commit comments

Comments
 (0)