When ranking constraint solutions, consider anything that causes

a function conversion to be bad.

This encourages the type-checker to place conversions within
closures rather than outside; the test case here crashed in
SIL verification because of that.  (Yes, that means that there's
an underlying problem still when the function conversion is
required; that's tracked by rdar://15875305.)  But in general,
function conversions are likely to be expensive, and it's good
to avoid them when possible.

The setup work to add SK_FunctionConversion was accidentally
committed as part of r12813.

Swift SVN r12839
This commit is contained in:
John McCall
2014-01-23 01:28:48 +00:00
parent fe0c17cb20
commit 59ffc88fa7
2 changed files with 12 additions and 0 deletions

View File

@@ -946,6 +946,14 @@ commit_to_conversions:
return SolutionKind::Error;
}
// Okay, we need to perform one or more conversions. If this
// conversion will cause a function conversion, score it as worse.
// This induces conversions to occur within closures instead of
// outside of them wherever possible.
if (locator.isFunctionConversion()) {
increaseScore(SK_FunctionConversion);
}
// Where there is more than one potential conversion, create a disjunction
// so that we'll explore all of the options.
if (potentialConversions.size() > 1) {