Skip to content

Commit c1e2223

Browse files
authored
Merge pull request #37856 from xedin/skip-useless-ref-notifies
[ConstraintGraph] Don't notify referenced var if constraint is not useful
2 parents e3ba609 + 7e022b2 commit c1e2223

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

lib/Sema/ConstraintGraph.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ ConstraintGraphNode::getEquivalenceClassUnsafe() const{
103103
}
104104

105105
#pragma mark Node mutation
106+
107+
static bool isUsefulForReferencedVars(Constraint *constraint) {
108+
switch (constraint->getKind()) {
109+
// Don't attempt to propagate information about `Bind`s and
110+
// `BindOverload`s to referenced variables since they are
111+
// adjacent through that binding already, and there is no
112+
// useful information in trying to process that kind of
113+
// constraint.
114+
case ConstraintKind::Bind:
115+
case ConstraintKind::BindOverload:
116+
return false;
117+
118+
default:
119+
return true;
120+
}
121+
}
122+
106123
void ConstraintGraphNode::addConstraint(Constraint *constraint) {
107124
assert(ConstraintIndex.count(constraint) == 0 && "Constraint re-insertion");
108125
ConstraintIndex[constraint] = Constraints.size();
@@ -111,9 +128,11 @@ void ConstraintGraphNode::addConstraint(Constraint *constraint) {
111128
{
112129
introduceToInference(constraint);
113130

114-
notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
115-
referencedVar.introduceToInference(constraint);
116-
});
131+
if (isUsefulForReferencedVars(constraint)) {
132+
notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
133+
referencedVar.introduceToInference(constraint);
134+
});
135+
}
117136
}
118137
}
119138

@@ -129,9 +148,11 @@ void ConstraintGraphNode::removeConstraint(Constraint *constraint) {
129148
{
130149
retractFromInference(constraint);
131150

132-
notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
133-
referencedVar.retractFromInference(constraint);
134-
});
151+
if (isUsefulForReferencedVars(constraint)) {
152+
notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
153+
referencedVar.retractFromInference(constraint);
154+
});
155+
}
135156
}
136157

137158
// If this is the last constraint, just pop it off the list and we're done.
@@ -230,6 +251,9 @@ void ConstraintGraphNode::addToEquivalenceClass(
230251
for (auto *constraint : node.getConstraints()) {
231252
introduceToInference(constraint);
232253

254+
if (!isUsefulForReferencedVars(constraint))
255+
continue;
256+
233257
notifyReferencedVars([&](ConstraintGraphNode &referencedVar) {
234258
referencedVar.introduceToInference(constraint);
235259
});
@@ -295,22 +319,6 @@ inference::PotentialBindings &ConstraintGraphNode::getCurrentBindings() {
295319
return *Bindings;
296320
}
297321

298-
static bool isUsefulForReferencedVars(Constraint *constraint) {
299-
switch (constraint->getKind()) {
300-
// Don't attempt to propagate information about `Bind`s and
301-
// `BindOverload`s to referenced variables since they are
302-
// adjacent through that binding already, and there is no
303-
// useful information in trying to process that kind of
304-
// constraint.
305-
case ConstraintKind::Bind:
306-
case ConstraintKind::BindOverload:
307-
return false;
308-
309-
default:
310-
return true;
311-
}
312-
}
313-
314322
void ConstraintGraphNode::introduceToInference(Constraint *constraint) {
315323
if (forRepresentativeVar()) {
316324
auto fixedType = TypeVar->getImpl().getFixedType(/*record=*/nullptr);

0 commit comments

Comments
 (0)