[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`.
This commit is contained in:
Pavel Yaskevich
2019-12-18 13:31:32 -08:00
parent 30876a42de
commit cf2cad0cd5
3 changed files with 27 additions and 9 deletions

View File

@@ -434,7 +434,10 @@ ConstraintLocator *ConstraintSystem::getConstraintLocator(
ConstraintLocator *ConstraintSystem::getCalleeLocator(
ConstraintLocator *locator, bool lookThroughApply,
llvm::function_ref<Type(const Expr *)> getType) {
llvm::function_ref<Type(const Expr *)> getType,
llvm::function_ref<Type(Type)> simplifyType,
llvm::function_ref<Optional<SelectedOverload>(ConstraintLocator *)>
getOverloadFor) {
auto *anchor = locator->getAnchor();
assert(anchor && "Expected an anchor!");
@@ -494,7 +497,7 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
// Unfortunately CSDiag currently calls into getCalleeLocator, so all bets
// are off. Once we remove that legacy diagnostic logic, we should be able
// to assert here.
fnTy = getFixedTypeRecursive(fnTy, /*wantRValue*/ true);
fnTy = simplifyType(fnTy);
// For an apply of a metatype, we have a short-form constructor. Unlike
// other locators to callees, these are anchored on the apply expression
@@ -550,7 +553,7 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
// and clean up a bunch of other special cases. Doing so may require a bit
// of hacking in CSGen though.
if (UME->hasArguments()) {
if (auto overload = findSelectedOverloadFor(calleeLoc)) {
if (auto overload = getOverloadFor(calleeLoc)) {
if (auto *loc = getSpecialFnCalleeLoc(overload->boundType))
return loc;
}
@@ -2790,7 +2793,7 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
locator = getConstraintLocator(assignExpr->getSrc());
}
auto *calleeLocator = getCalleeLocator(locator);
auto *calleeLocator = solution.getCalleeLocator(locator);
if (!commonCalleeLocator)
commonCalleeLocator = calleeLocator;
else if (commonCalleeLocator != calleeLocator)