Skip to content

Commit 8726d88

Browse files
committed
[CSBindings] Filter out some of the constraints which can't delay hole propagation
If member type is unknown (determined to be a hole) `applicable function` of any kind or `overload choice` cannot delay attempting it because doing so would allow solver to make forward progress.
1 parent 06a7065 commit 8726d88

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ bool PotentialBinding::isViableForJoin() const {
5757
}
5858

5959
bool PotentialBindings::isDelayed() const {
60-
if (!DelayedBy.empty())
61-
return true;
62-
6360
if (isHole()) {
6461
auto *locator = TypeVar->getImpl().getLocator();
6562
assert(locator && "a hole without locator?");
@@ -76,9 +73,32 @@ bool PotentialBindings::isDelayed() const {
7673
// relies solely on contextual information.
7774
if (locator->directlyAt<NilLiteralExpr>())
7875
return true;
76+
77+
// It's possible that type of member couldn't be determined,
78+
// and if so it would be beneficial to bind member to a hole
79+
// early to propagate that information down to arguments,
80+
// result type of a call that references such a member.
81+
//
82+
// Note: This is done here instead of during binding inference,
83+
// because it's possible that variable is marked as a "hole"
84+
// (or that status is propagated to it) after constraints
85+
// mentioned below are recorded.
86+
return llvm::any_of(DelayedBy, [&](Constraint *constraint) {
87+
switch (constraint->getKind()) {
88+
case ConstraintKind::ApplicableFunction:
89+
case ConstraintKind::DynamicCallableApplicableFunction:
90+
case ConstraintKind::BindOverload: {
91+
return !ConstraintSystem::typeVarOccursInType(
92+
TypeVar, CS.simplifyType(constraint->getSecondType()));
93+
}
94+
95+
default:
96+
return true;
97+
}
98+
});
7999
}
80100

81-
return false;
101+
return !DelayedBy.empty();
82102
}
83103

84104
bool PotentialBindings::involvesTypeVariables() const {
@@ -1182,16 +1202,6 @@ void PotentialBindings::infer(Constraint *constraint) {
11821202
case ConstraintKind::ApplicableFunction:
11831203
case ConstraintKind::DynamicCallableApplicableFunction:
11841204
case ConstraintKind::BindOverload: {
1185-
// It's possible that type of member couldn't be determined,
1186-
// and if so it would be beneficial to bind member to a hole
1187-
// early to propagate that information down to arguments,
1188-
// result type of a call that references such a member.
1189-
if (CS.shouldAttemptFixes() && TypeVar->getImpl().canBindToHole()) {
1190-
if (ConstraintSystem::typeVarOccursInType(
1191-
TypeVar, CS.simplifyType(constraint->getSecondType())))
1192-
break;
1193-
}
1194-
11951205
DelayedBy.push_back(constraint);
11961206
break;
11971207
}

0 commit comments

Comments
 (0)