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

Enable using complex type inputs on dynamic slice intrinsics #3364

Closed
Tracked by #3363
vezenovm opened this issue Oct 30, 2023 · 0 comments · Fixed by #3617
Closed
Tracked by #3363

Enable using complex type inputs on dynamic slice intrinsics #3364

vezenovm opened this issue Oct 30, 2023 · 0 comments · Fixed by #3617
Labels
acir-gen enhancement New feature or request ssa

Comments

@vezenovm
Copy link
Contributor

vezenovm commented Oct 30, 2023

Problem

We can appropriately use a dynamic slice intrinsic on a nested slice whose element types are primitive types, but we should be able to also use dynamic slice intrinsics on a nested slice whose element types are also complex types such as another nested slice.

Happy Case

If I have this nested slice:

struct FooParent {
    parent_arr: [Field; 3],
    foos: [Foo],
}

struct Bar {
    inner: [Field; 3],
}

struct Foo {
    a: Field,
    b: [Field],
    bar: Bar,
}

    let q = x.push_back(foo_four);
    let foo_parent_one = FooParent { parent_arr: [0, 1, 2], foos: x };
    let foo_parent_two = FooParent { parent_arr: [3, 4, 5], foos: q };
    let mut foo_parents = [foo_parent_one];
    foo_parents = foo_parents.push_back(foo_parent_two);

I should be able to do:

    assert(foo_parents[y - 2].foos.len() == 5);
    foo_parents[y - 2].foos = foo_parents[y - 2].foos.push_back(foo_four);
    assert(foo_parents[y - 2].foos.len() == 6);

the same way I can do:

    foo_parents[y - 2].foos[y - 1].b = foo_parents[y - 2].foos[y - 1].b.push_back(500);
    assert(foo_parents[y - 2].foos[y - 1].b.len() == 7);
    assert(foo_parents[y - 2].foos[y - 1].b[6] == 500);

where the nested slice simply has primitive element types.

Alternatives Considered

N/A

Additional Context

Nested dynamic slices were made possible by this pass (#3258). There is a chance that something is simply off in this pass rather than the ACIR gen.

After some investigation it does look like the fill internal slices pass is working as expected but this is still important to note in case I missed something.

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Oct 30, 2023
github-merge-queue bot pushed a commit that referenced this issue Nov 30, 2023
# Description

## Problem\*

Resolves #3364 

## Summary\*

This PR heavily changes the way slice intrinsics are implemented in ACIR
gen. Following the `fill_internal_slices` pass nested slices now have
dummy data automatically attached to them to enable known sizes to be
used when fetching from an array with nested slices. Most of the slice
intrinsics were written for non-complex inputs and also did not account
for the addition of already included dummy data. With dummy data already
included we cannot simply push back or push front elements for example,
we need to make sure we do not alter the size of the internal slice we
are using.

The slice intrinsic implementations essentially treat the input already
as a dynamic array and perform the appropriate memory operations upon
them. I considered alternatives and went with what I think is the most
efficient way to implement these intrinsics, however, there is
definitely room for cleanup and in the name of getting a first iteration
working, we can consider how to optimize these intrinsics in another PR.

I have added comments in the ACIR gen itself to help with some of the
logic for the implementation, but do let me know if something is not
clear and I can document it further.

The `fill_internal_slices` pass now also accounts for slice constants
passed as inputs to slice intrinsics as these must also be filled with
dummy data when they are being attached to a nested slice.

## Additional Context

A bug was found in the `fill_internal_slices` pass that was necessary to
resolve this issue. Essentially the children fetched from a slice were
not being accurately tracked when an `array_get` occurs. This fix is
included in this PR as it did not come up until more complex operations
with nested slices were attempted.

SliceInsert and SliceRemove now use a dynamic index. I only tested using
a constant index in this PR and will have a followup PR that shows this
tested out as this PR is already large enough.

## Documentation\*

Check one:
- [ ] No documentation needed.
- [X] 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>
Co-authored-by: Tom French <tom@tomfren.ch>
Co-authored-by: jfecher <jake@aztecprotocol.com>
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acir-gen enhancement New feature or request ssa
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant