Skip to content

Commit 19fe19e

Browse files
committed
Address review feedback
1 parent f6324c8 commit 19fe19e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lib/Sema/CSApply.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,17 @@ namespace {
542542
/// given callee locator.
543543
llvm::DenseMap<ConstraintLocator *, ConcreteDeclRef> CachedConcreteRefs;
544544

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.
545548
ConcreteDeclRef
546549
resolveConcreteDeclRef(ValueDecl *decl, ConstraintLocatorBuilder locator) {
547550
if (!decl)
548551
return ConcreteDeclRef();
549552

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`.
550556
auto *loc = getConstraintSystem().getConstraintLocator(locator);
551557
auto &ref = CachedConcreteRefs[loc];
552558
if (!ref)
@@ -3044,7 +3050,9 @@ namespace {
30443050
auto *calleeLoc = CalleeLocators[expr];
30453051
assert(calleeLoc);
30463052

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.
30483056
ConcreteDeclRef callee;
30493057
if (auto overload = solution.getOverloadChoiceIfAvailable(calleeLoc)) {
30503058
auto *decl = overload->choice.getDeclOrNull();
@@ -5216,12 +5224,12 @@ static bool hasCurriedSelf(ConstraintSystem &cs, ConcreteDeclRef callee,
52165224
return false;
52175225
}
52185226

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) {
52255233
auto &tc = getConstraintSystem().getTypeChecker();
52265234
auto params = funcType->getParams();
52275235

0 commit comments

Comments
 (0)