phobos icon indicating copy to clipboard operation
phobos copied to clipboard

Fix Issue 10706 setops functions need to require SortedRanges

Open burner opened this issue 5 years ago • 42 comments

https://issues.dlang.org/show_bug.cgi?id=10706

  • largestPartialIntersection
  • largestPartialIntersectionWeighted
  • multiwayMerge
  • multiwayUnion
  • setDifference
  • setIntersection
  • setSymmetricDifference

Now all require SortedRanges to be passed, as that is what they expect implicitly anyway.

A new public symbol isSortedRange was added to std.range.

burner avatar Dec 06 '18 12:12 burner

Thanks for your pull request, @burner!

Bugzilla references

Auto-close Bugzilla Severity Description
10706 enhancement Functions that require a sorted range to take a SortedRange?

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#6795"

dlang-bot avatar Dec 06 '18 12:12 dlang-bot

LGTM, given the possible fixing breakage that this will incur, this needs a changelog.

thewilsonator avatar Dec 06 '18 12:12 thewilsonator

changelog added

burner avatar Dec 06 '18 16:12 burner

Nice idea!

thewilsonator avatar Dec 07 '18 07:12 thewilsonator

I will do the suggested change, but SortedRange will check for sortedness in debug. So this is still a breaking change.

But from

Assuming for the sake of argument that this should go ahead

it sounds like an opinion has already been formed regarding this PR. If this would be my first PR it would be my last. It's the tone that makes the music.

burner avatar Dec 09 '18 20:12 burner

I'm sorry it came across that way. I think the red X makes the tone seem more negative than intended.

n8sh avatar Dec 11 '18 01:12 n8sh

@n8sh I didn't notice the red X until you just mentioned it.

Anyway, what is the way forward with this.

burner avatar Dec 11 '18 09:12 burner

Anyway, what is the way forward with this.

You said you intend to do the suggested change, so when that is done this should be ready to go ahead.

n8sh avatar Dec 11 '18 10:12 n8sh

I already added the overloads.

But I can't mark them as deprecated as phobos will fail to build.

burner avatar Dec 11 '18 10:12 burner

I already added the overloads.

Could you please point me to them.

But I can't mark them as deprecated as phobos will fail to build.

Bummer.

thewilsonator avatar Dec 11 '18 11:12 thewilsonator

But I can't mark them as deprecated as phobos will fail to build.

Well, all tests that use them need to be marked as deprecated too then (or use assumeSorted or similar).

wilzbach avatar Dec 11 '18 11:12 wilzbach

Ok, I'll mark the tests as deprecated and see what happens.

burner avatar Dec 11 '18 11:12 burner

All tests that rely on the non SortedRange input have been marked deprecated. I can't mark the non SortedRange version of the functions deprecated as they call each other.

I'm inclined to add a comment saying the will go away at some point in the future.

burner avatar Dec 11 '18 11:12 burner

I can't mark the non SortedRange version of the functions deprecated as they call each other.

Can't each non-SortedRange function just call the SortedRange equivalent?

n8sh avatar Dec 11 '18 12:12 n8sh

that would require to duplicate the impl. let me check something

burner avatar Dec 11 '18 12:12 burner

I hope to wrap sub calls in assumeSorted, by that doesn't work as I would have to reconstruct RangeOfRanges which could be everything. I think this is as good as it gets right now.

burner avatar Dec 11 '18 14:12 burner

added a red comment in the docs to state that the usage of non SortedRange ranges is deprecated

burner avatar Dec 13 '18 12:12 burner

@andralex You've got 3 days to give input on this.

thewilsonator avatar Dec 13 '18 13:12 thewilsonator

I can't mark the non SortedRange version of the functions deprecated as they call each other.

I think they can all be marked deprecated without a problem except for multiwayMerge (EDIT: and largestPartialIntersectionWeighted). I'll push that change to this PR.

n8sh avatar Dec 13 '18 21:12 n8sh

thank you

burner avatar Dec 17 '18 09:12 burner

anything else?

burner avatar Dec 20 '18 09:12 burner

@burner I know this is old, but any chance of applying @andralex 's feedback and then tackle another round of review?

RazvanN7 avatar Apr 22 '21 11:04 RazvanN7

I'll take another look

burner avatar Apr 23 '21 14:04 burner

ping @burner

RazvanN7 avatar Sep 28 '21 15:09 RazvanN7

yeah I know, shame on me. I promise I'll get to it. :disappointed:

burner avatar Sep 28 '21 20:09 burner

@burner sorry for poking you like this, but have you made any progress on this?

RazvanN7 avatar Nov 15 '21 13:11 RazvanN7

@RazvanN7 please don't feel sorry, I have not. But I just opened up the std.algorithm.setup. Thank you for being my naggy feeling in the back of my mind !

burner avatar Nov 16 '21 07:11 burner

@RazvanN7 I actually got it done I think.

burner avatar Jun 02 '22 09:06 burner

@RazvanN7 should we take another look at this?

burner avatar Feb 17 '23 16:02 burner

FWIW: I would prefer if this did not go ahead. We are not really doing this kind of thing with any other invariants and SortedRange is not even able to properly enforce its own invariant due to mutable aliasing. In fact, I would also prefer to have binary search functions in std.algorithm that do not require a sorted range.

tgehr avatar Mar 11 '23 22:03 tgehr