Skip to content

Commit 61d5ae9

Browse files
committed
[CSSimplify] Avoid resolving closures passed to a parameter that doesn't accept them
Doing so improves performance if closure is passed as an argument to a (heavily) overloaded declaration, avoid unrelated errors, propagate holes, and record a more impactful fix.
1 parent e40d4e4 commit 61d5ae9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11547,6 +11547,28 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1154711547
return true;
1154811548
};
1154911549

11550+
// If contextual type is not a function type or `Any` and this
11551+
// closure is used as an argument, let's skip resolution.
11552+
//
11553+
// Doing so improves performance if closure is passed as an argument
11554+
// to a (heavily) overloaded declaration, avoid unrelated errors,
11555+
// propagate holes, and record a more impactful fix.
11556+
if (!contextualType->isTypeVariableOrMember() &&
11557+
!(contextualType->is<FunctionType>() || contextualType->isAny()) &&
11558+
locator.endsWith<LocatorPathElt::ApplyArgToParam>()) {
11559+
if (!shouldAttemptFixes())
11560+
return false;
11561+
11562+
assignFixedType(typeVar, PlaceholderType::get(getASTContext(), typeVar),
11563+
closureLocator);
11564+
recordTypeVariablesAsHoles(inferredClosureType);
11565+
11566+
return !recordFix(
11567+
AllowArgumentMismatch::create(*this, typeVar, contextualType,
11568+
getConstraintLocator(locator)),
11569+
/*impact=*/15);
11570+
}
11571+
1155011572
// Determine whether a result builder will be applied.
1155111573
auto resultBuilderType = getOpenedResultBuilderTypeFor(*this, locator);
1155211574

0 commit comments

Comments
 (0)