-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[WIP][Stdlib][SR-1052] Added @discardableResult attr to mutating functions #2044
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
@@ -1412,6 +1416,7 @@ extension Array { | |||
/// | |||
/// - Complexity: O(`self.count`) if the array is bridged, | |||
/// otherwise O(1). | |||
@discardableResult | |||
public mutating func popLast() -> Element? { |
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'm not sure why, but the popLast
here and later in this same file differ in "discardability" from the popLast
in Collection.swift, where it has @warn_unused_result
.
If these need to be reconciled, I'm happy to do that under this PR.
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.
Not sure either, but please keep them consistent.
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.
Any idea which is preferable for the consistent solution? They seem to be so close to remove
and removeLast
that they should have the same "discardability", meaning that all of the pop*
functions should have @discardableResult
.
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.
They seem to be so close to remove and removeLast that they should have the same "discardability"
I tend to agree.
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.
Actually, I think I see why the pop*
functions should warn on unused results. Unlike the remove
and removeLast
functions, the pop*
functions return an optional (nil
indicating the collection was empty). This is a success/failure indicator and shouldn't be ignored.
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.
Good point, I'd appreciate @dabrahams thoughts on that.
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.
LGTM.
Sent from my moss-covered three-handled family gradunza
On Apr 3, 2016, at 6:18 PM, Chris Lattner notifications@github.com wrote:
In stdlib/public/core/Arrays.swift.gyb:
@@ -1412,6 +1416,7 @@ extension Array {
///
/// - Complexity: O(self.count
) if the array is bridged,
/// otherwise O(1).
- @discardableResult
public mutating func popLast() -> Element? {
Good point, I'd appreciate @dabrahams thoughts on that.—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
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.
on Sun Apr 03 2016, Chris Lattner <notifications-AT-github.com> wrote:
In stdlib/public/core/Arrays.swift.gyb:
@@ -1412,6 +1416,7 @@ extension Array {
///
/// - Complexity: O(self.count
) if the array is bridged,
/// otherwise O(1).
- @discardableResult
public mutating func popLast() -> Element? {Good point, I'd appreciate @dabrahams thoughts on that.
On second thought, I think we should say, “use removeLast if you don't
want the result.”
Dave
Did you audit the underscore-land? I see a few cases in |
@gribozavr, I was looking at mutating functions in particular as they have side-effects and the result may be unneeded. I don't see any mutating functions in Do you have an example of where it should be added in that file? |
032b819
to
dd0475e
Compare
@tanadeau I was thinking about But there seem to be other cases -- for example what do you think about |
I believe I've addressed all the comments with the exception of Dmitri's dealing with
|
dd0475e
to
f266a7b
Compare
I added |
Your patch LGTM to the extent of the changes that you made, but I'm still a little concerned about errors of omission. |
@gribozavr, understood. One thing to keep in mind with this PR is that the |
@tanadeau OK. If you are happy with the current state of the patch, we can merge it. |
I'm happy if you're happy 😄 |
@swift-ci Please test and merge |
f266a7b
to
515df05
Compare
I think I fixed the test failure that CI found. The expected output for the serialized XML version of the I'm not sure why this test doesn't run for me. I'm testing in an Ubuntu VM using |
@tanadeau Thank you! Could you resolve merge conflicts? |
515df05
to
f96ad26
Compare
@gribozavr I rebased and fixed the conflicts. I believe this is ready for a CI test-and-merge. |
@swift-ci Please test and merge |
@gribozavr The OS X build passed. The Linux build failed due to a mismatch between a change in swift-corelibs-xctest and swift-integration-tests.
The change at swiftlang/swift-corelibs-xctest@ce992f5 added a new required initializer to None of the above was due to this PR. |
What's in this pull request?
Part 2 for SR-1052: Add
@discardableResult
attr to mutating functions in stdlib that return resultsResolved bug number: Part 2 of (SR-1052)
I tried to find all of the mutating functions with non-Void return values and that were not marked with
@warn_unused_result
. I then marked them with the new@discardableResult
attribute. These will stay around after the@warn_unused_result
attribute is removed and warning on unused results becomes the default.Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
Validation Testing
Note: Only members of the Apple organization can trigger swift-ci.