Bug 16705 – [REG2.069] TaskPool.reduce fails to compile "cannot get frame pointer to D main"
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-11-20T12:46:50Z
Last change time
2021-10-18T19:42:09Z
Keywords
pull
Assigned to
No Owner
Creator
Mihai
Comments
Comment #0 by mihai — 2016-11-20T12:46:50Z
The synopsis code from https://dlang.org/phobos/std_parallelism.html generates a "cannot get frame pointer" compile error:
/Library/D/dmd/src/phobos/std/parallelism.d(2633): Error: function std.parallelism.TaskPool.reduce!"a + b".reduce!(MapResult!(getTerm, Result)).reduce cannot get frame pointer to D main
```d
import std.algorithm, std.parallelism, std.range;
void main() {
// Parallel reduce can be combined with
// std.algorithm.map to interesting effect.
// The following example (thanks to Russel Winder)
// calculates pi by quadrature using
// std.algorithm.map and TaskPool.reduce.
// getTerm is evaluated in parallel as needed by
// TaskPool.reduce.
//
// Timings on an Athlon 64 X2 dual core machine:
//
// TaskPool.reduce: 12.170 s
// std.algorithm.reduce: 24.065 s
immutable n = 1_000_000_000;
immutable delta = 1.0 / n;
real getTerm(int i)
{
immutable x = ( i - 0.5 ) * delta;
return delta / ( 1.0 + x * x ) ;
}
immutable pi = 4.0 * taskPool.reduce!"a + b"(
std.algorithm.map!getTerm(iota(n))
);
}
```
Comment #1 by petar.p.kirov — 2016-11-20T16:04:01Z
Comment #3 by petar.p.kirov — 2016-11-22T18:38:13Z
The documentation fix is in, but I want to investigate further this regression, so I will reopen it.
Comment #4 by petar.p.kirov — 2016-11-23T09:44:53Z
Changing this is to a regression as the code used to work up to and including DMD 2.068.2. DMD 2.069.0 is the first version that it started failing. I will try to bisect the exact commit that introduced this.
Comment #5 by github-bugzilla — 2016-12-07T16:09:12Z
*** Issue 17092 has been marked as a duplicate of this issue. ***
Comment #11 by bugzilla — 2019-12-27T17:56:50Z
Not sure, if this helps. With the help of dustmite I reduced the example and Phobos to the following code:
---
void main()
{
TaskPool pool;
pool.reduce(map!(a=>1));
}
struct Task(Args)
{
Args a;
}
struct TaskPool
{
auto reduce(Args)(Args args)
{
return Task!(typeof(args))();
}
}
auto map(fun...)()
{
return MapResult!fun();
}
struct MapResult(alias fun)
{
void x() {}
}
---
Comment #12 by Ajieskola — 2021-08-09T20:39:25Z
Simplified case of what the frame pointer error is about:
```d
void main()
{ struct X{ void x(){} }
auto a = defInit!X;
}
auto defInit(T)(){ return T(); }
```
This won't work, because `struct X` default constructor needs a hidden pointer to `main` local variables, and `defInit` does not have that pointer. So far, so good.
However, it also fails in this form:
```d
void main()
{ auto a = defInit!(X!(x=>1));
}
struct X(alias f){ void x(){} }
auto defInit(T)(){ return T(); }
```
I would have expected this one to pass. `x=>1` is completely context independant, so theoretically `X` should not need a frame pointer to `main()`. I'm not sure what the langauge spec says about this.
Comment #13 by Ajieskola — 2021-08-09T21:14:24Z
Simplified test case of the issue itself:
```d
void main()
{ import std.parallelism;
struct MyIota
{ size_t front;
void popFront(){front++;}
auto empty(){return front >= 100;}
auto opIndex(size_t i){return front+i;}
auto length(){return 100-front;}
}
auto mySum = taskPool.reduce!"a + b"(MyIota());
}
```
Comment #14 by dlang-bot — 2021-09-30T15:28:45Z
@dukc created dlang/phobos pull request #8258 "Fix regression 16705" fixing this issue:
- Fix issue 16705 - TaskPool.reduce did not work with non-copyable ranges
https://github.com/dlang/phobos/pull/8258
Comment #15 by dlang-bot — 2021-10-15T13:10:48Z
@dukc created dlang/phobos pull request #8282 "Fix regression 16705 - another attempt" fixing this issue:
- Fix issue 16705 - TaskPool.reduce did not work with non-default initializable ranges
https://github.com/dlang/phobos/pull/8282
Comment #16 by dlang-bot — 2021-10-18T19:42:09Z
dlang/phobos pull request #8258 "Fix regression 16705" was merged into stable:
- 1d5d1822ed5081867d2c6c19d2a9b0da03154114 by Ate Eskola:
Fix issue 16705 - TaskPool.reduce did not work with non-default initializable ranges
https://github.com/dlang/phobos/pull/8258