Given the code:
import std.algorithm ;
import std.range ;
import std.stdio ;
import std.typecons ;
double partialSum ( immutable Tuple ! ( int , int , double ) data ) {
return 1.0 ;
}
void execute ( immutable int numberOfTasks ) {
immutable n = 1000000000 ;
immutable delta = 1.0 / n ;
immutable sliceSize = n / numberOfTasks ;
immutable pi = reduce ! ( ( a , b ) => a + b ) ( 0.0 , map ! ( partialSum ) (
map ! ( i => tuple ( i , cast ( int ) sliceSize , cast ( double ) delta ) ) ( iota ( numberOfTasks ) ) ) ) ;
}
int main ( immutable string[] args ) {
execute ( 1 ) ;
return 0 ;
}
The problem lies with the cast of sliceSice. Change the parameter to a literal and it goes away. Change the definition of sliceSize and it goes away.
Comment #3 by bearophile_hugs — 2012-04-16T04:56:08Z
(In reply to comment #2)
> import std.algorithm ;
> import std.range ;
> import std.stdio ;
> import std.typecons ;
>
> double partialSum ( immutable Tuple ! ( int , int , double ) data ) {
> return 1.0 ;
> }
>
> void execute ( immutable int numberOfTasks ) {
> immutable n = 1000000000 ;
> immutable delta = 1.0 / n ;
> immutable sliceSize = n / numberOfTasks ;
> immutable pi = reduce ! ( ( a , b ) => a + b ) ( 0.0 , map ! ( partialSum ) (
> map ! ( i => tuple ( i , cast ( int ) sliceSize , cast ( double ) delta ) )
> ( iota ( numberOfTasks ) ) ) ) ;
> }
>
> int main ( immutable string[] args ) {
> execute ( 1 ) ;
> return 0 ;
> }
Maybe you are able to trim away some more stuff from that code, to minimize it some more.
Comment #4 by russel — 2012-04-16T05:08:36Z
As far as I can see in the time available any further reduction loses the error message.
Comment #5 by bearophile_hugs — 2012-04-17T11:15:02Z
(In reply to comment #4)
> As far as I can see in the time available any further reduction loses the error
> message.
A first reduction:
import std.algorithm: map;
import std.typecons: tuple, Tuple;
int foo(Tuple!(int)) {
return 1;
}
void main() {
int x = 2;
map!foo(map!(_ => tuple(x))([3]));
}
Comment #6 by bearophile_hugs — 2012-04-17T11:37:14Z
I am hitting the same "Internal error: toir.c 178" even without -inline with this reduced code:
import std.algorithm: sort;
struct Foo(int m) {
int x;
}
void bar(int m)(Foo!m[] foos) {
void spam() {
//sort!((Foo!m a, Foo!m b) => true)(foos); // no error
sort!((a, b) => true)(foos);
}
}
void main() {
alias Foo!2 F2;
bar([F2(1)]);
alias Foo!3 F3;
bar([F3(2)]);
}
Comment #7 by lovelydear — 2012-04-21T12:31:03Z
Also happens on 2.059 Win32
Comment #8 by verylonglogin.reg — 2012-05-03T03:25:30Z
This issue is derived from Issue 7955. Everything you need to create this issue from Issue 7955 is to wrap lambda template in a nested function.
Code from Issue 7955 comment #1 with addition of `spam`:
---
void f(alias fun)() { }
void g(T)() {
void spam() {
f!(a => a)();
}
}
void main() {
g!int();
g!long();
}
---