Skip to content

Commit 12a63ce

Browse files
committed
[ConstraintSystem] Switch getContextualType and its variants to use TypedNode
1 parent e5c94bf commit 12a63ce

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

lib/Sema/CSDiagnostics.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,17 @@ class FailureDiagnostic {
119119

120120
Type getContextualType(TypedNode anchor) const {
121121
auto &cs = getConstraintSystem();
122-
return cs.getContextualType(anchor.get<const Expr *>());
122+
return cs.getContextualType(anchor);
123123
}
124124

125125
TypeLoc getContextualTypeLoc(TypedNode anchor) const {
126126
auto &cs = getConstraintSystem();
127-
return cs.getContextualTypeLoc(anchor.get<const Expr *>());
127+
return cs.getContextualTypeLoc(anchor);
128128
}
129129

130130
ContextualTypePurpose getContextualTypePurpose(TypedNode anchor) const {
131131
auto &cs = getConstraintSystem();
132-
return cs.getContextualTypePurpose(anchor.get<const Expr *>());
132+
return cs.getContextualTypePurpose(anchor);
133133
}
134134

135135
DeclContext *getDC() const {

lib/Sema/CSFix.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ bool MissingConformance::diagnose(const Solution &solution, bool asNote) const {
189189

190190
if (IsContextual) {
191191
auto &cs = solution.getConstraintSystem();
192-
auto context =
193-
cs.getContextualTypePurpose(locator->getAnchor().get<const Expr *>());
192+
auto context = cs.getContextualTypePurpose(locator->getAnchor());
194193
MissingContextualConformanceFailure failure(
195194
solution, context, NonConformingType, ProtocolType, locator);
196195
return failure.diagnose(asNote);
@@ -265,7 +264,7 @@ getStructuralTypeContext(const Solution &solution, ConstraintLocator *locator) {
265264
locator->isLastElement<LocatorPathElt::FunctionArgument>());
266265

267266
auto &cs = solution.getConstraintSystem();
268-
auto *anchor = locator->getAnchor().get<const Expr *>();
267+
auto anchor = locator->getAnchor();
269268
auto contextualType = cs.getContextualType(anchor);
270269
auto exprType = cs.getType(anchor);
271270
return std::make_tuple(cs.getContextualTypePurpose(anchor), exprType,
@@ -314,8 +313,7 @@ bool AllowTupleTypeMismatch::coalesceAndDiagnose(
314313
Type toType;
315314

316315
if (getFromType()->is<TupleType>() && getToType()->is<TupleType>()) {
317-
purpose =
318-
cs.getContextualTypePurpose(locator->getAnchor().get<const Expr *>());
316+
purpose = cs.getContextualTypePurpose(locator->getAnchor());
319317
fromType = getFromType();
320318
toType = getToType();
321319
} else if (auto contextualTypeInfo =

lib/Sema/ConstraintSystem.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ class Solution {
917917
llvm::MapVector<TypedNode, Type> nodeTypes;
918918

919919
/// Contextual types introduced by this solution.
920-
std::vector<std::pair<const Expr *, ContextualTypeInfo>> contextualTypes;
920+
std::vector<std::pair<TypedNode, ContextualTypeInfo>> contextualTypes;
921921

922922
/// Maps AST nodes to their solution application targets.
923923
llvm::MapVector<SolutionApplicationTargetsKey, SolutionApplicationTarget>
@@ -1719,7 +1719,7 @@ class ConstraintSystem {
17191719

17201720
/// Contextual type information for expressions that are part of this
17211721
/// constraint system.
1722-
llvm::MapVector<const Expr *, ContextualTypeInfo> contextualTypes;
1722+
llvm::MapVector<TypedNode, ContextualTypeInfo> contextualTypes;
17231723

17241724
/// Information about each case label item tracked by the constraint system.
17251725
llvm::SmallMapVector<const CaseLabelItem *, CaseLabelItemInfo, 4>
@@ -2527,37 +2527,37 @@ class ConstraintSystem {
25272527
return E;
25282528
}
25292529

2530-
void setContextualType(
2531-
const Expr *expr, TypeLoc T, ContextualTypePurpose purpose) {
2532-
assert(expr != nullptr && "Expected non-null expression!");
2533-
assert(contextualTypes.count(expr) == 0 &&
2530+
void setContextualType(TypedNode node, TypeLoc T,
2531+
ContextualTypePurpose purpose) {
2532+
assert(bool(node) && "Expected non-null expression!");
2533+
assert(contextualTypes.count(node) == 0 &&
25342534
"Already set this contextual type");
2535-
contextualTypes[expr] = { T, purpose };
2535+
contextualTypes[node] = {T, purpose};
25362536
}
25372537

2538-
Optional<ContextualTypeInfo> getContextualTypeInfo(const Expr *expr) const {
2539-
auto known = contextualTypes.find(expr);
2538+
Optional<ContextualTypeInfo> getContextualTypeInfo(TypedNode node) const {
2539+
auto known = contextualTypes.find(node);
25402540
if (known == contextualTypes.end())
25412541
return None;
25422542
return known->second;
25432543
}
25442544

2545-
Type getContextualType(const Expr *expr) const {
2546-
auto result = getContextualTypeInfo(expr);
2545+
Type getContextualType(TypedNode node) const {
2546+
auto result = getContextualTypeInfo(node);
25472547
if (result)
25482548
return result->typeLoc.getType();
25492549
return Type();
25502550
}
25512551

2552-
TypeLoc getContextualTypeLoc(const Expr *expr) const {
2553-
auto result = getContextualTypeInfo(expr);
2552+
TypeLoc getContextualTypeLoc(TypedNode node) const {
2553+
auto result = getContextualTypeInfo(node);
25542554
if (result)
25552555
return result->typeLoc;
25562556
return TypeLoc();
25572557
}
25582558

2559-
ContextualTypePurpose getContextualTypePurpose(const Expr *expr) const {
2560-
auto result = getContextualTypeInfo(expr);
2559+
ContextualTypePurpose getContextualTypePurpose(TypedNode node) const {
2560+
auto result = getContextualTypeInfo(node);
25612561
if (result)
25622562
return result->purpose;
25632563
return CTP_Unused;

0 commit comments

Comments
 (0)