Skip to content

Commit 2aa98eb

Browse files
committed
[ConstraintSystem] Always propagate inout/variadic flags to type-less closure parameters
Instead of infer all of the flags only for anonymous parameters, let's infer inout/variadic for all type-less parameters - anonymous and named. This allows to correctly form internal parameter type and reduce amount of inference in the body (e.g. `BindParam` could be simplified inline).
1 parent 5ea28a7 commit 2aa98eb

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8831,11 +8831,16 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
88318831
auto param = inferredClosureType->getParams()[i];
88328832
auto *paramDecl = paramList->get(i);
88338833

8834-
// In case of anonymous parameters let's infer flags from context
8835-
// that helps to infer variadic and inout earlier.
8836-
if (closure->hasAnonymousClosureVars()) {
8837-
if (auto contextualParam = getContextualParamAt(i))
8838-
param = param.withFlags(contextualParam->getParameterFlags());
8834+
// In case of anonymous or name-only parameters, let's infer inout/variadic
8835+
// flags from context, that helps to propagate type information into the
8836+
// internal type of the parameter and reduces inference solver has to make.
8837+
if (!paramDecl->getTypeRepr()) {
8838+
if (auto contextualParam = getContextualParamAt(i)) {
8839+
auto flags = param.getParameterFlags();
8840+
param =
8841+
param.withFlags(flags.withInOut(contextualParam->isInOut())
8842+
.withVariadic(contextualParam->isVariadic()));
8843+
}
88398844
}
88408845

88418846
if (paramDecl->hasAttachedPropertyWrapper()) {

0 commit comments

Comments
 (0)