Thread overview
[Issue 23976] std.range.slide fails in dmd-2.104.0
Jun 07, 2023
cbleser
Jun 15, 2023
hsteoh@qfbox.info
Jun 15, 2023
hsteoh@qfbox.info
Jun 16, 2023
FeepingCreature
Jun 23, 2023
Dlang Bot
Jun 23, 2023
Dlang Bot
June 07, 2023
https://issues.dlang.org/show_bug.cgi?id=23976

cbleser <cr@tagion.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cr@tagion.org

--- Comment #1 from cbleser <cr@tagion.org> ---
Created attachment 1880
  --> https://issues.dlang.org/attachment.cgi?id=1880&action=edit
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.

--
June 15, 2023
https://issues.dlang.org/show_bug.cgi?id=23976

hsteoh@qfbox.info changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@qfbox.info
           Severity|enhancement                 |regression

--- Comment #2 from hsteoh@qfbox.info ---
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.

--
June 15, 2023
https://issues.dlang.org/show_bug.cgi?id=23976

--- Comment #3 from hsteoh@qfbox.info ---
Direct link: https://github.com/dlang/phobos/pull/8738

--
June 16, 2023
https://issues.dlang.org/show_bug.cgi?id=23976

FeepingCreature <default_357-line@yahoo.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |default_357-line@yahoo.de

--- Comment #4 from FeepingCreature <default_357-line@yahoo.de> ---
Please join the discussion at https://forum.dlang.org/post/ivmrolypalfsoqeqecki@forum.dlang.org .

--
June 23, 2023
https://issues.dlang.org/show_bug.cgi?id=23976

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@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

--
June 23, 2023
https://issues.dlang.org/show_bug.cgi?id=23976

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
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

--