Type inference and overloaded functions

bearophile bearophileHUGS at lycos.com
Thu Dec 12 18:44:02 PST 2013


Namespace:

> Why don't you discuss on github?

I sometimes discuss on GitHub, but when the amount of things I 
have to say are large enough I think a forum like this is better. 
Also I don't like the lack of threading in GitHub comments.


> And finally I did it:
>
> ----
> auto[$] a_arr2 = dyn_arr[4 .. 8];
> assert(is(typeof(a_arr2) == int[4]));
> ----
>
> I will make a Pull Request tomorrow.

Good :-)

------------------

Regarding fixed sized arrays there's another point, visible here:

void main() {
     int[3] a, b, c;
     pragma(msg, typeof(a[] + b[]));
}

It prints:
int[]

So it seems the compiler loses track of the compile-time 
knowledge of the length of those arrays (it's probably caused by 
the slicing). In my opinion this is quite important because such 
loss of information makes it harder for the compiler to rewrite 
code as "c[] = a[] + b[]" as:

foreach (immutable i; 0 .. 3)
     c[i] = a[i] + b[i];

That later the back-end should unroll in just three sums (this is 
routinely done by the Fortran array ops); and a smart back-end 
can even rewrite with a single SIMD instruction (adding padding 
to the a, b, and c arrays making them 4 integers long).

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list