@@ -3228,23 +3228,22 @@ static ManagedValue createThunk(SILGenFunction &SGF,
3228
3228
static CanSILFunctionType buildWithoutActuallyEscapingThunkType (
3229
3229
SILGenFunction &SGF, CanSILFunctionType &noEscapingType,
3230
3230
CanSILFunctionType &escapingType, GenericEnvironment *&genericEnv,
3231
- SubstitutionMap &interfaceSubs) {
3231
+ SubstitutionMap &interfaceSubs, CanType &dynamicSelfType ) {
3232
3232
3233
3233
assert (escapingType->getExtInfo () ==
3234
3234
noEscapingType->getExtInfo ().withNoEscape (false ));
3235
3235
3236
3236
CanType inputSubstType, outputSubstType;
3237
- CanType dynamicSelfType;
3238
3237
auto type = SGF.buildThunkType (noEscapingType, escapingType,
3239
3238
inputSubstType, outputSubstType,
3240
3239
genericEnv, interfaceSubs,
3241
3240
dynamicSelfType,
3242
3241
/* withoutActuallyEscaping=*/ true );
3243
- assert (!dynamicSelfType && " not implemented" );
3244
3242
return type;
3245
3243
}
3246
3244
3247
- static void buildWithoutActuallyEscapingThunkBody (SILGenFunction &SGF) {
3245
+ static void buildWithoutActuallyEscapingThunkBody (SILGenFunction &SGF,
3246
+ CanType dynamicSelfType) {
3248
3247
PrettyStackTraceSILFunction stackTrace (
3249
3248
" emitting withoutAcutallyEscaping thunk in" , &SGF.F );
3250
3249
@@ -3256,6 +3255,11 @@ static void buildWithoutActuallyEscapingThunkBody(SILGenFunction &SGF) {
3256
3255
SmallVector<SILArgument*, 8 > indirectResults;
3257
3256
SGF.collectThunkParams (loc, params, &indirectResults);
3258
3257
3258
+ // Ignore the self parameter at the SIL level. IRGen will use it to
3259
+ // recover type metadata.
3260
+ if (dynamicSelfType)
3261
+ params.pop_back ();
3262
+
3259
3263
ManagedValue fnValue = params.pop_back_val ();
3260
3264
auto fnType = fnValue.getType ().castTo <SILFunctionType>();
3261
3265
@@ -3297,47 +3301,37 @@ SILGenFunction::createWithoutActuallyEscapingClosure(
3297
3301
auto noEscapingFnTy =
3298
3302
noEscapingFunctionValue.getType ().castTo <SILFunctionType>();
3299
3303
3304
+ CanType dynamicSelfType;
3300
3305
auto thunkType = buildWithoutActuallyEscapingThunkType (
3301
- *this , noEscapingFnTy, escapingFnTy, genericEnv, interfaceSubs);
3306
+ *this , noEscapingFnTy, escapingFnTy, genericEnv, interfaceSubs,
3307
+ dynamicSelfType);
3302
3308
3303
3309
auto *thunk = SGM.getOrCreateReabstractionThunk (
3304
- thunkType, noEscapingFnTy, escapingFnTy,
3305
- /* dynamicSelfType=*/ CanType ());
3310
+ thunkType, noEscapingFnTy, escapingFnTy, dynamicSelfType);
3306
3311
3307
3312
if (thunk->empty ()) {
3308
3313
thunk->setWithoutActuallyEscapingThunk ();
3309
3314
thunk->setGenericEnvironment (genericEnv);
3310
3315
SILGenFunction thunkSGF (SGM, *thunk, FunctionDC);
3311
- buildWithoutActuallyEscapingThunkBody (thunkSGF);
3316
+ buildWithoutActuallyEscapingThunkBody (thunkSGF, dynamicSelfType );
3312
3317
}
3313
3318
assert (thunk->isWithoutActuallyEscapingThunk ());
3314
3319
3315
- CanSILFunctionType substFnTy = thunkType;
3316
- // Use the subsitution map in the context of the current function.
3317
- // thunk->getForwardingSubstitutionMap() / thunk might have been created in a
3318
- // different function's generic enviroment.
3319
- if (thunkType->getGenericSignature ()) {
3320
- substFnTy = thunkType->substGenericArgs (F.getModule (), interfaceSubs);
3321
- }
3322
-
3323
- // Create it in our current function.
3324
- auto thunkValue = B.createFunctionRefFor (loc, thunk);
3325
-
3326
3320
// Create a copy for the noescape value, so we can mark_dependence upon the
3327
3321
// original value.
3328
- SILValue noEscapeValue =
3329
- noEscapingFunctionValue.copy (*this , loc).forward (*this );
3330
- SingleValueInstruction *thunkedFn = B.createPartialApply (
3331
- loc, thunkValue,
3332
- SILType::getPrimitiveObjectType (substFnTy),
3333
- interfaceSubs,
3334
- noEscapeValue,
3335
- SILType::getPrimitiveObjectType (escapingFnTy));
3322
+ auto noEscapeValue = noEscapingFunctionValue.copy (*this , loc);
3323
+
3324
+ auto thunkedFn =
3325
+ createPartialApplyOfThunk (*this , loc, thunk, interfaceSubs, dynamicSelfType,
3326
+ escapingFnTy, noEscapeValue);
3327
+
3336
3328
// We need to ensure the 'lifetime' of the trivial values context captures. As
3337
3329
// long as we represent these captures by the same value the following works.
3338
- thunkedFn = B.createMarkDependence (loc, thunkedFn, noEscapingFunctionValue.getValue ());
3330
+ thunkedFn = emitManagedRValueWithCleanup (
3331
+ B.createMarkDependence (loc, thunkedFn.forward (*this ),
3332
+ noEscapingFunctionValue.getValue ()));
3339
3333
3340
- return emitManagedRValueWithCleanup ( thunkedFn) ;
3334
+ return thunkedFn;
3341
3335
}
3342
3336
3343
3337
ManagedValue Transform::transformFunction (ManagedValue fn,
0 commit comments