@@ -391,7 +391,13 @@ FuncDecl *
391
391
SILGenModule::getResumeUnsafeThrowingContinuationWithError () {
392
392
return lookupConcurrencyIntrinsic (getASTContext (),
393
393
ResumeUnsafeThrowingContinuationWithError,
394
- " _resumeUnsafeThrowingContinuationWithError" );
394
+ " _resumeUnsafeThrowingContinuationWithError" );
395
+ }
396
+ FuncDecl *
397
+ SILGenModule::getRunTaskForBridgedAsyncMethod () {
398
+ return lookupConcurrencyIntrinsic (getASTContext (),
399
+ RunTaskForBridgedAsyncMethod,
400
+ " _runTaskForBridgedAsyncMethod" );
395
401
}
396
402
FuncDecl *
397
403
SILGenModule::getRunAsyncHandler () {
@@ -776,7 +782,16 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
776
782
PrettyStackTraceSILFunction X (" silgen emitNativeToForeignThunk" , f);
777
783
f->setBare (IsBare);
778
784
f->setThunk (IsThunk);
785
+ // If the native function is async, then the foreign entry point is not,
786
+ // so it needs to spawn a detached task in which to run the native
787
+ // implementation, so the actual thunk logic needs to go into a closure
788
+ // implementation function.
789
+ if (constant.hasAsync ()) {
790
+ f = SILGenFunction (*this , *f, dc).emitNativeAsyncToForeignThunk (constant);
791
+ }
792
+
779
793
SILGenFunction (*this , *f, dc).emitNativeToForeignThunk (constant);
794
+
780
795
postEmitFunction (constant, f);
781
796
return ;
782
797
}
0 commit comments