Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent compiler panic when popping from empty slices (#6274)
# Description ## Problem\* Partial fix to #5462 ## Summary\* This PR doesn't fully fix #5462 but allows full compilation of a program without panicking. The test program from #5462 now successfully compiles (due to us being able to remove the inactive branch during inlining) We still fail to properly handle branches which are conditional on runtime values such as the below: ``` fn main(active: bool) { let empty_slice: [u8] = &[]; if !active { let _ = empty_slice.pop_front(); } } ``` This compiles to the below program ``` Compiled ACIR for main (unoptimized): func 0 current witness index : 2 private parameters indices : [0] public parameters indices : [] return value indices : [] BLACKBOX::RANGE [(0)] [ ] INIT (id: 0, len: 0) EXPR [ (-1, _1) 0 ] MEM (id: 0, read at: x1, value: x2) ``` This will then fail to execute with the below error: ``` error: Index out of bounds, array has size 0, but index was 0 ┌─ /mnt/user-data/tom/noir/test_programs/execution_success/inactive_slice_popping/src/main.nr:11:17 │ 11 │ let _ = empty_slice.pop_front(); │ --------------------- │ = Call stack: 1. /mnt/user-data/tom/noir/test_programs/execution_success/inactive_slice_popping/src/main.nr:11:17 ``` Note the memory block has been allocated with a length of 0 so even applying a predicate to the array get will fail. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** 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