@@ -882,7 +882,6 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
882
882
FuncDecl *builtinDecl = cast<FuncDecl>(getBuiltinValueDecl (
883
883
getASTContext (),
884
884
ctx.getIdentifier (getBuiltinName (BuiltinValueKind::CreateAsyncTask))));
885
-
886
885
auto subs = SubstitutionMap::get (builtinDecl->getGenericSignature (),
887
886
{TupleType::getEmpty (ctx)},
888
887
ArrayRef<ProtocolConformanceRef>{});
@@ -907,6 +906,7 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
907
906
908
907
// Get swiftJobRun
909
908
FuncDecl *swiftJobRunFuncDecl = SGM.getSwiftJobRun ();
909
+ assert (swiftJobRunFuncDecl && " Failed to find swift_job_run function decl" );
910
910
SILFunction *swiftJobRunSILFunc =
911
911
SGM.getFunction (SILDeclRef (swiftJobRunFuncDecl, SILDeclRef::Kind::Func),
912
912
NotForDefinition);
@@ -924,6 +924,28 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
924
924
925
925
// Get main executor
926
926
FuncDecl *getMainExecutorFuncDecl = SGM.getGetMainExecutor ();
927
+ if (!getMainExecutorFuncDecl) {
928
+ // If it doesn't exist due to an SDK-compiler mismatch, we can conjure one
929
+ // up instead of crashing:
930
+ // @available(SwiftStdlib 5.5, *)
931
+ // @_silgen_name("swift_task_getMainExecutor")
932
+ // internal func _getMainExecutor() -> Builtin.Executor
933
+
934
+ ParameterList *emptyParams = ParameterList::createEmpty (getASTContext ());
935
+ getMainExecutorFuncDecl = FuncDecl::createImplicit (
936
+ getASTContext (), StaticSpellingKind::None,
937
+ DeclName (
938
+ getASTContext (),
939
+ DeclBaseName (getASTContext ().getIdentifier (" _getMainExecutor" )),
940
+ /* Arguments*/ emptyParams),
941
+ {}, /* async*/ false , /* throws*/ false , {}, emptyParams,
942
+ getASTContext ().TheExecutorType ,
943
+ entryPoint.getDecl ()->getModuleContext ());
944
+ getMainExecutorFuncDecl->getAttrs ().add (
945
+ new (getASTContext ())
946
+ SILGenNameAttr (" swift_task_getMainExecutor" , /* implicit*/ true ));
947
+ }
948
+
927
949
SILFunction *getMainExeutorSILFunc = SGM.getFunction (
928
950
SILDeclRef (getMainExecutorFuncDecl, SILDeclRef::Kind::Func),
929
951
NotForDefinition);
0 commit comments