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

Casting array to its own type is not allowed (+ bad error message) #1939

Open
mikex-oss opened this issue Feb 19, 2025 · 1 comment
Open
Labels
dslx DSLX (domain specific language) implementation / front-end 🧦 sox

Comments

@mikex-oss
Copy link
Collaborator

Describe the bug
It seems you can cast scalar values to their own types, but XLS will error out with an unhelpful error message if you try to do the same with arrays.

Error: INTERNAL: XLS_RET_CHECK failure (xls/dslx/diagnostics/format_type_mismatch.cc:250) !data.mismatches.empty() FormatTypeMismatch; type mismatch info not constructed correctly for types array vs. array -- we got no mismatches when zip...
=== Source Location Trace: ===
xls/common/status/status_builder.cc:197
xls/dslx/diagnostics/format_type_mismatch.cc:250
xls/dslx/diagnostics/maybe_explain_error.cc:42
xls/dslx/parse_and_typecheck.cc:102
xls/dslx/interpreter_main.cc:198
__main__.XlsRuntimeError('Error: INTERNAL: XLS_RET_CHECK failure (xls/dslx/diagnostics/format_type_mismatch.cc:250) !data.mismatches.empty() FormatTypeMismatch; type mismatch info not constructed correctly for types array vs. array -- we got no mismatches when zipping the types; lhs: uN[32][4] rhs: uN[32][4]\n=== Source Location Trace: ===\nxls/common/status/status_builder.cc:197\nxls/dslx/diagnostics/format_type_mismatch.cc:250\nxls/dslx/diagnostics/maybe_explain_error.cc:42\nxls/dslx/parse_and_typecheck.cc:102\nxls/dslx/interpreter_main.cc:198\n')

To Reproduce
Steps to reproduce the behavior:

Compile the following DSLX code:

fn foo() {
  let x = u32:1;
  let _y = x as u32;  // OK
  
  let indices = u32[4]:[0, 1, 3, 4];
  const DATA_W = u32:32;
  let _data = indices as uN[DATA_W][4];  // Error
}

Expected behavior
If you try to do the same with a different size element bitwidth, you get a more reasonable error:

0011:   let indices = u32[4]:[0, 1, 3, 4];
0012:   const DATA_W = u32:64;
0013:   let _data = indices as uN[DATA_W][4];
~~~~~~~~~~~~~~~~~~~~^----------------------^ XlsTypeError: Cannot cast from expression type uN[32][4] to uN[64][4].
Type mismatch:
   uN[32][4]
vs uN[64][4]

Side note: this syntax would be useful to avoid a for loop (#1671), at least until (perhaps even with?) map with lambdas (#1542).

@mikex-oss mikex-oss added the dslx DSLX (domain specific language) implementation / front-end label Feb 19, 2025
@cdleary
Copy link
Collaborator

cdleary commented Feb 19, 2025

Note that the internal error is just flagging that a type error was created with identical types (so it probably shouldn't have been a type mismatch error, as your OP points out)

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 🧦 sox
Projects
Status: No status
Development

No branches or pull requests

2 participants