-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Swift4 Modernizations Compatible with Swift 3.2 #10982
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
@swift-ci Please test |
@swift-ci Please test source compatibility |
Build failed |
Build failed |
In Swift 3 shifts used to be defined on the concrete integer types, so the right-hand-side value in the shift expression could define a type for the result, as in `1 << i32` would have the type Int32. Swift 4 makes shift operators heterogeneous, so now `1 << i32` will result in an Int, according to the type of the left-hand-side value, which gets a default type for integer literals.
I believe #10994 will make these tests pass |
@swift-ci Please test source compatibility |
@swift-ci Please test |
@moiseev @airspeedswift Can I get a review? We really should apply these changes ASAP. The source compatibility failure is an unrelated UPASS. |
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.
It all seems reasonable to me, but I do have a question as to why String.init?(_)
became String.init?(_:obsoletedInSwift4:)
.
@@ -44,7 +44,7 @@ extension String : StringProtocol, RangeReplaceableCollection { | |||
|
|||
// This initializer satisfies the LosslessStringConvertible conformance | |||
@available(swift, obsoleted: 4, message: "String.init(_:String) is no longer failable") | |||
public init?(_ other: String) { | |||
public init?(_ other: String, obsoletedInSwift4: () = ()) { |
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.
Could you explain what this change is for?
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.
Was going to ask same thing, other than this patch lgtm.
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.
This hack prevents the init?
from being used to satisfy a protocol requirement; you can satisfy a protocol requirement with something that's not yet available, but not with something that has become unavailable. IOW, without this, we can't throw the switch on the Swift 4 transition. I should add a comment to make that clear.
@swift-ci Please smoke test and merge |
Applies most of the changes to make the standard library build under Swift 4 mode, but doesn't throw the switch. See #10981, which isn't ready for merge, for the whole megillah. Whether this is ready is arguable; it could use review even if all the tests pass.