Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSLX type checker should not error on width slice of 0-bit value #1969

Open
mikex-oss opened this issue Feb 28, 2025 · 0 comments
Open

DSLX type checker should not error on width slice of 0-bit value #1969

mikex-oss opened this issue Feb 28, 2025 · 0 comments
Assignees
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end 🧦 sox

Comments

@mikex-oss
Copy link
Collaborator

mikex-oss commented Feb 28, 2025

Describe the bug
The following code does not compile, even though we'd expect to "skip the loop" for N == 0.

fn foo<N: u32>(x: uN[N]) {
    for (idx, _): (u32, ()) in range(u32:0, N) {
        trace_fmt!("{}", x[idx+:u1]);
    }(())
}

fn main() { foo(uN[0]:0); }
0020:         trace_fmt!("{}", x[idx+:u1]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^-^ XlsTypeError: uN[0] vs uN[1]: Slice type must have <= original number of bits; attempted slice from 0 to 1 bits.

You cannot get around this with x[idx:idx + 1] or special casing if N == u32:0 ... inside the function (inside or outside the loop).

Note that the array version does work (though runs into IR conversion issues - #917).

fn foo<N: u32>(x: u1[N]) {
    for (idx, _): (u32, ()) in range(u32:0, N) {
        trace_fmt!("{}", x[idx]);
    }(())
}

fn main() { foo(u1[0]:[]); }

To Reproduce
Compile the code above.

Expected behavior
There should be a way for this to type check since other parts of XLS allow the 0-bit type.

@mikex-oss mikex-oss added bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end 🧦 sox labels Feb 28, 2025
@richmckeever richmckeever self-assigned this Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end 🧦 sox
Projects
Status: No status
Development

No branches or pull requests

2 participants