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

unroll_for does not unroll constants #1721

Open
mikex-oss opened this issue Nov 16, 2024 · 0 comments
Open

unroll_for does not unroll constants #1721

mikex-oss opened this issue Nov 16, 2024 · 0 comments
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end

Comments

@mikex-oss
Copy link
Collaborator

Describe the bug
Constants can not be declared in unroll_for loops, even though they work with let binding or used inline.

TypeMissingError: node: 0x30d27fe5f6c0 user: 0x30d27e4e4d98 internal error: AST node is missing a corresponding type: B 0x30d27fe5f6c0 (kind: NameDef) defined @ foo.x10:15-10:16. This may be due to recursion, which is not supported.

To Reproduce

fn main() -> bool {
    unroll_for! (i, b): (u32, bool) in u32:0..u32:10 {
        const B: bool = i == u32:1;
        b ^ B
    }(true)
}

The following work:

fn main() -> bool {
    unroll_for! (i, b): (u32, bool) in u32:0..u32:10 {
        let B: bool = i == u32:1;
        b ^ B
    }(true)
}
fn main() -> bool {
    unroll_for! (i, b): (u32, bool) in u32:0..u32:10 {
        b ^ (i == u32:1)
    }(true)
}

Expected behavior
Since the loop index is constexpr, it seems reasonable to define a const that depends on it. I would expect it to work like variables.

Additional context
Above is for minimal repro, but a more realistic example would be where B is defined for multiple parametric function invocations.

fn foo<B: bool>(x: u32) -> u32 { if B { x } else { u32:0 } }

fn bar<B: bool>(x: u32) -> bool { if B { x != u32:0 } else { x != u32:1 } }

fn main(x: u32) {
    unroll_for! (i, _): (u32, ()) in u32:0..u32:10 {
        const B = (i % u32:2 == u32:1);
        foo<B>(x);
        bar<B>(x);
    }(());
}
@mikex-oss mikex-oss added bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end labels Nov 16, 2024
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
Projects
Status: No status
Development

No branches or pull requests

1 participant