Thread overview
[Issue 18804] std.algorithm.mutation.copy puts whole source range into target range when it should put elements
Apr 30, 2018
ag0aep6g
April 30, 2018
https://issues.dlang.org/show_bug.cgi?id=18804

ag0aep6g <ag0aep6g@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
                 CC|                            |ag0aep6g@gmail.com
          Component|dmd                         |phobos
           Hardware|x86                         |All
            Summary|Side effects incorrectly    |std.algorithm.mutation.copy
                   |optimized out when results  |puts whole source range
                   |are discarded               |into target range when it
                   |                            |should put elements
                 OS|Windows                     |All

--- Comment #1 from ag0aep6g <ag0aep6g@gmail.com> ---
Generally, please post complete code, including imports. Also include the contents of other files like "in".

What happens here is that `copy` puts the range as a whole into the NullSink. This is not DMD optimizing anything out.

Reduced test case:

----
import std.algorithm.mutation: copy;

struct NullSink
{
    void put(E)(E) {}
}

int line = 0;

struct R
{
    int front;
    @property bool empty() { return line == 1; }
    void popFront() { line = 1; }
}

void main()
{
    R r;
    copy(r, NullSink());
    assert(line == 1); /* fails; should pass */
}
----

Pull request to fix this: https://github.com/dlang/phobos/pull/6485

--
April 30, 2018
https://issues.dlang.org/show_bug.cgi?id=18804

--- Comment #2 from Ajieskola@gmail.com ---
Already being fixed? Thanks!

imports are, on top of file:

import std.stdio, std.file, std.conv, std.algorithm, std.range, std.string, std.typecons, std.math, std.csv;

A few examples of correct lines from "in":

Kukat,Gif\Kukat\1_Tumma_patina\05_Ruusu_tu.gif,false,"0.07,0.18,0.0; 0.09,0.25,0.0" Kukat,Gif\Kukat\1_Tumma_patina\06_Ruusu_tu.gif,false,"0.07,0.19,0.0; 0.1,0.28,0.0" Kukat,Gif\Kukat\1_Tumma_patina\09_Ruusu_tu.gif,false,"0.1,0.4,0.0; 0.1,0.56,0.0" Kukat,Gif\Kukat\1_Tumma_patina\10_Ruusukoynnos_tu.gif,false,"0.1,0.375,0.0"

--
June 18, 2018
https://issues.dlang.org/show_bug.cgi?id=18804

--- Comment #3 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/19052b08de1e269bf7e8ad1fef89540a5427b5d7 fix issue 18804 - std.algorithm.mutation.copy puts whole source range into target range when it should put elements

https://github.com/dlang/phobos/commit/1d70525d00ec2aa6dbbe2713531f6c9fc7e19abb Merge pull request #6485 from aG0aep6G/18804

fix issue 18804 - std.algorithm.mutation.copy puts whole source range… merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>

--
June 18, 2018
https://issues.dlang.org/show_bug.cgi?id=18804

github-bugzilla@puremagic.com changed:

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

--