google / google/xls

[enhancement] dslx should support empty for loops

Open
#3,965 0 comments 0 reactions 0 assignees View on GitHub
dslx enhancement
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

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

currently one cannot write an empty for loop like `for n in 0..0 {}` in DSLX, as it produces the following typesystem error:
```
0004: for (i, accum) in u32:0..WIDTH {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^----------^ `u32:0..WIDTH` from `u32:0` to `u32:0` is an empty range
```
Note: this can happens when parametrics (or constant computed parametrics) resolve to `0` and are used in range expressions.

### Current best alternative workaround (limit 100 words)

Increase the range expression by 1 and special case inside the for loop) or leverage the new `const_if` https://github.com/google/xls/pull/3268 (otherwise it would still not typecheck) and special case the `0` case outside of the for loop.

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

Just like rust https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=6e03e45ee17e40e962267f3d0b42de9f DSLX would relax errors on empty ranges.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.