Bugfix for takeOne (issue 16999)#4984
Conversation
wilzbach
left a comment
There was a problem hiding this comment.
Good catch! Two general remarks:
- When touching uncovered code, it's considered a good style to provide a unittest for it.
- It would be nice if you could file an issue at Bugzilla and reference it in your commit message, s.t. our bot can do it's work and for example include the fix in the changelog for the next release. The bot uses the same issue reference syntax as Bugzilla does. See other PRs, e.g. this one for examples.
| void popBack() | ||
| { | ||
| assert(!empty, "Attempting to popBack an empty takeOne"); | ||
| _source.popFront(); |
There was a problem hiding this comment.
This should be popBack and it's not even covered :/
(please add a test)
There was a problem hiding this comment.
Wrong! I almost introduced a bug by doing first making it popBack(), but luckily some unittest didn't compile.
Think what happens if I takeOne from, say a refrange which contains [1, 2, 3, 4] and then popBack the takeOne. The range would become [1, 2, 3] even when its 1 i took from it.
There was a problem hiding this comment.
You're correct about that testing thing trough
There was a problem hiding this comment.
I aliased popBack to popFront. They do the same thing so this perhaps removes some bloat. At the same time it should fix that testing thing.
std/range/package.d
Outdated
| regardless of $(D R)'s capabilities (another feature that distinguishes | ||
| $(D takeOne) from $(D take)). | ||
| $(D takeOne) from $(D take)). One exception: The range can save() only | ||
| if $(D R) can. |
There was a problem hiding this comment.
How about using the term ForwardRange, e.g.
"However, it is a ForwardRange if range is forwardable."
(I am not sure whether this makes it clearer)
There was a problem hiding this comment.
It does not: a random access range should always be a forward range, and takeOne clains to be a random access range (and thus ForwardRange) no matter what.
There was a problem hiding this comment.
a random access range should always be a forward range
This is not necessarily required by the definition.
There was a problem hiding this comment.
Hehe, check definition of isBidirectionalRange :-)
There was a problem hiding this comment.
So I thought a bit about this and technically the status quo for takeOne is:
If only provided with an
InputRange,takeOneis neither aRandomAccessnor aForwardRange
but the spec also says:
r.frontevaluated multiple times, without callingr.popFront, or otherwise mutating the range object or the underlying data, yields the same result for every evaluation.
So before your PR it would have been possible to provide save even for a InputRange, because a call to front is always guaranteed to yield the same element and the range can be "saved" as currently by storing it's emptiness, the source range and not calling popFront on the source range.
The spec only has been updated to this tight definition quite recently (since 2.072), before it was allowed to yield different results for multiple calls on front and e.g. most famously generate did so.
CC @JackStouffer and @schveiguy (the authors of this change)
There was a problem hiding this comment.
Same conclusion. I clarified the thing in doc.
|
Too hard for me. I can't use Vim controls at all... were I to mistype a single key, I would not know what to do. Is there a non-interactive way to rename commits? |
|
@dukc Then just change the editor, if you don't like vim ;) https://git-scm.com/book/tr/v2/Customizing-Git-Git-Configuration E.g. |
Two other possibilities:
|
|
I had already changed the editor -- I just did not except that other editors could do interactive mode. Thanks for the info. |
@dukc now you seem to have added a lot more commits. Maybe a simple |
|
i have a feeling i am screwing the whole thing up just trying to rename a single commit... |
|
No, I can't get it to work now... I edit the message, save it and then get a merge problem or something. Too much new stuff to handle at once. I aborted the rebase. |
|
I somehow managed to apparently include everything that has happened in the master branch recenty in the pr... I believe I have to close this and do the whole pr again? |
Nope - fixed it for you ;-) |
|
Thanks. I'm not going to be trying to rebase anything I've made pr's of anytime soon. |
|
What's that CircleCI failure about... "reference is not a tree" sounds like a checker bug? |
|
Please explain the above, pull or close. I messed up my private fork but I dare not to try to clean it up as long as this pr is based from it. That means my possible further work is blocked by this in the queue. |
|
@wilzbach I will close this pr if no-one has anything to say about it anymore. Post above explains why. |
Yep, I think it was due to this fixed problem. I rebased your PR and hopefully everything should be green now.
Hmm - you just need to reset your
Don't worry about - in the worst case - GitHub makes copies of all PRs and I have them on my machines, so I could easily recreate this PRs.
Sorry, I was away for a bit. Please don't let yourself get blocked by this. As said we will manage to find a way ;-) |
|
Thanks, that means I can continue with other stuff, if I more find things fit for me. |
JackStouffer
left a comment
There was a problem hiding this comment.
Looks good, just address the nitpicks
std/range/package.d
Outdated
| assert(s.back == 43); | ||
| assert(s[0] == 43); | ||
| s.popFront(); | ||
| s.popBack(); |
There was a problem hiding this comment.
no reason to change this
There was a problem hiding this comment.
Just wanted to make sure my alias works. Do you want me to put it elsewhere instead?
| @safe void popFront(){front++;} | ||
| enum empty = false; | ||
| }; | ||
| auto iotaPart = myIota.takeOne; |
There was a problem hiding this comment.
auto iotaPart = iota(4);?
There was a problem hiding this comment.
Won't do, because the bug affects only RefRanges.
|
Finally, fixed that fork! Trough, the lesson with pushing and pulling appears to be that if something is rejected, force it... usually that's a bad sign. |
|
A short note on why you need to force a push to a remote branch. I hope you will find this helpful. After you've rebased your local branch, you will have to force the push to your remote branch. That is because When you pull from a remote branch, it is probably a good idea to use the I have found rebasing explained really well (imho) here. Hope this helps. |
|
Thanks, perhaps it will help if/whn i encounter more problems. My problems probably were due to thinking that if I'm forcing, I'm doing something wrong. |
|
@JackStouffer Both nitpicks addressed. But are they ok now? |
|
Please squash and push: https://wiki.dlang.org/Starting_as_a_Contributor#Squashing |
…ge when popped. This made it inconsistent with take and takeExactly when using reference ranges. Also corrected its documentation.
|
Thanks. Done, hopefully without complications. |
|
Auto-merge toggled on |
|
Oh no, I screwed something with squashing, popBack is not aliased to popFront anymore. That's a secondary thing trough. Perhaps i'll do a separate pr about that. |
Fixed a bug: takeOne with unslicabe ranges did not pop its source range when popped. This made it inconsistent with take and takeExactly when using reference ranges. Also corrected its documentation.