Sema: Fold ConstraintGraph::updateFixedType() into its last caller

This commit is contained in:
Slava Pestov
2025-02-18 17:53:30 -05:00
parent 58fdc4f805
commit 2cf365fa19
2 changed files with 22 additions and 35 deletions

View File

@@ -287,17 +287,33 @@ void ConstraintGraphNode::removeReferencedBy(TypeVariableType *typeVar) {
}
}
void ConstraintGraphNode::updateFixedType(
Type fixedType,
llvm::function_ref<void (ConstraintGraphNode &,
Constraint *)> notification) const {
void ConstraintGraphNode::retractFromInference() {
auto &cs = CG.getConstraintSystem();
// Notify all of the type variables that reference this one.
//
// Since this type variable is going to be replaced with a fixed type
// all of the concrete types that reference it are going to change,
// which means that all of the not-yet-attempted bindings should
// change as well.
return notifyReferencingVars(
[&cs](ConstraintGraphNode &node, Constraint *constraint) {
node.getPotentialBindings().retract(cs, node.getTypeVariable(), constraint);
});
}
void ConstraintGraphNode::introduceToInference(Type fixedType) {
auto &cs = CG.getConstraintSystem();
// Notify all of the type variables that reference this one.
//
// Since this type variable has been replaced with a fixed type
// all of the concrete types that reference it are going to change,
// which means that all of the not-yet-attempted bindings should
// change as well.
notifyReferencingVars(notification);
notifyReferencingVars([&cs](ConstraintGraphNode &node, Constraint *constraint) {
node.getPotentialBindings().infer(cs, node.getTypeVariable(), constraint);
});
if (!fixedType->hasTypeVariable())
return;
@@ -317,35 +333,11 @@ void ConstraintGraphNode::updateFixedType(
// all of the constraints that reference bound type variable.
for (auto *constraint : getConstraints()) {
if (isUsefulForReferencedVars(constraint))
notification(node, constraint);
node.getPotentialBindings().infer(cs, node.getTypeVariable(), constraint);
}
}
}
void ConstraintGraphNode::retractFromInference() {
auto &cs = CG.getConstraintSystem();
// Notify all of the type variables that reference this one.
//
// Since this type variable is going to be replaced with a fixed type
// all of the concrete types that reference it are going to change,
// which means that all of the not-yet-attempted bindings should
// change as well.
return notifyReferencingVars(
[&cs](ConstraintGraphNode &node, Constraint *constraint) {
node.getPotentialBindings().retract(cs, node.getTypeVariable(), constraint);
});
}
void ConstraintGraphNode::introduceToInference(Type fixedType) {
auto &cs = CG.getConstraintSystem();
return updateFixedType(
fixedType,
[&cs](ConstraintGraphNode &node, Constraint *constraint) {
node.getPotentialBindings().infer(cs, node.getTypeVariable(), constraint);
});
}
#pragma mark Graph mutation
void ConstraintGraph::removeNode(TypeVariableType *typeVar) {