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] In struct parametrics as is not constexpr-compatible #1859

Open
dank-openai opened this issue Jan 16, 2025 · 2 comments
Open

[DSLX] In struct parametrics as is not constexpr-compatible #1859

dank-openai opened this issue Jan 16, 2025 · 2 comments
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end

Comments

@dank-openai
Copy link

dank-openai commented Jan 16, 2025

Describe the bug

Try to build this:

pub struct foo<IS_SIGNED: u32 , NUM_BITS: u32> {
    data: xN[IS_SIGNED as u1][NUM_BITS], 
}

#[test]
fn test_instantiate_foo() {
    let _ = foo<u32:0, u32:1> { data: u1:0};
}

observe error:

Could not evaluate dimension expression `IS_SIGNED as u1` to a constant value.

To Reproduce
Use code above, try to compile.

Expected behavior
I expect that I can cast a u32 to a u1 to define a type. That is, I expect that casting is constexpr-compatible.

More comments
I tried another way of accomplishing the same thing:

pub struct foo<IS_SIGNED: u32 , NUM_BITS: u32, sign:bool = {IS_SIGNED > u32:0} > {
    data: xN[sign][NUM_BITS], 
}

#[test]
fn test_instantiate_foo() {
    let _ = foo<u32:0, u32:1> { data: u1:0};
}

and when I try to build and test:

Error: INVALID_ARGUMENT: Cannot convert expression to parametric: IS_SIGNED > u32:0

let's try again, but same error (i.e., Cannot convert expression to parametric):

pub struct foo<IS_SIGNED: u32 , NUM_BITS: u32, sign:bool = {if IS_SIGNED > u32:0 {true}else{false}} > {
    data: xN[sign][NUM_BITS], 
}
@dank-openai dank-openai changed the title Could not evaluate dimension expression ... to a constant value as is not constexpr-compatible Jan 16, 2025
@cdleary cdleary changed the title as is not constexpr-compatible [DSLX] In struct parametrics as is not constexpr-compatible Jan 17, 2025
@cdleary
Copy link
Collaborator

cdleary commented Jan 17, 2025

@dank-openai struct parametrics are different from function parametrics, as is fine for constexpr in a general sense it's just a problem in the context of struct parametrics.

@cdleary cdleary added bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end labels Jan 17, 2025
@dank-openai
Copy link
Author

@dank-openai struct parametrics are different from function parametrics, as is fine for constexpr in a general sense it's just a problem in the context of struct parametrics.

I see. Thanks for the explanation.

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

2 participants