Skip to content

[enhancement] dslx should support empty for loops #3965

@proppy

Description

@proppy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    dslxDSLX (domain specific language) implementation / front-endenhancementNew feature or request

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions