Open mikex-oss opened 1 month ago
Yeah any more imperative syntax will be dependent on let mut
and there are also "data flow clarity" tradeoffs around let mut
. I'd also like the for loops to be friendlier to newcomers but there's a bit of an inherent challenge in then quickly teaching them stuff that obscures the dataflow.
For your use case with multidim arrays, in a short term solve, I think we can probably make a cartesian product helper (like a shorthand for an array builder along the lines of itertools.product(range(), range()
) -- would probably dovetail reasonably with the multidimensional update
index.
Related: it would be nice to have a for syntax variant to loop over all the possible value of an enum; currently it can involve casting the bounds to the uN[std::sizeof(EnumType) + u32:1]
to be able to encode the "excluded" upper bound (eg: if the the last enum value saturate all the bits of the underlying uN type).
What's hard to do? (limit 100 words)
for loops are quite cumbersome compared to other languages like C++ or SystemVerilog.
This largely stems from the lack of
mut
, probably, but it is still a pain every time I need to write a for loop.Consider an egregious case of building 2 related 2D arrays. In other languages, this would otherwise be a trivial nested for loop with adjacent inner loops. Let's take SystemVerilog as an example, since the focus is on representing synthesizable hardware:
This takes significantly more thought to write in DSLX (see below).
Current best alternative workaround (limit 100 words)
Two approaches come to mind (just sketched out, may have errors). Neither seems as easy to get right without thinking as the code above.
Do all the updates in the inner loop and keep track of multiple layers of the full array accumulator. Something like:
Split this into two outer loops, so you can do the array updates in the same direction as the nested looping:
Your view of the "best case XLS enhancement" (limit 100 words)
Make it easier to write for loops.