@@ -96,6 +96,17 @@ SubstitutionMap Solution::computeSubstitutions(
96
96
lookupConformanceFn);
97
97
}
98
98
99
+ ConcreteDeclRef
100
+ Solution::resolveConcreteDeclRef (ValueDecl *decl,
101
+ ConstraintLocatorBuilder locator) const {
102
+ if (!decl)
103
+ return ConcreteDeclRef ();
104
+
105
+ // Get the generic signatue of the decl and compute the substitutions.
106
+ auto sig = decl->getInnermostDeclContext ()->getGenericSignatureOfContext ();
107
+ return ConcreteDeclRef (decl, computeSubstitutions (sig, locator));
108
+ }
109
+
99
110
static bool shouldAccessStorageDirectly (Expr *base, VarDecl *member,
100
111
DeclContext *DC) {
101
112
// This only matters for stored properties.
@@ -490,13 +501,9 @@ namespace {
490
501
return typeExpr;
491
502
}
492
503
493
- auto substitutions =
494
- solution.computeSubstitutions (
495
- decl->getInnermostDeclContext ()->getGenericSignatureOfContext (),
496
- locator);
504
+ auto ref = solution.resolveConcreteDeclRef (decl, locator);
497
505
auto declRefExpr =
498
- new (ctx) DeclRefExpr (ConcreteDeclRef (decl, substitutions),
499
- loc, implicit, semantics, type);
506
+ new (ctx) DeclRefExpr (ref, loc, implicit, semantics, type);
500
507
cs.cacheType (declRefExpr);
501
508
declRefExpr->setFunctionRefKind (functionRefKind);
502
509
return forceUnwrapIfExpected (declRefExpr, choice, locator);
@@ -751,12 +758,7 @@ namespace {
751
758
}
752
759
753
760
// Build a member reference.
754
- SubstitutionMap substitutions =
755
- solution.computeSubstitutions (
756
- member->getInnermostDeclContext ()->getGenericSignatureOfContext (),
757
- memberLocator);
758
- auto memberRef = ConcreteDeclRef (member, substitutions);
759
-
761
+ auto memberRef = solution.resolveConcreteDeclRef (member, memberLocator);
760
762
auto refTy = solution.simplifyType (openedFullType);
761
763
762
764
// If we're referring to the member of a module, it's just a simple
@@ -1400,12 +1402,9 @@ namespace {
1400
1402
1401
1403
// Form the subscript expression.
1402
1404
1403
- // Compute the substitutions used to reference the subscript.
1404
- SubstitutionMap substitutions =
1405
- solution.computeSubstitutions (
1406
- subscript->getInnermostDeclContext ()->getGenericSignatureOfContext (),
1407
- locator.withPathElement (locatorKind));
1408
- ConcreteDeclRef subscriptRef (subscript, substitutions);
1405
+ // Compute the concrete reference to the subscript.
1406
+ auto subscriptRef = solution.resolveConcreteDeclRef (
1407
+ subscript, locator.withPathElement (locatorKind));
1409
1408
1410
1409
// Handle dynamic lookup.
1411
1410
if (choice.getKind () == OverloadChoiceKind::DeclViaDynamic ||
@@ -1480,10 +1479,7 @@ namespace {
1480
1479
auto &ctx = tc.Context ;
1481
1480
1482
1481
// Compute the concrete reference.
1483
- SubstitutionMap substitutions =
1484
- solution.computeSubstitutions (ctor->getGenericSignature (), locator);
1485
-
1486
- auto ref = ConcreteDeclRef (ctor, substitutions);
1482
+ auto ref = solution.resolveConcreteDeclRef (ctor, locator);
1487
1483
1488
1484
// The constructor was opened with the allocating type, not the
1489
1485
// initializer type. Map the former into the latter.
@@ -4525,17 +4521,11 @@ namespace {
4525
4521
// There is a fix which diagnoses such situation already.
4526
4522
assert (!varDecl->isStatic ());
4527
4523
4528
- auto dc = property->getInnermostDeclContext ();
4529
-
4530
- // Compute substitutions to refer to the member.
4531
- SubstitutionMap subs = solution.computeSubstitutions (
4532
- dc->getGenericSignatureOfContext (), locator);
4533
-
4534
4524
auto resolvedTy = overload.openedType ;
4535
4525
resolvedTy = simplifyType (resolvedTy);
4536
4526
4537
- auto ref = ConcreteDeclRef (property, subs);
4538
-
4527
+ // Compute the concrete reference to the member.
4528
+ auto ref = solution. resolveConcreteDeclRef (property, locator);
4539
4529
return KeyPathExpr::Component::forProperty (ref, resolvedTy,
4540
4530
componentLoc);
4541
4531
}
@@ -4561,12 +4551,9 @@ namespace {
4561
4551
subscript->getInterfaceType ()->castTo <AnyFunctionType>()->getParams (),
4562
4552
/* canonicalVararg=*/ false );
4563
4553
4564
- SubstitutionMap subs;
4565
- if (auto sig = dc->getGenericSignatureOfContext ()) {
4566
- // Compute substitutions to refer to the member.
4567
- subs = solution.computeSubstitutions (sig, locator);
4568
- indexType = indexType.subst (subs);
4569
- }
4554
+ // Compute substitutions to refer to the member.
4555
+ auto ref = solution.resolveConcreteDeclRef (subscript, locator);
4556
+ indexType = indexType.subst (ref.getSubstitutions ());
4570
4557
4571
4558
// If this is a @dynamicMemberLookup reference to resolve a property
4572
4559
// through the subscript(dynamicMember:) member, restore the
@@ -4599,7 +4586,6 @@ namespace {
4599
4586
auto subscriptType =
4600
4587
simplifyType (overload.openedType )->castTo <AnyFunctionType>();
4601
4588
auto resolvedTy = subscriptType->getResult ();
4602
- auto ref = ConcreteDeclRef (subscript, subs);
4603
4589
4604
4590
// Coerce the indices to the type the subscript expects.
4605
4591
auto *newIndexExpr =
0 commit comments