@@ -928,7 +928,6 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
928
928
FuncDecl *builtinDecl = cast<FuncDecl>(getBuiltinValueDecl (
929
929
getASTContext (),
930
930
ctx.getIdentifier (getBuiltinName (BuiltinValueKind::CreateAsyncTask))));
931
-
932
931
auto subs = SubstitutionMap::get (builtinDecl->getGenericSignature (),
933
932
{TupleType::getEmpty (ctx)},
934
933
ArrayRef<ProtocolConformanceRef>{});
@@ -953,6 +952,7 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
953
952
954
953
// Get swiftJobRun
955
954
FuncDecl *swiftJobRunFuncDecl = SGM.getSwiftJobRun ();
955
+ assert (swiftJobRunFuncDecl && " Failed to find swift_job_run function decl" );
956
956
SILFunction *swiftJobRunSILFunc =
957
957
SGM.getFunction (SILDeclRef (swiftJobRunFuncDecl, SILDeclRef::Kind::Func),
958
958
NotForDefinition);
@@ -970,6 +970,28 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
970
970
971
971
// Get main executor
972
972
FuncDecl *getMainExecutorFuncDecl = SGM.getGetMainExecutor ();
973
+ if (!getMainExecutorFuncDecl) {
974
+ // If it doesn't exist due to an SDK-compiler mismatch, we can conjure one
975
+ // up instead of crashing:
976
+ // @available(SwiftStdlib 5.5, *)
977
+ // @_silgen_name("swift_task_getMainExecutor")
978
+ // internal func _getMainExecutor() -> Builtin.Executor
979
+
980
+ ParameterList *emptyParams = ParameterList::createEmpty (getASTContext ());
981
+ getMainExecutorFuncDecl = FuncDecl::createImplicit (
982
+ getASTContext (), StaticSpellingKind::None,
983
+ DeclName (
984
+ getASTContext (),
985
+ DeclBaseName (getASTContext ().getIdentifier (" _getMainExecutor" )),
986
+ /* Arguments*/ emptyParams),
987
+ {}, /* async*/ false , /* throws*/ false , {}, emptyParams,
988
+ getASTContext ().TheExecutorType ,
989
+ entryPoint.getDecl ()->getModuleContext ());
990
+ getMainExecutorFuncDecl->getAttrs ().add (
991
+ new (getASTContext ())
992
+ SILGenNameAttr (" swift_task_getMainExecutor" , /* implicit*/ true ));
993
+ }
994
+
973
995
SILFunction *getMainExeutorSILFunc = SGM.getFunction (
974
996
SILDeclRef (getMainExecutorFuncDecl, SILDeclRef::Kind::Func),
975
997
NotForDefinition);
@@ -983,6 +1005,25 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
983
1005
984
1006
// Start Main loop!
985
1007
FuncDecl *drainQueueFuncDecl = SGM.getAsyncMainDrainQueue ();
1008
+ if (!drainQueueFuncDecl) {
1009
+ // If it doesn't exist, we can conjure one up instead of crashing
1010
+ // @available(SwiftStdlib 5.5, *)
1011
+ // @_silgen_name("swift_task_asyncMainDrainQueue")
1012
+ // internal func _asyncMainDrainQueue() -> Never
1013
+ ParameterList *emptyParams = ParameterList::createEmpty (getASTContext ());
1014
+ drainQueueFuncDecl = FuncDecl::createImplicit (
1015
+ getASTContext (), StaticSpellingKind::None,
1016
+ DeclName (
1017
+ getASTContext (),
1018
+ DeclBaseName (getASTContext ().getIdentifier (" _asyncMainDrainQueue" )),
1019
+ /* Arguments*/ emptyParams),
1020
+ {}, /* async*/ false , /* throws*/ false , {}, emptyParams,
1021
+ getASTContext ().getNeverType (),
1022
+ entryPoint.getDecl ()->getModuleContext ());
1023
+ drainQueueFuncDecl->getAttrs ().add (
1024
+ new (getASTContext ()) SILGenNameAttr (" swift_task_asyncMainDrainQueue" , /* implicit*/ true ));
1025
+ }
1026
+
986
1027
SILFunction *drainQueueSILFunc = SGM.getFunction (
987
1028
SILDeclRef (drainQueueFuncDecl, SILDeclRef::Kind::Func), NotForDefinition);
988
1029
SILValue drainQueueFunc =
0 commit comments