Bug 16073 – Ranges without opDollar not supported

Status
NEW
Severity
minor
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-05-25T14:37:24Z
Last change time
2024-12-01T16:26:56Z
Assigned to
No Owner
Creator
qznc
Moved to GitHub: phobos#10179 →

Comments

Comment #0 by qznc — 2016-05-25T14:37:24Z
Various algorithms in std.algorithm.searching use opDollar, although given ranges might not implement it. For example: https://github.com/dlang/phobos/blob/master/std/algorithm/searching.d#L1781 These should be converted into `x.length` instead and unittests should be inserted to check that range algorithms work without opDollar.
Comment #1 by jack — 2016-05-25T14:42:45Z
I'd imagine this is an issue throughout Phobos. All functions that use isRandomAccessRange need to be checked as well.
Comment #2 by jack — 2016-05-31T14:27:34Z
Comment #3 by github-bugzilla — 2016-06-02T18:30:31Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/a818c7e059bf0e37609c7030b8306daf54909beb [Issue 16073] Fix incorrect uses of random access range primitives in std.algorithm.iteration https://github.com/dlang/phobos/commit/3a1db06f41eca48e1b1b46ca05bb221c01714160 [Issue 16073] Fix incorrect uses of random access range primitives in std.algorithm.mutation https://github.com/dlang/phobos/commit/74398e70cf79acab6a352e7bbec614ce2f91dffb [Issue 16073] Fix incorrect uses of random access range primitives in std.algorithm.searching https://github.com/dlang/phobos/commit/e216c10b2ce08cb8ae5c64983a2f24367f4b86e4 Merge pull request #4383 from JackStouffer/issue16073 Partial Fix for Issue 16073
Comment #4 by github-bugzilla — 2016-06-14T15:02:02Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/94d74ac8f5772e3e32f7c2e2b4b59fd0783a6ad5 [Issue 16073] Fix incorrect uses of random access range primitives in std.algorithm.sorting https://github.com/dlang/phobos/commit/c5bb43ce54d7feb244ba032c43aecd7aa7c9356a Merge pull request #4425 from JackStouffer/issue16073 Partial Fix for Issue 16073 (part 2)
Comment #5 by github-bugzilla — 2016-10-01T11:45:14Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/a818c7e059bf0e37609c7030b8306daf54909beb [Issue 16073] Fix incorrect uses of random access range primitives in std.algorithm.iteration https://github.com/dlang/phobos/commit/3a1db06f41eca48e1b1b46ca05bb221c01714160 [Issue 16073] Fix incorrect uses of random access range primitives in std.algorithm.mutation https://github.com/dlang/phobos/commit/74398e70cf79acab6a352e7bbec614ce2f91dffb [Issue 16073] Fix incorrect uses of random access range primitives in std.algorithm.searching https://github.com/dlang/phobos/commit/e216c10b2ce08cb8ae5c64983a2f24367f4b86e4 Merge pull request #4383 from JackStouffer/issue16073 https://github.com/dlang/phobos/commit/94d74ac8f5772e3e32f7c2e2b4b59fd0783a6ad5 [Issue 16073] Fix incorrect uses of random access range primitives in std.algorithm.sorting https://github.com/dlang/phobos/commit/c5bb43ce54d7feb244ba032c43aecd7aa7c9356a Merge pull request #4425 from JackStouffer/issue16073
Comment #6 by github-bugzilla — 2016-10-09T16:28:26Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/06c9dca2daf3edfde85ba01a9d22d842621fad1c [Issue 16073] Fix incorrect uses of random access range primitives in std.range.package https://github.com/dlang/phobos/commit/86ef3a224ed05bfe52b63caedc53ebdcf5be513e Merge pull request #4463 from JackStouffer/issue16073 Partial Fix for Issue 16073 (part 3)
Comment #7 by andrei — 2016-12-24T10:06:00Z
I think we should require opDollar to be implemented instead.
Comment #8 by jack — 2016-12-24T14:49:36Z
(In reply to Andrei Alexandrescu from comment #7) > I think we should require opDollar to be implemented instead. That would be a breaking change, as suddenly hasLength would fail for lots of user types.
Comment #9 by andrei — 2016-12-24T14:52:20Z
We can leave hasLength as is for the time but at least new algorithms should just use $. All of these useless options left to sloppy range implementations don't bring value.
Comment #10 by greeenify — 2016-12-24T15:08:37Z
> All of these useless options left to sloppy range implementations don't bring value. This has probably been proposed before, but what about letting the compiler insert an opDollar alias if length is defined? This should greatly help to avoid sloppy implementation differences and one can still opt to use the opDollar overloads for superior performance.
Comment #11 by github-bugzilla — 2017-01-07T03:02:04Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/06c9dca2daf3edfde85ba01a9d22d842621fad1c [Issue 16073] Fix incorrect uses of random access range primitives in std.range.package https://github.com/dlang/phobos/commit/86ef3a224ed05bfe52b63caedc53ebdcf5be513e Merge pull request #4463 from JackStouffer/issue16073
Comment #12 by issues.dlang — 2017-01-20T18:27:52Z
(In reply to greenify from comment #10) > > All of these useless options left to sloppy range implementations don't bring value. > > This has probably been proposed before, but what about letting the compiler > insert an opDollar alias if length is defined? This should greatly help to > avoid sloppy implementation differences and one can still opt to use the > opDollar overloads for superior performance. https://issues.dlang.org/show_bug.cgi?id=7177 covers fixing it so that ranges that define length automatically get opDollar, but it's never gone anywhere. There has been discussion on it from time to time, but without implementing it, requiring ranges to work with $ is going to break a lot of code, since odds are that very few folks are implementing opDollar. Phobos itself doesn't do it consistently. But it's pretty ridiculous that we can't use $ with anything but arrays (which is basically where we sit now), and it really should be fixed. I did fix it some time ago so that isRandomAccessRange and hasSlicing verify that $ works correctly if it works (at least verifies it as much as can be done statically), but they've never required that $ works, because so few ranges implement opDollar, and issue #7177 has never been implemented. I'd have changed isRandomAccessRange and hasSlicing to require that $ work years ago if it weren't for that.
Comment #13 by robert.schadek — 2024-12-01T16:26:56Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10179 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB