Skip to content

[SR-1516][stdlib] Implement SE-0045 prefix(while:) and drop(while:) #3600

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 1 commit into from
Aug 16, 2016

Conversation

russbishop
Copy link
Contributor

@russbishop russbishop commented Jul 19, 2016

What's in this pull request?

Implementation for SE-0045 add prefix(while:) and drop(while:).

Resolved bug number: (SR-1516)


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

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

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@russbishop russbishop changed the title [SR-1516][stdlib] Implement SE-0045 prefix(while:) and drop(while:) [WIP][SR-1516][stdlib] Implement SE-0045 prefix(while:) and drop(while:) Jul 19, 2016
public func drop(
while predicate: @noescape (Iterator.Element) throws -> Bool
) rethrows -> SubSequence {
var start = startIndex

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed tabs and spaces

@russbishop russbishop force-pushed the se0045 branch 2 times, most recently from 56e3c3d to 8af6317 Compare July 20, 2016 14:30
@russbishop
Copy link
Contributor Author

@gribozavr Still working on tests for the lazy wrappers but any issues with the current implementation?

while predicate: @noescape (Iterator.Element) throws -> Bool
) rethrows -> SubSequence {
var start = startIndex
while try start < endIndex && predicate(self[start]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start != endIndex can be cheaper than <. It is usually the same, but in some cases can be cheaper by a constant factor.

@russbishop
Copy link
Contributor Author

I need to do the drop wrapper. Nate is doing the lazy test coverage. Then we should be in good shape.

@gribozavr
Copy link
Contributor

@russbishop Thanks!

@russbishop
Copy link
Contributor Author

@gribozavr I think we are done, subject to @natecook1000 's question about the base property.

@russbishop russbishop changed the title [WIP][SR-1516][stdlib] Implement SE-0045 prefix(while:) and drop(while:) [SR-1516][stdlib] Implement SE-0045 prefix(while:) and drop(while:) Jul 28, 2016
@gribozavr
Copy link
Contributor

Thanks! I haven't looked at the code yet, but let's get a CI run.

@swift-ci Please test

expectEqual(nil, iter1.next())
iter2 = iter1.base
expectEqual(5, iter2.next())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question from the other PR:

@gribozavr: If this is the result of providing a base property on LazyPrefixWhileIterator, does it make sense? It loses the first element that fails the predicate. I'm just not sure what the purpose is of having these base properties available—I used the other lazy iterators as a template for these, but I don't see a reason for including it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natecook1000 @gribozavr Did we get a resolution on this? I think I agree with Nate that the base property doesn't make sense in this context because we have no way to stuff the element back into the sequence.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dmitri is out. If you feel the base property can be elided and reintroduced later then please remove it. Else let me know and we can get this merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CodaFi I removed it. I'd rather be safe and not expose something with surprising behavior since we can always add it back in later.

@russbishop
Copy link
Contributor Author

@CodaFi All validation and unit tests pass. I'm just going to assume we missed the Swift 3 release train so this can go to master. If not let me know.

@CodaFi
Copy link
Contributor

CodaFi commented Aug 12, 2016

Very nice!

@swift-ci please smoke test OS X platform.

@russbishop
Copy link
Contributor Author

@CodaFi any chance we can merge this? I don't want it to get stale again if we can help it!

@CodaFi
Copy link
Contributor

CodaFi commented Aug 14, 2016

I'm concerned about @natecook1000's question. Was there ever a response?

@CodaFi
Copy link
Contributor

CodaFi commented Aug 15, 2016

@russbishop Unless you see a reason to keep it, please remove the base property.

Includes lazy implementation courtesy of Nate Cook
@russbishop
Copy link
Contributor Author

@CodaFi Removed and pushed. Validation passed locally.

@russbishop
Copy link
Contributor Author

@CodaFi This should be good

@CodaFi
Copy link
Contributor

CodaFi commented Aug 16, 2016

So it is. Thank you for being patient @russbishop.

@CodaFi CodaFi merged commit e6c313b into swiftlang:master Aug 16, 2016
@lattner
Copy link
Contributor

lattner commented Aug 16, 2016

Woot, congrats @russbishop

@@ -200,6 +200,12 @@ internal class _AnyRandomAccessCollectionBox<Element>
% end

% override = 'override' if Kind != 'Sequence' else ''
internal ${override} func _drop(
while predicate: (Element) throws -> Bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All new predicates in this file should be @noescape. Please also add dispatch tests in validation-test/stdlib/ExistentialCollection.swift.gyb.

@CodaFi
Copy link
Contributor

CodaFi commented Aug 17, 2016

I will clean up this pull request in a subsequent patch @gribozavr.

CodaFi added a commit to CodaFi/swift that referenced this pull request Aug 17, 2016
jtbandes added a commit to jtbandes/swift-evolution that referenced this pull request Aug 19, 2016
DougGregor added a commit to swiftlang/swift-evolution that referenced this pull request Aug 19, 2016
@jtbandes
Copy link
Contributor

Is this going to be included in Swift 3.0? If so, I think someone will need to cherry-pick it to swift-3.0-branch. (I just updated swiftlang/swift-evolution#503, but I was premature in assuming this would be part of 3.0.)

@CodaFi
Copy link
Contributor

CodaFi commented Aug 19, 2016

Dmitri had reservations about its inclusion this late in the game. Besides, it is a purely additive component.

@jtbandes
Copy link
Contributor

In that case, perhaps we had better add a new section to the proposals page... ("Post-3.0"?)

@benrimmington
Copy link
Contributor

@jtbandes SE-0045 is also in the wrong section of the CHANGELOG.md.

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.

9 participants