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] Not able to assert on parametrics (as constexpr) in const_assert! #1674

Open
cdleary opened this issue Oct 30, 2024 · 0 comments
Open
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end

Comments

@cdleary
Copy link
Collaborator

cdleary commented Oct 30, 2024

Describe the bug

Parametric values are flagging an issue in const_assert! as not being registered as constexpr -- I think this happens when we provide an incomplete set of parametrics -- the phantom parametric probably resolves to a ParametricSymbol (which we have intent to rip out) but the body of the function is still being evaluated for constexprs somehow. cc @richmckeever

To Reproduce

$ ~/opt/xlsynth/latest/dslx_interpreter_main reverse_chunks.x 
reverse_chunks.x:19:3-19:36
0017: 
0018: fn reverse_chunks<N: u32, FLAT: u32>(x: bits[FLAT]) -> bits[FLAT] {
0019:   const_assert!(FLAT % N == u32:0);  // Ensure FLAT is a multiple of N.
~~~~~~~~^-------------------------------^ TypeInferenceError: const_assert! expression is not constexpr
0020:   const NUM_CHUNKS = FLAT / N;

Minimal reproducer:

fn f<N: u32, FLAT: u32>(x: bits[FLAT]) {
  const_assert!(FLAT % N == u32:0);
}

#[test]
fn test_f() {
    f(bits[42]:0)
}
$ ~/opt/xlsynth/latest/dslx_interpreter_main reverse_chunks.x 
reverse_chunks.x:2:3-2:36
0001: fn f<N: u32, FLAT: u32>(x: bits[FLAT]) {
0002:   const_assert!(FLAT % N == u32:0);
~~~~~~~~^-------------------------------^ TypeInferenceError: const_assert! expression is not constexpr
0003: }
0004: 

Expected behavior
I'd expect this expression to be constexpr as the parametric values are compile-time constant, or to flag that not enough parametrics were provided to instantiate the function.

@cdleary cdleary added bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end labels Oct 30, 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