Skip to content

Commit f5d6620

Browse files
committed
Unify @_predatesConcurrency behavior for dynamic data race detection
Don't treat "unsafe" and safe global actor isolation differently with respect to dynamic data race detection, because this `@_predatesConcurrency` is only supposed to affect the interface (not the implementation).
1 parent 30c5cf2 commit f5d6620

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -560,34 +560,30 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
560560
dyn_cast_or_null<AbstractFunctionDecl>(FunctionDC->getAsDecl())) {
561561
auto actorIsolation = getActorIsolation(funcDecl);
562562
switch (actorIsolation.getKind()) {
563-
case ActorIsolation::Unspecified:
564-
case ActorIsolation::Independent:
565-
// If this is an async function that has an isolated parameter, hop
566-
// to it.
567-
if (F.isAsync()) {
568-
for (auto param : *funcDecl->getParameters()) {
569-
if (param->isIsolated()) {
570-
auto loc = RegularLocation::getAutoGeneratedLocation(F.getLocation());
571-
Type actorType = param->getType();
572-
RValue actorInstanceRV = emitRValueForDecl(
573-
loc, param, actorType, AccessSemantics::Ordinary);
574-
ManagedValue actorInstance =
575-
std::move(actorInstanceRV).getScalarValue();
576-
ExpectedExecutor = emitLoadActorExecutor(loc, actorInstance);
577-
break;
578-
}
563+
case ActorIsolation::Unspecified:
564+
case ActorIsolation::Independent:
565+
// If this is an async function that has an isolated parameter, hop
566+
// to it.
567+
if (F.isAsync()) {
568+
for (auto param : *funcDecl->getParameters()) {
569+
if (param->isIsolated()) {
570+
auto loc = RegularLocation::getAutoGeneratedLocation(F.getLocation());
571+
Type actorType = param->getType();
572+
RValue actorInstanceRV = emitRValueForDecl(
573+
loc, param, actorType, AccessSemantics::Ordinary);
574+
ManagedValue actorInstance =
575+
std::move(actorInstanceRV).getScalarValue();
576+
ExpectedExecutor = emitLoadActorExecutor(loc, actorInstance);
577+
break;
579578
}
580579
}
581-
582-
break;
583-
584-
case ActorIsolation::GlobalActorUnsafe:
585-
break;
586-
587-
case ActorIsolation::DistributedActorInstance: {
588-
// TODO: perhaps here we can emit our special handling to make a message?
589-
LLVM_FALLTHROUGH;
590580
}
581+
break;
582+
583+
case ActorIsolation::DistributedActorInstance: {
584+
// TODO: perhaps here we can emit our special handling to make a message?
585+
LLVM_FALLTHROUGH;
586+
}
591587

592588
case ActorIsolation::ActorInstance: {
593589
assert(selfParam && "no self parameter for ActorInstance isolation");
@@ -605,6 +601,7 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
605601
}
606602

607603
case ActorIsolation::GlobalActor:
604+
case ActorIsolation::GlobalActorUnsafe:
608605
if (F.isAsync() || wantDataRaceChecks) {
609606
ExpectedExecutor =
610607
emitLoadGlobalActorExecutor(actorIsolation.getGlobalActor());

test/SILGen/check_executor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import _Concurrency
1313
// CHECK-CANONICAL: function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
1414
@MainActor public func onMainActor() { }
1515

16+
// CHECK-CANONICAL-LABEL: sil [ossa] @$s4test17onMainActorUnsafeyyF
17+
// CHECK-CANONICAL: function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF
18+
@_predatesConcurrency @MainActor public func onMainActorUnsafe() { }
19+
1620
func takeClosure(_ fn: @escaping () -> Int) { }
1721

1822
@_predatesConcurrency func takeUnsafeMainActorClosure(_ fn: @MainActor @escaping () -> Int) { }

0 commit comments

Comments
 (0)