xls
xls copied to clipboard
`zero!` should support parametric structs and arrays of structs
https://google.github.io/xls/dslx_reference/#zerot doesn't seems to work with parametric strucst and arrays of structs.
Is that a known limitation, are there possible workaround?
Re: #982 -- we generally don't want to introduce more backtracking into the parser as an implementation strategy, since it makes for bad error messages and slow parsing. I was hoping to restructure the grammar around types a bit, this is one of the first instances where we have parametric types so the grammar was a bit overfit for parametric-values-only.
The test cases looked good though, maybe those can be used with a DISABLED_ and a TODO referencing this issue?
See also related #904
Oh, and the workaround is to define a type alias and then use that as the parametric argument to zero!
I've created PR #985 with tests and disabled ones that don't work right now. I think #976 can benefit from adding type parsing to parametric pass.
I've also created draft PR #986 with a possible solution to parse parametric types.
It doesn't parse :: after first < or [, it also doesn't allow for using
fields from const arrays, like:
const a = u32[2] : {1,2}
fn b<A:u32>(x: u32) -> u32 {
x + A
}
b<a[0]>(a[1])
As far as I can tell, using const array's fields was never allowed, so proposed solution doesn't break it.
@mtdudek is that blocking #994 and #995?
It's not blocking. There is workaround to pass any type to zero!<> using type definitions.
+1. Just ran into this myself.
In my case, the zero! is within a parametric function intended specifically to adjust the array size of the struct. So it's not really viable to make an explicit type without making the function non-parameteric.