Bug 23976 – std.range.slide fails in dmd-2.104.0

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-06-07T07:46:50Z
Last change time
2023-06-23T17:48:27Z
Keywords
pull
Assigned to
No Owner
Creator
cbleser

Attachments

IDFilenameSummaryContent-TypeSize
1880slide_bug.dunittest which shows the bugapplication/x-dsrc794

Comments

Comment #0 by cr — 2023-06-07T07:46:50Z
Comment #1 by cr — 2023-06-07T08:02:29Z
Created attachment 1880 unittest which shows the bug The bug occurs in the latest version dmd-2.104.0 but works in dmd-2.103.1 and older. The problem is when a slide(2) is taken of a rbtree range the last element contains 1 element and not two. But it only fails in combination with rbtree as far as I know. The sample code is as follows. ``` import std.container.rbtree; import std.range; import std.stdio; import std.algorithm; struct RecycleSegment { int index; // uint size; } alias Indices = RedBlackTree!(RecycleSegment*, (a, b) => a.index < b.index); // RecycleSegment: sorted by size. unittest { const a=[17,42]; writefln("%s", a.slide(2)); // This passes for both dmd-2.103.1 and dmd-2.104.0 assert(a.slide(2).map!(r => r.walkLength == 2).all); auto indices = new Indices; indices.insert(new RecycleSegment(42)); indices.insert(new RecycleSegment(17)); writefln("%s", indices[].slide(2)); writefln("%s", indices[].slide(2).map!(r => r.walkLength == 2)); // This passes in dmd-2.103.1 but fails in dmd-2.104.0 assert(indices[].slide(2).map!(r => r.walkLength == 2).all); } ``` This is the print out of dmd-1.103.1 ``` [[17, 42]] [[7F6E7F100020, 7F6E7F100010]] [true] ``` And this is the print out of dmd-1.104.0 (Where it fails in the last assert) ``` [[17, 42]] [[7F7622B00020, 7F7622B00010], [7F7622B00010]] [true, false] slide_bug.d(23): [unittest] unittest failure ``` As can be seen, the last slide has one element but it should not even be in the new list. But for some reason, it works with a simple array. I hope this help to fix it. Thanks.
Comment #2 by hsteoh — 2023-06-15T19:12:42Z
Ran into a similar problem today: ----------- import std; void main() { auto input = "1<2"; foreach (pair; input.splitter("<").slide(2)) { writeln(pair); } } ----------- Expected output: ----------- ["1", "2"] ----------- Actual output: ----------- ["1", "2"] ["2"] ----------- Digging into git history reveals that this is a regression caused by Phobos PR #8738 (commit 8a9cfa2677). Rolling back Phobos to the commit before 8a9cfa2677 causes the correct output to be produced.
Comment #3 by hsteoh — 2023-06-15T19:18:55Z
Comment #4 by default_357-line — 2023-06-16T08:42:55Z
Please join the discussion at https://forum.dlang.org/post/[email protected] .
Comment #5 by dlang-bot — 2023-06-23T05:27:42Z
@FeepingCreature created dlang/phobos pull request #8773 "Fix issue 23976: std.range.slide fails in dmd-2.104.0" fixing this issue: - Fix issue 23976: std.range.slide fails in dmd-2.104.0 I think possibly `hasShownPartialBefore` is just simply wrongly named in the `withPartial` branch. https://github.com/dlang/phobos/pull/8773
Comment #6 by dlang-bot — 2023-06-23T17:48:27Z
dlang/phobos pull request #8773 "Fix issue 23976: std.range.slide fails in dmd-2.104.0" was merged into stable: - 1d2b992c4410787159f0fe2b6dca5ba3ddc321d8 by Mathis Beer: Fix issue 23976: std.range.slide fails in dmd-2.104.0 I think possibly `hasShownPartialBefore` is just simply wrongly named in the `withPartial` branch. https://github.com/dlang/phobos/pull/8773