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

feat: Sync from noir #10047

Merged
merged 25 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3f9c7ad
[1 changes] feat: Sync from aztec-packages (https://github.com/noir-l…
AztecBot Nov 19, 2024
b4559e5
chore: apply sync fixes
AztecBot Nov 19, 2024
654c381
[1 changes] chore: remove separate acvm versioning (https://github.co…
AztecBot Nov 20, 2024
6e2548a
chore: apply sync fixes
AztecBot Nov 20, 2024
6145b41
chore: remove separate acvm versioning (https://github.com/noir-lang/…
AztecBot Nov 20, 2024
696265c
Merge branch 'master' into sync-noir
sirasistant Nov 20, 2024
95f2fb6
update locks
sirasistant Nov 20, 2024
e12edb7
update yarn lock
sirasistant Nov 20, 2024
5651e12
Merge branch 'master' into sync-noir
sirasistant Nov 20, 2024
9535f92
Merge branch 'master' into sync-noir
TomAFrench Nov 20, 2024
e255a67
[1 changes] chore: embed package name in logs (https://github.com/noi…
AztecBot Nov 20, 2024
0976714
chore: apply sync fixes
AztecBot Nov 20, 2024
6124536
chore: embed package name in logs (https://github.com/noir-lang/noir/…
AztecBot Nov 20, 2024
992a059
Merge branch 'master' into sync-noir
sirasistant Nov 20, 2024
35eb1c9
chore: remove cross-block constant folding
TomAFrench Nov 20, 2024
57b4735
.
TomAFrench Nov 20, 2024
de8e126
[1 changes] feat: trait aliases (https://github.com/noir-lang/noir/pu…
AztecBot Nov 21, 2024
ba1d3a3
chore: apply sync fixes
AztecBot Nov 21, 2024
1ca25e0
feat: trait aliases (https://github.com/noir-lang/noir/pull/6431)
AztecBot Nov 21, 2024
7561c19
revert noir/6434 and noir/6522
sirasistant Nov 21, 2024
f01793d
Merge branch 'master' into sync-noir
sirasistant Nov 21, 2024
1c8d32c
chore: revert cross-block constant folding
TomAFrench Nov 21, 2024
0acc7cf
.
TomAFrench Nov 21, 2024
5a95121
.
TomAFrench Nov 21, 2024
d707523
.
TomAFrench Nov 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading