Skip to content

Commit 12e9686

Browse files
committed
[ConstraintGraph] Remove flags from inference methods
Use newly added `notifyReferencedVars` in `{add, remove}Constraint`.
1 parent d4cb756 commit 12e9686

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

include/swift/Sema/ConstraintGraph.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ class ConstraintGraphNode {
125125
/// Infer bindings from the given constraint and notify referenced variables
126126
/// about its arrival (if requested). This happens every time a new constraint
127127
/// gets added to a constraint graph node.
128-
void introduceToInference(Constraint *constraint, bool notifyReferencedVars);
128+
void introduceToInference(Constraint *constraint);
129129

130130
/// Forget about the given constraint. This happens every time a constraint
131131
/// gets removed for a constraint graph.
132-
void retractFromInference(Constraint *constraint, bool notifyReferencedVars);
132+
void retractFromInference(Constraint *constraint);
133133

134134
/// Re-evaluate the given constraint. This happens when there are changes
135135
/// in associated type variables e.g. bound/unbound to/from a fixed type,
136136
/// equivalence class changes.
137-
void reintroduceToInference(Constraint *constraint, bool notifyReferencedVars);
137+
void reintroduceToInference(Constraint *constraint);
138138

139139
/// Similar to \c introduceToInference(Constraint *, ...) this method is going
140140
/// to notify inference that this type variable has been bound to a concrete

lib/Sema/ConstraintGraph.cpp

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@ void ConstraintGraphNode::addConstraint(Constraint *constraint) {
107107
assert(ConstraintIndex.count(constraint) == 0 && "Constraint re-insertion");
108108
ConstraintIndex[constraint] = Constraints.size();
109109
Constraints.push_back(constraint);
110-
introduceToInference(constraint, /*notifyFixedBindings=*/true);
110+
111+
{
112+
introduceToInference(constraint);
113+
114+
notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
115+
referencedVar.introduceToInference(constraint);
116+
});
117+
}
111118
}
112119

113120
void ConstraintGraphNode::removeConstraint(Constraint *constraint) {
@@ -119,8 +126,13 @@ void ConstraintGraphNode::removeConstraint(Constraint *constraint) {
119126
ConstraintIndex.erase(pos);
120127
assert(Constraints[index] == constraint && "Mismatched constraint");
121128

122-
retractFromInference(constraint,
123-
/*notifyFixedBindings=*/true);
129+
{
130+
retractFromInference(constraint);
131+
132+
notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
133+
referencedVar.retractFromInference(constraint);
134+
});
135+
}
124136

125137
// If this is the last constraint, just pop it off the list and we're done.
126138
unsigned lastIndex = Constraints.size()-1;
@@ -160,8 +172,7 @@ void ConstraintGraphNode::notifyReferencingVars() const {
160172
affectedVar->getImpl().getRepresentative(/*record=*/nullptr);
161173

162174
if (!repr->getImpl().getFixedType(/*record=*/nullptr))
163-
CG[repr].reintroduceToInference(constraint,
164-
/*notifyReferencedVars=*/false);
175+
CG[repr].reintroduceToInference(constraint);
165176
}
166177
}
167178
};
@@ -217,7 +228,11 @@ void ConstraintGraphNode::addToEquivalenceClass(
217228
auto &node = CG[newMember];
218229

219230
for (auto *constraint : node.getConstraints()) {
220-
introduceToInference(constraint, /*notifyReferencedVars=*/true);
231+
introduceToInference(constraint);
232+
233+
notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
234+
referencedVar.introduceToInference(constraint);
235+
});
221236
}
222237

223238
node.notifyReferencingVars();
@@ -296,52 +311,51 @@ static bool isUsefulForReferencedVars(Constraint *constraint) {
296311
}
297312
}
298313

299-
void ConstraintGraphNode::introduceToInference(Constraint *constraint,
300-
bool notifyReferencedVars) {
314+
void ConstraintGraphNode::introduceToInference(Constraint *constraint) {
301315
if (forRepresentativeVar()) {
302316
auto fixedType = TypeVar->getImpl().getFixedType(/*record=*/nullptr);
303317
if (!fixedType)
304318
getCurrentBindings().infer(constraint);
305319
} else {
306320
auto *repr =
307321
getTypeVariable()->getImpl().getRepresentative(/*record=*/nullptr);
308-
CG[repr].introduceToInference(constraint, /*notifyReferencedVars=*/false);
322+
CG[repr].introduceToInference(constraint);
309323
}
310324

325+
/*
311326
if (!notifyReferencedVars || !isUsefulForReferencedVars(constraint))
312327
return;
313328
314329
this->notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
315-
referencedVar.introduceToInference(constraint,
316-
/*notifyReferencedVars=*/false);
330+
referencedVar.introduceToInference(constraint);
317331
});
332+
*/
318333
}
319334

320-
void ConstraintGraphNode::retractFromInference(Constraint *constraint,
321-
bool notifyReferencedVars) {
335+
void ConstraintGraphNode::retractFromInference(Constraint *constraint) {
322336
if (forRepresentativeVar()) {
323337
auto fixedType = TypeVar->getImpl().getFixedType(/*record=*/nullptr);
324338
if (!fixedType)
325339
getCurrentBindings().retract(constraint);
326340
} else {
327341
auto *repr =
328342
getTypeVariable()->getImpl().getRepresentative(/*record=*/nullptr);
329-
CG[repr].retractFromInference(constraint, /*notifyReferencedVars=*/false);
343+
CG[repr].retractFromInference(constraint);
330344
}
331345

346+
/*
332347
if (!notifyReferencedVars || !isUsefulForReferencedVars(constraint))
333348
return;
334349
335350
this->notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
336-
referencedVar.retractFromInference(constraint,
337-
/*notifyReferencedVars=*/false);
351+
referencedVar.retractFromInference(constraint);
338352
});
353+
*/
339354
}
340355

341-
void ConstraintGraphNode::reintroduceToInference(Constraint *constraint,
342-
bool notifyReferencedVars) {
343-
retractFromInference(constraint, notifyReferencedVars);
344-
introduceToInference(constraint, notifyReferencedVars);
356+
void ConstraintGraphNode::reintroduceToInference(Constraint *constraint) {
357+
retractFromInference(constraint);
358+
introduceToInference(constraint);
345359
}
346360

347361
void ConstraintGraphNode::introduceToInference(Type fixedType) {
@@ -367,8 +381,7 @@ void ConstraintGraphNode::introduceToInference(Type fixedType) {
367381
// all of the constraints that reference bound type variable.
368382
for (auto *constraint : getConstraints()) {
369383
if (isUsefulForReferencedVars(constraint))
370-
node.reintroduceToInference(constraint,
371-
/*notifyReferencedVars=*/false);
384+
node.reintroduceToInference(constraint);
372385
}
373386
}
374387
}

0 commit comments

Comments
 (0)