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

Seemingly valid bit vector indexing yields parse errors #1727

Open
meheff opened this issue Nov 19, 2024 · 2 comments
Open

Seemingly valid bit vector indexing yields parse errors #1727

meheff opened this issue Nov 19, 2024 · 2 comments
Labels
dslx DSLX (domain specific language) implementation / front-end

Comments

@meheff
Copy link
Collaborator

meheff commented Nov 19, 2024

Code is below. Errors and the problematic code are in the comments

# my_lib
pub const W = s32:16;
pub const Z = s32:24;
import my_lib;

pub const A = s32:16;
pub const B = s32:24;

fn foo(x: u32) -> () {
// 0013:   let a = x[my_lib::W : s32:24];
// ~~~~~~~~~~~~~~~~~^------------------^ TypeInferenceError: uN[32] Value to index is not an array.
//  let a = x[my_lib::W : s32:24];

// 0017:   let b = x[my_lib::W : my_lib::Z];
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ ParseError: Old-style cast only permitted for constant arrays/tuples and literal numbers.
//  let b = x[my_lib::W : my_lib::Z];

  // OK.
  let c = x[A:my_lib::Z];

  // OK.
  let d = x[A:B];

  ()
}
@meheff meheff added the dslx DSLX (domain specific language) implementation / front-end label Nov 19, 2024
@mikex-oss
Copy link
Collaborator

Agreed this is confusing, but I guess this is because indices should be raw decimal literals, while constants always have a type?

Sized literals are not ever shown in the documentation:

https://google.github.io/xls/dslx_reference/#bit-slice-examples
https://github.com/google/xls/blob/main/xls/dslx/tests/bit_slice_syntax.x

@meheff
Copy link
Collaborator Author

meheff commented Nov 19, 2024

Agreed this is confusing, but I guess this is because indices should be raw decimal literals, while constants always have a type?

Sized literals are not ever shown in the documentation:

https://google.github.io/xls/dslx_reference/#bit-slice-examples https://github.com/google/xls/blob/main/xls/dslx/tests/bit_slice_syntax.x

Indices using named constants works fine if the constants are locally declared, but not if they are imported (well, at least if the start index is imported). So support is inconsistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dslx DSLX (domain specific language) implementation / front-end
Projects
Status: No status
Development

No branches or pull requests

2 participants