Skip to content

Commit 668928e

Browse files
authored
Merge pull request swiftlang#79475 from slavapestov/issue-a-retraction
Sema: Clean up odd bit of dead code in binding inference
2 parents a7b50c0 + 2cf365f commit 668928e

File tree

3 files changed

+27
-34
lines changed

3 files changed

+27
-34
lines changed

include/swift/Sema/ConstraintGraph.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class ConstraintGraphNode {
148148

149149
/// Perform graph updates that must be undone after we bind a fixed type
150150
/// to a type variable.
151-
void retractFromInference(Type fixedType);
151+
void retractFromInference();
152152

153153
/// Perform graph updates that must be undone before we bind a fixed type
154154
/// to a type variable.
@@ -175,11 +175,6 @@ class ConstraintGraphNode {
175175
/// Notify all of the type variables referenced by this one about a change.
176176
void notifyReferencedVars(
177177
llvm::function_ref<void(ConstraintGraphNode &)> notification) const;
178-
179-
void updateFixedType(
180-
Type fixedType,
181-
llvm::function_ref<void (ConstraintGraphNode &,
182-
Constraint *)> notification) const;
183178
/// }
184179

185180
/// The constraint graph this node belongs to.
@@ -294,7 +289,7 @@ class ConstraintGraph {
294289

295290
/// Perform graph updates that must be undone after we bind a fixed type
296291
/// to a type variable.
297-
void retractFromInference(TypeVariableType *typeVar, Type fixedType);
292+
void retractFromInference(TypeVariableType *typeVar);
298293

299294
/// Perform graph updates that must be undone before we bind a fixed type
300295
/// to a type variable.

lib/Sema/ConstraintGraph.cpp

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,33 @@ void ConstraintGraphNode::removeReferencedBy(TypeVariableType *typeVar) {
287287
}
288288
}
289289

290-
void ConstraintGraphNode::updateFixedType(
291-
Type fixedType,
292-
llvm::function_ref<void (ConstraintGraphNode &,
293-
Constraint *)> notification) const {
290+
void ConstraintGraphNode::retractFromInference() {
291+
auto &cs = CG.getConstraintSystem();
292+
293+
// Notify all of the type variables that reference this one.
294+
//
295+
// Since this type variable is going to be replaced with a fixed type
296+
// all of the concrete types that reference it are going to change,
297+
// which means that all of the not-yet-attempted bindings should
298+
// change as well.
299+
return notifyReferencingVars(
300+
[&cs](ConstraintGraphNode &node, Constraint *constraint) {
301+
node.getPotentialBindings().retract(cs, node.getTypeVariable(), constraint);
302+
});
303+
}
304+
305+
void ConstraintGraphNode::introduceToInference(Type fixedType) {
306+
auto &cs = CG.getConstraintSystem();
307+
294308
// Notify all of the type variables that reference this one.
295309
//
296310
// Since this type variable has been replaced with a fixed type
297311
// all of the concrete types that reference it are going to change,
298312
// which means that all of the not-yet-attempted bindings should
299313
// change as well.
300-
notifyReferencingVars(notification);
314+
notifyReferencingVars([&cs](ConstraintGraphNode &node, Constraint *constraint) {
315+
node.getPotentialBindings().infer(cs, node.getTypeVariable(), constraint);
316+
});
301317

302318
if (!fixedType->hasTypeVariable())
303319
return;
@@ -317,29 +333,11 @@ void ConstraintGraphNode::updateFixedType(
317333
// all of the constraints that reference bound type variable.
318334
for (auto *constraint : getConstraints()) {
319335
if (isUsefulForReferencedVars(constraint))
320-
notification(node, constraint);
336+
node.getPotentialBindings().infer(cs, node.getTypeVariable(), constraint);
321337
}
322338
}
323339
}
324340

325-
void ConstraintGraphNode::retractFromInference(Type fixedType) {
326-
auto &cs = CG.getConstraintSystem();
327-
return updateFixedType(
328-
fixedType,
329-
[&cs](ConstraintGraphNode &node, Constraint *constraint) {
330-
node.getPotentialBindings().retract(cs, node.getTypeVariable(), constraint);
331-
});
332-
}
333-
334-
void ConstraintGraphNode::introduceToInference(Type fixedType) {
335-
auto &cs = CG.getConstraintSystem();
336-
return updateFixedType(
337-
fixedType,
338-
[&cs](ConstraintGraphNode &node, Constraint *constraint) {
339-
node.getPotentialBindings().infer(cs, node.getTypeVariable(), constraint);
340-
});
341-
}
342-
343341
#pragma mark Graph mutation
344342

345343
void ConstraintGraph::removeNode(TypeVariableType *typeVar) {
@@ -523,8 +521,8 @@ void ConstraintGraph::bindTypeVariable(TypeVariableType *typeVar, Type fixed) {
523521
}
524522
}
525523

526-
void ConstraintGraph::retractFromInference(TypeVariableType *typeVar, Type fixed) {
527-
(*this)[typeVar].retractFromInference(fixed);
524+
void ConstraintGraph::retractFromInference(TypeVariableType *typeVar) {
525+
(*this)[typeVar].retractFromInference();
528526
}
529527

530528
void ConstraintGraph::introduceToInference(TypeVariableType *typeVar, Type fixed) {

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void ConstraintSystem::assignFixedType(TypeVariableType *typeVar, Type type,
217217
assert(!type->hasError() &&
218218
"Should not be assigning a type involving ErrorType!");
219219

220-
CG.retractFromInference(typeVar, type);
220+
CG.retractFromInference(typeVar);
221221
typeVar->getImpl().assignFixedType(type, getTrail());
222222

223223
if (!updateState)

0 commit comments

Comments
 (0)