Array indexing in type checking for constexpr index does not match IR behavior
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
**Describe the bug**
The DSLX type system validation will error when a constexpr array index is out of bounds:
https://github.com/google/xls/blob/c59b6a21b8bc362f2899706bd74eb8ea7708644f/xls/dslx/type_system/deduce_utils.cc#L404-L410
However, as discussed in https://github.com/google/xls/discussions/1494, the IR documentation states:
> Any out-of-bounds indices idx_{i} are clamped to the maximum in bounds index for the respective dimension.
**To Reproduce**
```
fn foo(arr: u32[10]) -> u32 {
arr[10]
}
#[test]
fn foo_test() {
assert_eq(foo(u32[10]:[u32:1, ...]), u32:1);
}
```
yields the error:
> TypeInferenceError: uN[32][10] Index has a compile-time constant value 10 that is out of bounds of the array type.
Note that this behavior appears to be retained in TIv2:
https://github.com/google/xls/blob/c59b6a21b8bc362f2899706bd74eb8ea7708644f/xls/dslx/type_system_v2/typecheck_module_v2_test.cc#L735-L742
Contributor guide
Assessment
This issue has not been assessed yet.