Incorrect zero function used for record tensor comprehensions
Records do not play well with tensor-comprehensions.
The following code produces an error:
struct Foo { int x; };
int main()
{
y = { [i] -> Foo{ i } | [i] < [3] };
return _dim_A_(y);
}
No definition found for a function "sacprelude_d::zero" that accepts an argument of type "_MAIN::_struct_Foo" as parameter no 1. Full argument types are "( _MAIN::_struct_Foo)".
Applying the zero
function manually works as expected.
struct Foo { int x; };
int main()
{
y = with {
( . <= [i] <= .) : Foo{ i };
} : genarray([3], zero(Foo{0}));
return _dim_A_(y);
}
The problem is that the zero
overload for the Foo
record is not being applied in the expanded tensor-comprehension.
After hide-structs (-bpre:hs
) we have:
int main()
{
y = { [i] -> _struct_con_Foo( i) | (NULL) <= ? < [ 3 ] };
return( _dim_A_( y));
}
Which is later (-bpre:hse
) transformed into:
int main()
/*
* main :: ---
*/
{
_mose_2 = _struct_con_Foo( 0) ;
y = with {
blah
} : genarray([ 3 ], with {
(. <= _hse_3 <= .) : sacprelude_d::zero( _mose_2) ;
} : genarray( _shape_A_( _mose_2), sacprelude_d::zero( _mose_2) ));
return _dim_A_(y);
}
Note that sacprelude_d::zero
is being applied here, which does not exist for record type Foo
.
It should have been _MAIN::zero(_mose_2)
instead.