Skip to content

Bugfix for takeOne (issue 16999)#4984

Merged
JackStouffer merged 1 commit intodlang:masterfrom
dukc:takeOneFix
Jan 26, 2017
Merged

Bugfix for takeOne (issue 16999)#4984
JackStouffer merged 1 commit intodlang:masterfrom
dukc:takeOneFix

Conversation

@dukc
Copy link
Contributor

@dukc dukc commented Dec 21, 2016

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.

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

Good catch! Two general remarks:

  1. When touching uncovered code, it's considered a good style to provide a unittest for it.
  2. 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();
Copy link
Contributor

@wilzbach wilzbach Dec 21, 2016

Choose a reason for hiding this comment

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

This should be popBack and it's not even covered :/
(please add a test)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're correct about that testing thing trough

Copy link
Contributor Author

@dukc dukc Dec 21, 2016

Choose a reason for hiding this comment

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

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.

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@wilzbach wilzbach Dec 21, 2016

Choose a reason for hiding this comment

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

a random access range should always be a forward range

This is not necessarily required by the definition.

Copy link
Contributor Author

@dukc dukc Dec 21, 2016

Choose a reason for hiding this comment

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

Hehe, check definition of isBidirectionalRange :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

So I thought a bit about this and technically the status quo for takeOne is:

If only provided with an InputRange, takeOne is neither a RandomAccess nor a ForwardRange

but the spec also says:

r.front evaluated multiple times, without calling r.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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same conclusion. I clarified the thing in doc.

@dukc dukc changed the title Bugfix for takeOne Bugfix for takeOne (issue 16999) Dec 22, 2016
@dukc
Copy link
Contributor Author

dukc commented Dec 27, 2016

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?

@PetarKirov
Copy link
Member

@dukc Then just change the editor, if you don't like vim ;)

https://git-scm.com/book/tr/v2/Customizing-Git-Git-Configuration
git config --global core.editor [editor exe name]

E.g. git config --global core.editor subl (if you use Sublime Text).

@wilzbach
Copy link
Contributor

Is there a non-interactive way to rename commits?

Two other possibilities:

  • You can also use one of the GUI editors
  • I can also do the rebase for you - just let me know if you want to go this way

@dukc
Copy link
Contributor Author

dukc commented Dec 27, 2016

I had already changed the editor -- I just did not except that other editors could do interactive mode. Thanks for the info.

@wilzbach
Copy link
Contributor

I just did not except that other editors could do interactive mode

@dukc now you seem to have added a lot more commits. Maybe a simple git rebase upstream/master will do?

@dukc
Copy link
Contributor Author

dukc commented Dec 27, 2016

i have a feeling i am screwing the whole thing up just trying to rename a single commit...

@dukc
Copy link
Contributor Author

dukc commented Dec 27, 2016

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.

@dukc
Copy link
Contributor Author

dukc commented Dec 27, 2016

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?

@wilzbach
Copy link
Contributor

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 ;-)

@dukc
Copy link
Contributor Author

dukc commented Dec 27, 2016

Thanks. I'm not going to be trying to rebase anything I've made pr's of anytime soon.

@dukc
Copy link
Contributor Author

dukc commented Jan 2, 2017

What's that CircleCI failure about... "reference is not a tree" sounds like a checker bug?

@dukc
Copy link
Contributor Author

dukc commented Jan 2, 2017

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.

@dukc
Copy link
Contributor Author

dukc commented Jan 4, 2017

@wilzbach I will close this pr if no-one has anything to say about it anymore. Post above explains why.

@wilzbach
Copy link
Contributor

wilzbach commented Jan 4, 2017

What's that CircleCI failure about... "reference is not a tree" sounds like a checker bug?

Yep, I think it was due to this fixed problem. I rebased your PR and hopefully everything should be green now.
Also note that passing CircleCi is not enforced nor required, it's a mere tool to help reviewers.

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.

Hmm - you just need to reset your master branch. As long as you don't delete your fork or the takeOneFix branch nothing should be affected.

That means my possible further work is blocked by this in the queue.

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.

@wilzbach I will close this pr if no-one has anything to say about it anymore. Post above explains why.

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 ;-)

@dukc
Copy link
Contributor Author

dukc commented Jan 4, 2017

Thanks, that means I can continue with other stuff, if I more find things fit for me.

Copy link
Contributor

@JackStouffer JackStouffer left a comment

Choose a reason for hiding this comment

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

Looks good, just address the nitpicks

assert(s.back == 43);
assert(s[0] == 43);
s.popFront();
s.popBack();
Copy link
Contributor

Choose a reason for hiding this comment

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

no reason to change this

Copy link
Contributor Author

@dukc dukc Jan 13, 2017

Choose a reason for hiding this comment

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

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

auto iotaPart = iota(4);?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Won't do, because the bug affects only RefRanges.

@dukc
Copy link
Contributor Author

dukc commented Jan 13, 2017

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.

@edi33416
Copy link
Contributor

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 git rebase rewrites your commits history and you want to force the rewrite to the remote branch as well. If you don't force, the push will be rejected because of a mismatch in the commits history.

When you pull from a remote branch, it is probably a good idea to use the --ff-only option. The --ff-only option is to ensure that your local branch is identical to the remote branch, since otherwise you will end up with a very messy history that will be hard to clean up.

I have found rebasing explained really well (imho) here.

Hope this helps.
Cheers

@dukc
Copy link
Contributor Author

dukc commented Jan 14, 2017

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.

@dukc
Copy link
Contributor Author

dukc commented Jan 26, 2017

@JackStouffer Both nitpicks addressed. But are they ok now?

@JackStouffer
Copy link
Contributor

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.
@dukc
Copy link
Contributor Author

dukc commented Jan 26, 2017

Thanks. Done, hopefully without complications.

@JackStouffer
Copy link
Contributor

Auto-merge toggled on

@dukc
Copy link
Contributor Author

dukc commented Jan 26, 2017

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.

@JackStouffer JackStouffer merged commit d60f32c into dlang:master Jan 26, 2017
@dukc dukc deleted the takeOneFix branch January 27, 2017 09:05
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.

5 participants