Bug 12733 – parallelism.amap incorrect assignment without initialization
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-11T17:33:00Z
Last change time
2014-08-23T03:54:23Z
Assigned to
nobody
Creator
monarchdodra
Comments
Comment #0 by monarchdodra — 2014-05-11T17:33:59Z
This code from Rosettacode fails in 2.065:
//----
ulong[] decompose(ulong n) pure nothrow {
typeof(return) result;
for (ulong i = 2; n >= i * i; i++)
for (; n % i == 0; n /= i)
result ~= i;
if (n != 1)
result ~= n;
return result;
}
void main() {
import std.stdio, std.algorithm, std.parallelism, std.typecons;
immutable ulong[] data = [
2UL^^59-1, 2UL^^59-1, 2UL^^59-1, 112_272_537_195_293UL,
115_284_584_522_153, 115_280_098_190_773,
115_797_840_077_099, 112_582_718_962_171,
112_272_537_095_293, 1_099_726_829_285_419];
//auto factors = taskPool.amap!(n => tuple(decompose(n), n))(data);
//static enum genPair = (ulong n) pure => tuple(decompose(n), n);
static genPair(ulong n) pure { return tuple(decompose(n), n); }
auto factors = taskPool.amap!genPair(data);
auto pairs = factors.map!(p => tuple(p[0].reduce!min, p[1]));
writeln("N. with largest min factor: ", pairs.reduce!max[1]);
}
//----
It errors in swap because of internal pointers, when calling Tuple.opAssign.
You'll notice it now works in Head, but this is only because we lifted the check in:
https://github.com/D-Programming-Language/phobos/pull/1390
However, even if the code "runs", it is still wrong, and not yet fixed, as evidenced by this test:
//----
struct S
{
invariant()
{
assert(checksum == 1234567890);
}
this(ulong u){n = u;}
void opAssign(S s){this.n = s.n;}
ulong n;
ulong checksum = 1234567890;
}
void main()
{
import std.stdio, std.algorithm, std.parallelism, std.typecons;
immutable ulong[] data = [ 2UL^^59-1, 2UL^^59-1, 2UL^^59-1, 112_272_537_195_293UL ];
static auto genPair(ulong n) { return S(n); }
taskPool.amap!genPair(data);
}
//----
Comment #1 by github-bugzilla — 2014-08-23T03:54:23Z