Skip to content

Commit abbed68

Browse files
committed
[SILGen] Don't emit executor checks for @_unsafeMainActor closures.
Narrow fix for rdar://76860623. (cherry picked from commit 4d6f07e)
1 parent 6afa3bd commit abbed68

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,10 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
524524
break;
525525
}
526526
} else if (auto *closureExpr = dyn_cast<AbstractClosureExpr>(FunctionDC)) {
527-
bool wantExecutor = F.isAsync() || !isInActorDestructor(closureExpr);
527+
bool wantExecutor = F.isAsync() ||
528+
(!isInActorDestructor(closureExpr) &&
529+
!(isa<ClosureExpr>(closureExpr) &&
530+
cast<ClosureExpr>(closureExpr)->isUnsafeMainActor()));
528531
auto actorIsolation = closureExpr->getActorIsolation();
529532
switch (actorIsolation.getKind()) {
530533
case ClosureActorIsolation::Independent:

test/SILGen/check_executor.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import _Concurrency
1515

1616
func takeClosure(_ fn: @escaping () -> Int) { }
1717

18+
func takeUnsafeMainActorClosure(@_unsafeMainActor _ fn: @escaping () -> Int) { }
19+
1820
public actor MyActor {
1921
var counter = 0
2022

@@ -36,4 +38,15 @@ public actor MyActor {
3638
deinit {
3739
takeClosure { self.counter }
3840
}
41+
42+
// CHECK-RAW-LABEL: sil private [ossa] @$s4test7MyActorC0A10UnsafeMainyyFSiycfU_
43+
// CHECK-RAW-NOT: _checkExpectedExecutor
44+
// CHECK-RAW: onMainActor
45+
// CHECK-RAW: return
46+
public func testUnsafeMain() {
47+
takeUnsafeMainActorClosure {
48+
onMainActor()
49+
return 5
50+
}
51+
}
3952
}

0 commit comments

Comments
 (0)