15
15
#include " RValue.h"
16
16
#include " Scope.h"
17
17
#include " swift/AST/ASTContext.h"
18
+ #include " swift/AST/Availability.h"
18
19
#include " swift/AST/ProtocolConformance.h"
19
20
#include " swift/Basic/Range.h"
20
21
@@ -589,10 +590,38 @@ void SILGenFunction::emitHopToActorValue(SILLocation loc, ManagedValue actor) {
589
590
executor, /* mandatory*/ true );
590
591
}
591
592
592
- void SILGenFunction::emitPreconditionCheckExpectedExecutor (
593
- SILLocation loc, SILValue executorOrActor) {
593
+ static bool isCheckExpectedExecutorIntrinsicAvailable (SILGenModule &SGM) {
594
594
auto checkExecutor = SGM.getCheckExpectedExecutor ();
595
595
if (!checkExecutor)
596
+ return false ;
597
+
598
+ // Forego a check if instrinsic is unavailable, this could happen
599
+ // in main-actor context.
600
+ auto &C = checkExecutor->getASTContext ();
601
+ if (!C.LangOpts .DisableAvailabilityChecking ) {
602
+ auto deploymentAvailability = AvailabilityContext::forDeploymentTarget (C);
603
+ auto declAvailability =
604
+ AvailabilityInference::availableRange (checkExecutor, C);
605
+ return deploymentAvailability.isContainedIn (declAvailability);
606
+ }
607
+
608
+ return true ;
609
+ }
610
+
611
+ void SILGenFunction::emitPreconditionCheckExpectedExecutor (
612
+ SILLocation loc, ActorIsolation isolation,
613
+ std::optional<ManagedValue> actorSelf) {
614
+ if (!isCheckExpectedExecutorIntrinsicAvailable (SGM))
615
+ return ;
616
+
617
+ auto executor = emitExecutor (loc, isolation, actorSelf);
618
+ assert (executor);
619
+ emitPreconditionCheckExpectedExecutor (loc, *executor);
620
+ }
621
+
622
+ void SILGenFunction::emitPreconditionCheckExpectedExecutor (
623
+ SILLocation loc, SILValue executorOrActor) {
624
+ if (!isCheckExpectedExecutorIntrinsicAvailable (SGM))
596
625
return ;
597
626
598
627
// We don't want the debugger to step into these.
@@ -605,7 +634,7 @@ void SILGenFunction::emitPreconditionCheckExpectedExecutor(
605
634
auto args = emitSourceLocationArgs (loc.getSourceLoc (), loc);
606
635
607
636
emitApplyOfLibraryIntrinsic (
608
- loc, checkExecutor , SubstitutionMap (),
637
+ loc, SGM. getCheckExpectedExecutor () , SubstitutionMap (),
609
638
{args.filenameStartPointer , args.filenameLength , args.filenameIsAscii ,
610
639
args.line , ManagedValue::forObjectRValueWithoutOwnership (executor)},
611
640
SGFContext ());
0 commit comments