Skip to content

Commit cf2cad0

Browse files
committed
[ConstraintSystem] Add more information retrieval callbacks to getCalleeLocator
`getCalleeLocator` has to be able to: - Retrieve type for given expression via `getType`; - Simplify given type via `simplifyType`; and - Retrieve a selected overload choice for a given locator via `getOverloadFor`.
1 parent 30876a4 commit cf2cad0

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ ConstraintLocator *Solution::getCalleeLocator(ConstraintLocator *locator,
157157
auto &cs = getConstraintSystem();
158158
return cs.getCalleeLocator(
159159
locator, lookThroughApply,
160-
[&](const Expr *expr) -> Type { return getType(expr); });
160+
[&](const Expr *expr) -> Type { return getType(expr); },
161+
[&](Type type) -> Type { return simplifyType(type)->getRValueType(); },
162+
[&](ConstraintLocator *locator) -> Optional<SelectedOverload> {
163+
return getOverloadChoiceIfAvailable(locator);
164+
});
161165
}
162166

163167
/// Return the implicit access kind for a MemberRefExpr with the

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,10 @@ ConstraintLocator *ConstraintSystem::getConstraintLocator(
434434

435435
ConstraintLocator *ConstraintSystem::getCalleeLocator(
436436
ConstraintLocator *locator, bool lookThroughApply,
437-
llvm::function_ref<Type(const Expr *)> getType) {
437+
llvm::function_ref<Type(const Expr *)> getType,
438+
llvm::function_ref<Type(Type)> simplifyType,
439+
llvm::function_ref<Optional<SelectedOverload>(ConstraintLocator *)>
440+
getOverloadFor) {
438441
auto *anchor = locator->getAnchor();
439442
assert(anchor && "Expected an anchor!");
440443

@@ -494,7 +497,7 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
494497
// Unfortunately CSDiag currently calls into getCalleeLocator, so all bets
495498
// are off. Once we remove that legacy diagnostic logic, we should be able
496499
// to assert here.
497-
fnTy = getFixedTypeRecursive(fnTy, /*wantRValue*/ true);
500+
fnTy = simplifyType(fnTy);
498501

499502
// For an apply of a metatype, we have a short-form constructor. Unlike
500503
// other locators to callees, these are anchored on the apply expression
@@ -550,7 +553,7 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
550553
// and clean up a bunch of other special cases. Doing so may require a bit
551554
// of hacking in CSGen though.
552555
if (UME->hasArguments()) {
553-
if (auto overload = findSelectedOverloadFor(calleeLoc)) {
556+
if (auto overload = getOverloadFor(calleeLoc)) {
554557
if (auto *loc = getSpecialFnCalleeLoc(overload->boundType))
555558
return loc;
556559
}
@@ -2790,7 +2793,7 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
27902793
locator = getConstraintLocator(assignExpr->getSrc());
27912794
}
27922795

2793-
auto *calleeLocator = getCalleeLocator(locator);
2796+
auto *calleeLocator = solution.getCalleeLocator(locator);
27942797
if (!commonCalleeLocator)
27952798
commonCalleeLocator = calleeLocator;
27962799
else if (commonCalleeLocator != calleeLocator)

lib/Sema/ConstraintSystem.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,15 +2270,26 @@ class ConstraintSystem {
22702270
/// callee locator will only be returned for a direct reference such as
22712271
/// \c x.foo rather than \c x.foo().
22722272
/// \param getType The callback to fetch a type for given expression.
2273-
ConstraintLocator *
2274-
getCalleeLocator(ConstraintLocator *locator, bool lookThroughApply,
2275-
llvm::function_ref<Type(const Expr *)> getType);
2273+
/// \param simplifyType The callback to attempt to resolve any type
2274+
/// variables which appear in the given type.
2275+
/// \param getOverloadFor The callback to fetch overload for a given
2276+
/// locator if available.
2277+
ConstraintLocator *getCalleeLocator(
2278+
ConstraintLocator *locator, bool lookThroughApply,
2279+
llvm::function_ref<Type(const Expr *)> getType,
2280+
llvm::function_ref<Type(Type)> simplifyType,
2281+
llvm::function_ref<Optional<SelectedOverload>(ConstraintLocator *)>
2282+
getOverloadFor);
22762283

22772284
ConstraintLocator *getCalleeLocator(ConstraintLocator *locator,
22782285
bool lookThroughApply = true) {
22792286
return getCalleeLocator(
22802287
locator, lookThroughApply,
2281-
[&](const Expr *expr) -> Type { return getType(expr); });
2288+
[&](const Expr *expr) -> Type { return getType(expr); },
2289+
[&](Type type) -> Type { return simplifyType(type)->getRValueType(); },
2290+
[&](ConstraintLocator *locator) -> Optional<SelectedOverload> {
2291+
return findSelectedOverloadFor(locator);
2292+
});
22822293
}
22832294

22842295
public:

0 commit comments

Comments
 (0)