Skip to content

Commit

Permalink
feat: Sync from noir (#6138)
Browse files Browse the repository at this point in the history
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix: Require for all foldable functions to use distinct return
(noir-lang/noir#4949)
feat!: use `distinct` return value witnesses by default
(noir-lang/noir#4951)
chore(docs): adding matomo tracking
(noir-lang/noir#4898)
chore: fix typo in `ResolverError::AbiAttributeOutsideContract`
(noir-lang/noir#4933)
chore: Add test for recursing a foldable function
(noir-lang/noir#4948)
feat: Handle `no_predicates` attribute
(noir-lang/noir#4942)
fix: ensure where clauses propagated to trait default definitions
(noir-lang/noir#4894)
chore: Remove unnecessary `pub(super)` in interpreter
(noir-lang/noir#4939)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <[email protected]>
Co-authored-by: Maxim Vezenov <[email protected]>
  • Loading branch information
3 people authored May 1, 2024
1 parent af3192d commit 4dc5efb
Show file tree
Hide file tree
Showing 86 changed files with 588 additions and 329 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8aad2e45acbe08afc3902db95a83324f822c35eb
d4c68066ab35ce1c52510cf0c038fb627a0677c3
9 changes: 5 additions & 4 deletions avm-transpiler/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ pub fn extract_brillig_from_acir_program(program: &Program) -> &[BrilligOpcode]
assert_eq!(
program.functions.len(),
1,
"An AVM program should have only a single ACIR function flagged as 'BrilligCall'"
"An AVM program should have only a single ACIR function with a 'BrilligCall'"
);
let opcodes = &program.functions[0].opcodes;
let main_function = &program.functions[0];
let opcodes = &main_function.opcodes;
assert_eq!(
opcodes.len(),
1,
"An AVM program should have only a single ACIR function flagged as 'BrilligCall'"
"An AVM program should only have a single `BrilligCall`"
);
match opcodes[0] {
Opcode::BrilligCall { .. } => {}
Opcode::BrilligCall { id, .. } => assert_eq!(id, 0, "The ID of the `BrilligCall` must be 0 as we have a single `Brillig` function"),
_ => panic!("Tried to extract a Brillig program from its ACIR wrapper opcode, but the opcode doesn't contain Brillig!"),
}
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/acir_tests/run_acir_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export BIN CRS_PATH VERBOSE BRANCH
cd acir_tests

# Convert them to array
SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member)
SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member witness_compression)

function test() {
cd $1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ contract DocsExample {
b: Field // The actual return type of our circuit is the PrivateCircuitPublicInputs struct, this will be the
// input to our kernel!
// docs:start:context-example-return
) -> distinct pub PrivateCircuitPublicInputs {
) -> pub PrivateCircuitPublicInputs {
// docs:end:context-example-return
// ************************************************************
// The hasher is a structure used to generate a hash of the circuits inputs.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::parity_lib::{BaseParityInputs, ParityPublicInputs};

#[recursive]
fn main(inputs: BaseParityInputs) -> distinct pub ParityPublicInputs {
fn main(inputs: BaseParityInputs) -> pub ParityPublicInputs {
inputs.base_parity_circuit()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::parity_lib::{RootParityInputs, ParityPublicInputs};

#[recursive]
fn main(inputs: RootParityInputs) -> distinct pub ParityPublicInputs {
fn main(inputs: RootParityInputs) -> pub ParityPublicInputs {
inputs.root_parity_circuit()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::private_kernel_lib::PrivateKernelInitCircuitPrivateInputs;
use dep::types::PrivateKernelCircuitPublicInputs;

unconstrained fn main(input: PrivateKernelInitCircuitPrivateInputs) -> distinct pub PrivateKernelCircuitPublicInputs {
unconstrained fn main(input: PrivateKernelInitCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs {
input.native_private_kernel_circuit_initial()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::private_kernel_lib::PrivateKernelInitCircuitPrivateInputs;
use dep::types::PrivateKernelCircuitPublicInputs;

fn main(input: PrivateKernelInitCircuitPrivateInputs) -> distinct pub PrivateKernelCircuitPublicInputs {
fn main(input: PrivateKernelInitCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs {
input.native_private_kernel_circuit_initial()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::private_kernel_lib::PrivateKernelInnerCircuitPrivateInputs;
use dep::types::PrivateKernelCircuitPublicInputs;

unconstrained fn main(input: PrivateKernelInnerCircuitPrivateInputs) -> distinct pub PrivateKernelCircuitPublicInputs {
unconstrained fn main(input: PrivateKernelInnerCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs {
input.native_private_kernel_circuit_inner()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::private_kernel_lib::PrivateKernelInnerCircuitPrivateInputs;
use dep::types::PrivateKernelCircuitPublicInputs;

fn main(input: PrivateKernelInnerCircuitPrivateInputs) -> distinct pub PrivateKernelCircuitPublicInputs {
fn main(input: PrivateKernelInnerCircuitPrivateInputs) -> pub PrivateKernelCircuitPublicInputs {
input.native_private_kernel_circuit_inner()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::private_kernel_lib::PrivateKernelTailCircuitPrivateInputs;
use dep::types::KernelCircuitPublicInputs;

unconstrained fn main(input: PrivateKernelTailCircuitPrivateInputs) -> distinct pub KernelCircuitPublicInputs {
unconstrained fn main(input: PrivateKernelTailCircuitPrivateInputs) -> pub KernelCircuitPublicInputs {
input.native_private_kernel_circuit_tail()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::private_kernel_lib::PrivateKernelTailToPublicCircuitPrivateInputs;
use dep::types::PublicKernelCircuitPublicInputs;

unconstrained fn main(input: PrivateKernelTailToPublicCircuitPrivateInputs) -> distinct pub PublicKernelCircuitPublicInputs {
unconstrained fn main(input: PrivateKernelTailToPublicCircuitPrivateInputs) -> pub PublicKernelCircuitPublicInputs {
input.execute()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::private_kernel_lib::PrivateKernelTailToPublicCircuitPrivateInputs;
use dep::types::PublicKernelCircuitPublicInputs;

fn main(input: PrivateKernelTailToPublicCircuitPrivateInputs) -> distinct pub PublicKernelCircuitPublicInputs {
fn main(input: PrivateKernelTailToPublicCircuitPrivateInputs) -> pub PublicKernelCircuitPublicInputs {
input.execute()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::private_kernel_lib::PrivateKernelTailCircuitPrivateInputs;
use dep::types::KernelCircuitPublicInputs;

fn main(input: PrivateKernelTailCircuitPrivateInputs) -> distinct pub KernelCircuitPublicInputs {
fn main(input: PrivateKernelTailCircuitPrivateInputs) -> pub KernelCircuitPublicInputs {
input.native_private_kernel_circuit_tail()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::public_kernel_lib::PublicKernelAppLogicCircuitPrivateInputs;
use dep::types::PublicKernelCircuitPublicInputs;

unconstrained fn main(input: PublicKernelAppLogicCircuitPrivateInputs) -> distinct pub PublicKernelCircuitPublicInputs {
unconstrained fn main(input: PublicKernelAppLogicCircuitPrivateInputs) -> pub PublicKernelCircuitPublicInputs {
input.public_kernel_app_logic()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::public_kernel_lib::PublicKernelAppLogicCircuitPrivateInputs;
use dep::types::PublicKernelCircuitPublicInputs;

fn main(input: PublicKernelAppLogicCircuitPrivateInputs) -> distinct pub PublicKernelCircuitPublicInputs {
fn main(input: PublicKernelAppLogicCircuitPrivateInputs) -> pub PublicKernelCircuitPublicInputs {
input.public_kernel_app_logic()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::public_kernel_lib::PublicKernelSetupCircuitPrivateInputs;
use dep::types::PublicKernelCircuitPublicInputs;

unconstrained fn main(input: PublicKernelSetupCircuitPrivateInputs) -> distinct pub PublicKernelCircuitPublicInputs {
unconstrained fn main(input: PublicKernelSetupCircuitPrivateInputs) -> pub PublicKernelCircuitPublicInputs {
input.public_kernel_setup()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::public_kernel_lib::PublicKernelSetupCircuitPrivateInputs;
use dep::types::PublicKernelCircuitPublicInputs;

fn main(input: PublicKernelSetupCircuitPrivateInputs) -> distinct pub PublicKernelCircuitPublicInputs {
fn main(input: PublicKernelSetupCircuitPrivateInputs) -> pub PublicKernelCircuitPublicInputs {
input.public_kernel_setup()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::public_kernel_lib::PublicKernelTailCircuitPrivateInputs;
use dep::types::KernelCircuitPublicInputs;

unconstrained fn main(input: PublicKernelTailCircuitPrivateInputs) -> distinct pub KernelCircuitPublicInputs {
unconstrained fn main(input: PublicKernelTailCircuitPrivateInputs) -> pub KernelCircuitPublicInputs {
input.public_kernel_tail()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::public_kernel_lib::PublicKernelTailCircuitPrivateInputs;
use dep::types::KernelCircuitPublicInputs;

fn main(input: PublicKernelTailCircuitPrivateInputs) -> distinct pub KernelCircuitPublicInputs {
fn main(input: PublicKernelTailCircuitPrivateInputs) -> pub KernelCircuitPublicInputs {
input.public_kernel_tail()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::public_kernel_lib::PublicKernelTeardownCircuitPrivateInputs;
use dep::types::PublicKernelCircuitPublicInputs;

unconstrained fn main(input: PublicKernelTeardownCircuitPrivateInputs) -> distinct pub PublicKernelCircuitPublicInputs {
unconstrained fn main(input: PublicKernelTeardownCircuitPrivateInputs) -> pub PublicKernelCircuitPublicInputs {
input.public_kernel_teardown()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::public_kernel_lib::PublicKernelTeardownCircuitPrivateInputs;
use dep::types::PublicKernelCircuitPublicInputs;

fn main(input: PublicKernelTeardownCircuitPrivateInputs) -> distinct pub PublicKernelCircuitPublicInputs {
fn main(input: PublicKernelTeardownCircuitPrivateInputs) -> pub PublicKernelCircuitPublicInputs {
input.public_kernel_teardown()
}
2 changes: 2 additions & 0 deletions noir/noir-repo/.github/workflows/docs-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ jobs:
run: yarn workspace docs version::stables

- name: Build docs
env:
MATOMO_ENV: staging # not really a secret, it will show in the footer anyway
run: yarn workspaces foreach -Rpt --from docs run build

- name: Upload artifact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ jobs:
- name: Run tests
run: |
cargo nextest run --archive-file nextest-archive.tar.zst \
--partition count:${{ matrix.partition }}/4
--partition count:${{ matrix.partition }}/4 \
--no-fail-fast
# This is a job which depends on all test jobs and reports the overall status.
# This allows us to add/remove test jobs without having to update the required workflows.
Expand Down
3 changes: 2 additions & 1 deletion noir/noir-repo/.github/workflows/test-rust-workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ jobs:
- name: Run tests
run: |
cargo nextest run --archive-file nextest-archive.tar.zst \
--partition count:${{ matrix.partition }}/4
--partition count:${{ matrix.partition }}/4 \
--no-fail-fast
# This is a job which depends on all test jobs and reports the overall status.
# This allows us to add/remove test jobs without having to update the required workflows.
Expand Down
9 changes: 2 additions & 7 deletions noir/noir-repo/aztec_macros/src/transforms/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use convert_case::{Case, Casing};
use noirc_errors::Span;
use noirc_frontend::ast;
use noirc_frontend::ast::{
BlockExpression, ConstrainKind, ConstrainStatement, Distinctness, Expression, ExpressionKind,
BlockExpression, ConstrainKind, ConstrainStatement, Expression, ExpressionKind,
ForLoopStatement, ForRange, FunctionReturnType, Ident, Literal, NoirFunction, NoirStruct,
Param, PathKind, Pattern, Signedness, Statement, StatementKind, UnresolvedType,
UnresolvedTypeData, Visibility,
Expand Down Expand Up @@ -104,13 +104,8 @@ pub fn transform_function(
func.def.return_visibility = Visibility::Public;
}

// Distinct return types are only required for private functions
// Public functions should have unconstrained auto-inferred
match ty {
"Private" => func.def.return_distinctness = Distinctness::Distinct,
"Public" | "Avm" => func.def.is_unconstrained = true,
_ => (),
}
func.def.is_unconstrained = matches!(ty, "Public" | "Avm");

Ok(())
}
Expand Down
7 changes: 4 additions & 3 deletions noir/noir-repo/compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ pub(crate) fn optimize_into_acir(
force_brillig_output: bool,
print_timings: bool,
) -> Result<Artifacts, RuntimeError> {
let abi_distinctness = program.return_distinctness;

let ssa_gen_span = span!(Level::TRACE, "ssa_generation");
let ssa_gen_span_guard = ssa_gen_span.enter();
let ssa = SsaBuilder::new(program, print_passes, force_brillig_output, print_timings)?
Expand All @@ -67,6 +65,9 @@ pub(crate) fn optimize_into_acir(
.run_pass(Ssa::remove_bit_shifts, "After Removing Bit Shifts:")
// Run mem2reg once more with the flattened CFG to catch any remaining loads/stores
.run_pass(Ssa::mem2reg, "After Mem2Reg:")
// Run the inlining pass again to handle functions with `InlineType::NoPredicates`.
// Before flattening is run, we treat functions marked with the `InlineType::NoPredicates` as an entry point.
.run_pass(Ssa::inline_functions_with_no_predicates, "After Inlining:")
.run_pass(Ssa::fold_constants, "After Constant Folding:")
.run_pass(Ssa::remove_enable_side_effects, "After EnableSideEffects removal:")
.run_pass(Ssa::fold_constants_using_constraints, "After Constraint Folding:")
Expand All @@ -78,7 +79,7 @@ pub(crate) fn optimize_into_acir(

drop(ssa_gen_span_guard);

time("SSA to ACIR", print_timings, || ssa.into_acir(&brillig, abi_distinctness))
time("SSA to ACIR", print_timings, || ssa.into_acir(&brillig))
}

// Helper to time SSA passes
Expand Down
Loading

0 comments on commit 4dc5efb

Please sign in to comment.