-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Compute the correct slice length when coercing from a literal ar…
…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.
- Loading branch information
Showing
6 changed files
with
43 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters