@@ -180,6 +180,27 @@ static ValueDecl *rewriteIntegerTypes(SubstitutionMap subst, ValueDecl *oldDecl,
180
180
return newDecl;
181
181
}
182
182
183
+ static Expr *createSelfExpr (FuncDecl *fnDecl) {
184
+ ASTContext &ctx = fnDecl->getASTContext ();
185
+
186
+ auto selfDecl = fnDecl->getImplicitSelfDecl ();
187
+ auto selfRefExpr = new (ctx) DeclRefExpr (selfDecl, DeclNameLoc (),
188
+ /* implicit*/ true );
189
+
190
+ if (!fnDecl->isMutating ()) {
191
+ selfRefExpr->setType (selfDecl->getInterfaceType ());
192
+ return selfRefExpr;
193
+ }
194
+ selfRefExpr->setType (LValueType::get (selfDecl->getInterfaceType ()));
195
+
196
+ auto inoutSelfExpr = new (ctx) InOutExpr (
197
+ SourceLoc (), selfRefExpr,
198
+ fnDecl->mapTypeIntoContext (selfDecl->getValueInterfaceType ()),
199
+ /* isImplicit*/ true );
200
+ inoutSelfExpr->setType (InOutType::get (selfDecl->getInterfaceType ()));
201
+ return inoutSelfExpr;
202
+ }
203
+
183
204
// Synthesize a thunk body for the function created in
184
205
// "addThunkForDependentTypes". This will just cast all params and forward them
185
206
// along to the specialized function. It will also cast the result before
@@ -217,10 +238,27 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
217
238
paramIndex++;
218
239
}
219
240
220
- auto *specializedFuncDeclRef = new (ctx) DeclRefExpr (ConcreteDeclRef (specializedFuncDecl),
241
+ Expr *specializedFuncDeclRef = new (ctx) DeclRefExpr (ConcreteDeclRef (specializedFuncDecl),
221
242
DeclNameLoc (), true );
222
243
specializedFuncDeclRef->setType (specializedFuncDecl->getInterfaceType ());
223
244
245
+ if (specializedFuncDecl->isInstanceMember ()) {
246
+ auto selfExpr = createSelfExpr (thunkDecl);
247
+ auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfExpr);
248
+ memberCall->setThrows (false );
249
+ auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
250
+ specializedFuncDeclRef = memberCall;
251
+ specializedFuncDeclRef->setType (resultType);
252
+ } else if (specializedFuncDecl->isStatic ()) {
253
+ auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
254
+ auto selfType = cast<NominalTypeDecl>(thunkDecl->getDeclContext ()->getAsDecl ())->getDeclaredInterfaceType ();
255
+ auto selfTypeExpr = TypeExpr::createImplicit (selfType, ctx);
256
+ auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfTypeExpr);
257
+ memberCall->setThrows (false );
258
+ specializedFuncDeclRef = memberCall;
259
+ specializedFuncDeclRef->setType (resultType);
260
+ }
261
+
224
262
auto argList = ArgumentList::createImplicit (ctx, forwardingParams);
225
263
auto *specializedFuncCallExpr = CallExpr::createImplicit (ctx, specializedFuncDeclRef, argList);
226
264
specializedFuncCallExpr->setType (specializedFuncDecl->getResultInterfaceType ());
@@ -291,6 +329,7 @@ static ValueDecl *addThunkForDependentTypes(FuncDecl *oldDecl,
291
329
newFnDecl->copyFormalAccessFrom (newDecl);
292
330
newFnDecl->setBodySynthesizer (synthesizeDependentTypeThunkParamForwarding, newDecl);
293
331
newFnDecl->setSelfAccessKind (newDecl->getSelfAccessKind ());
332
+ if (newDecl->isStatic ()) newFnDecl->setStatic ();
294
333
newFnDecl->getAttrs ().add (
295
334
new (newDecl->getASTContext ()) TransparentAttr (/* IsImplicit=*/ true ));
296
335
return newFnDecl;
@@ -320,10 +359,27 @@ synthesizeForwardingThunkBody(AbstractFunctionDecl *afd, void *context) {
320
359
forwardingParams.push_back (Argument (SourceLoc (), Identifier (), paramRefExpr));
321
360
}
322
361
323
- auto *specializedFuncDeclRef = new (ctx) DeclRefExpr (ConcreteDeclRef (specializedFuncDecl),
362
+ Expr *specializedFuncDeclRef = new (ctx) DeclRefExpr (ConcreteDeclRef (specializedFuncDecl),
324
363
DeclNameLoc (), true );
325
364
specializedFuncDeclRef->setType (specializedFuncDecl->getInterfaceType ());
326
365
366
+ if (specializedFuncDecl->isInstanceMember ()) {
367
+ auto selfExpr = createSelfExpr (thunkDecl);
368
+ auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfExpr);
369
+ memberCall->setThrows (false );
370
+ auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
371
+ specializedFuncDeclRef = memberCall;
372
+ specializedFuncDeclRef->setType (resultType);
373
+ } else if (specializedFuncDecl->isStatic ()) {
374
+ auto resultType = specializedFuncDecl->getInterfaceType ()->getAs <FunctionType>()->getResult ();
375
+ auto selfType = cast<NominalTypeDecl>(thunkDecl->getDeclContext ()->getAsDecl ())->getDeclaredInterfaceType ();
376
+ auto selfTypeExpr = TypeExpr::createImplicit (selfType, ctx);
377
+ auto *memberCall = DotSyntaxCallExpr::create (ctx, specializedFuncDeclRef, SourceLoc (), selfTypeExpr);
378
+ memberCall->setThrows (false );
379
+ specializedFuncDeclRef = memberCall;
380
+ specializedFuncDeclRef->setType (resultType);
381
+ }
382
+
327
383
auto argList = ArgumentList::createImplicit (ctx, forwardingParams);
328
384
auto *specializedFuncCallExpr = CallExpr::createImplicit (ctx, specializedFuncDeclRef, argList);
329
385
specializedFuncCallExpr->setType (thunkDecl->getResultInterfaceType ());
@@ -391,6 +447,7 @@ static ValueDecl *generateThunkForExtraMetatypes(SubstitutionMap subst,
391
447
thunk->copyFormalAccessFrom (newDecl);
392
448
thunk->setBodySynthesizer (synthesizeForwardingThunkBody, newDecl);
393
449
thunk->setSelfAccessKind (newDecl->getSelfAccessKind ());
450
+ if (newDecl->isStatic ()) thunk->setStatic ();
394
451
thunk->getAttrs ().add (
395
452
new (newDecl->getASTContext ()) TransparentAttr (/* IsImplicit=*/ true ));
396
453
0 commit comments