-
Notifications
You must be signed in to change notification settings - Fork 10.5k
AST, Sema: Teach findProtocolSelfReferences that some stdlib collections preserve variance #34140
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is big enough of a change to warrant an evolution proposal. I had a brain fart and thought this was about covariance in witness matching and not calling on an existential. Still, we should get a second opinion about the soundness of this.
Does SILGen actually generate the correct conversion from Array<Self>
to Array<P>
when you call an Array<Self>
-returning method on an existential?
Ought the conversion to be special compared to other Array upcasts? The SIL generated for
I am always happy to add more tests though! |
2578323
to
be016c8
Compare
@jckarter ping |
@swift-ci Please test |
@swift-ci Please test source compatibility |
Build failed |
Build failed |
87a5d05
to
c691b4f
Compare
There was a conflict. @swift-ci please test |
@swift-ci please test source compatibility |
I think this looks good, as long as there aren't any source compat subtleties. |
Build failed |
@jckarter Thanks for taking the time to have a look! @slavapestov Do you have any additional comments? @swift-ci please test Linux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. One more thing -- do you mind adding an entry to CHANGELOG.md? You can do that in a separate PR if you like.
c691b4f
to
3ca7cc6
Compare
…ons preserve variance * Swift.Array preserves variance in its 'Element' type * Swift.Dictionary preserves variance in its 'Value' type
3ca7cc6
to
1ee4d5b
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
@swift-ci please smoke test |
@swift-ci please test source compatibility DEBUG |
@@ -2931,8 +2931,8 @@ ERROR(dynamic_self_non_method,none, | |||
"%select{global|local}0 function cannot return 'Self'", (bool)) | |||
|
|||
ERROR(dynamic_self_invalid,none, | |||
"covariant 'Self' can only appear as the type of a property, subscript or method result; " | |||
"did you mean '%0'?", (StringRef)) | |||
"covariant 'Self' can only appear as the possibly optional type of a " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this sentence mean simply covariant Self
or Self?
? I struggle a little with how to parse “possibly optional type.”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intention was to convey that both Self
and Self?
are supported. Do you happen to have a suggestion for a better wording?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps simply: "covariant 'Self' or 'Self?' can only appear as..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, indeed. Thank you, I'll take care of this!
Add CHANGELOG entry for #34140
… collection The devirtualizer does not support handling these yet, which wasn't anticipated in swiftlang#34140
Extending this to other covariant stdlib collections is problematic due to the
Hashable
requirement.