[CS] Use subclasses to expose locator element info

Instead of adding specific accessors directly to
ConstraintLocator::PathElement, add subclasses that expose these
accessors.
This commit is contained in:
Hamish Knight
2019-08-10 18:10:23 +01:00
parent 258d05aab8
commit a0919f73b0
12 changed files with 484 additions and 368 deletions

View File

@@ -1542,14 +1542,14 @@ namespace {
auto *componentLoc = cs.getConstraintLocator(
memberLoc,
LocatorPathElt::getKeyPathDynamicMember(keyPathTy->getAnyNominal()));
LocatorPathElt::KeyPathDynamicMember(keyPathTy->getAnyNominal()));
auto overload = solution.getOverloadChoice(componentLoc);
auto getKeyPathComponentIndex =
[](ConstraintLocator *locator) -> unsigned {
for (const auto &elt : locator->getPath()) {
if (elt.getKind() == ConstraintLocator::KeyPathComponent)
return elt.getKeyPathComponentIdx();
if (auto kpElt = elt.getAs<LocatorPathElt::KeyPathComponent>())
return kpElt->getIndex();
}
llvm_unreachable("no keypath component node");
};
@@ -4245,7 +4245,7 @@ namespace {
Optional<SelectedOverload> foundDecl;
auto locator = cs.getConstraintLocator(
E, ConstraintLocator::PathElement::getKeyPathComponent(i));
E, LocatorPathElt::KeyPathComponent(i));
if (kind == KeyPathExpr::Component::Kind::UnresolvedSubscript) {
locator =
cs.getConstraintLocator(locator,
@@ -5027,7 +5027,7 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr,
auto *toElt
= coerceToType(fromElt, toEltType,
locator.withPathElement(
LocatorPathElt::getTupleElement(i)));
LocatorPathElt::TupleElement(i)));
if (!toElt)
return nullptr;
@@ -5070,7 +5070,7 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr,
auto *toElt
= coerceToType(fromElt, toEltType,
locator.withPathElement(
LocatorPathElt::getTupleElement(source)));
LocatorPathElt::TupleElement(source)));
if (!toElt)
return nullptr;
@@ -5390,7 +5390,7 @@ Expr *ExprRewriter::coerceCallArguments(
auto getArgLocator = [&](unsigned argIdx, unsigned paramIdx)
-> ConstraintLocatorBuilder {
return locator.withPathElement(
LocatorPathElt::getApplyArgToParam(argIdx, paramIdx));
LocatorPathElt::ApplyArgToParam(argIdx, paramIdx));
};
bool matchCanFail =
@@ -5934,8 +5934,7 @@ buildOpaqueElementConversion(ExprRewriter &rewriter, SourceRange srcRange,
Expr *conversion = buildElementConversion(
rewriter, srcRange, srcType, destType, bridged,
locator.withPathElement(
ConstraintLocator::PathElement::getGenericArgument(typeArgIndex)),
locator.withPathElement(LocatorPathElt::GenericArgument(typeArgIndex)),
opaque);
return { opaque, conversion };
@@ -5954,8 +5953,7 @@ void ExprRewriter::peepholeArrayUpcast(ArrayExpr *expr, Type toType,
// Convert the elements.
ConstraintLocatorBuilder innerLocator =
locator.withPathElement(
ConstraintLocator::PathElement::getGenericArgument(0));
locator.withPathElement(LocatorPathElt::GenericArgument(0));
for (auto &element : expr->getElements()) {
if (auto newElement = buildElementConversion(*this, expr->getLoc(),
cs.getType(element),
@@ -5982,8 +5980,7 @@ void ExprRewriter::peepholeDictionaryUpcast(DictionaryExpr *expr,
expr->setType(toType);
ConstraintLocatorBuilder valueLocator =
locator.withPathElement(
ConstraintLocator::PathElement::getGenericArgument(1));
locator.withPathElement(LocatorPathElt::GenericArgument(1));
// Convert the elements.
TupleTypeElt tupleTypeElts[2] = { keyType, valueType };