@@ -660,13 +660,6 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
660
660
}
661
661
}
662
662
}
663
-
664
- // In async functions, the generic executor is our expected executor
665
- // if we don't have any sort of isolation.
666
- if (!ExpectedExecutor && F.isAsync ()) {
667
- ExpectedExecutor = emitGenericExecutor (
668
- RegularLocation::getAutoGeneratedLocation (F.getLocation ()));
669
- }
670
663
671
664
// Jump to the expected executor.
672
665
if (ExpectedExecutor) {
@@ -686,54 +679,6 @@ void SILGenFunction::emitProlog(CaptureInfo captureInfo,
686
679
}
687
680
}
688
681
689
- SILValue SILGenFunction::emitMainExecutor (SILLocation loc) {
690
- // Get main executor
691
- FuncDecl *getMainExecutorFuncDecl = SGM.getGetMainExecutor ();
692
- if (!getMainExecutorFuncDecl) {
693
- // If it doesn't exist due to an SDK-compiler mismatch, we can conjure one
694
- // up instead of crashing:
695
- // @available(SwiftStdlib 5.1, *)
696
- // @_silgen_name("swift_task_getMainExecutor")
697
- // internal func _getMainExecutor() -> Builtin.Executor
698
- auto &ctx = getASTContext ();
699
-
700
- ParameterList *emptyParams = ParameterList::createEmpty (ctx);
701
- getMainExecutorFuncDecl = FuncDecl::createImplicit (
702
- ctx, StaticSpellingKind::None,
703
- DeclName (
704
- ctx,
705
- DeclBaseName (ctx.getIdentifier (" _getMainExecutor" )),
706
- /* Arguments*/ emptyParams),
707
- {}, /* async*/ false , /* throws*/ false , {}, emptyParams,
708
- ctx.TheExecutorType ,
709
- getModule ().getSwiftModule ());
710
- getMainExecutorFuncDecl->getAttrs ().add (
711
- new (ctx)
712
- SILGenNameAttr (" swift_task_getMainExecutor" , /* implicit*/ true ));
713
- }
714
-
715
- auto fn = SGM.getFunction (
716
- SILDeclRef (getMainExecutorFuncDecl, SILDeclRef::Kind::Func),
717
- NotForDefinition);
718
- SILValue fnRef = B.createFunctionRefFor (loc, fn);
719
- return B.createApply (loc, fnRef, {}, {});
720
- }
721
-
722
- SILValue SILGenFunction::emitGenericExecutor (SILLocation loc) {
723
- // The generic executor is encoded as the nil value of
724
- // Optional<Builtin.SerialExecutor>.
725
- auto ty = SILType::getOptionalType (
726
- SILType::getPrimitiveObjectType (
727
- getASTContext ().TheExecutorType ));
728
- return B.createOptionalNone (loc, ty);
729
- }
730
-
731
- void SILGenFunction::emitPrologGlobalActorHop (SILLocation loc,
732
- Type globalActor) {
733
- ExpectedExecutor = emitLoadGlobalActorExecutor (globalActor);
734
- B.createHopToExecutor (loc, ExpectedExecutor, /* mandatory*/ false );
735
- }
736
-
737
682
SILValue SILGenFunction::emitLoadGlobalActorExecutor (Type globalActor) {
738
683
CanType actorType = CanType (globalActor);
739
684
NominalTypeDecl *nominal = actorType->getNominalOrBoundGenericNominal ();
@@ -873,8 +818,19 @@ void ExecutorBreadcrumb::emit(SILGenFunction &SGF, SILLocation loc) {
873
818
}
874
819
875
820
SILValue SILGenFunction::emitGetCurrentExecutor (SILLocation loc) {
876
- assert (ExpectedExecutor && " prolog failed to set up expected executor?" );
877
- return ExpectedExecutor;
821
+ // If this is an actor method, then the actor is the only executor we should
822
+ // be running on (if we aren't setting up for a cross-actor call).
823
+ if (ExpectedExecutor)
824
+ return ExpectedExecutor;
825
+
826
+ // Otherwise, we'll have to ask the current task what executor it's running
827
+ // on.
828
+ auto &ctx = getASTContext ();
829
+ return B.createBuiltin (
830
+ loc,
831
+ ctx.getIdentifier (getBuiltinName (BuiltinValueKind::GetCurrentExecutor)),
832
+ getLoweredType (OptionalType::get (ctx.TheExecutorType )),
833
+ SubstitutionMap (), { });
878
834
}
879
835
880
836
static void emitIndirectResultParameters (SILGenFunction &SGF,
0 commit comments