nightly-2024-04-23: feat(acir_gen): Brillig stdlib (#4848)
Pre-release
Pre-release
·
1291 commits
to master
since this release
# Description ## Problem\* Expands usage of https://github.com/noir-lang/noir/issues/3907 to our Brillig directives. ## Summary\* The Brillig stdlib differs slightly from normal Brillig functions calls. We can insert the generated Brillig bytecode at any point during ACIR gen. This includes within the `GeneratedAcir` struct itself. We have a few requirements on what we want to achieve: - We do want to have to thread the ACIR gen `SharedContext` that is used for generating normal Brillig function pointers to the `GeneratedAcir`. Why would we want a reference to code generation inside of our Generated ACIR structure (we don't)? - We want to maintain one Brillig stdlib for an entire program. We do not want to change the `BrilligCall` opcode so we need them to be a part of the main list of `unconstrained_functions` in a program. - Function IDs reference a flat list, so reserving some number of slots would be wasteful if the program does not eventually use a Brillig stdlib function in that slot. So instead we maintain a map as part of the `GeneratedAcir` that notes when we at which opcode location we inserted a call to a `BrilligStdlibFunc`. The ID at this point will just be `0`. After finishing ACIR generation for a function, only then do we resolve the IDs for these `BrilligCall` opcodes. ## Additional Context ## 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. --------- Co-authored-by: Tom French <[email protected]> Co-authored-by: jfecher <[email protected]> Co-authored-by: TomAFrench <[email protected]>