@@ -882,7 +882,6 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
882882 FuncDecl *builtinDecl = cast<FuncDecl>(getBuiltinValueDecl (
883883 getASTContext (),
884884 ctx.getIdentifier (getBuiltinName (BuiltinValueKind::CreateAsyncTask))));
885-
886885 auto subs = SubstitutionMap::get (builtinDecl->getGenericSignature (),
887886 {TupleType::getEmpty (ctx)},
888887 ArrayRef<ProtocolConformanceRef>{});
@@ -907,6 +906,7 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
907906
908907 // Get swiftJobRun
909908 FuncDecl *swiftJobRunFuncDecl = SGM.getSwiftJobRun ();
909+ assert (swiftJobRunFuncDecl && " Failed to find swift_job_run function decl" );
910910 SILFunction *swiftJobRunSILFunc =
911911 SGM.getFunction (SILDeclRef (swiftJobRunFuncDecl, SILDeclRef::Kind::Func),
912912 NotForDefinition);
@@ -924,6 +924,28 @@ void SILGenFunction::emitAsyncMainThreadStart(SILDeclRef entryPoint) {
924924
925925 // Get main executor
926926 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+
927949 SILFunction *getMainExeutorSILFunc = SGM.getFunction (
928950 SILDeclRef (getMainExecutorFuncDecl, SILDeclRef::Kind::Func),
929951 NotForDefinition);
0 commit comments