Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sema] Penalize conversions to Any. #7222

Merged
merged 2 commits into from Feb 3, 2017
Merged

[Sema] Penalize conversions to Any. #7222

merged 2 commits into from Feb 3, 2017

Conversation

rudkx
Copy link
Member

@rudkx rudkx commented Feb 3, 2017

[Sema] Penalize conversions to Any.

We previously penalized bindings to Any, and that resulted in inappropriately rejecting solutions where we bind a decl that is explicitly typed Any. That penalty was removed in 170dc8a, but that has led to a variety of source compatibility issues.

So now, we'll reintroduce a penalty for Any-typed things, but instead of penalizing bindings (which happen both because of explicitly-typed values in the source, and implicitly due to attempting various types for a particular type variable), penalize casts, which are always present in some form in the source.

Thanks go to John for the suggestion.

Fixes

  • SR-3817 (aka rdar://problem/30311052)
  • SR-3786 (aka rdar://problem/30268529)
  • rdar://problem/29907555

…ersion.

This change is needed by a separate change I have that penalizes
conversions to Any. That change exposed a problem where we ended up
doing a direct lvalue-to-Any conversion without first loading as part of
an lvalue-to-rvalue conversion.

We should really only be doing most of these other conversions/fixes on
rvalues.

Unfortunately I don't know of a way to hit this without the other
change, and thus don't have a test case.

As a side note, this also helps some (perhaps most, but definitely not
all) of the exponential type inference cases involving arrays and
dictionaries. Unfortunately again, we don't currently have a testing
mechanism in place to ensure we don't regress those cases, and I don't
want to add a test that will completely hang every bot if it does
regress, so...*sad face*...no test case for that either.
We previously penalized bindings to Any, and that resulted in
inappropriately rejecting solutions where we bind a decl that is
explicitly typed Any. That penalty was removed in
170dc8a, but that has led to a variety
of source compatibility issues.

So now, we'll reintroduce a penalty for Any-typed things, but instead of
penalizing bindings (which happen both because of explicitly-typed
values in the source, and implicitly due to attempting various types for
a particular type variable), penalize casts, which are always present in
some form in the source.

Thanks go to John for the suggestion.

Fixes
  SR-3817 (aka rdar://problem/30311052)
  SR-3786 (aka rdar://problem/30268529)
  rdar://problem/29907555
@@ -407,8 +407,10 @@ enum ScoreKind {
SK_ScalarPointerConversion,
/// A conversion from an array to a pointer of matching element type.
SK_ArrayPointerConversion,
/// A conversion to an empty existential type ('Any' or '{}').
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: what is {}?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is a partial revert of code that I pulled out a while back. I take that to mean empty protocol composition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but that's never been a valid spelling for an empty protocol composition. It's not important enough to reset your smoke test for, but if you do another round here can you remove it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I'll definitely be revisiting this area at some point in the nearish future.

@rudkx
Copy link
Member Author

rudkx commented Feb 3, 2017

@swift-ci Please smoke test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As much as it pains me to introduce another score kind now, this does look like a good solution for preferring non-Any solutions. Thanks!

@rudkx rudkx merged commit c452cfa into apple:master Feb 3, 2017
@rudkx rudkx deleted the fix-rdar29960575 branch February 3, 2017 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants