Skip to content

Commit

Permalink
fix(acir_gen): More granular element sizes array check (#4528)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

The `array_typ.contains_slice_element()` check in
`can_omit_element_sizes_array` is incorrect.

This should have been `is_nested_slice()` but we already banned nested
slices so I just removed it. This leads to improvements for slices in
general so I have made it a separate PR.

This was also a blocker for #4523.
When working with `AsSlice` we would omit the element sizes array. When
it came time to access a slice created with `as_slice()` we would
attempt to use the element sizes array which was never initialized
correctly and we would go out of bounds.

## Additional Context



## Documentation\*

Check one:
- [X] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [X] I have tested the changes locally.
- [X] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
vezenovm committed Mar 11, 2024
1 parent 3f67605 commit f93d16e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2268,11 +2268,9 @@ impl Context {

// We can omit the element size array for arrays which don't contain arrays or slices.
fn can_omit_element_sizes_array(array_typ: &Type) -> bool {
if array_typ.contains_slice_element() {
return false;
}
let Type::Array(types, _) = array_typ else {
panic!("ICE: expected array type");
let types = match array_typ {
Type::Array(types, _) | Type::Slice(types) => types,
_ => panic!("ICE: expected array or slice type"),
};

!types.iter().any(|typ| typ.contains_an_array())
Expand Down

0 comments on commit f93d16e

Please sign in to comment.