@@ -185,6 +185,7 @@ SILFunction *
185
185
SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction (
186
186
CanSILFunctionType blockType,
187
187
CanType continuationTy,
188
+ CanGenericSignature sig,
188
189
ForeignAsyncConvention convention) {
189
190
// Extract the result and error types from the continuation type.
190
191
auto resumeType = cast<BoundGenericType>(continuationTy).getGenericArgs ()[0 ];
@@ -207,10 +208,11 @@ SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
207
208
blockType->getClangTypeInfo ().getType (),
208
209
getASTContext ().getClangTypeForIRGen (blockStorageTy));
209
210
210
- auto implTy = SILFunctionType::get (GenericSignature () ,
211
+ auto implTy = SILFunctionType::get (sig ,
211
212
blockType->getExtInfo ().intoBuilder ()
212
213
.withRepresentation (SILFunctionTypeRepresentation::CFunctionPointer)
213
214
.withClangFunctionType (newClangTy)
215
+ .withIsPseudogeneric ((bool )sig)
214
216
.build (),
215
217
SILCoroutineKind::None,
216
218
ParameterConvention::Direct_Unowned,
@@ -223,6 +225,7 @@ SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
223
225
Mangle::ASTMangler Mangler;
224
226
auto name = Mangler.mangleObjCAsyncCompletionHandlerImpl (blockType,
225
227
resumeType,
228
+ sig,
226
229
/* predefined*/ false );
227
230
228
231
SILGenFunctionBuilder builder (*this );
@@ -234,6 +237,9 @@ SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
234
237
235
238
if (F->empty ()) {
236
239
// Emit the implementation.
240
+ if (sig)
241
+ F->setGenericEnvironment (sig->getGenericEnvironment ());
242
+
237
243
SILGenFunction SGF (*this , *F, SwiftModule);
238
244
{
239
245
Scope scope (SGF, loc);
@@ -282,6 +288,8 @@ SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
282
288
// Resume the continuation as throwing the given error, bridged to a
283
289
// native Swift error.
284
290
auto nativeError = SGF.emitBridgedToNativeError (loc, matchedError);
291
+ Type replacementTypes[]
292
+ = {F->mapTypeIntoContext (resumeType)->getCanonicalType ()};
285
293
auto subs = SubstitutionMap::get (errorIntrinsic->getGenericSignature (),
286
294
replacementTypes,
287
295
ArrayRef<ProtocolConformanceRef>{});
@@ -296,7 +304,7 @@ SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
296
304
}
297
305
298
306
auto loweredResumeTy = SGF.getLoweredType (AbstractionPattern::getOpaque (),
299
- resumeType);
307
+ F-> mapTypeIntoContext ( resumeType) );
300
308
301
309
// Prepare the argument for the resume intrinsic, using the non-error
302
310
// arguments to the callback.
@@ -343,6 +351,8 @@ SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
343
351
344
352
// Resume the continuation with the composed bridged result.
345
353
ManagedValue resumeArg = SGF.emitManagedBufferWithCleanup (resumeArgBuf);
354
+ Type replacementTypes[]
355
+ = {F->mapTypeIntoContext (resumeType)->getCanonicalType ()};
346
356
auto subs = SubstitutionMap::get (resumeIntrinsic->getGenericSignature (),
347
357
replacementTypes,
348
358
ArrayRef<ProtocolConformanceRef>{});
0 commit comments