Skip to content

Commit

Permalink
feat: Sync from noir (#10047)
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
feat: trait aliases (noir-lang/noir#6431)
chore: Added test showcasing performance regression
(noir-lang/noir#6566)
chore: embed package name in logs
(noir-lang/noir#6564)
chore: remove separate acvm versioning
(noir-lang/noir#6561)
chore: switch to 1.0.0-beta versioning
(noir-lang/noir#6503)
chore: Release Noir(0.39.0)
(noir-lang/noir#6484)
feat: Sync from aztec-packages
(noir-lang/noir#6557)
feat(ssa): Unroll small loops in brillig
(noir-lang/noir#6505)
fix: Do a shallow follow_bindings before unification
(noir-lang/noir#6558)
chore: remove some `_else_condition` tech debt
(noir-lang/noir#6522)
chore: revert #6375 (noir-lang/noir#6552)
feat: simplify constant MSM calls in SSA
(noir-lang/noir#6547)
chore(test): Remove duplicate brillig tests
(noir-lang/noir#6523)
chore: restructure `noirc_evaluator` crate
(noir-lang/noir#6534)
fix: take blackbox function outputs into account when merging
expressions (noir-lang/noir#6532)
chore: Add `Instruction::MakeArray` to SSA
(noir-lang/noir#6071)
feat(profiler): Reduce memory in Brillig execution flamegraph
(noir-lang/noir#6538)
chore: convert some tests to use SSA parser
(noir-lang/noir#6543)
chore(ci): bump mac github runner image to `macos-14`
(noir-lang/noir#6545)
chore(test): More descriptive labels in test matrix
(noir-lang/noir#6542)
chore: Remove unused methods from implicit numeric generics
(noir-lang/noir#6541)
fix: Fix poor handling of aliased references in flattening pass causing
some values to be zeroed (noir-lang/noir#6434)
fix: allow range checks to be performed within the comptime intepreter
(noir-lang/noir#6514)
fix: disallow `#[test]` on associated functions
(noir-lang/noir#6449)
chore(ssa): Skip array_set pass for Brillig functions
(noir-lang/noir#6513)
chore: Reverse ssa parser diff order
(noir-lang/noir#6511)
chore: Parse negatives in SSA parser
(noir-lang/noir#6510)
feat: avoid unnecessary ssa passes while loop unrolling
(noir-lang/noir#6509)
fix(tests): Use a file lock as well as a mutex to isolate tests cases
(noir-lang/noir#6508)
fix: set local_module before elaborating each trait
(noir-lang/noir#6506)
fix: parse Slice type in SSa
(noir-lang/noir#6507)
fix: perform arithmetic simplification through `CheckedCast`
(noir-lang/noir#6502)
feat: SSA parser (noir-lang/noir#6489)
chore(test): Run test matrix on test_programs
(noir-lang/noir#6429)
chore(ci): fix cargo deny (noir-lang/noir#6501)
feat: Deduplicate instructions across blocks
(noir-lang/noir#6499)
chore: move tests for arithmetic generics closer to the code
(noir-lang/noir#6497)
fix(docs): Fix broken links in oracles doc
(noir-lang/noir#6488)
fix: Treat all parameters as possible aliases of each other
(noir-lang/noir#6477)
chore: bump rust dependencies
(noir-lang/noir#6482)
feat: use a full `BlackBoxFunctionSolver` implementation when execution
brillig during acirgen (noir-lang/noir#6481)
chore(docs): Update How to Oracles
(noir-lang/noir#5675)
chore: Release Noir(0.38.0)
(noir-lang/noir#6422)
fix(ssa): Change array_set to not mutate slices coming from function
inputs (noir-lang/noir#6463)
chore: update example to show how to split public inputs in bash
(noir-lang/noir#6472)
fix: Discard optimisation that would change execution ordering or that
is related to call outputs (noir-lang/noir#6461)
chore: proptest for `canonicalize` on infix type expressions
(noir-lang/noir#6269)
fix: let formatter respect newlines between comments
(noir-lang/noir#6458)
fix: check infix expression is valid in program input
(noir-lang/noir#6450)
fix: don't crash on AsTraitPath with empty path
(noir-lang/noir#6454)
fix(tests): Prevent EOF error while running test programs
(noir-lang/noir#6455)
fix(sea): mem2reg to treat block input references as alias
(noir-lang/noir#6452)
chore: revamp attributes (noir-lang/noir#6424)
feat!: Always Check Arithmetic Generics at Monomorphization
(noir-lang/noir#6329)
chore: split path and import lookups
(noir-lang/noir#6430)
fix(ssa): Resolve value IDs in terminator before comparing to array
(noir-lang/noir#6448)
fix: right shift is not a regular division
(noir-lang/noir#6400)
END_COMMIT_OVERRIDE

---------

Co-authored-by: sirasistant <[email protected]>
Co-authored-by: Tom French <[email protected]>
Co-authored-by: TomAFrench <[email protected]>
  • Loading branch information
4 people authored Nov 21, 2024
1 parent 55564aa commit b8bace9
Show file tree
Hide file tree
Showing 67 changed files with 2,777 additions and 951 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13856a121125b1ccca15919942081a5d157d280e
68c32b4ffd9b069fe4b119327dbf4018c17ab9d4
2 changes: 1 addition & 1 deletion noir/noir-repo/compiler/noirc_evaluator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ fxhash.workspace = true
iter-extended.workspace = true
thiserror.workspace = true
num-bigint = "0.4"
num-traits.workspace = true
im.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand All @@ -33,6 +32,7 @@ cfg-if.workspace = true
[dev-dependencies]
proptest.workspace = true
similar-asserts.workspace = true
num-traits.workspace = true

[features]
bn254 = ["noirc_frontend/bn254"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
use super::big_int::BigIntContext;
use super::generated_acir::{BrilligStdlibFunc, GeneratedAcir, PLACEHOLDER_BRILLIG_INDEX};
use crate::brillig::brillig_gen::brillig_directive;
use crate::brillig::brillig_ir::artifact::GeneratedBrillig;
use crate::errors::{InternalBug, InternalError, RuntimeError, SsaReport};
use crate::ssa::acir_gen::{AcirDynamicArray, AcirValue};
use crate::ssa::ir::dfg::CallStack;
use crate::ssa::ir::types::Type as SsaType;
use crate::ssa::ir::{instruction::Endian, types::NumericType};
use acvm::acir::circuit::brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs};
use acvm::acir::circuit::opcodes::{
AcirFunctionId, BlockId, BlockType, ConstantOrWitnessEnum, MemOp,
};
use acvm::acir::circuit::{AssertionPayload, ExpressionOrMemory, ExpressionWidth, Opcode};
use acvm::brillig_vm::{MemoryValue, VMStatus, VM};
use acvm::BlackBoxFunctionSolver;
use acvm::{
acir::AcirField,
acir::{
brillig::Opcode as BrilligOpcode,
circuit::opcodes::FunctionInput,
circuit::{
brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs},
opcodes::{
AcirFunctionId, BlockId, BlockType, ConstantOrWitnessEnum, FunctionInput, MemOp,
},
AssertionPayload, ExpressionOrMemory, ExpressionWidth, Opcode,
},
native_types::{Expression, Witness},
BlackBoxFunc,
AcirField, BlackBoxFunc,
},
brillig_vm::{MemoryValue, VMStatus, VM},
BlackBoxFunctionSolver,
};
use fxhash::FxHashMap as HashMap;
use iter_extended::{try_vecmap, vecmap};
use num_bigint::BigUint;
use std::cmp::Ordering;
use std::{borrow::Cow, hash::Hash};

use crate::brillig::brillig_ir::artifact::GeneratedBrillig;
use crate::errors::{InternalBug, InternalError, RuntimeError, SsaReport};
use crate::ssa::ir::{
dfg::CallStack, instruction::Endian, types::NumericType, types::Type as SsaType,
};

use super::big_int::BigIntContext;
use super::generated_acir::{BrilligStdlibFunc, GeneratedAcir, PLACEHOLDER_BRILLIG_INDEX};
use super::{brillig_directive, AcirDynamicArray, AcirValue};

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
/// High level Type descriptor for Variables.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
//! `GeneratedAcir` is constructed as part of the `acir_gen` pass to accumulate all of the ACIR
//! program as it is being converted from SSA form.
use std::{collections::BTreeMap, u32};
use std::collections::BTreeMap;

use crate::{
brillig::{brillig_gen::brillig_directive, brillig_ir::artifact::GeneratedBrillig},
errors::{InternalError, RuntimeError, SsaReport},
ssa::ir::{dfg::CallStack, instruction::ErrorType},
};
use acvm::acir::{
circuit::{
brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs},
opcodes::{BlackBoxFuncCall, FunctionInput, Opcode as AcirOpcode},
AssertionPayload, BrilligOpcodeLocation, ErrorSelector, OpcodeLocation,
},
native_types::Witness,
BlackBoxFunc,
native_types::{Expression, Witness},
AcirField, BlackBoxFunc,
};

use super::brillig_directive;
use crate::{
brillig::brillig_ir::artifact::GeneratedBrillig,
errors::{InternalError, RuntimeError, SsaReport},
ssa::ir::dfg::CallStack,
ErrorType,
};
use acvm::{acir::native_types::Expression, acir::AcirField};

use iter_extended::vecmap;
use noirc_errors::debug_info::ProcedureDebugId;
Expand Down Expand Up @@ -155,7 +157,7 @@ impl<F: AcirField> GeneratedAcir<F> {
/// This means you cannot multiply an infinite amount of `Expression`s together.
/// Once the `Expression` goes over degree-2, then it needs to be reduced to a `Witness`
/// which has degree-1 in order to be able to continue the multiplication chain.
pub(crate) fn create_witness_for_expression(&mut self, expression: &Expression<F>) -> Witness {
fn create_witness_for_expression(&mut self, expression: &Expression<F>) -> Witness {
let fresh_witness = self.next_witness_index();

// Create a constraint that sets them to be equal to each other
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,58 @@
//! This file holds the pass to convert from Noir's SSA IR to ACIR.
mod acir_ir;

use fxhash::FxHashMap as HashMap;
use im::Vector;
use std::collections::{BTreeMap, HashSet};
use std::fmt::Debug;

use self::acir_ir::acir_variable::{AcirContext, AcirType, AcirVar};
use self::acir_ir::generated_acir::BrilligStdlibFunc;
use super::function_builder::data_bus::DataBus;
use super::ir::dfg::CallStack;
use super::ir::function::FunctionId;
use super::ir::instruction::ConstrainError;
use super::ir::printer::try_to_extract_string_from_error_payload;
use super::{
use acvm::acir::{
circuit::{
brillig::{BrilligBytecode, BrilligFunctionId},
opcodes::{AcirFunctionId, BlockType},
AssertionPayload, ErrorSelector, ExpressionWidth, OpcodeLocation,
},
native_types::Witness,
BlackBoxFunc,
};
use acvm::{acir::circuit::opcodes::BlockId, acir::AcirField, FieldElement};
use bn254_blackbox_solver::Bn254BlackBoxSolver;
use iter_extended::{try_vecmap, vecmap};
use noirc_frontend::monomorphization::ast::InlineType;

mod acir_variable;
mod big_int;
mod brillig_directive;
mod generated_acir;

use crate::brillig::{
brillig_gen::brillig_fn::FunctionContext as BrilligFunctionContext,
brillig_ir::{
artifact::{BrilligParameter, GeneratedBrillig},
BrilligContext,
},
Brillig,
};
use crate::errors::{InternalError, InternalWarning, RuntimeError, SsaReport};
use crate::ssa::{
function_builder::data_bus::DataBus,
ir::{
dfg::DataFlowGraph,
function::{Function, RuntimeType},
dfg::{CallStack, DataFlowGraph},
function::{Function, FunctionId, RuntimeType},
instruction::{
Binary, BinaryOp, Instruction, InstructionId, Intrinsic, TerminatorInstruction,
Binary, BinaryOp, ConstrainError, Instruction, InstructionId, Intrinsic,
TerminatorInstruction,
},
map::Id,
printer::try_to_extract_string_from_error_payload,
types::{NumericType, Type},
value::{Value, ValueId},
},
ssa_gen::Ssa,
};
use crate::brillig::brillig_ir::artifact::{BrilligParameter, GeneratedBrillig};
use crate::brillig::brillig_ir::BrilligContext;
use crate::brillig::{brillig_gen::brillig_fn::FunctionContext as BrilligFunctionContext, Brillig};
use crate::errors::{InternalError, InternalWarning, RuntimeError, SsaReport};
pub(crate) use acir_ir::generated_acir::GeneratedAcir;
use acvm::acir::circuit::opcodes::{AcirFunctionId, BlockType};
use bn254_blackbox_solver::Bn254BlackBoxSolver;
use noirc_frontend::monomorphization::ast::InlineType;

use acvm::acir::circuit::brillig::{BrilligBytecode, BrilligFunctionId};
use acvm::acir::circuit::{AssertionPayload, ErrorSelector, ExpressionWidth, OpcodeLocation};
use acvm::acir::native_types::Witness;
use acvm::acir::BlackBoxFunc;
use acvm::{acir::circuit::opcodes::BlockId, acir::AcirField, FieldElement};
use fxhash::FxHashMap as HashMap;
use im::Vector;
use iter_extended::{try_vecmap, vecmap};
use noirc_frontend::Type as HirType;
use acir_variable::{AcirContext, AcirType, AcirVar};
use generated_acir::BrilligStdlibFunc;
pub(crate) use generated_acir::GeneratedAcir;
use noirc_frontend::hir_def::types::Type as HirType;

#[derive(Default)]
struct SharedContext<F> {
Expand Down Expand Up @@ -772,6 +783,12 @@ impl<'a> Context<'a> {
Instruction::IfElse { .. } => {
unreachable!("IfElse instruction remaining in acir-gen")
}
Instruction::MakeArray { elements, typ: _ } => {
let elements = elements.iter().map(|element| self.convert_value(*element, dfg));
let value = AcirValue::Array(elements.collect());
let result = dfg.instruction_results(instruction_id)[0];
self.ssa_values.insert(result, value);
}
}

self.acir_context.set_call_stack(CallStack::new());
Expand Down Expand Up @@ -1562,7 +1579,7 @@ impl<'a> Context<'a> {
if !already_initialized {
let value = &dfg[array];
match value {
Value::Array { .. } | Value::Instruction { .. } => {
Value::Instruction { .. } => {
let value = self.convert_value(array, dfg);
let array_typ = dfg.type_of_value(array);
let len = if !array_typ.contains_slice_element() {
Expand Down Expand Up @@ -1605,13 +1622,6 @@ impl<'a> Context<'a> {
match array_typ {
Type::Array(_, _) | Type::Slice(_) => {
match &dfg[array_id] {
Value::Array { array, .. } => {
for (i, value) in array.iter().enumerate() {
flat_elem_type_sizes.push(
self.flattened_slice_size(*value, dfg) + flat_elem_type_sizes[i],
);
}
}
Value::Instruction { .. } | Value::Param { .. } => {
// An instruction representing the slice means it has been processed previously during ACIR gen.
// Use the previously defined result of an array operation to fetch the internal type information.
Expand Down Expand Up @@ -1744,13 +1754,6 @@ impl<'a> Context<'a> {
fn flattened_slice_size(&mut self, array_id: ValueId, dfg: &DataFlowGraph) -> usize {
let mut size = 0;
match &dfg[array_id] {
Value::Array { array, .. } => {
// The array is going to be the flattened outer array
// Flattened slice size from SSA value does not need to be multiplied by the len
for value in array {
size += self.flattened_slice_size(*value, dfg);
}
}
Value::NumericConstant { .. } => {
size += 1;
}
Expand Down Expand Up @@ -1914,10 +1917,6 @@ impl<'a> Context<'a> {
Value::NumericConstant { constant, typ } => {
AcirValue::Var(self.acir_context.add_constant(*constant), typ.into())
}
Value::Array { array, .. } => {
let elements = array.iter().map(|element| self.convert_value(*element, dfg));
AcirValue::Array(elements.collect())
}
Value::Intrinsic(..) => todo!(),
Value::Function(function_id) => {
// This conversion is for debugging support only, to allow the
Expand Down Expand Up @@ -2840,22 +2839,6 @@ impl<'a> Context<'a> {
Ok(())
}

/// Given an array value, return the numerical type of its element.
/// Panics if the given value is not an array or has a non-numeric element type.
fn array_element_type(dfg: &DataFlowGraph, value: ValueId) -> AcirType {
match dfg.type_of_value(value) {
Type::Array(elements, _) => {
assert_eq!(elements.len(), 1);
(&elements[0]).into()
}
Type::Slice(elements) => {
assert_eq!(elements.len(), 1);
(&elements[0]).into()
}
_ => unreachable!("Expected array type"),
}
}

/// Convert a Vec<AcirVar> into a Vec<AcirValue> using the given result ids.
/// If the type of a result id is an array, several acir vars are collected into
/// a single AcirValue::Array of the same length.
Expand Down Expand Up @@ -2946,9 +2929,9 @@ mod test {
use std::collections::BTreeMap;

use crate::{
acir::BrilligStdlibFunc,
brillig::Brillig,
ssa::{
acir_gen::acir_ir::generated_acir::BrilligStdlibFunc,
function_builder::FunctionBuilder,
ir::{function::FunctionId, instruction::BinaryOp, map::Id, types::Type},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub(crate) mod brillig_black_box;
pub(crate) mod brillig_block;
pub(crate) mod brillig_block_variables;
pub(crate) mod brillig_directive;
pub(crate) mod brillig_fn;
pub(crate) mod brillig_slice_ops;
mod constant_allocation;
Expand Down
Loading

0 comments on commit b8bace9

Please sign in to comment.