xls icon indicating copy to clipboard operation
xls copied to clipboard

Tuple destructuring syntax for "rest of tuple"

Open mikex-oss opened this issue 1 year ago • 1 comments

What's hard to do? (limit 100 words)

Destructuring a tuple in DSLX where you only want to bind a small subset of elements to variables is overly verbose, since you need to throw away each "don't care" element separately.

Current best alternative workaround (limit 100 words)

Use _ to mean "don't bind this element in the tuple to a variable" for each individual element you want to ignore.

For example:

https://github.com/google/xls/blob/bc04b2bb786ad3c9f4914c38a5f58c67f57ada29/xls/examples/dslx_intro/prefix_scan_equality.x#L18

https://github.com/google/xls/blob/a3073f96eea81515d2b735ce5dad5e929596c459/xls/dslx/stdlib/std.x#L208

Your view of the "best case XLS enhancement" (limit 100 words)

Support Rust .. syntax to ignore the rest of the tuple (https://doc.rust-lang.org/rust-by-example/flow_control/match/destructuring/destructure_tuple.html). The section describes the application for match patterns, but the same works on the LHS of a let.

So in the last example, this would become:

let (.., div_result) = for 

The .. can capture one arbitrarily long subsequence within the tuple, e.g. for some foo N-tuple with N >= 2, you can write:

let (bar, .., baz) = foo;

mikex-oss avatar Jun 05 '24 17:06 mikex-oss

+1 this would be quite nice to support, and can follow our "feature that matches Rust" principle!

cdleary avatar Jun 15 '24 19:06 cdleary

TODO:

  1. Parser infrastructure - done
  2. Type deduction - done
  3. Bytecode generation - done
  4. IR conversion - done
  5. Fuzz testing - done

dplassgit avatar Aug 06 '24 15:08 dplassgit