@@ -1298,57 +1298,15 @@ namespace {
1298
1298
ConstraintLocatorBuilder locator) {
1299
1299
auto &context = cs.getASTContext ();
1300
1300
1301
- OptionSet<ParameterList::CloneFlags> options
1302
- = (ParameterList::Implicit |
1303
- ParameterList::NamedArguments);
1304
- auto *params = getParameterList (member)->clone (context, options);
1305
-
1306
- for (auto idx : indices (*params)) {
1307
- auto *param = params->get (idx);
1308
- auto arg = selfFnTy->getParams ()[idx];
1309
-
1310
- param->setInterfaceType (
1311
- arg.getParameterType ()->mapTypeOutOfContext ());
1312
- param->setSpecifier (
1313
- ParamDecl::getParameterSpecifierForValueOwnership (
1314
- arg.getValueOwnership ()));
1315
- }
1316
-
1317
1301
auto resultTy = selfFnTy->getResult ();
1318
- auto discriminator = AutoClosureExpr::InvalidDiscriminator;
1319
- auto closure = new (context) AutoClosureExpr (/* set body later*/ nullptr ,
1320
- resultTy, discriminator, dc);
1321
- closure->setParameterList (params);
1322
- closure->setType (selfFnTy);
1323
- closure->setThunkKind (AutoClosureExpr::Kind::SingleCurryThunk);
1324
- cs.cacheType (closure);
1325
1302
1326
1303
auto refTy = cs.getType (ref)->castTo <FunctionType>();
1327
- auto calleeFnType = refTy->getResult ()->castTo <FunctionType>();
1328
- auto calleeParams = calleeFnType->getParams ();
1329
- auto calleeResultTy = calleeFnType->getResult ();
1330
1304
1331
1305
auto selfParam = refTy->getParams ()[0 ];
1332
1306
auto selfParamTy = selfParam.getPlainType ();
1333
1307
1334
1308
Expr *selfOpenedRef = selfParamRef;
1335
1309
1336
- // If the 'self' parameter has non-trivial ownership, adjust the
1337
- // argument accordingly.
1338
- switch (selfParam.getValueOwnership ()) {
1339
- case ValueOwnership::Default:
1340
- case ValueOwnership::InOut:
1341
- break ;
1342
-
1343
- case ValueOwnership::Owned:
1344
- case ValueOwnership::Shared:
1345
- auto selfArgTy = ParenType::get (context, selfParam.getPlainType (),
1346
- selfParam.getParameterFlags ());
1347
- selfOpenedRef->setType (selfArgTy);
1348
- cs.cacheType (selfOpenedRef);
1349
- break ;
1350
- }
1351
-
1352
1310
if (selfParamTy->hasOpenedExistential ()) {
1353
1311
// If we're opening an existential:
1354
1312
// - the type of 'ref' inside the closure is written in terms of the
@@ -1363,93 +1321,23 @@ namespace {
1363
1321
cs.cacheType (selfOpenedRef);
1364
1322
}
1365
1323
1366
- // (Self) -> ...
1367
- ApplyExpr *selfCall =
1368
- DotSyntaxCallExpr::create (context, ref, SourceLoc (), selfOpenedRef);
1369
- selfCall->setType (refTy->getResult ());
1370
- cs.cacheType (selfCall);
1324
+ // FIXME: selfParamRef ownership
1371
1325
1372
- auto &appliedWrappers = solution.appliedPropertyWrappers [locator.getAnchor ()];
1373
- if (!appliedWrappers.empty ()) {
1374
- auto fnDecl = AnyFunctionRef (dyn_cast<AbstractFunctionDecl>(member));
1375
- auto callee = resolveConcreteDeclRef (member, locator);
1376
- auto *closure = buildPropertyWrapperFnThunk (selfCall, calleeFnType,
1377
- fnDecl, callee, appliedWrappers);
1378
-
1379
- // FIXME: Verify ExtInfo state is correct, not working by accident.
1380
- FunctionType::ExtInfo info;
1381
- ref->setType (
1382
- FunctionType::get (refTy->getParams (), selfCall->getType (), info));
1383
- cs.cacheType (ref);
1384
-
1385
- // FIXME: There's more work to do.
1386
- return closure;
1387
- }
1388
-
1389
- // Pass all the closure parameters to the call.
1390
- SmallVector<Argument, 4 > args;
1391
- for (auto idx : indices (*params)) {
1392
- auto *param = params->get (idx);
1393
- auto calleeParamType = calleeParams[idx].getParameterType ();
1394
-
1395
- auto type = param->getType ();
1396
-
1397
- Expr *paramRef =
1398
- new (context) DeclRefExpr (param, DeclNameLoc (), /* implicit*/ true );
1399
- paramRef->setType (
1400
- param->isInOut ()
1401
- ? LValueType::get (type)
1402
- : type);
1403
- cs.cacheType (paramRef);
1404
-
1405
- paramRef = coerceToType (
1406
- paramRef,
1407
- param->isInOut ()
1408
- ? LValueType::get (calleeParamType)
1409
- : calleeParamType,
1410
- locator);
1411
-
1412
- if (param->isInOut ()) {
1413
- paramRef =
1414
- new (context) InOutExpr (SourceLoc (), paramRef, calleeParamType,
1415
- /* implicit=*/ true );
1416
- cs.cacheType (paramRef);
1417
- } else if (param->isVariadic ()) {
1418
- assert (calleeParamType->isEqual (paramRef->getType ()));
1419
- paramRef = VarargExpansionExpr::createParamExpansion (context, paramRef);
1420
- cs.cacheType (paramRef);
1421
- }
1422
-
1423
- args.emplace_back (SourceLoc (), calleeParams[idx].getLabel (), paramRef);
1424
- }
1425
-
1426
- // (Self) -> (Args...) -> ...
1427
- auto *argList = ArgumentList::createImplicit (context, args);
1428
- auto *closureCall = CallExpr::createImplicit (context, selfCall, argList);
1429
- closureCall->setType (calleeResultTy);
1430
- cs.cacheType (closureCall);
1431
-
1432
- Expr *closureBody = closureCall;
1433
- closureBody = coerceToType (closureCall, resultTy, locator);
1434
-
1435
- if (selfFnTy->getExtInfo ().isThrowing ()) {
1436
- closureBody = new (context) TryExpr (closureBody->getStartLoc (), closureBody,
1437
- cs.getType (closureBody),
1438
- /* implicit=*/ true );
1439
- cs.cacheType (closureBody);
1440
- }
1326
+ auto *const thunk = buildSingleCurryThunk (
1327
+ selfOpenedRef, ref, dyn_cast<AbstractFunctionDecl>(member), selfFnTy,
1328
+ locator);
1441
1329
1442
1330
if (selfParam.getPlainType ()->hasOpenedExistential ()) {
1443
- closureBody =
1444
- new (context) OpenExistentialExpr (
1445
- selfParamRef, cast<OpaqueValueExpr>(selfOpenedRef),
1446
- closureBody, resultTy);
1447
- cs.cacheType (closureBody);
1448
- }
1331
+ auto *body = thunk->getSingleExpressionBody ();
1332
+ body = new (context) OpenExistentialExpr (
1333
+ selfParamRef, cast<OpaqueValueExpr>(selfOpenedRef), body,
1334
+ resultTy);
1335
+ cs.cacheType (body);
1449
1336
1450
- closure->setBody (closureBody);
1337
+ thunk->setBody (body);
1338
+ }
1451
1339
1452
- return closure ;
1340
+ return thunk ;
1453
1341
}
1454
1342
1455
1343
// / Build a new member reference with the given base and member.
0 commit comments