@@ -84,8 +84,13 @@ ConstraintGraph::lookupNode(TypeVariableType *typeVar) {
84
84
return { *nodePtr, index };
85
85
}
86
86
87
+ bool ConstraintGraphNode::forRepresentativeVar () const {
88
+ auto *typeVar = getTypeVariable ();
89
+ return typeVar == typeVar->getImpl ().getRepresentative (nullptr );
90
+ }
91
+
87
92
ArrayRef<TypeVariableType *> ConstraintGraphNode::getEquivalenceClass () const {
88
- assert (TypeVar == TypeVar-> getImpl (). getRepresentative ( nullptr ) &&
93
+ assert (forRepresentativeVar ( ) &&
89
94
" Can't request equivalence class from non-representative type var" );
90
95
return getEquivalenceClassUnsafe ();
91
96
}
@@ -131,10 +136,10 @@ void ConstraintGraphNode::removeConstraint(Constraint *constraint) {
131
136
132
137
void ConstraintGraphNode::addToEquivalenceClass (
133
138
ArrayRef<TypeVariableType *> typeVars) {
134
- assert (TypeVar == TypeVar-> getImpl (). getRepresentative ( nullptr ) &&
139
+ assert (forRepresentativeVar ( ) &&
135
140
" Can't extend equivalence class of non-representative type var" );
136
141
if (EquivalenceClass.empty ())
137
- EquivalenceClass.push_back (TypeVar );
142
+ EquivalenceClass.push_back (getTypeVariable () );
138
143
EquivalenceClass.append (typeVars.begin (), typeVars.end ());
139
144
}
140
145
@@ -1189,6 +1194,7 @@ void ConstraintGraphNode::print(llvm::raw_ostream &out, unsigned indent,
1189
1194
SmallVector<Constraint *, 4 > sortedConstraints (Constraints.begin (),
1190
1195
Constraints.end ());
1191
1196
std::sort (sortedConstraints.begin (), sortedConstraints.end ());
1197
+
1192
1198
for (auto constraint : sortedConstraints) {
1193
1199
out.indent (indent + 4 );
1194
1200
constraint->print (out, &TypeVar->getASTContext ().SourceMgr );
@@ -1218,8 +1224,7 @@ void ConstraintGraphNode::print(llvm::raw_ostream &out, unsigned indent,
1218
1224
}
1219
1225
1220
1226
// Print equivalence class.
1221
- if (TypeVar->getImpl ().getRepresentative (nullptr ) == TypeVar &&
1222
- EquivalenceClass.size () > 1 ) {
1227
+ if (forRepresentativeVar () && EquivalenceClass.size () > 1 ) {
1223
1228
out.indent (indent + 2 );
1224
1229
out << " Equivalence class:" ;
1225
1230
for (unsigned i = 1 , n = EquivalenceClass.size (); i != n; ++i) {
0 commit comments