@@ -384,12 +384,13 @@ namespace {
384
384
385
385
public:
386
386
// / Build a reference to the given declaration.
387
- Expr *buildDeclRef (OverloadChoice choice , DeclNameLoc loc, Type openedType ,
387
+ Expr *buildDeclRef (SelectedOverload overload , DeclNameLoc loc,
388
388
ConstraintLocatorBuilder locator, bool implicit,
389
- FunctionRefKind functionRefKind,
390
389
AccessSemantics semantics) {
390
+ auto choice = overload.choice ;
391
391
assert (choice.getKind () != OverloadChoiceKind::DeclViaDynamic);
392
392
auto *decl = choice.getDecl ();
393
+ auto fullType = simplifyType (overload.openedFullType );
393
394
394
395
// Determine the declaration selected for this overloaded reference.
395
396
auto &ctx = cs.getASTContext ();
@@ -399,10 +400,7 @@ namespace {
399
400
if (decl->getDeclContext ()->isTypeContext () && isa<FuncDecl>(decl)) {
400
401
assert (cast<FuncDecl>(decl)->isOperator () && " Must be an operator" );
401
402
402
- auto openedFnType = openedType->castTo <FunctionType>();
403
- auto simplifiedFnType
404
- = simplifyType (openedFnType)->castTo <FunctionType>();
405
- auto baseTy = getBaseType (simplifiedFnType);
403
+ auto baseTy = getBaseType (fullType->castTo <FunctionType>());
406
404
407
405
// Handle operator requirements found in protocols.
408
406
if (auto proto = dyn_cast<ProtocolDecl>(decl->getDeclContext ())) {
@@ -424,7 +422,10 @@ namespace {
424
422
// FIXME: the hop through 'getDecl()' is because
425
423
// SpecializedProtocolConformance doesn't substitute into
426
424
// witnesses' ConcreteDeclRefs.
427
- Type expectedFnType = simplifiedFnType->getResult ();
425
+ Type expectedFnType = simplifyType (overload.openedType );
426
+ assert (expectedFnType->isEqual (
427
+ fullType->castTo <AnyFunctionType>()->getResult ()) &&
428
+ " Cannot handle adjustments made to the opened type" );
428
429
Expr *refExpr;
429
430
if (witness->getDeclContext ()->isTypeContext ()) {
430
431
Expr *base =
@@ -435,7 +436,7 @@ namespace {
435
436
} else {
436
437
auto declRefExpr = new (ctx) DeclRefExpr (witness, loc,
437
438
/* Implicit=*/ false );
438
- declRefExpr->setFunctionRefKind (functionRefKind );
439
+ declRefExpr->setFunctionRefKind (choice. getFunctionRefKind () );
439
440
refExpr = declRefExpr;
440
441
}
441
442
@@ -464,26 +465,22 @@ namespace {
464
465
TypeExpr::createImplicitHack (loc.getBaseNameLoc (), baseTy, ctx);
465
466
cs.cacheExprTypes (base);
466
467
467
- return buildMemberRef (base, openedType, SourceLoc (), choice, loc,
468
- openedFnType->getResult (), locator, locator,
469
- implicit, functionRefKind, semantics);
468
+ return buildMemberRef (base, SourceLoc (), overload, loc, locator,
469
+ locator, implicit, semantics);
470
470
}
471
471
472
- auto type = solution.simplifyType (openedType);
473
-
474
472
if (isa<TypeDecl>(decl) && !isa<ModuleDecl>(decl)) {
475
473
auto typeExpr = TypeExpr::createImplicitHack (
476
- loc.getBaseNameLoc (), type->getMetatypeInstanceType (),
477
- ctx);
474
+ loc.getBaseNameLoc (), fullType->getMetatypeInstanceType (), ctx);
478
475
cs.cacheType (typeExpr);
479
476
return typeExpr;
480
477
}
481
478
482
479
auto ref = resolveConcreteDeclRef (decl, locator);
483
480
auto declRefExpr =
484
- new (ctx) DeclRefExpr (ref, loc, implicit, semantics, type );
481
+ new (ctx) DeclRefExpr (ref, loc, implicit, semantics, fullType );
485
482
cs.cacheType (declRefExpr);
486
- declRefExpr->setFunctionRefKind (functionRefKind );
483
+ declRefExpr->setFunctionRefKind (choice. getFunctionRefKind () );
487
484
return forceUnwrapIfExpected (declRefExpr, choice, locator);
488
485
}
489
486
@@ -734,12 +731,15 @@ namespace {
734
731
}
735
732
736
733
// / Build a new member reference with the given base and member.
737
- Expr *buildMemberRef (Expr *base, Type openedFullType, SourceLoc dotLoc,
738
- OverloadChoice choice , DeclNameLoc memberLoc,
739
- Type openedType, ConstraintLocatorBuilder locator,
734
+ Expr *buildMemberRef (Expr *base, SourceLoc dotLoc,
735
+ SelectedOverload overload , DeclNameLoc memberLoc,
736
+ ConstraintLocatorBuilder locator,
740
737
ConstraintLocatorBuilder memberLocator, bool Implicit,
741
- FunctionRefKind functionRefKind,
742
738
AccessSemantics semantics) {
739
+ auto choice = overload.choice ;
740
+ auto openedType = overload.openedType ;
741
+ auto openedFullType = overload.openedFullType ;
742
+
743
743
ValueDecl *member = choice.getDecl ();
744
744
745
745
auto &context = cs.getASTContext ();
@@ -770,7 +770,7 @@ namespace {
770
770
" Direct property access doesn't make sense for this" );
771
771
auto ref = new (context) DeclRefExpr (memberRef, memberLoc, Implicit);
772
772
cs.setType (ref, refTy);
773
- ref->setFunctionRefKind (functionRefKind );
773
+ ref->setFunctionRefKind (choice. getFunctionRefKind () );
774
774
auto *DSBI = cs.cacheType (new (context) DotSyntaxBaseIgnoredExpr (
775
775
base, dotLoc, ref, cs.getType (ref)));
776
776
return forceUnwrapIfExpected (DSBI, choice, memberLocator);
@@ -969,7 +969,7 @@ namespace {
969
969
// Handle all other references.
970
970
auto declRefExpr = new (context) DeclRefExpr (memberRef, memberLoc,
971
971
Implicit, semantics);
972
- declRefExpr->setFunctionRefKind (functionRefKind );
972
+ declRefExpr->setFunctionRefKind (choice. getFunctionRefKind () );
973
973
cs.setType (declRefExpr, refTy);
974
974
Expr *ref = declRefExpr;
975
975
@@ -1005,9 +1005,6 @@ namespace {
1005
1005
1006
1006
return finishApply (apply, memberRef, openedType, locator);
1007
1007
}
1008
-
1009
- // / Describes either a type or the name of a type to be resolved.
1010
- using TypeOrName = llvm::PointerUnion<Identifier, Type>;
1011
1008
1012
1009
// / Convert the given literal expression via a protocol pair.
1013
1010
// /
@@ -2273,10 +2270,8 @@ namespace {
2273
2270
return expr;
2274
2271
}
2275
2272
2276
- return buildDeclRef (selected->choice , expr->getNameLoc (),
2277
- selected->openedFullType , locator, expr->isImplicit (),
2278
- expr->getFunctionRefKind (),
2279
- expr->getAccessSemantics ());
2273
+ return buildDeclRef (*selected, expr->getNameLoc (), locator,
2274
+ expr->isImplicit (), expr->getAccessSemantics ());
2280
2275
}
2281
2276
2282
2277
Expr *visitSuperRefExpr (SuperRefExpr *expr) {
@@ -2304,12 +2299,9 @@ namespace {
2304
2299
// Determine the declaration selected for this overloaded reference.
2305
2300
auto locator = cs.getConstraintLocator (expr);
2306
2301
auto selected = solution.getOverloadChoice (locator);
2307
- auto choice = selected.choice ;
2308
2302
2309
- return buildDeclRef (choice, expr->getNameLoc (), selected.openedFullType ,
2310
- locator, expr->isImplicit (),
2311
- choice.getFunctionRefKind (),
2312
- AccessSemantics::Ordinary);
2303
+ return buildDeclRef (selected, expr->getNameLoc (), locator,
2304
+ expr->isImplicit (), AccessSemantics::Ordinary);
2313
2305
}
2314
2306
2315
2307
Expr *visitUnresolvedDeclRefExpr (UnresolvedDeclRefExpr *expr) {
@@ -2328,10 +2320,9 @@ namespace {
2328
2320
ConstraintLocator::Member);
2329
2321
auto selected = solution.getOverloadChoice (memberLocator);
2330
2322
return buildMemberRef (
2331
- expr->getBase (), selected.openedFullType , expr->getDotLoc (),
2332
- selected.choice , expr->getNameLoc (), selected.openedType ,
2323
+ expr->getBase (), expr->getDotLoc (), selected, expr->getNameLoc (),
2333
2324
cs.getConstraintLocator (expr), memberLocator, expr->isImplicit (),
2334
- selected. choice . getFunctionRefKind (), expr->getAccessSemantics ());
2325
+ expr->getAccessSemantics ());
2335
2326
}
2336
2327
2337
2328
Expr *visitDynamicMemberRefExpr (DynamicMemberRefExpr *expr) {
@@ -2373,10 +2364,8 @@ namespace {
2373
2364
// Build the member reference.
2374
2365
auto *exprLoc = cs.getConstraintLocator (expr);
2375
2366
auto result = buildMemberRef (
2376
- base, selected.openedFullType , expr->getDotLoc (), selected.choice ,
2377
- expr->getNameLoc (), selected.openedType ,
2378
- exprLoc, memberLocator, expr->isImplicit (),
2379
- selected.choice .getFunctionRefKind (), AccessSemantics::Ordinary);
2367
+ base, expr->getDotLoc (), selected, expr->getNameLoc (), exprLoc,
2368
+ memberLocator, expr->isImplicit (), AccessSemantics::Ordinary);
2380
2369
if (!result)
2381
2370
return nullptr ;
2382
2371
@@ -2515,18 +2504,17 @@ namespace {
2515
2504
Expr *applyCtorRefExpr (Expr *expr, Expr *base, SourceLoc dotLoc,
2516
2505
DeclNameLoc nameLoc, bool implicit,
2517
2506
ConstraintLocator *ctorLocator,
2518
- OverloadChoice choice,
2519
- FunctionRefKind functionRefKind, Type openedType) {
2507
+ SelectedOverload overload) {
2508
+ auto choice = overload. choice ;
2520
2509
assert (choice.getKind () != OverloadChoiceKind::DeclViaDynamic);
2521
2510
auto *ctor = cast<ConstructorDecl>(choice.getDecl ());
2522
2511
2523
2512
// If the subexpression is a metatype, build a direct reference to the
2524
2513
// constructor.
2525
2514
if (cs.getType (base)->is <AnyMetatypeType>()) {
2526
2515
return buildMemberRef (
2527
- base, openedType, dotLoc, choice, nameLoc, cs.getType (expr),
2528
- ConstraintLocatorBuilder (cs.getConstraintLocator (expr)),
2529
- ctorLocator, implicit, functionRefKind, AccessSemantics::Ordinary);
2516
+ base, dotLoc, overload, nameLoc, cs.getConstraintLocator (expr),
2517
+ ctorLocator, implicit, AccessSemantics::Ordinary);
2530
2518
}
2531
2519
2532
2520
// The subexpression must be either 'self' or 'super'.
@@ -2570,8 +2558,9 @@ namespace {
2570
2558
2571
2559
// Build a partial application of the delegated initializer.
2572
2560
auto callee = resolveConcreteDeclRef (ctor, ctorLocator);
2573
- Expr *ctorRef = buildOtherConstructorRef (openedType, callee, base,
2574
- nameLoc, ctorLocator, implicit);
2561
+ Expr *ctorRef = buildOtherConstructorRef (overload.openedFullType , callee,
2562
+ base, nameLoc, ctorLocator,
2563
+ implicit);
2575
2564
auto *call = new (cs.getASTContext ()) DotSyntaxCallExpr (ctorRef, dotLoc,
2576
2565
base);
2577
2566
@@ -2587,10 +2576,8 @@ namespace {
2587
2576
expr,
2588
2577
ConstraintLocator::ConstructorMember);
2589
2578
if (auto selected = solution.getOverloadChoiceIfAvailable (ctorLocator)) {
2590
- auto choice = selected->choice ;
2591
2579
return applyCtorRefExpr (
2592
- expr, base, dotLoc, nameLoc, implicit, ctorLocator, choice,
2593
- choice.getFunctionRefKind (), selected->openedFullType );
2580
+ expr, base, dotLoc, nameLoc, implicit, ctorLocator, *selected);
2594
2581
}
2595
2582
2596
2583
// Determine the declaration selected for this overloaded reference.
@@ -2618,9 +2605,7 @@ namespace {
2618
2605
cs.diagnoseDeprecatedConditionalConformanceOuterAccess (
2619
2606
UDE, selected.choice .getDecl ());
2620
2607
2621
- return buildDeclRef (selected.choice , nameLoc, selected.openedFullType ,
2622
- memberLocator, implicit,
2623
- selected.choice .getFunctionRefKind (),
2608
+ return buildDeclRef (selected, nameLoc, memberLocator, implicit,
2624
2609
AccessSemantics::Ordinary);
2625
2610
}
2626
2611
@@ -2651,11 +2636,9 @@ namespace {
2651
2636
case OverloadChoiceKind::Decl:
2652
2637
case OverloadChoiceKind::DeclViaUnwrappedOptional:
2653
2638
case OverloadChoiceKind::DeclViaDynamic:
2654
- return buildMemberRef (base, selected.openedFullType , dotLoc,
2655
- selected.choice , nameLoc, selected.openedType ,
2639
+ return buildMemberRef (base, dotLoc, selected, nameLoc,
2656
2640
cs.getConstraintLocator (expr), memberLocator,
2657
- implicit, selected.choice .getFunctionRefKind (),
2658
- AccessSemantics::Ordinary);
2641
+ implicit, AccessSemantics::Ordinary);
2659
2642
2660
2643
case OverloadChoiceKind::TupleIndex: {
2661
2644
Type toType = simplifyType (cs.getType (expr));
@@ -6485,12 +6468,10 @@ static Expr *buildCallAsFunctionMethodRef(
6485
6468
ExprRewriter &rewriter, ApplyExpr *apply, SelectedOverload selected,
6486
6469
ConstraintLocatorBuilder applyFunctionLoc) {
6487
6470
auto *fn = apply->getFn ();
6488
- auto choice = selected.choice ;
6489
6471
// Create direct reference to `callAsFunction` method.
6490
6472
auto *declRef = rewriter.buildMemberRef (
6491
- fn, selected.openedFullType , /* dotLoc*/ SourceLoc (), choice,
6492
- DeclNameLoc (fn->getEndLoc ()), selected.openedType , applyFunctionLoc,
6493
- applyFunctionLoc, /* implicit*/ true , choice.getFunctionRefKind (),
6473
+ fn, /* dotLoc*/ SourceLoc (), selected, DeclNameLoc (fn->getEndLoc ()),
6474
+ applyFunctionLoc, applyFunctionLoc, /* implicit*/ true ,
6494
6475
AccessSemantics::Ordinary);
6495
6476
if (!declRef)
6496
6477
return nullptr ;
@@ -6523,12 +6504,9 @@ ExprRewriter::finishApplyDynamicCallable(ApplyExpr *apply,
6523
6504
bool useKwargsMethod = argumentLabel == ctx.Id_withKeywordArguments ;
6524
6505
6525
6506
// Construct expression referencing the `dynamicallyCall` method.
6526
- auto member = buildMemberRef (fn, selected.openedFullType ,
6527
- SourceLoc (), selected.choice ,
6528
- DeclNameLoc (method->getNameLoc ()),
6529
- selected.openedType , loc, loc, /* implicit*/ true ,
6530
- selected.choice .getFunctionRefKind (),
6531
- AccessSemantics::Ordinary);
6507
+ auto member = buildMemberRef (fn, SourceLoc (), selected,
6508
+ DeclNameLoc (method->getNameLoc ()), loc, loc,
6509
+ /* implicit*/ true , AccessSemantics::Ordinary);
6532
6510
6533
6511
// Construct argument to the method (either an array or dictionary
6534
6512
// expression).
@@ -6883,12 +6861,9 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, ConcreteDeclRef callee,
6883
6861
// Consider the constructor decl reference expr 'implicit', but the
6884
6862
// constructor call expr itself has the apply's 'implicitness'.
6885
6863
auto ctorRef = resolveConcreteDeclRef (choice.getDecl (), ctorLocator);
6886
- Expr *declRef = buildMemberRef (fn, selected->openedFullType ,
6887
- /* dotLoc=*/ SourceLoc (), choice,
6888
- DeclNameLoc (fn->getEndLoc ()),
6889
- selected->openedType , locator, ctorLocator,
6890
- /* Implicit=*/ true ,
6891
- choice.getFunctionRefKind (),
6864
+ Expr *declRef = buildMemberRef (fn, /* dotLoc=*/ SourceLoc (), *selected,
6865
+ DeclNameLoc (fn->getEndLoc ()), locator,
6866
+ ctorLocator, /* Implicit=*/ true ,
6892
6867
AccessSemantics::Ordinary);
6893
6868
if (!declRef)
6894
6869
return nullptr ;
0 commit comments