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
@@ -589,10 +590,38 @@ void SILGenFunction::emitHopToActorValue(SILLocation loc, ManagedValue actor) {
589590 executor, /* mandatory*/ true );
590591}
591592
592- void SILGenFunction::emitPreconditionCheckExpectedExecutor (
593- SILLocation loc, SILValue executorOrActor) {
593+ static bool isCheckExpectedExecutorIntrinsicAvailable (SILGenModule &SGM) {
594594 auto checkExecutor = SGM.getCheckExpectedExecutor ();
595595 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))
596625 return ;
597626
598627 // We don't want the debugger to step into these.
@@ -605,7 +634,7 @@ void SILGenFunction::emitPreconditionCheckExpectedExecutor(
605634 auto args = emitSourceLocationArgs (loc.getSourceLoc (), loc);
606635
607636 emitApplyOfLibraryIntrinsic (
608- loc, checkExecutor , SubstitutionMap (),
637+ loc, SGM. getCheckExpectedExecutor () , SubstitutionMap (),
609638 {args.filenameStartPointer , args.filenameLength , args.filenameIsAscii ,
610639 args.line , ManagedValue::forObjectRValueWithoutOwnership (executor)},
611640 SGFContext ());
0 commit comments