nightly-2024-05-07: fix: Compute the correct slice length when coercing from a literal ar…
Pre-release
Pre-release
github-actions
released this
07 May 02:17
·
59 commits
to master
since this release
…ray of complex types (#4986) # Description ## Problem\* Resolves #4967 ## Summary\* There is a problem in the [array to slice coercion](https://github.com/noir-lang/noir/blob/07930d4373a393146210efae69e6ec40171f047b/compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs#L87) code. When evaluating the coercion, it does not take into account that for SSA, complex types such as tuples and structs are flattened, resulting in an array representation with length of elements times the size of the complex type (as a result of the flattening). This results in the replacement slice having an incorrect size. Then, because the slice has an inflated size, the code which decodes the elements of the slice for printing or tracking (in the debugger) crashes when it attempts to decode beyond the values that it has available. ## Additional Context There are two additional minor changes introduced in this PR: 1. Removed the `Optional<>` for `PrintableType::Array`'s length. This was introduced to be able to print slices (setting the length to `None`), but those are now represented properly with `PrintableType::Slice`. 2. Added support for printing slices. Both are pretty small changes which I made while investigating the issue, but I'm willing to send separate PRs for those if required. I also expanded the existing test cases to verify both the coerced slice length and printing of slices. ## 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.