Skip to content

Commit 326b371

Browse files
committed
[ConstraintSystem] Switch auxiliary functions to use ASTNode instead of TypedNode
1 parent a483b34 commit 326b371

File tree

5 files changed

+68
-80
lines changed

5 files changed

+68
-80
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,8 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
767767
bool isVarAndNotProtocol2 = false;
768768

769769
auto getWeight = [&](ConstraintLocator *locator) -> unsigned {
770-
if (auto *anchor = locator->getAnchor().dyn_cast<const Expr *>()) {
771-
auto weight = cs.getExprDepth(const_cast<Expr *>(anchor));
770+
if (auto *anchor = locator->getAnchor().dyn_cast<Expr *>()) {
771+
auto weight = cs.getExprDepth(anchor);
772772
if (weight)
773773
return *weight + 1;
774774
}

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ static bool isSingleTupleParam(ASTContext &ctx,
13531353
}
13541354

13551355
static ConstraintFix *fixRequirementFailure(ConstraintSystem &cs, Type type1,
1356-
Type type2, TypedNode anchor,
1356+
Type type2, ASTNode anchor,
13571357
ArrayRef<LocatorPathElt> path);
13581358

13591359
static ConstraintFix *fixRequirementFailure(ConstraintSystem &cs, Type type1,
@@ -1444,7 +1444,7 @@ assessRequirementFailureImpact(ConstraintSystem &cs, Type requirementType,
14441444

14451445
/// Attempt to fix missing arguments by introducing type variables
14461446
/// and inferring their types from parameters.
1447-
static bool fixMissingArguments(ConstraintSystem &cs, TypedNode anchor,
1447+
static bool fixMissingArguments(ConstraintSystem &cs, ASTNode anchor,
14481448
SmallVectorImpl<AnyFunctionType::Param> &args,
14491449
ArrayRef<AnyFunctionType::Param> params,
14501450
unsigned numMissing,
@@ -2562,7 +2562,7 @@ ConstraintSystem::matchTypesBindTypeVar(
25622562
}
25632563

25642564
static ConstraintFix *fixRequirementFailure(ConstraintSystem &cs, Type type1,
2565-
Type type2, TypedNode anchor,
2565+
Type type2, ASTNode anchor,
25662566
ArrayRef<LocatorPathElt> path) {
25672567
// Can't fix not yet properly resolved types.
25682568
if (type1->isTypeVariableOrMember() || type2->isTypeVariableOrMember())
@@ -2905,7 +2905,7 @@ static bool repairOutOfOrderArgumentsInBinaryFunction(
29052905

29062906
bool isOperatorRef = overload->choice.getDecl()->isOperator();
29072907

2908-
auto matchArgToParam = [&](Type argType, Type paramType, TypedNode anchor) {
2908+
auto matchArgToParam = [&](Type argType, Type paramType, ASTNode anchor) {
29092909
auto *loc = cs.getConstraintLocator(anchor);
29102910
// If argument (and/or parameter) is a generic type let's not even try this
29112911
// fix because it would be impossible to match given types without delaying
@@ -2974,7 +2974,7 @@ bool ConstraintSystem::repairFailures(
29742974
// explicit call.
29752975
if (fnType->getNumParams() > 0) {
29762976
auto anchor = simplifyLocatorToAnchor(getConstraintLocator(locator));
2977-
if (!anchor.is<const Expr *>())
2977+
if (!anchor.is<Expr *>())
29782978
return false;
29792979

29802980
auto overload = findSelectedOverloadFor(getAsExpr(anchor));
@@ -6307,7 +6307,7 @@ static ConstraintFix *validateInitializerRef(ConstraintSystem &cs,
63076307
if (!anchor)
63086308
return nullptr;
63096309

6310-
auto getType = [&cs](const Expr *expr) -> Type {
6310+
auto getType = [&cs](Expr *expr) -> Type {
63116311
return cs.simplifyType(cs.getType(expr))->getRValueType();
63126312
};
63136313

@@ -9219,7 +9219,7 @@ bool ConstraintSystem::recordFix(ConstraintFix *fix, unsigned impact) {
92199219
// Only useful to record if no pre-existing fix is associated with
92209220
// current anchor or, in case of anchor being an expression, any of
92219221
// its sub-expressions.
9222-
llvm::SmallDenseSet<TypedNode> anchors;
9222+
llvm::SmallDenseSet<ASTNode> anchors;
92239223
for (const auto *fix : Fixes)
92249224
anchors.insert(fix->getAnchor());
92259225

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ ConstraintSystem::SolverScope::~SolverScope() {
522522
// Remove any node types we registered.
523523
for (unsigned i :
524524
reverse(range(numAddedNodeTypes, cs.addedNodeTypes.size()))) {
525-
TypedNode node = cs.addedNodeTypes[i].first;
525+
auto node = cs.addedNodeTypes[i].first;
526526
if (Type oldType = cs.addedNodeTypes[i].second)
527527
cs.NodeTypes[node] = oldType;
528528
else

lib/Sema/ConstraintSystem.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,13 @@ getAlternativeLiteralTypes(KnownProtocolKind kind) {
364364
}
365365

366366
ConstraintLocator *ConstraintSystem::getConstraintLocator(
367-
TypedNode anchor, ArrayRef<ConstraintLocator::PathElement> path) {
367+
ASTNode anchor, ArrayRef<ConstraintLocator::PathElement> path) {
368368
auto summaryFlags = ConstraintLocator::getSummaryFlagsForPath(path);
369369
return getConstraintLocator(anchor, path, summaryFlags);
370370
}
371371

372372
ConstraintLocator *ConstraintSystem::getConstraintLocator(
373-
TypedNode anchor, ArrayRef<ConstraintLocator::PathElement> path,
373+
ASTNode anchor, ArrayRef<ConstraintLocator::PathElement> path,
374374
unsigned summaryFlags) {
375375
assert(summaryFlags == ConstraintLocator::getSummaryFlagsForPath(path));
376376

@@ -423,7 +423,7 @@ ConstraintLocator *ConstraintSystem::getConstraintLocator(
423423

424424
ConstraintLocator *ConstraintSystem::getCalleeLocator(
425425
ConstraintLocator *locator, bool lookThroughApply,
426-
llvm::function_ref<Type(const Expr *)> getType,
426+
llvm::function_ref<Type(Expr *)> getType,
427427
llvm::function_ref<Type(Type)> simplifyType,
428428
llvm::function_ref<Optional<SelectedOverload>(ConstraintLocator *)>
429429
getOverloadFor) {
@@ -3302,7 +3302,7 @@ constraints::simplifyLocator(ConstraintSystem &cs, ConstraintLocator *locator,
33023302
return cs.getConstraintLocator(anchor, path);
33033303
}
33043304

3305-
void constraints::simplifyLocator(TypedNode &anchor,
3305+
void constraints::simplifyLocator(ASTNode &anchor,
33063306
ArrayRef<LocatorPathElt> &path,
33073307
SourceRange &range) {
33083308
range = SourceRange();
@@ -3514,7 +3514,7 @@ void constraints::simplifyLocator(TypedNode &anchor,
35143514
}
35153515
}
35163516

3517-
TypedNode constraints::simplifyLocatorToAnchor(ConstraintLocator *locator) {
3517+
ASTNode constraints::simplifyLocatorToAnchor(ConstraintLocator *locator) {
35183518
if (!locator)
35193519
return nullptr;
35203520

@@ -3531,7 +3531,7 @@ TypedNode constraints::simplifyLocatorToAnchor(ConstraintLocator *locator) {
35313531
return path.empty() ? anchor : nullptr;
35323532
}
35333533

3534-
Expr *constraints::getArgumentExpr(TypedNode node, unsigned index) {
3534+
Expr *constraints::getArgumentExpr(ASTNode node, unsigned index) {
35353535
auto *expr = castToExpr(node);
35363536
Expr *argExpr = nullptr;
35373537
if (auto *AE = dyn_cast<ApplyExpr>(expr))
@@ -4460,26 +4460,20 @@ void ConstraintSystem::maybeProduceFallbackDiagnostic(
44604460
ctx.Diags.diagnose(target.getLoc(), diag::failed_to_produce_diagnostic);
44614461
}
44624462

4463-
SourceLoc constraints::getLoc(TypedNode anchor) {
4464-
if (auto *E = anchor.dyn_cast<const Expr *>()) {
4463+
SourceLoc constraints::getLoc(ASTNode anchor) {
4464+
if (auto *E = anchor.dyn_cast<Expr *>()) {
44654465
return E->getLoc();
4466-
} else if (auto *T = anchor.dyn_cast<const TypeLoc *>()) {
4466+
} else if (auto *T = anchor.dyn_cast<TypeLoc *>()) {
44674467
return T->getLoc();
4468-
} else if (auto *V = anchor.dyn_cast<const VarDecl *>()) {
4469-
return V->getNameLoc();
4468+
} else if (auto *V = anchor.dyn_cast<Decl *>()) {
4469+
if (auto VD = dyn_cast<VarDecl>(V))
4470+
return VD->getNameLoc();
4471+
return anchor.getStartLoc();
44704472
} else {
4471-
return anchor.get<const Pattern *>()->getLoc();
4473+
return anchor.get<Pattern *>()->getLoc();
44724474
}
44734475
}
44744476

4475-
SourceRange constraints::getSourceRange(TypedNode anchor) {
4476-
if (auto *E = anchor.dyn_cast<const Expr *>()) {
4477-
return E->getSourceRange();
4478-
} else if (auto *T = anchor.dyn_cast<const TypeLoc *>()) {
4479-
return T->getSourceRange();
4480-
} else if (auto *V = anchor.dyn_cast<const VarDecl *>()) {
4481-
return V->getSourceRange();
4482-
} else {
4483-
return anchor.get<const Pattern *>()->getSourceRange();
4484-
}
4477+
SourceRange constraints::getSourceRange(ASTNode anchor) {
4478+
return anchor.getSourceRange();
44854479
}

0 commit comments

Comments
 (0)