Thread overview
[Issue 12839] std.parallelism with nested functions and lambdas. Segfault
Jun 02, 2014
John Colvin
Jun 02, 2014
John Colvin
Aug 14, 2014
Maxim Fomin
May 12, 2015
Maxim Fomin
Jun 13, 2018
RazvanN
June 02, 2014
https://issues.dlang.org/show_bug.cgi?id=12839

--- Comment #1 from John Colvin <john.loughran.colvin@gmail.com> ---
Interestingly, the following works fine. It should be the same as the lambda-based version, no?

import std.parallelism;
import std.algorithm;

auto loo(int a, int[] b)
{
    auto inner(int c)
    {
        return a;
    }
    auto wrapper(int x)
    {
        auto wrapperInner()
        {
            return inner(x);
        }
        return &wrapperInner;
    }
    return b.map!wrapper;
}

void main()
{
    defaultPoolThreads = 1;
    auto res = loo(3, [1,2,3]);
    auto jobs = taskPool.map!"a()"(res);
    assert(jobs.front() == 3);
}

--
June 02, 2014
https://issues.dlang.org/show_bug.cgi?id=12839

--- Comment #2 from John Colvin <john.loughran.colvin@gmail.com> ---
sorry, ignore the () on jobs.front

--
August 14, 2014
https://issues.dlang.org/show_bug.cgi?id=12839

Maxim Fomin <maxim-fomin@outlook.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim-fomin@outlook.com
                 OS|Linux                       |All

--- Comment #3 from Maxim Fomin <maxim-fomin@outlook.com> ---
Fails on win64 too.

--
January 19, 2015
https://issues.dlang.org/show_bug.cgi?id=12839

sinkuupump@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sinkuupump@gmail.com
          Component|Phobos                      |DMD

--- Comment #4 from sinkuupump@gmail.com ---
Even replacing "taskPool.amap" with "map!"a()".array", it still segfaults.


import std.algorithm;
import std.array;

auto loo(int a, int[] b)
{
    auto inner(int c)
    {
        return a; // debugger caught SEGV at this line
    }
    return b.map!((x) => () => inner(x));
}

void main()
{
    auto res = loo(3, [1,2,3]);
    auto jobs = map!"a()"(res).array; // evaluate eagerly
}


I reduced 'map' version, and found that just returning "() => () => inner()"
and calling it segfaults. IIUC this seems a compiler bug.


auto loo(int a)
{
    auto inner()
    {
        return a; // debugger caught SEGV at this line
    }

    return () => () => inner();
}

void main()
{
    assert(loo(3)()() == 3);
}

--
May 12, 2015
https://issues.dlang.org/show_bug.cgi?id=12839

--- Comment #5 from Maxim Fomin <maxim-fomin@outlook.com> ---
Now it gives ice.

auto loo(int a)
{
    auto inner()
    {
        return a; // debugger caught SEGV at this line
    }

    return () => () => inner();
}

void main()
{
    assert(loo(3)()() == 3);
}

DMD v2.068-devel-df9b8af-dirty DEBUG
dmd: toir.c:183: elem* getEthis(Loc, IRState*, Dsymbol*): Assertion
`thisfd->isNested() || thisfd->vthis' failed.
Aborted

--
June 09, 2015
https://issues.dlang.org/show_bug.cgi?id=12839

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |D2

--
May 21, 2016
https://issues.dlang.org/show_bug.cgi?id=12839

Lars T. Kyllingstad <bugzilla@kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@kyllingen.net

--
May 21, 2016
https://issues.dlang.org/show_bug.cgi?id=12839

--- Comment #6 from Lars T. Kyllingstad <bugzilla@kyllingen.net> ---
See also issue #16051, which deals with the same ICE.  Not sure if it's a duplicate, though.

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

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |FIXED

--- Comment #7 from RazvanN <razvan.nitu1305@gmail.com> ---
All the examples in this bug report now compile successfully. However, Issue 16051 is still valid. Closing as fixed.

--