Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable dynamic indices on slices #2446

Merged
merged 58 commits into from
Sep 7, 2023
Merged

feat: Enable dynamic indices on slices #2446

merged 58 commits into from
Sep 7, 2023

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Aug 25, 2023

Description

Problem*

Resolves #374
Resolves #2536
Resolves #2538

Summary*

This PR implements handling of dynamic indices for slices. After #2347 the slice structure was changed to be a tuple (length, contents) so that we can dynamic carry a slice's true user-facing length throughout SSA. This new length value can now be used to implement dynamic indexing and merging of slices.

The slice length eventually becomes known by the end of SSA through multiple optimization passes such as mem2reg and constant folding. Additional handling of this length needed to be included in flattening. This is the final location in SSA where the length of a slice must be resolved, and where the majority of SSA changes can be found.

All slice intrinsics now need to also be handled inside of ACIR gen.

SliceInsert and SliceRemove in ACIR gen still need to be implemented #2462 (specifically the case where we want to perform an insertion or removal at a dynamic index), and dynamic indexing of arrays/slices needs to be implemented in general (#2461)

Documentation

  • This PR requires documentation updates when merged.

    • I will submit a noir-lang/docs PR.
    • I will request for and support Dev Rel's help in documenting this PR.

Additional Context

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@vezenovm
Copy link
Contributor Author

  • This PR requires documentation updates when merged.

I mainly checked this box because once this PR is merged, support for slices will fully match arrays. I wasn't sure if the documentation had anything noting that slices have certain limitations vs. arrays.

kevaundray
kevaundray previously approved these changes Sep 6, 2023
@kevaundray kevaundray added this pull request to the merge queue Sep 6, 2023
@jfecher jfecher removed this pull request from the merge queue due to a manual request Sep 6, 2023
Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking this temporarily to give me time to review

Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly questions on the various parts of this PR, why certain parts are needed, etc

Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that loop unrolling is disabled for brillig, can you merge master and verify the checks that were removed are still not needed? Or I suppose that will be done by the CI automatically.

@jfecher
Copy link
Contributor

jfecher commented Sep 7, 2023

We can look into removing last_block_stores at a later date

@jfecher jfecher added this pull request to the merge queue Sep 7, 2023
Merged via the queue into master with commit c5c4052 Sep 7, 2023
13 checks passed
@jfecher jfecher deleted the mv/slice-dyn-index branch September 7, 2023 14:52
github-merge-queue bot pushed a commit that referenced this pull request Feb 8, 2024
# Description

## Problem\*

Resolves #4202 and
#2446 (comment)
## Summary\*

This PR brings back the `capacity_tracker` that was used by the fill
internal slices pass and for merging nested slices
(#3979). We now track the capacity
of slices as we insert instructions. The capacity tracker has also been
simplified as it no longer needs to handle nested slice.

The current strategy checks for previously saved store instructions and
backtracks the instructions to see what is the capacity of a slice when
it comes time to merge two slice values. This required an additional
`outer_block_stores` map as we `store_values` only track stores within
the current branch that is being inlined, and a `get_slice_length`
method that ultimately did the recursive backtracking to determine the
slice length. With the capacity tracker we already have the slice length
once it comes time to perform a slice merger allowing us to remove
`outer_block_stores` and `get_slice_length`.

Overall, the capacity tracker enables us to have more accurate tracking
of slice capacities and gives us a more general strategy for tracking a
slice capacity per instruction.

## 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.

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants