Skip to content

Commit 5bb9d75

Browse files
committed
[CSBindings] Allow early conjunction solving if all of the contextual parameters are bound
Instead of allowing only disjunctions with no parameters, let's use a contextual type to determine whether all of the parameters have been inferred.
1 parent 38f8be1 commit 5bb9d75

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,27 +1088,27 @@ bool BindingSet::favoredOverConjunction(Constraint *conjunction) const {
10881088
if (!(contextualType && contextualType->is<FunctionType>()))
10891089
return true;
10901090

1091-
auto *contextualFnType = contextualType->castTo<FunctionType>();
1092-
auto resultType = contextualFnType->getResult();
1093-
if (resultType->hasTypeVariable()) {
1094-
auto *typeVar = resultType->getAs<TypeVariableType>();
1095-
// If contextual result type is represented by an opaque type,
1096-
// it's a strong indication that body is self-contained, otherwise
1097-
// closure might rely on external types flowing into the body for
1098-
// disambiguation of `build{Partial}Block` or `buildFinalResult`
1099-
// calls.
1100-
if (!(typeVar && typeVar->getImpl().isOpaqueType()))
1101-
return true;
1091+
auto *contextualFnType =
1092+
CS.simplifyType(contextualType)->castTo<FunctionType>();
1093+
{
1094+
auto resultType = contextualFnType->getResult();
1095+
if (resultType->hasTypeVariable()) {
1096+
auto *typeVar = resultType->getAs<TypeVariableType>();
1097+
// If contextual result type is represented by an opaque type,
1098+
// it's a strong indication that body is self-contained, otherwise
1099+
// closure might rely on external types flowing into the body for
1100+
// disambiguation of `build{Partial}Block` or `buildFinalResult`
1101+
// calls.
1102+
if (!(typeVar && typeVar->getImpl().isOpaqueType()))
1103+
return true;
1104+
}
11021105
}
11031106

1104-
auto *closureType = CS.getClosureType(closure);
1105-
// If closure has parameters, it has to be delayed to give
1106-
// them a chance to be resolved.
1107-
//
1108-
// Note: Since we have access to a contextual type here it should be
1109-
// possible to transform this check into - if some of the parameters
1110-
// have type variables (that means not-yet-resolved generic parameters).
1111-
if (closureType->getNumParams() != 0)
1107+
// If some of the closure parameters are unresolved, the conjunction
1108+
// has to be delayed to give them a chance to be inferred.
1109+
if (llvm::any_of(contextualFnType->getParams(), [](const auto &param) {
1110+
return param.getPlainType()->hasTypeVariable();
1111+
}))
11121112
return true;
11131113

11141114
// If conjunction references a single type variable (closure itself)

0 commit comments

Comments
 (0)