-
Notifications
You must be signed in to change notification settings - Fork 466
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
Swift 5: adopt new Data.withUnsafeBytes API #843
Conversation
Why? We already use directive like that without problems. |
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.
Rather that duplicating some of the larger blocks of code, can any of this be down by providing shims for for older Swift version that expose the new api names instead? Like:
This way the code gets update to the Swift 5 syntax and the conditionals are kept to a minium reducing the chance of a bug that can exist in two almost identical blocks.
Sorry I should've been more clear. I didn't see any in the codebase when I grep'd for it, but I would prefer to be wrong because I want to use that here :)
Yep! I'll take a stab at it. |
Our policy is to support one full major version back. Since 5.0 is the current release version, that means we still support 4.0 and later. Once 5.2 is released, we'll be able to use |
I also don't know the ps - I completely read that initial comment as |
Yep you're totally right. These changes are all Swift 5 compiler in 5.0 mode, not backwards compatible with 5 compiler in 4.2 mode. |
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.
A few suggestions to simplify/improve the code.
Note: You don't need to fix all the Swift 5 issues at once. Multiple smaller PRs are easier to review.
@alanzeino -- I'm testing a branch where I've globally replaced all of the |
Yep, I'll rebase. |
The following seems sufficient to emulate the Swift 5 API on Swift 4:
Note that every place we used the old Using the above, I've experimentally switched a couple of places to use the Swift 5 APIs -- the result seems to work correctly on both Swift 4 and Swift 5. In the process, I did see some spots where the resulting code could probably be simplified, but I think such improvements can wait until after we get a clean build. |
Ah I didn't think to hardcode the type. Updating now. |
Updated all the cases. One thing to mention, looks like the master branch does not compile right now. So I did this rebased on top of a commit that did compile, then once I verified that it all compiled after my changes, I rebased so that the diff didn't have any conflicts. Any plan to add a CI check to these PRs? |
We don't have PR testing, but we do have CI for the master branch: https://ci.swift.org/job/swift-protobuf-linux-ubuntu-16_04/ According to that, the master branch did build last night. I'll take a look when I get a chance. |
If I were to guess, I'd say that master branch build uses That also raises another question I had — should we add the .xcodeproj to the |
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.
Much better! The one cleanup I'd like to see right away is to fix a few places where the closure is accessing the Data object directly instead of using the buffer argument. I've marked some of them.
Does your branch pass the test suite? (E.g. I'm seeing failures here in the following three tests: I find it interesting that the failing cases all relate to JSON and all of them have a |
Since SwiftPM doesn't really do iOS, and to better support users wanting Carthage, etc.; I think we end up needing a project file checked in. 🙁 The |
I should've taken your advice and just converted a few cases just to be safe. Unfortunately I have a bit of a problem in that I'm starting at a new employer next week that might not want me working on Open Source so how about for now I just land the back–ported extension in |
If you can fix the style issues I pointed out earlier, I'll see if I can debug that test failure. |
Okay! |
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 figured out why zero-length bytes
fields were failing.
Looks good. I'm going to run some more tests before I merge this. |
Cool! Lemme know if there's more changes I should make. |
I ran tests on Ubuntu with Swift 4.0 through a 5.0 beta and it all looks good. Thanks for working through this! |
Unfortunately I wasn't able to use the
#if compiler(>=5.0)
flag since the project supports older swift versions where this directive is not available.