Skip to content

[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

Merged
merged 2 commits into from
Jul 21, 2017

Conversation

dabrahams
Copy link
Contributor

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.

@dabrahams
Copy link
Contributor Author

@swift-ci Please test

@dabrahams
Copy link
Contributor Author

@swift-ci Please test source compatibility

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - c497969
Test requested by - @dabrahams

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - c497969
Test requested by - @dabrahams

dabrahams referenced this pull request Jul 16, 2017
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.
@dabrahams
Copy link
Contributor Author

I believe #10994 will make these tests pass

@dabrahams
Copy link
Contributor Author

@swift-ci Please test source compatibility

@dabrahams
Copy link
Contributor Author

@swift-ci Please test

@dabrahams
Copy link
Contributor Author

@moiseev @airspeedswift Can I get a review? We really should apply these changes ASAP. The source compatibility failure is an unrelated UPASS.

@dabrahams dabrahams requested a review from milseman July 20, 2017 00:34
Copy link
Member

@milseman milseman left a 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: () = ()) {
Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

@dabrahams
Copy link
Contributor Author

@swift-ci Please smoke test and merge

@swift-ci swift-ci merged commit 9289861 into master Jul 21, 2017
@jrose-apple jrose-apple deleted the stdlib-swift4-modernization branch November 29, 2017 22:35
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.

4 participants