Skip to content

Commit d8bd62d

Browse files
authored
Merge pull request #31210 from xedin/anchor-locator-from-typednode
[ConstraintSystem] Switch `ConstraintLocator` to be anchored on `TypedNode`
2 parents 46703b4 + 4405768 commit d8bd62d

18 files changed

+409
-397
lines changed

lib/Sema/CSApply.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ ConstraintLocator *Solution::getCalleeLocator(ConstraintLocator *locator,
123123
}
124124

125125
ConstraintLocator *
126-
Solution::getConstraintLocator(const Expr *anchor,
126+
Solution::getConstraintLocator(TypedNode anchor,
127127
ArrayRef<LocatorPathElt> path) const {
128128
auto &cs = getConstraintSystem();
129-
return cs.getConstraintLocator(const_cast<Expr *>(anchor), path);
129+
return cs.getConstraintLocator(anchor, path);
130130
}
131131

132132
ConstraintLocator *
@@ -1204,9 +1204,9 @@ namespace {
12041204
// For properties, build member references.
12051205
if (isa<VarDecl>(member)) {
12061206
if (isUnboundInstanceMember) {
1207-
assert(memberLocator.getBaseLocator() &&
1207+
assert(memberLocator.getBaseLocator() &&
12081208
cs.UnevaluatedRootExprs.count(
1209-
memberLocator.getBaseLocator()->getAnchor()) &&
1209+
getAsExpr(memberLocator.getBaseLocator()->getAnchor())) &&
12101210
"Attempt to reference an instance member of a metatype");
12111211
auto baseInstanceTy = cs.getType(base)
12121212
->getInOutObjectType()->getMetatypeInstanceType();
@@ -1618,7 +1618,7 @@ namespace {
16181618

16191619
if (selected.choice.getKind() ==
16201620
OverloadChoiceKind::KeyPathDynamicMemberLookup &&
1621-
!isa<SubscriptExpr>(locator.getAnchor()))
1621+
!isExpr<SubscriptExpr>(locator.getAnchor()))
16221622
locatorKind = ConstraintLocator::Member;
16231623

16241624
newSubscript =
@@ -1744,7 +1744,7 @@ namespace {
17441744
locatorKind = ConstraintLocator::Member;
17451745

17461746
if (choice.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup) {
1747-
locatorKind = isa<SubscriptExpr>(locator.getAnchor())
1747+
locatorKind = isExpr<SubscriptExpr>(locator.getAnchor())
17481748
? ConstraintLocator::SubscriptMember
17491749
: ConstraintLocator::Member;
17501750
}
@@ -1898,7 +1898,7 @@ namespace {
18981898
SourceLoc dotLoc,
18991899
ConstraintLocator *memberLoc) {
19001900
auto &ctx = cs.getASTContext();
1901-
auto *anchor = memberLoc->getAnchor();
1901+
auto *anchor = getAsExpr(memberLoc->getAnchor());
19021902

19031903
SmallVector<KeyPathExpr::Component, 2> components;
19041904

@@ -7804,13 +7804,13 @@ namespace {
78047804
explicit CompareExprSourceLocs(SourceManager &sourceMgr)
78057805
: sourceMgr(sourceMgr) { }
78067806

7807-
bool operator()(Expr *lhs, Expr *rhs) const {
7807+
bool operator()(TypedNode lhs, TypedNode rhs) const {
78087808
if (static_cast<bool>(lhs) != static_cast<bool>(rhs)) {
78097809
return static_cast<bool>(lhs);
78107810
}
78117811

7812-
auto lhsLoc = lhs->getLoc();
7813-
auto rhsLoc = rhs->getLoc();
7812+
auto lhsLoc = getLoc(lhs);
7813+
auto rhsLoc = getLoc(rhs);
78147814
if (lhsLoc.isValid() != rhsLoc.isValid())
78157815
return lhsLoc.isValid();
78167816

@@ -7824,26 +7824,27 @@ namespace {
78247824
/// able to emit an error message, or false if none of the fixits worked out.
78257825
bool ConstraintSystem::applySolutionFixes(const Solution &solution) {
78267826
/// Collect the fixes on a per-expression basis.
7827-
llvm::SmallDenseMap<Expr *, SmallVector<ConstraintFix *, 4>> fixesPerExpr;
7827+
llvm::SmallDenseMap<TypedNode, SmallVector<ConstraintFix *, 4>>
7828+
fixesPerAnchor;
78287829
for (auto *fix : solution.Fixes) {
7829-
fixesPerExpr[fix->getAnchor()].push_back(fix);
7830+
fixesPerAnchor[fix->getAnchor()].push_back(fix);
78307831
}
78317832

78327833
// Collect all of the expressions that have fixes, and sort them by
78337834
// source ordering.
7834-
SmallVector<Expr *, 4> exprsWithFixes;
7835-
for (const auto &fix : fixesPerExpr) {
7836-
exprsWithFixes.push_back(fix.getFirst());
7835+
SmallVector<TypedNode, 4> orderedAnchors;
7836+
for (const auto &fix : fixesPerAnchor) {
7837+
orderedAnchors.push_back(fix.getFirst());
78377838
}
7838-
std::sort(exprsWithFixes.begin(), exprsWithFixes.end(),
7839+
std::sort(orderedAnchors.begin(), orderedAnchors.end(),
78397840
CompareExprSourceLocs(Context.SourceMgr));
78407841

78417842
// Walk over each of the expressions, diagnosing fixes.
78427843
bool diagnosedAnyErrors = false;
78437844

7844-
for (auto expr : exprsWithFixes) {
7845+
for (auto anchor : orderedAnchors) {
78457846
// Coalesce fixes with the same locator to avoid duplicating notes.
7846-
auto fixes = fixesPerExpr[expr];
7847+
auto fixes = fixesPerAnchor[anchor];
78477848

78487849
using ConstraintFixVector = llvm::SmallVector<ConstraintFix *, 4>;
78497850
llvm::SmallMapVector<ConstraintLocator *,

lib/Sema/CSBindings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,8 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) const {
459459
// of the optional type extracted by force unwrap.
460460
bool isOptionalObject = false;
461461
if (auto *locator = typeVar->getImpl().getLocator()) {
462-
auto *anchor = locator->getAnchor();
463-
isOptionalObject = anchor && isa<ForceValueExpr>(anchor);
462+
auto anchor = locator->getAnchor();
463+
isOptionalObject = isExpr<ForceValueExpr>(anchor);
464464
}
465465

466466
// Gather the constraints associated with this type variable.
@@ -1104,7 +1104,7 @@ bool TypeVariableBinding::attempt(ConstraintSystem &cs) const {
11041104
if (cs.recordFix(fix))
11051105
return true;
11061106
} else if (srcLocator->getAnchor() &&
1107-
isa<ObjectLiteralExpr>(srcLocator->getAnchor())) {
1107+
isExpr<ObjectLiteralExpr>(srcLocator->getAnchor())) {
11081108
auto *fix = SpecifyObjectLiteralTypeImport::create(
11091109
cs, TypeVar->getImpl().getLocator());
11101110
if (cs.recordFix(fix))

0 commit comments

Comments
 (0)