Bug 15230 – Inconsistent std.range.SortedRange predicate checks

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-10-21T11:22:00Z
Last change time
2019-10-02T07:41:19Z
Keywords
pull
Assigned to
No Owner
Creator
John Colvin

Comments

Comment #0 by john.loughran.colvin — 2015-10-21T11:22:00Z
SortedRange doesn't check that it's predicate actually works unless you use one of lowerbound, upperBound etc. or you compile with -debug, in which case things will fail internally to std.functional.binaryFun due to the usage of the predicate in dbgVerifySorted. Note that people could be signalling sorted-ness using SortedRange, not considering they have invalid predicates, e.g. struct S { int a,b; } void foo(R)(R r) if(isInstanceOf!(SortedRange, P) && is(ElementType!R == S)) { //assumes some idea of sorted-ness } only(S(0,1), S(0,4), S(3,4), S(4,4)).assumeSorted.foo(); but I guess it's OK to break that because it was technically incorrect, if rather opaquely so....
Comment #1 by jack — 2015-10-26T01:52:40Z
I would consider this as "working as intended", as the checks are only supposed to happen in debug mode. In a PR of mine, I asked @schveiguy if it made any sense to have any checks in a function that is supposed to be assuming something. He said it's strange, but it's nice to have something that double checks for you, in debug mode only.
Comment #2 by john.loughran.colvin — 2015-10-26T07:36:52Z
(In reply to Jack Stouffer from comment #1) > I would consider this as "working as intended", as the checks are only > supposed to happen in debug mode. In a PR of mine, I asked @schveiguy if it > made any sense to have any checks in a function that is supposed to be > assuming something. He said it's strange, but it's nice to have something > that double checks for you, in debug mode only. It's fine to have extra runtime checks in debug mode that check data, but I think the API should not change. The predicate should either always be verified to be valid or be optional.
Comment #3 by dlang-bugzilla — 2017-07-21T10:30:29Z
Verifying the predicate statically regardless of -debug does sound like a good idea.
Comment #4 by dlang-bugzilla — 2017-07-21T10:30:41Z
*** Issue 15537 has been marked as a duplicate of this issue. ***
Comment #5 by dlang — 2019-09-29T11:44:11Z
An other solution might be, to add an (optional) option parameter, like in https://dlang.org/phobos/std_range.html#transposed. The parameter decides if sortedness should be striktly checked (O(n)), roughly checked (O(log(n)) or assumed.
Comment #6 by dlang-bot — 2019-09-29T15:05:22Z
@crocopaw created dlang/phobos pull request #7205 "Fix Issue 15230 - Inconsistent std.range.SortedRange predicate checks" fixing this issue: - Fix Issue 15230 - Inconsistent std.range.SortedRange predicate checks https://github.com/dlang/phobos/pull/7205
Comment #7 by dlang-bot — 2019-10-02T07:41:19Z
dlang/phobos pull request #7205 "Fix Issue 15230 - Inconsistent std.range.SortedRange predicate checks" was merged into master: - 58c3a7573865f70f5c25b15af4a70257b3a8998e by Berni: Fix Issue 15230 - Inconsistent std.range.SortedRange predicate checks https://github.com/dlang/phobos/pull/7205