Skip to content

Commit f977996

Browse files
committed
[SILGen] Emit _checkExpectedExecutor only if its available on a deployment target
Don't emit `_checkExpectedExecutor` check if deployment target is not sufficiently new otherwise it would result in crash. Resolves: rdar://106827064
1 parent ed745a5 commit f977996

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/SILGen/SILGenConcurrency.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "RValue.h"
1616
#include "Scope.h"
1717
#include "swift/AST/ASTContext.h"
18+
#include "swift/AST/Availability.h"
1819
#include "swift/AST/ProtocolConformance.h"
1920
#include "swift/Basic/Range.h"
2021

@@ -595,6 +596,17 @@ void SILGenFunction::emitPreconditionCheckExpectedExecutor(
595596
if (!checkExecutor)
596597
return;
597598

599+
// Forego a check if instrinsic is unavailable, this could happen
600+
// in main-actor context.
601+
auto &C = checkExecutor->getASTContext();
602+
if (!C.LangOpts.DisableAvailabilityChecking) {
603+
auto deploymentAvailability = AvailabilityContext::forDeploymentTarget(C);
604+
auto declAvailability =
605+
AvailabilityInference::availableRange(checkExecutor, C);
606+
if (!deploymentAvailability.isContainedIn(declAvailability))
607+
return;
608+
}
609+
598610
// We don't want the debugger to step into these.
599611
loc.markAutoGenerated();
600612

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-frontend -primary-file %s -target %target-cpu-apple-macosx10.14 -enable-experimental-feature DynamicActorIsolation -emit-silgen -o - | %FileCheck %s
2+
3+
// REQUIRES: asserts
4+
// REQUIRES: concurrency
5+
// REQUIRES: OS=macosx
6+
7+
protocol P {
8+
associatedtype T
9+
10+
func fn() -> T?
11+
}
12+
13+
@MainActor
14+
struct IsolatedType<T> : @preconcurrency P {
15+
func fn() -> T? { nil }
16+
}
17+
18+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s38preconcurrency_conformances_backdeploy12IsolatedTypeVyxGAA1PA2aEP2fn1TQzSgyFTW
19+
// CHECK-NOT: function_ref @$ss22_checkExpectedExecutor14_filenameStart01_D6Length01_D7IsASCII5_line9_executoryBp_BwBi1_BwBetF

0 commit comments

Comments
 (0)