Skip to content

Commit 80e67f6

Browse files
committed
Sema: Fold ConstraintGraph::lookupNode() into ::operator[]
lookupNode() returned a pair but both callers only looked at the first element of the pair.
1 parent 0f10333 commit 80e67f6

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

include/swift/Sema/ConstraintGraph.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,7 @@ class ConstraintGraph {
245245
ConstraintSystem &getConstraintSystem() const { return CS; }
246246

247247
/// Access the node corresponding to the given type variable.
248-
ConstraintGraphNode &operator[](TypeVariableType *typeVar) {
249-
return lookupNode(typeVar).first;
250-
}
251-
252-
/// Retrieve the node and index corresponding to the given type variable.
253-
std::pair<ConstraintGraphNode &, unsigned>
254-
lookupNode(TypeVariableType *typeVar);
248+
ConstraintGraphNode &operator[](TypeVariableType *typeVar);
255249

256250
/// Add a new constraint to the graph.
257251
void addConstraint(Constraint *constraint);

lib/Sema/ConstraintGraph.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ ConstraintGraph::~ConstraintGraph() {
5050

5151
#pragma mark Graph accessors
5252

53-
std::pair<ConstraintGraphNode &, unsigned>
54-
ConstraintGraph::lookupNode(TypeVariableType *typeVar) {
53+
ConstraintGraphNode &
54+
ConstraintGraph::operator[](TypeVariableType *typeVar) {
5555
// Check whether we've already created a node for this type variable.
5656
auto &impl = typeVar->getImpl();
5757
if (auto nodePtr = impl.getGraphNode()) {
@@ -60,7 +60,7 @@ ConstraintGraph::lookupNode(TypeVariableType *typeVar) {
6060
"Type variable mismatch");
6161
ASSERT(nodePtr->TypeVar == typeVar &&
6262
"Use-after-free");
63-
return { *nodePtr, impl.getGraphIndex() };
63+
return *nodePtr;
6464
}
6565

6666
// Allocate the new node.
@@ -98,7 +98,7 @@ ConstraintGraph::lookupNode(TypeVariableType *typeVar) {
9898
bindTypeVariable(typeVar, fixed);
9999
}
100100

101-
return { *nodePtr, index };
101+
return *nodePtr;
102102
}
103103

104104
void ConstraintGraphNode::reset() {

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,8 @@ TypeVariableType *ConstraintSystem::isRepresentativeFor(
11031103
return nullptr;
11041104

11051105
auto &CG = getConstraintGraph();
1106-
auto result = CG.lookupNode(typeVar);
1107-
auto equivalence = result.first.getEquivalenceClass();
1106+
auto &result = CG[typeVar];
1107+
auto equivalence = result.getEquivalenceClass();
11081108
auto member = llvm::find_if(equivalence, [=](TypeVariableType *eq) {
11091109
auto *loc = eq->getImpl().getLocator();
11101110
if (!loc)

0 commit comments

Comments
 (0)