Skip to content

Commit d4cb756

Browse files
committed
[ConstraintGraph] Extract logic to notify referenced variable into a dedicated method
1 parent c139bb4 commit d4cb756

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Diff for: include/swift/Sema/ConstraintGraph.h

+4
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ class ConstraintGraphNode {
166166
/// or equivalence class changes.
167167
void notifyReferencingVars() const;
168168

169+
/// Notify all of the type variables referenced by this one about a change.
170+
void notifyReferencedVars(
171+
llvm::function_ref<void(ConstraintGraphNode &)> notification);
172+
169173
/// }
170174

171175
/// The constraint graph this node belongs to.

Diff for: lib/Sema/ConstraintGraph.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ void ConstraintGraphNode::notifyReferencingVars() const {
197197
}
198198
}
199199

200+
void ConstraintGraphNode::notifyReferencedVars(
201+
llvm::function_ref<void(ConstraintGraphNode &)> notification) {
202+
for (auto *fixedBinding : getReferencedVars()) {
203+
notification(CG[fixedBinding]);
204+
}
205+
}
206+
200207
void ConstraintGraphNode::addToEquivalenceClass(
201208
ArrayRef<TypeVariableType *> typeVars) {
202209
assert(forRepresentativeVar() &&
@@ -304,10 +311,10 @@ void ConstraintGraphNode::introduceToInference(Constraint *constraint,
304311
if (!notifyReferencedVars || !isUsefulForReferencedVars(constraint))
305312
return;
306313

307-
for (auto *fixedBinding : getReferencedVars()) {
308-
CG[fixedBinding].introduceToInference(constraint,
309-
/*notifyReferencedVars=*/false);
310-
}
314+
this->notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
315+
referencedVar.introduceToInference(constraint,
316+
/*notifyReferencedVars=*/false);
317+
});
311318
}
312319

313320
void ConstraintGraphNode::retractFromInference(Constraint *constraint,
@@ -325,10 +332,10 @@ void ConstraintGraphNode::retractFromInference(Constraint *constraint,
325332
if (!notifyReferencedVars || !isUsefulForReferencedVars(constraint))
326333
return;
327334

328-
for (auto *fixedBinding : getReferencedVars()) {
329-
CG[fixedBinding].retractFromInference(constraint,
330-
/*notifyReferencedVars=*/false);
331-
}
335+
this->notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
336+
referencedVar.retractFromInference(constraint,
337+
/*notifyReferencedVars=*/false);
338+
});
332339
}
333340

334341
void ConstraintGraphNode::reintroduceToInference(Constraint *constraint,

0 commit comments

Comments
 (0)