Open rw1nkler opened 7 months ago
Note that this is what unroll_for!
is for in the DSL -- in a normal type system that doesn't macro expand it doesn't make sense to have one binding (i.e. name in the program) with different types in different loop iterations, which is why having i
be constexpr doesn't make as much sense.
I'm not sure how fully supported it is at the moment: https://github.com/google/xls/blob/164fe8a8e320ce6c32a4a9548ae0c783f70503f6/xls/dslx/frontend/parser_test.cc#L1706
It's something @RobSpringer was working on that we didn't get to pick up and run with in the time since.
@richmckeever @meheff is this something we still want to leave open given unroll_for!
from https://github.com/google/xls/issues/1387#issuecomment-2067090587 is resolved?
I found one scenario where unroll_for!
is insufficient because the DSLX to IR conversion does not guarantee any ordering in the unrolled for.
Take this contrived example:
import std;
fn foo() -> u32 {
unroll_for! (j, result): (u32, u32) in range(u32:0, u32:10) {
for (k, _): (u32, u32) in range(u32:0, std::upow(u32:2, j)) {
k
}(result)
}(u32:0)
}
#[test]
fn foo_test() { assert_eq(foo(), u32:511); }
This passes in DSLX but generates a JIT mismatch.
What's hard to do? (limit 100 words)
As for today, the value of DSLX for-loop iterator is not treated as constant when iterating over constant values. Having the ability to use the for-loop iterator in this way can improve the expressiveness of the language. In all these cases, when iterating over constant values it should be possible to unroll the for-loop.
These small examples show the current limitations of the language:
Current best alternative workaround (limit 100 words)
Unroll the for-loop as in the examples above
Your view of the "best case XLS enhancement" (limit 100 words)
In cases when the for-loop iterates over constant values, the iterator can be treated as a constant and XLS can treat the loop as if it were unrolled