feat(stdlib): add subarray method for fixed-size arrays#11560
feat(stdlib): add subarray method for fixed-size arrays#11560illegalcall wants to merge 7 commits intonoir-lang:masterfrom
Conversation
|
Thank you for your contribution to the Noir language. Please do not force push to this branch after the Noir team have started review of this PR. Doing so will only delay us merging your PR as we will need to start the review process from scratch. Thanks for your understanding. |
jfecher
left a comment
There was a problem hiding this comment.
LGTM after pending suggestions. This has come up often enough where I do think we should add this to the stdlib. IMO, the name subarray is good in that it hints the operation is more expensive than a traditional slice operation which returns an offset reference.
|
@illegalcall do you mind running |
|
Hey @jfecher, absolutely my pleasure to run the scripts. I have accepted the changes. |
|
@illegalcall sorry, one more command to run for stdlib changes: (I'd also appreciate if you could add |
|
Yeah, ofcourse. Doing this right now. |
|
Done. Lets hope CI passes this time 🤞 |
|
@illegalcall looks like there's still a diff when running |
|
@jfecher Um, I am not sure what am I missing. I have redone the cargo t --release build, run $ rm -rf noir_stdlib/docs
$ mv noir_stdlib/target/docs noir_stdlib/docsstill no diff. Should i rollback 1 commit and regen and force push? To be extra sure, i have cloned the repo again and ran the same commands, only to reach the same outcome. :( (I am eager to know about the issue, and would love to work with you and fix this. illegalcall is my discord username too, and i am on Noir server) |
|
@illegalcall odd, when I pulled this PR and ran |
|
@jfecher Yeah, when i run i dont see a diff. |
|
And following the docs rm and mv commands results in the same doc. |
|
@illegalcall it calls |
|
The diff is here https://github.com/noir-lang/noir/actions/runs/21960924441/job/63438631636?pr=11560 but I've also copied it down below: |
|
Yes @jfecher, i didnt have to use the diff starting with |
|
CC @TomAFrench may need a force merge here as the upload brillig execution reports CI step is failing. |
|
Thanks for all the changes @illegalcall! PR looks good now. |
|
Glad to be a part of this, and thank you @jfecher for helping out. |
|
Its unfortunate to see so many merge conflicts here 🙁. Should i go ahead and resolve them, if there is a posiblity of merging this soon? @jfecher |
|
I'll pull this branch into the repo so we can clean up the merge conflicts and get it over the line |
|
Thank you so much, lmk if anything comes up with which I can help. :) |

Description
Problem
Resolves #11106
Users frequently need to extract a fixed-size subarray from a larger array. Currently this requires manually writing a helper function with a loop, as noted by multiple users in the issue and the related #1240.
Summary
Adds a
subarraymethod to[T; N]in the stdlib that returns a contiguous slice ofMelements starting at a given offset.Implementation details:
crate::mem::zeroed()for initialization, consistent withconcat,map, andmapi— avoids requiring aT: Emptytrait bound.offset + M <= N) with a descriptive error message, following the stdlib convention used invector::as_array,poseidon2::absorb, etc.docs/docs/noir/concepts/data_types/arrays.md.Additional Context
The original issue proposed a standalone function with a
T: Emptybound. This PR instead implements it as a method on[T; N]usingmem::zeroed(), which is more ergonomic and consistent with existing array methods.User Documentation
Check one:
PR Checklist
cargo fmton default settings.