Bug 12174 – Problems caused by enum predicate with std.algorithm.sum
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-02-15T02:46:00Z
Last change time
2014-04-10T04:06:47Z
Keywords
ice, pull, wrong-code
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2014-02-15T02:46:13Z
I think this is a problem caused by enum predicates:
import std.stdio, std.algorithm, std.range, std.conv;
void main() {
enum foo1 = (int n) => n.text.map!(d => d - '0').reduce!q{a + b};
enum bar1 = iota(1, int.max).filter!(n => n % foo1(n) == 0);
bar1.take(20).writeln; // OK
auto foo2 = (int n) => n.text.map!(d => d - '0').sum;
auto bar2 = iota(1, int.max).filter!(n => n % foo2(n) == 0);
bar2.take(20).writeln; // OK
enum foo3 = (int n) => n.text.map!(d => d - '0').sum;
enum bar3 = iota(1, int.max).filter!(n => n % foo3(n) == 0);
bar3.take(20).writeln; // object.Error: Integer Divide by Zero
}
DMD 2.065beta3 print sat run-time:
object.Error: Integer Divide by Zero
----------------
0x0041F424 in _ULDIV
0x00407DD7 in pure @safe void std.algorithm.FilterResult!(main9__lambda6, std.range.iota!(int, int).iota(int, int).Result).FilterResult.popFront() at ...\dmd2\src\phobos\std\algorithm.d(1632)
0x00408009 in pure @safe void std.range.Take!(std.algorithm.FilterResult!(main9__lambda6, std.range.iota!(int, int).iota(int, int).Result).FilterResult).Take.popFront() at ...\dmd2\src\phobos\std\range.d(3129)
0x0040882C in D3std6format194__T11formatRangeTS3std5stdio4File17LockingTextWriterTS3std5range119__T4TakeTS3st88A2D7F05DA1FFDEB975F087094CCBFF at ...\dmd2\src\phobos\std\format.d(2198)
0x00408763 in D3std6format194__T11formatValueTS3std5stdio4File17LockingTextWriterTS3std5range119__T4TakeTS3st237782F52D5136BBE0731FA4A3A06E27 at ...\dmd2\src\phobos\std\format.d(2768)
0x004086CC in D3std6format196__T13formatGenericTS3std5stdio4File17LockingTextWriterTS3std5range119__T4TakeTS3A824662D3C5CD961F4ABE4F8B3D05451 at ...\dmd2\src\phobos\std\format.d(3062)
0x004085E1 in D3std6format197__T14formattedWriteTS3std5stdio4File17LockingTextWriterTaTS3std5range119__T4Take8E20DD5C0605C68157C9473AF7F4B209 at ...\dmd2\src\phobos\std\format.d(510)
0x004081E4 in D3std5stdio4File151__T5writeTS3std5range119__T4TakeTS3std9algorithm78__T12FilterResultS14main9_67CA17369C70201CAC91E877226367DB at ...\dmd2\src\phobos\std\stdio.d(1034)
0x00408143 in D3std5stdio151__T7writelnTS3std5range119__T4TakeTS3std9algorithm78__T12FilterResultS14main9__laA2546B4D3EC5E436248C74A47438FF6F at ...\dmd2\src\phobos\std\stdio.d(2345)
0x004020F6 in _Dmain at ...\test.d(11)
0x00408F54 in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll().void __lambda1()
0x00408F27 in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()
0x00408E40 in _d_run_main
0x00408C6C in main
0x0041F319 in mainCRTStartup
0x779FD2E9 in BaseThreadInitThunk
0x77AD1603 in RtlInitializeExceptionChain
0x77AD15D6 in RtlInitializeExceptionChain
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42]
[1
Comment #1 by monarchdodra — 2014-02-27T04:46:40Z
I have no idea what is going on, but on 2.065, I get:
main.d(7): Error: no property 'sum' for type 'MapResult!(__lambda2, string)'
main.d(10): Error: no property 'sum' for type 'MapResult!(__lambda2, string)'
Assertion failure: '0' on line 357 in file 'interpret.c'
abnormal program termination
Also on windows x86. Not sure what happened: I don't really understand your code, but why isn't it even compiling anymore?
In any case, adding ice and reg.
Comment #2 by dlang-bugzilla — 2014-03-18T21:39:22Z
(In reply to comment #0)
> DMD 2.065beta3 print sat run-time:
How can this be 2.065beta3 if that version did not yet have the "sum" function at all?
Comment #3 by k.hara.pg — 2014-04-06T05:51:24Z
(In reply to comment #1)
> I have no idea what is going on, but on 2.065, I get:
>
> main.d(7): Error: no property 'sum' for type 'MapResult!(__lambda2, string)'
> main.d(10): Error: no property 'sum' for type 'MapResult!(__lambda2, string)'
> Assertion failure: '0' on line 357 in file 'interpret.c'
>
> abnormal program termination
>
> Also on windows x86. Not sure what happened: I don't really understand your
> code, but why isn't it even compiling anymore?
>
> In any case, adding ice and reg.
The ICE regression is caused from 2.064.
https://github.com/D-Programming-Language/dmd/pull/3426
Comment #4 by k.hara.pg — 2014-04-09T09:09:44Z
*** Issue 11971 has been marked as a duplicate of this issue. ***
Comment #5 by monarchdodra — 2014-04-09T09:54:45Z
This now seems to work for me on win32 for the code in HEAD. Resolved fixed?
Comment #6 by k.hara.pg — 2014-04-09T10:13:12Z
(In reply to monarchdodra from comment #5)
> This now seems to work for me on win32 for the code in HEAD. Resolved fixed?
My pull is for the ICE issue in comment #1. In git-head, std.algorithm.sum is defined, so the issue is hidden. With following invalid code, you could reproduce it.
import std.stdio, std.algorithm, std.range, std.conv;
void main()
{
enum foo3 = (int n) => n.text.map!(d => d - '0').sumX;
enum bar3 = iota(1, int.max).filter!(n => n % foo3(n) == 0);
bar3.take(20).writeln;
}
Comment #7 by github-bugzilla — 2014-04-10T01:22:36Z