[ConstraintSystem] Adjust impact of implicit Double <-> CGFloat conversions

- Prefer CGFloat -> Double over the other way around to avoid
  ambiguities;

- Every new conversion impacts the score by factor of number of
  previously applied conversions to make it possible to select
  solutions that require the least such conversions.

- Prefer concrete overloads with Double <-> CGFloat conversion
  over generic ones.
This commit is contained in:
Pavel Yaskevich
2020-10-31 00:22:26 -07:00
parent 7fee5971d6
commit 4b01c8fd11
7 changed files with 25 additions and 16 deletions

View File

@@ -10527,7 +10527,14 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
case ConversionRestrictionKind::DoubleToCGFloat:
case ConversionRestrictionKind::CGFloatToDouble: {
increaseScore(SK_ImplicitValueConversion);
// Prefer CGFloat -> Double over other way araund.
auto defaultImpact =
restriction == ConversionRestrictionKind::CGFloatToDouble ? 1 : 2;
auto numConversions = CurrentScore.Data[SK_ImplicitValueConversion];
increaseScore(SK_ImplicitValueConversion,
defaultImpact * (numConversions + 1));
if (worseThanBestSolution())
return SolutionKind::Error;