xls icon indicating copy to clipboard operation
xls copied to clipboard

`zero!` should support parametric structs and arrays of structs

Open proppy opened this issue 2 years ago • 6 comments

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?

proppy avatar May 26 '23 02:05 proppy

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

cdleary avatar May 26 '23 02:05 cdleary

Oh, and the workaround is to define a type alias and then use that as the parametric argument to zero!

cdleary avatar May 26 '23 02:05 cdleary

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 avatar May 26 '23 16:05 mtdudek

@mtdudek is that blocking #994 and #995?

proppy avatar May 30 '23 12:05 proppy

It's not blocking. There is workaround to pass any type to zero!<> using type definitions.

mtdudek avatar May 30 '23 13:05 mtdudek

+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.

mikex-oss avatar Jun 18 '24 00:06 mikex-oss