Skip to content

Commit a0d12a2

Browse files
committed
Sema: Remove ConstraintGraph::reintroduceToInference()
1 parent e94f31c commit a0d12a2

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

include/swift/Sema/ConstraintGraph.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ class ConstraintGraphNode {
137137
/// gets removed for a constraint graph.
138138
void retractFromInference(Constraint *constraint);
139139

140-
/// Re-evaluate the given constraint. This happens when there are changes
141-
/// in associated type variables e.g. bound/unbound to/from a fixed type,
142-
/// equivalence class changes.
143-
void reintroduceToInference(Constraint *constraint);
144140

145141
/// Similar to \c introduceToInference(Constraint *, ...) this method is going
146142
/// to notify inference that this type variable has been bound to a concrete
@@ -161,11 +157,13 @@ class ConstraintGraphNode {
161157
///
162158
/// This is useful in situations when type variable gets bound and unbound,
163159
/// or equivalence class changes.
164-
void notifyReferencingVars() const;
160+
void notifyReferencingVars(
161+
llvm::function_ref<void(ConstraintGraphNode &,
162+
Constraint *)> notification) const;
165163

166164
/// Notify all of the type variables referenced by this one about a change.
167165
void notifyReferencedVars(
168-
llvm::function_ref<void(ConstraintGraphNode &)> notification);
166+
llvm::function_ref<void(ConstraintGraphNode &)> notification) const;
169167

170168
/// }
171169

lib/Sema/ConstraintGraph.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ void ConstraintGraphNode::removeConstraint(Constraint *constraint) {
177177
Constraints.pop_back();
178178
}
179179

180-
void ConstraintGraphNode::notifyReferencingVars() const {
180+
void ConstraintGraphNode::notifyReferencingVars(
181+
llvm::function_ref<void(ConstraintGraphNode &,
182+
Constraint *)> notification) const {
181183
SmallVector<TypeVariableType *, 4> stack;
182184

183185
stack.push_back(TypeVar);
@@ -199,7 +201,7 @@ void ConstraintGraphNode::notifyReferencingVars() const {
199201
affectedVar->getImpl().getRepresentative(/*record=*/nullptr);
200202

201203
if (!repr->getImpl().getFixedType(/*record=*/nullptr))
202-
CG[repr].reintroduceToInference(constraint);
204+
notification(CG[repr], constraint);
203205
}
204206
}
205207
};
@@ -236,7 +238,7 @@ void ConstraintGraphNode::notifyReferencingVars() const {
236238
}
237239

238240
void ConstraintGraphNode::notifyReferencedVars(
239-
llvm::function_ref<void(ConstraintGraphNode &)> notification) {
241+
llvm::function_ref<void(ConstraintGraphNode &)> notification) const {
240242
for (auto *fixedBinding : getReferencedVars()) {
241243
notification(CG[fixedBinding]);
242244
}
@@ -265,7 +267,14 @@ void ConstraintGraphNode::addToEquivalenceClass(
265267
});
266268
}
267269

268-
node.notifyReferencingVars();
270+
// FIXME: Perhaps this also needs to be split up into two stages,
271+
// where the first stage runs before we merge the equivalence
272+
// classes
273+
node.notifyReferencingVars(
274+
[&](ConstraintGraphNode &node, Constraint *constraint) {
275+
node.retractFromInference(constraint);
276+
node.introduceToInference(constraint);
277+
});
269278
}
270279
}
271280
}
@@ -343,10 +352,6 @@ void ConstraintGraphNode::retractFromInference(Constraint *constraint) {
343352
}
344353
}
345354

346-
void ConstraintGraphNode::reintroduceToInference(Constraint *constraint) {
347-
retractFromInference(constraint);
348-
introduceToInference(constraint);
349-
}
350355

351356
void ConstraintGraphNode::introduceToInference(Type fixedType) {
352357
// Notify all of the type variables that reference this one.
@@ -355,7 +360,11 @@ void ConstraintGraphNode::introduceToInference(Type fixedType) {
355360
// all of the concrete types that reference it are going to change,
356361
// which means that all of the not-yet-attempted bindings should
357362
// change as well.
358-
notifyReferencingVars();
363+
notifyReferencingVars(
364+
[&](ConstraintGraphNode &node, Constraint *constraint) {
365+
node.retractFromInference(constraint);
366+
node.introduceToInference(constraint);
367+
});
359368

360369
if (!fixedType->hasTypeVariable())
361370
return;
@@ -370,8 +379,10 @@ void ConstraintGraphNode::introduceToInference(Type fixedType) {
370379
// with this type variable since they are now going to be used in
371380
// all of the constraints that reference bound type variable.
372381
for (auto *constraint : getConstraints()) {
373-
if (isUsefulForReferencedVars(constraint))
374-
node.reintroduceToInference(constraint);
382+
if (isUsefulForReferencedVars(constraint)) {
383+
node.retractFromInference(constraint);
384+
node.introduceToInference(constraint);
385+
}
375386
}
376387
}
377388
}

0 commit comments

Comments
 (0)