@@ -542,11 +542,17 @@ namespace {
542
542
// / given callee locator.
543
543
llvm::DenseMap<ConstraintLocator *, ConcreteDeclRef> CachedConcreteRefs;
544
544
545
+ // / Resolves the contextual substitutions for a reference to a declaration
546
+ // / at a given locator. This should be preferred to
547
+ // / Solution::resolveConcreteDeclRef as it caches the result.
545
548
ConcreteDeclRef
546
549
resolveConcreteDeclRef (ValueDecl *decl, ConstraintLocatorBuilder locator) {
547
550
if (!decl)
548
551
return ConcreteDeclRef ();
549
552
553
+ // Cache the resulting concrete reference. Ideally this would be done on
554
+ // Solution, however unfortunately that would require a const_cast which
555
+ // would be undefined behaviour if we ever had a `const Solution`.
550
556
auto *loc = getConstraintSystem ().getConstraintLocator (locator);
551
557
auto &ref = CachedConcreteRefs[loc];
552
558
if (!ref)
@@ -3044,7 +3050,9 @@ namespace {
3044
3050
auto *calleeLoc = CalleeLocators[expr];
3045
3051
assert (calleeLoc);
3046
3052
3047
- // Resolve the callee for the application if we have one.
3053
+ // Resolve the callee for the application if we have one. Note that we're
3054
+ // using `resolveConcreteDeclRef` instead `solution.resolveLocatorToDecl`
3055
+ // here to benefit from ExprRewriter's cache of concrete refs.
3048
3056
ConcreteDeclRef callee;
3049
3057
if (auto overload = solution.getOverloadChoiceIfAvailable (calleeLoc)) {
3050
3058
auto *decl = overload->choice .getDeclOrNull ();
@@ -5216,12 +5224,12 @@ static bool hasCurriedSelf(ConstraintSystem &cs, ConcreteDeclRef callee,
5216
5224
return false ;
5217
5225
}
5218
5226
5219
- Expr *ExprRewriter::coerceCallArguments (
5220
- Expr *arg, AnyFunctionType *funcType, ConcreteDeclRef callee,
5221
- ApplyExpr *apply,
5222
- ArrayRef<Identifier> argLabels,
5223
- bool hasTrailingClosure,
5224
- ConstraintLocatorBuilder locator) {
5227
+ Expr *ExprRewriter::coerceCallArguments (Expr *arg, AnyFunctionType *funcType,
5228
+ ConcreteDeclRef callee,
5229
+ ApplyExpr *apply,
5230
+ ArrayRef<Identifier> argLabels,
5231
+ bool hasTrailingClosure,
5232
+ ConstraintLocatorBuilder locator) {
5225
5233
auto &tc = getConstraintSystem ().getTypeChecker ();
5226
5234
auto params = funcType->getParams ();
5227
5235
0 commit comments