D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14886 - [REG2.066] std.parallelism.parallel with large static array seems to hang compile
Summary: [REG2.066] std.parallelism.parallel with large static array seems to hang com...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: performance, pull
: 10716 15062 (view as issue list)
Depends on:
Blocks:
 
Reported: 2015-08-07 18:49 UTC by Steven Schveighoffer
Modified: 2017-08-02 08:07 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Steven Schveighoffer 2015-08-07 18:49:24 UTC
example:

import std.parallelism;

void main()
{
   int x[100_000];
   parallel(x);
}

If you remove one 0 from the number of elements, the compile finishes with an error:

/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/parallelism.d-mixin-3780(3878): Error: template std.range.primitives.popFront cannot deduce function from argument types !()(int[10000]), candidates are:
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/range/primitives.d(2032):        std.range.primitives.popFront(T)(ref T[] a) if (!isNarrowString!(T[]) && !is(T[] == void[]))
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/range/primitives.d(2055):        std.range.primitives.popFront(C)(ref C[] str) if (isNarrowString!(C[]))
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/parallelism.d-mixin-3780(3867): Error: function std.parallelism.ParallelForeach!(int[10000]).ParallelForeach.opApply.doIt.makeTemp no return exp; or assert(0); at end of function
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/parallelism.d-mixin-3792(3890): Error: template std.range.primitives.popFront cannot deduce function from argument types !()(int[10000]), candidates are:
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/range/primitives.d(2032):        std.range.primitives.popFront(T)(ref T[] a) if (!isNarrowString!(T[]) && !is(T[] == void[]))
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/range/primitives.d(2055):        std.range.primitives.popFront(C)(ref C[] str) if (isNarrowString!(C[]))
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/parallelism.d-mixin-3792(3879): Error: function std.parallelism.ParallelForeach!(int[10000]).ParallelForeach.opApply.doIt.makeTemp no return exp; or assert(0); at end of function
/Users/steves/git/dmd2/osx/bin/../../src/phobos/std/parallelism.d(3303): Error: template instance std.parallelism.ParallelForeach!(int[10000]) error instantiating
testarray.d(6):        instantiated from here: parallel!(int[10000])

I'm unsure if this is a bug in the compiler or a bug in std.parallelism. I don't know how the latter is designed to work, but it does appear that there isn't a valid instantiation for it, so I would suspect a compiler issue.

The timing seems to be non-linear based on the number of elements:

10k elements: 1.5 seconds to reach error
20k elements: 5.2 seconds to reach error
30k elements: 12.2 seconds to reach error
40k elements: 20.9 seconds to reach error
50k elements: 32.9 seconds to reach error

I stopped after that :)
Comment 1 Steven Schveighoffer 2015-08-07 18:50:05 UTC
Forgot to link thread that started this bug: http://forum.dlang.org/post/cxfeijupkxsfqmqyjovj@forum.dlang.org
Comment 2 Vladimir Panteleev 2015-09-01 08:23:01 UTC
Regression, introduced in https://github.com/D-Programming-Language/dmd/pull/3801
Comment 3 Kenji Hara 2015-09-01 10:05:27 UTC
Reduced test case:

@property ref T front(T)(T[] a)
{
    return a[0];
}

template ElementType(R)
{
    static if (is(typeof(R.init.front.init) T))
        alias ElementType = T;
    else
        alias ElementType = void;
}

void main()
{
    alias R = int[100_000];
    alias E = ElementType!R;

}
Comment 4 Kenji Hara 2015-09-01 10:26:16 UTC
More:

auto front(T)(T[] a) {}

void main()
{
    alias R = int[100_000];
    alias E = typeof(front(R.init));
}
Comment 5 Kenji Hara 2015-09-16 00:16:48 UTC
*** Issue 15062 has been marked as a duplicate of this issue. ***
Comment 7 github-bugzilla 2015-09-22 04:41:12 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/51ecaf8e47c82f41115cc1d59c6ed384e234eb60
fix Issue 14886 - std.parallelism.parallel with large static array seems to hang compile

Add ArrayLiteralExp.basis for repeated array literal elements.

https://github.com/D-Programming-Language/dmd/commit/a492f916d022698edb025c4b206ad1af75e0913d
Merge pull request #5085 from 9rnsr/fix14886

[REG2.066] Issue 14886 - std.parallelism.parallel with large static array seems to hang compile
Comment 8 Vladimir Panteleev 2017-07-05 15:18:57 UTC
*** Issue 10716 has been marked as a duplicate of this issue. ***
Comment 9 github-bugzilla 2017-08-02 08:07:27 UTC
Commit pushed to dmd-cxx at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/53ce42c3256e7a2265613a30399345eac85a7343
Issue 14886 - std.parallelism.parallel with large static array seems to hang compile