Tensor Comprehension (TC) default element problem
The following code exposes the default element problem of the desugaring of tensor comprehensions:
bool[+] eq(int[+] a, int[+] b)
{
shp = Array::shape(b);
#if TC_BUG
return { iv -> _eq_SxS_(_sel_VxA_(iv, a), _sel_VxA_(iv, b)) | iv < shp};
#else
return { iv -> _eq_SxS_(_sel_VxA_(iv, a), _sel_VxA_(iv, b)) | iv < shp;
iv -> true | iv < shp };
#endif
}
int main ()
{
StdIO::print( eq([], []));
return 0;
}
The seemingly redundant second partition is essential for this code not to fail. The reason is that the desugaring mechanism otherwise creates the following code for the default element:
tmp = _eq_SxS_ (_sel_VxA_( _mul_SxV_( 0, shp), a), _sel_VxA_( _mul_SxV_( 0, shp), b))
which makes the type checker scream before it can be optimised away!
NB: the actual default element is genarray( shape(tmp), zero(tmp))
For the time being, this means we have to change the Stdlib ArrayArith operations accordingly :-(