@@ -58,14 +58,13 @@ static bool isOpenedAnyObject(Type type) {
58
58
return archetype->getOpenedExistentialType ()->isAnyObject ();
59
59
}
60
60
61
- SubstitutionMap Solution::computeSubstitutions (
62
- GenericSignature sig,
63
- ConstraintLocatorBuilder locatorBuilder ) const {
61
+ SubstitutionMap
62
+ Solution::computeSubstitutions ( GenericSignature sig,
63
+ ConstraintLocator *locator ) const {
64
64
if (sig.isNull ())
65
65
return SubstitutionMap ();
66
66
67
67
// Gather the substitutions from dependent types to concrete types.
68
- auto locator = getConstraintSystem ().getConstraintLocator (locatorBuilder);
69
68
auto openedTypes = OpenedTypes.find (locator);
70
69
71
70
// If we have a member reference on an existential, there are no
@@ -98,7 +97,7 @@ SubstitutionMap Solution::computeSubstitutions(
98
97
99
98
ConcreteDeclRef
100
99
Solution::resolveConcreteDeclRef (ValueDecl *decl,
101
- ConstraintLocatorBuilder locator) const {
100
+ ConstraintLocator * locator) const {
102
101
if (!decl)
103
102
return ConcreteDeclRef ();
104
103
@@ -501,7 +500,7 @@ namespace {
501
500
return typeExpr;
502
501
}
503
502
504
- auto ref = solution. resolveConcreteDeclRef (decl, locator);
503
+ auto ref = resolveConcreteDeclRef (decl, locator);
505
504
auto declRefExpr =
506
505
new (ctx) DeclRefExpr (ref, loc, implicit, semantics, type);
507
506
cs.cacheType (declRefExpr);
@@ -539,6 +538,24 @@ namespace {
539
538
// / will no longer be equivalent to the one stored in the solution.
540
539
llvm::DenseMap<ApplyExpr *, ConstraintLocator *> CalleeLocators;
541
540
541
+ // / A cache of decl references with their contextual substitutions for a
542
+ // / given callee locator.
543
+ llvm::DenseMap<ConstraintLocator *, ConcreteDeclRef> CachedConcreteRefs;
544
+
545
+ ConcreteDeclRef
546
+ resolveConcreteDeclRef (ValueDecl *decl, ConstraintLocatorBuilder locator) {
547
+ if (!decl)
548
+ return ConcreteDeclRef ();
549
+
550
+ auto *loc = getConstraintSystem ().getConstraintLocator (locator);
551
+ auto &ref = CachedConcreteRefs[loc];
552
+ if (!ref)
553
+ ref = solution.resolveConcreteDeclRef (decl, loc);
554
+
555
+ assert (ref.getDecl () == decl);
556
+ return ref;
557
+ }
558
+
542
559
// / Members which are AbstractFunctionDecls but not FuncDecls cannot
543
560
// / mutate self.
544
561
bool isNonMutatingMember (ValueDecl *member) {
@@ -763,7 +780,7 @@ namespace {
763
780
}
764
781
765
782
// Build a member reference.
766
- auto memberRef = solution. resolveConcreteDeclRef (member, memberLocator);
783
+ auto memberRef = resolveConcreteDeclRef (member, memberLocator);
767
784
auto refTy = solution.simplifyType (openedFullType);
768
785
769
786
// If we're referring to the member of a module, it's just a simple
@@ -1381,7 +1398,7 @@ namespace {
1381
1398
}
1382
1399
1383
1400
// Compute the concrete reference to the subscript.
1384
- auto subscriptRef = solution. resolveConcreteDeclRef (subscript, memberLoc);
1401
+ auto subscriptRef = resolveConcreteDeclRef (subscript, memberLoc);
1385
1402
1386
1403
// Figure out the index and result types.
1387
1404
Type resultTy;
@@ -2412,8 +2429,8 @@ namespace {
2412
2429
2413
2430
// If there was an argument, apply it.
2414
2431
if (auto arg = expr->getArgument ()) {
2415
- auto callee = solution. resolveConcreteDeclRef (selected.choice .getDecl (),
2416
- memberLocator);
2432
+ auto callee = resolveConcreteDeclRef (selected.choice .getDecl (),
2433
+ memberLocator);
2417
2434
ApplyExpr *apply = CallExpr::create (
2418
2435
tc.Context , result, arg, expr->getArgumentLabels (),
2419
2436
expr->getArgumentLabelLocs (), expr->hasTrailingClosure (),
@@ -2593,7 +2610,7 @@ namespace {
2593
2610
}
2594
2611
2595
2612
// Build a partial application of the delegated initializer.
2596
- auto callee = solution. resolveConcreteDeclRef (ctor, ctorLocator);
2613
+ auto callee = resolveConcreteDeclRef (ctor, ctorLocator);
2597
2614
Expr *ctorRef = buildOtherConstructorRef (openedType, callee, base,
2598
2615
nameLoc, ctorLocator, implicit);
2599
2616
auto *call = new (cs.getASTContext ()) DotSyntaxCallExpr (ctorRef, dotLoc,
@@ -3028,7 +3045,11 @@ namespace {
3028
3045
assert (calleeLoc);
3029
3046
3030
3047
// Resolve the callee for the application if we have one.
3031
- auto callee = solution.resolveLocatorToDecl (calleeLoc);
3048
+ ConcreteDeclRef callee;
3049
+ if (auto overload = solution.getOverloadChoiceIfAvailable (calleeLoc)) {
3050
+ auto *decl = overload->choice .getDeclOrNull ();
3051
+ callee = resolveConcreteDeclRef (decl, calleeLoc);
3052
+ }
3032
3053
return finishApply (expr, callee, cs.getType (expr),
3033
3054
cs.getConstraintLocator (expr));
3034
3055
}
@@ -4535,7 +4556,7 @@ namespace {
4535
4556
resolvedTy = simplifyType (resolvedTy);
4536
4557
4537
4558
// Compute the concrete reference to the member.
4538
- auto ref = solution. resolveConcreteDeclRef (property, locator);
4559
+ auto ref = resolveConcreteDeclRef (property, locator);
4539
4560
return KeyPathExpr::Component::forProperty (ref, resolvedTy,
4540
4561
componentLoc);
4541
4562
}
@@ -4562,7 +4583,7 @@ namespace {
4562
4583
/* canonicalVararg=*/ false );
4563
4584
4564
4585
// Compute substitutions to refer to the member.
4565
- auto ref = solution. resolveConcreteDeclRef (subscript, locator);
4586
+ auto ref = resolveConcreteDeclRef (subscript, locator);
4566
4587
indexType = indexType.subst (ref.getSubstitutions ());
4567
4588
4568
4589
// If this is a @dynamicMemberLookup reference to resolve a property
@@ -6686,8 +6707,8 @@ static Expr *finishApplyCallAsFunctionMethod(
6686
6707
declRef->setImplicit (apply->isImplicit ());
6687
6708
apply->setFn (declRef);
6688
6709
// Coerce argument to input type of the `callAsFunction` method.
6689
- auto callee = rewriter.solution . resolveConcreteDeclRef (choice.getDecl (),
6690
- applyFunctionLoc);
6710
+ auto callee = rewriter.resolveConcreteDeclRef (choice.getDecl (),
6711
+ applyFunctionLoc);
6691
6712
SmallVector<Identifier, 2 > argLabelsScratch;
6692
6713
auto *arg = rewriter.coerceCallArguments (
6693
6714
apply->getArg (), openedMethodType, callee, apply,
@@ -7081,7 +7102,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, ConcreteDeclRef callee,
7081
7102
// Consider the constructor decl reference expr 'implicit', but the
7082
7103
// constructor call expr itself has the apply's 'implicitness'.
7083
7104
bool isDynamic = choice.getKind () == OverloadChoiceKind::DeclViaDynamic;
7084
- auto ctorRef = solution. resolveConcreteDeclRef (choice.getDecl (), ctorLocator);
7105
+ auto ctorRef = resolveConcreteDeclRef (choice.getDecl (), ctorLocator);
7085
7106
Expr *declRef = buildMemberRef (fn, selected->openedFullType ,
7086
7107
/* dotLoc=*/ SourceLoc (), choice,
7087
7108
DeclNameLoc (fn->getEndLoc ()),
0 commit comments