diff --git a/Cargo.lock b/Cargo.lock index 9f3590d259b..7bc6eb9984e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3332,6 +3332,7 @@ dependencies = [ "build-data", "color-eyre", "im", + "insta", "nargo", "noir_fuzzer", "noirc_abi", diff --git a/compiler/noirc_evaluator/src/ssa/ir/dfg.rs b/compiler/noirc_evaluator/src/ssa/ir/dfg.rs index dfef0ed5bb1..fbd05470714 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/dfg.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/dfg.rs @@ -12,6 +12,7 @@ use super::{ instruction::{ Instruction, InstructionId, InstructionResultType, Intrinsic, TerminatorInstruction, }, + integer::IntegerConstant, map::DenseMap, types::{NumericType, Type}, value::{Value, ValueId, ValueMapping}, @@ -582,13 +583,22 @@ impl DataFlowGraph { } /// Returns the field element represented by this value if it is a numeric constant. - /// Returns None if the given value is not a numeric constant. + /// Returns `None` if the given value is not a numeric constant. + /// + /// Use `get_integer_constant` if the underlying values need to be compared as signed integers. pub(crate) fn get_numeric_constant(&self, value: ValueId) -> Option { self.get_numeric_constant_with_type(value).map(|(value, _typ)| value) } + /// Similar to `get_numeric_constant` but returns the value as a signed or unsigned integer. + /// Returns `None` if the given value is not an integer constant. + pub(crate) fn get_integer_constant(&self, value: ValueId) -> Option { + self.get_numeric_constant_with_type(value) + .and_then(|(f, t)| IntegerConstant::from_numeric_constant(f, t)) + } + /// Returns the field element and type represented by this value if it is a numeric constant. - /// Returns None if the given value is not a numeric constant. + /// Returns `None` if the given value is not a numeric constant. pub(crate) fn get_numeric_constant_with_type( &self, value: ValueId, diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs index 7b428de7c4a..8a0ae62fc37 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction/binary.rs @@ -202,7 +202,10 @@ pub(crate) fn eval_constant_binary_op( /// Values in the range `[0, 2^(bit_size-1))` are interpreted as positive integers /// /// Values in the range `[2^(bit_size-1), 2^bit_size)` are interpreted as negative integers. -fn try_convert_field_element_to_signed_integer(field: FieldElement, bit_size: u32) -> Option { +pub(crate) fn try_convert_field_element_to_signed_integer( + field: FieldElement, + bit_size: u32, +) -> Option { let unsigned_int = truncate(field.try_into_u128()?, bit_size); let max_positive_value = 1 << (bit_size - 1); @@ -219,7 +222,7 @@ fn try_convert_field_element_to_signed_integer(field: FieldElement, bit_size: u3 Some(signed_int) } -fn convert_signed_integer_to_field_element(int: i128, bit_size: u32) -> FieldElement { +pub(crate) fn convert_signed_integer_to_field_element(int: i128, bit_size: u32) -> FieldElement { if int >= 0 { FieldElement::from(int) } else { @@ -375,4 +378,14 @@ mod test { assert!(BinaryOp::Shr.get_i128_function()(1, 128).is_none()); assert!(BinaryOp::Shl.get_i128_function()(1, 128).is_none()); } + + #[test] + fn test_plus_minus_one_as_field() { + for (i, u) in [(-1i64, u64::MAX), (-2i64, u64::MAX - 1), (1i64, 1u64)] { + let i: i128 = i.into(); + let f = convert_signed_integer_to_field_element(i, 64); + assert_eq!(f.to_u128(), u as u128); + assert_eq!(i, try_convert_field_element_to_signed_integer(f, 64).unwrap()); + } + } } diff --git a/compiler/noirc_evaluator/src/ssa/ir/integer.rs b/compiler/noirc_evaluator/src/ssa/ir/integer.rs new file mode 100644 index 00000000000..cccd147fee4 --- /dev/null +++ b/compiler/noirc_evaluator/src/ssa/ir/integer.rs @@ -0,0 +1,120 @@ +use std::cmp::Ordering; + +use acvm::{AcirField, FieldElement}; +use num_traits::Zero; + +use super::{instruction::binary, types::NumericType}; + +/// A `Signed` or `Unsigned` value of a `Value::NumericConstant`, converted to 128 bits. +/// +/// This type can be used in loops and other instances where values have to be compared, +/// with correct handling of negative values. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub(crate) enum IntegerConstant { + Signed { value: i128, bit_size: u32 }, + Unsigned { value: u128, bit_size: u32 }, +} + +impl IntegerConstant { + pub(crate) fn from_numeric_constant(field: FieldElement, typ: NumericType) -> Option { + match typ { + NumericType::Signed { bit_size } => { + binary::try_convert_field_element_to_signed_integer(field, bit_size) + .map(|value| Self::Signed { value, bit_size }) + } + NumericType::Unsigned { bit_size } => { + Some(Self::Unsigned { value: field.to_u128(), bit_size }) + } + NumericType::NativeField => None, + } + } + + /// Convert back into a field. + pub(crate) fn into_numeric_constant(self) -> (FieldElement, NumericType) { + match self { + Self::Signed { value, bit_size } => ( + binary::convert_signed_integer_to_field_element(value, bit_size), + NumericType::signed(bit_size), + ), + Self::Unsigned { value, bit_size } => { + (FieldElement::from(value), NumericType::unsigned(bit_size)) + } + } + } + + /// Reduce two constants into a result by applying functions on them if their signedness matches. + pub(crate) fn reduce( + self, + other: Self, + s: impl Fn(i128, i128) -> T, + u: impl Fn(u128, u128) -> T, + ) -> Option { + match (self, other) { + (Self::Signed { value: a, .. }, Self::Signed { value: b, .. }) => Some(s(a, b)), + (Self::Unsigned { value: a, .. }, Self::Unsigned { value: b, .. }) => Some(u(a, b)), + _ => None, + } + } + + /// Apply functions on signed/unsigned values. + pub(crate) fn apply(&self, s: impl Fn(i128) -> T, u: impl Fn(u128) -> T) -> T { + match self { + Self::Signed { value, .. } => s(*value), + Self::Unsigned { value, .. } => u(*value), + } + } + + /// Increment the value by 1, saturating at the maximum value. + pub(crate) fn inc(self) -> Self { + match self { + Self::Signed { value, bit_size } => { + Self::Signed { value: value.saturating_add(1), bit_size } + } + Self::Unsigned { value, bit_size } => { + Self::Unsigned { value: value.saturating_add(1), bit_size } + } + } + } + + /// Decrement the value by 1, saturating at the minimum value. + pub(crate) fn dec(self) -> Self { + match self { + Self::Signed { value, bit_size } => { + Self::Signed { value: value.saturating_sub(1), bit_size } + } + Self::Unsigned { value, bit_size } => { + Self::Unsigned { value: value.saturating_sub(1), bit_size } + } + } + } + + pub(crate) fn is_zero(&self) -> bool { + match self { + Self::Signed { value, .. } => value.is_zero(), + Self::Unsigned { value, .. } => value.is_zero(), + } + } +} + +impl PartialOrd for IntegerConstant { + fn partial_cmp(&self, other: &Self) -> Option { + match (self, other) { + (Self::Signed { value: a, .. }, Self::Signed { value: b, .. }) => a.partial_cmp(b), + (Self::Signed { value: a, .. }, Self::Unsigned { value: b, .. }) => { + if a.is_negative() { + Some(Ordering::Less) + } else { + (*a).try_into().ok().and_then(|a: u128| a.partial_cmp(b)) + } + } + (Self::Unsigned { value: a, .. }, Self::Signed { value: b, .. }) => { + if b.is_negative() { + Some(Ordering::Greater) + } else { + (*b).try_into().ok().and_then(|b: u128| a.partial_cmp(&b)) + } + } + (Self::Unsigned { value: a, .. }, Self::Unsigned { value: b, .. }) => a.partial_cmp(b), + } + } +} diff --git a/compiler/noirc_evaluator/src/ssa/ir/mod.rs b/compiler/noirc_evaluator/src/ssa/ir/mod.rs index fefaaf4cb5d..3c750d12b7e 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/mod.rs @@ -6,6 +6,7 @@ pub(crate) mod dom; pub mod function; pub(crate) mod function_inserter; pub mod instruction; +pub(crate) mod integer; pub mod map; pub(crate) mod post_order; pub(crate) mod printer; diff --git a/compiler/noirc_evaluator/src/ssa/opt/loop_invariant.rs b/compiler/noirc_evaluator/src/ssa/opt/loop_invariant.rs index 4e47e489e02..c0e7f91f6c1 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/loop_invariant.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/loop_invariant.rs @@ -61,6 +61,7 @@ use crate::ssa::{ Binary, BinaryOp, ConstrainError, Instruction, InstructionId, binary::eval_constant_binary_op, }, + integer::IntegerConstant, post_order::PostOrder, types::{NumericType, Type}, value::{Value, ValueId}, @@ -152,11 +153,11 @@ struct LoopInvariantContext<'f> { // This map is expected to only ever contain a singular value. // However, we store it in a map in order to match the definition of // `outer_induction_variables` as both maps share checks for evaluating binary operations. - current_induction_variables: HashMap, + current_induction_variables: HashMap, // Maps outer loop induction variable -> fixed lower and upper loop bound // This will be used by inner loops to determine whether they // have safe operations reliant upon an outer loop's maximum induction variable. - outer_induction_variables: HashMap, + outer_induction_variables: HashMap, // This context struct processes runs across all loops. // This stores the current loop's pre-header block. // It is wrapped in an Option as our SSA `Id` does not allow dummy values. @@ -396,7 +397,7 @@ impl<'f> LoopInvariantContext<'f> { let array_typ = self.inserter.function.dfg.type_of_value(*array); let upper_bound = self.outer_induction_variables.get(index).map(|bounds| bounds.1); if let (Type::Array(_, len), Some(upper_bound)) = (array_typ, upper_bound) { - upper_bound.to_u128() <= len.into() + upper_bound.apply(|i| i <= len.into(), |i| i <= len.into()) } else { false } @@ -408,7 +409,9 @@ impl<'f> LoopInvariantContext<'f> { // If the instruction were to be hoisted out of a loop that never executes it could potentially cause the program to fail when it is not meant to fail. let bounds = self.current_induction_variables.values().next().copied(); let does_loop_body_execute = bounds - .map(|(lower_bound, upper_bound)| !(upper_bound - lower_bound).is_zero()) + .and_then(|(lower_bound, upper_bound)| { + upper_bound.reduce(lower_bound, |u, l| u > l, |u, l| u > l) + }) .unwrap_or(false); // If we know the loop will be executed these instructions can still only be hoisted if the instructions // are in a non control dependent block. @@ -573,13 +576,13 @@ impl<'f> LoopInvariantContext<'f> { _ => None, }?; - let min_iter = self.inserter.function.dfg.make_constant(*lower, NumericType::length_type()); - assert!(*upper != FieldElement::zero(), "executing a non executable loop"); - let max_iter = self - .inserter - .function - .dfg - .make_constant(*upper - FieldElement::one(), NumericType::length_type()); + assert!(!upper.is_zero(), "executing a non executable loop"); + + let (upper_field, upper_type) = upper.dec().into_numeric_constant(); + let (lower_field, lower_type) = lower.into_numeric_constant(); + + let min_iter = self.inserter.function.dfg.make_constant(lower_field, lower_type); + let max_iter = self.inserter.function.dfg.make_constant(upper_field, upper_type); if (is_left && self.is_loop_invariant(rhs)) || (!is_left && self.is_loop_invariant(lhs)) { return Some((is_left, min_iter, max_iter)); } @@ -633,9 +636,9 @@ impl<'f> LoopInvariantContext<'f> { lhs: &ValueId, rhs: &ValueId, only_outer_induction: bool, - ) -> Option<(bool, FieldElement, FieldElement, FieldElement)> { - let lhs_const = self.inserter.function.dfg.get_numeric_constant_with_type(*lhs); - let rhs_const = self.inserter.function.dfg.get_numeric_constant_with_type(*rhs); + ) -> Option<(bool, IntegerConstant, IntegerConstant, IntegerConstant)> { + let lhs_const = self.inserter.function.dfg.get_integer_constant(*lhs); + let rhs_const = self.inserter.function.dfg.get_integer_constant(*rhs); match ( lhs_const, rhs_const, @@ -648,10 +651,10 @@ impl<'f> LoopInvariantContext<'f> { .and_then(|v| if only_outer_induction { None } else { Some(v) }) .or(self.outer_induction_variables.get(rhs)), ) { - (Some((lhs, _)), None, None, Some((lower_bound, upper_bound))) => { + (Some(lhs), None, None, Some((lower_bound, upper_bound))) => { Some((false, lhs, *lower_bound, *upper_bound)) } - (None, Some((rhs, _)), Some((lower_bound, upper_bound)), None) => { + (None, Some(rhs), Some((lower_bound, upper_bound)), None) => { Some((true, rhs, *lower_bound, *upper_bound)) } _ => None, @@ -704,6 +707,8 @@ impl<'f> LoopInvariantContext<'f> { // of its inputs to check whether it will ever overflow. // If so, this will cause `eval_constant_binary_op` to return `None`. // Therefore a `Some` value shows that this operation is safe. + let lhs = lhs.into_numeric_constant().0; + let rhs = rhs.into_numeric_constant().0; if eval_constant_binary_op(lhs, rhs, binary.operator, operand_type).is_some() { // Unchecked version of the binary operation let unchecked = Instruction::Binary(Binary { @@ -730,7 +735,7 @@ impl<'f> LoopInvariantContext<'f> { true if upper_bound <= value => SimplifyResult::SimplifiedTo(self.true_value), true if lower_bound >= value => SimplifyResult::SimplifiedTo(self.false_value), false if lower_bound > value => SimplifyResult::SimplifiedTo(self.true_value), - false if upper_bound <= value + FieldElement::one() => { + false if upper_bound <= value.inc() => { SimplifyResult::SimplifiedTo(self.false_value) } _ => SimplifyResult::None, @@ -757,10 +762,10 @@ impl<'f> LoopInvariantContext<'f> { return false; }; if left { - if value != FieldElement::zero() { + if !value.is_zero() { return true; } - } else if lower != FieldElement::zero() { + } else if !lower.is_zero() { return true; } diff --git a/compiler/noirc_evaluator/src/ssa/opt/normalize_value_ids.rs b/compiler/noirc_evaluator/src/ssa/opt/normalize_value_ids.rs index 4b3a7a0ad93..66a9e8e0af8 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/normalize_value_ids.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/normalize_value_ids.rs @@ -21,7 +21,7 @@ impl Ssa { /// During normal compilation this is often not the case since prior passes /// may increase the ID counter so that later passes start at different offsets, /// even if they contain the same SSA code. - pub(crate) fn normalize_ids(&mut self) { + pub fn normalize_ids(&mut self) { let mut context = Context::default(); context.populate_functions(&self.functions); for function in self.functions.values_mut() { diff --git a/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs b/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs index f5da6232e0e..200c8a759d5 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs @@ -20,7 +20,7 @@ //! only used by Brillig bytecode. use std::collections::BTreeSet; -use acvm::{FieldElement, acir::AcirField}; +use acvm::acir::AcirField; use im::HashSet; use crate::{ @@ -35,6 +35,7 @@ use crate::{ function::Function, function_inserter::{ArrayCache, FunctionInserter}, instruction::{Binary, BinaryOp, Instruction, InstructionId, TerminatorInstruction}, + integer::IntegerConstant, post_order::PostOrder, value::ValueId, }, @@ -300,9 +301,9 @@ impl Loop { &self, function: &Function, pre_header: BasicBlockId, - ) -> Option { + ) -> Option { let jump_value = get_induction_variable(function, pre_header).ok()?; - function.dfg.get_numeric_constant(jump_value) + function.dfg.get_integer_constant(jump_value) } /// Find the upper bound of the loop in the loop header and return it @@ -319,7 +320,7 @@ impl Loop { /// v5 = lt v1, u32 4 // Upper bound /// jmpif v5 then: b3, else: b2 /// ``` - fn get_const_upper_bound(&self, function: &Function) -> Option { + fn get_const_upper_bound(&self, function: &Function) -> Option { let block = &function.dfg[self.header]; let instructions = block.instructions(); if instructions.is_empty() { @@ -336,14 +337,14 @@ impl Loop { match &function.dfg[instructions[0]] { Instruction::Binary(Binary { lhs: _, operator: BinaryOp::Lt, rhs }) => { - function.dfg.get_numeric_constant(*rhs) + function.dfg.get_integer_constant(*rhs) } Instruction::Binary(Binary { lhs: _, operator: BinaryOp::Eq, rhs }) => { // `for i in 0..1` is turned into: // b1(v0: u32): // v12 = eq v0, u32 0 // jmpif v12 then: b2, else: b3 - function.dfg.get_numeric_constant(*rhs).map(|c| c + FieldElement::one()) + function.dfg.get_integer_constant(*rhs).map(|c| c.inc()) } Instruction::Not(_) => { // We simplify equality operations with booleans like `(boolean == false)` into `!boolean`. @@ -359,7 +360,7 @@ impl Loop { // b1(v0: u1): // v2 = not v0 // jmpif v2 then: b2, else: b3 - Some(true.into()) + Some(IntegerConstant::Unsigned { value: 1, bit_size: 1 }) } other => panic!("Unexpected instruction in header: {other:?}"), } @@ -370,7 +371,7 @@ impl Loop { &self, function: &Function, pre_header: BasicBlockId, - ) -> Option<(FieldElement, FieldElement)> { + ) -> Option<(IntegerConstant, IntegerConstant)> { let lower = self.get_const_lower_bound(function, pre_header)?; let upper = self.get_const_upper_bound(function)?; Some((lower, upper)) @@ -696,21 +697,22 @@ impl Loop { ) -> Option { let pre_header = self.get_pre_header(function, cfg).ok()?; let (lower, upper) = self.get_const_bounds(function, pre_header)?; - let lower = lower.try_to_u64()?; - let upper = upper.try_to_u64()?; let refs = self.find_pre_header_reference_values(function, cfg)?; let (loads, stores) = self.count_loads_and_stores(function, &refs); let increments = self.count_induction_increments(function); let all_instructions = self.count_all_instructions(function); - Some(BoilerplateStats { - iterations: (upper - lower) as usize, - loads, - stores, - increments, - all_instructions, - }) + // Currently we don't iterate in reverse, so if upper <= lower it means 0 iterations. + let iterations: usize = upper + .reduce( + lower, + |u, l| u.saturating_sub(l).max(0) as usize, + |u, l| u.saturating_sub(l) as usize, + ) + .unwrap_or_default(); + + Some(BoilerplateStats { iterations, loads, stores, increments, all_instructions }) } } @@ -1047,11 +1049,11 @@ fn is_new_size_ok(orig_size: usize, new_size: usize, max_incr_pct: i32) -> bool #[cfg(test)] mod tests { - use acvm::FieldElement; use test_case::test_case; use crate::assert_ssa_snapshot; use crate::errors::RuntimeError; + use crate::ssa::ir::integer::IntegerConstant; use crate::ssa::{Ssa, ir::value::ValueId, opt::assert_normalized_ssa_equals}; use super::{BoilerplateStats, Loops, is_new_size_ok}; @@ -1178,8 +1180,8 @@ mod tests { let (lower, upper) = loop_.get_const_bounds(function, pre_header).expect("bounds are numeric const"); - assert_eq!(lower, FieldElement::from(0u32)); - assert_eq!(upper, FieldElement::from(4u32)); + assert_eq!(lower, IntegerConstant::Unsigned { value: 0, bit_size: 32 }); + assert_eq!(upper, IntegerConstant::Unsigned { value: 4, bit_size: 32 }); } #[test] @@ -1215,6 +1217,29 @@ mod tests { assert!(stats.is_small()); } + #[test] + fn test_boilerplate_stats_i64_empty() { + // Looping 0..-1, which should be 0 iterations. + // u64::MAX is how -1 is represented as a Field. + let ssa = brillig_unroll_test_case_6470_with_params("i64", "0", &format!("{}", u64::MAX)); + let stats = loop0_stats(&ssa); + assert_eq!(stats.iterations, 0); + assert_eq!(stats.unrolled_instructions(), 0); + } + + #[test] + fn test_boilerplate_stats_i64_non_empty() { + // Looping -4..-1, which should be 3 iterations. + // u64::MAX-3 is how -4 is represented as a Field. + let ssa = brillig_unroll_test_case_6470_with_params( + "i64", + &format!("{}", u64::MAX - 3), + &format!("{}", u64::MAX), + ); + let stats = loop0_stats(&ssa); + assert_eq!(stats.iterations, 3); + } + #[test] fn test_boilerplate_stats_6470() { let ssa = brillig_unroll_test_case_6470(3); @@ -1411,30 +1436,36 @@ mod tests { /// removing the `unconstrained` from the `main` function and /// compiling the program with `nargo --test-program . compile --show-ssa`. fn brillig_unroll_test_case() -> Ssa { - let src = " + brillig_unroll_test_case_with_params("u32", "0", "4") + } + + fn brillig_unroll_test_case_with_params(idx_type: &str, lower: &str, upper: &str) -> Ssa { + let src = format!( + " // After `static_assert` and `assert_constant`: - brillig(inline) fn main f0 { + brillig(inline) fn main f0 {{ b0(v0: u32): v2 = allocate -> &mut u32 store u32 0 at v2 - jmp b1(u32 0) - b1(v1: u32): - v5 = lt v1, u32 4 + jmp b1({idx_type} {lower}) + b1(v1: {idx_type}): + v5 = lt v1, {idx_type} {upper} jmpif v5 then: b3, else: b2 b3(): v8 = load v2 -> u32 v9 = add v8, v1 store v9 at v2 - v11 = add v1, u32 1 + v11 = add v1, {idx_type} 1 jmp b1(v11) b2(): v6 = load v2 -> u32 v7 = eq v6, v0 constrain v6 == v0 return - } - "; - Ssa::from_str(src).unwrap() + }} + " + ); + Ssa::from_str(&src).unwrap() } /// Test case from #6470: @@ -1451,6 +1482,10 @@ mod tests { /// ``` /// The `num_iterations` parameter can be used to make it more costly to inline. fn brillig_unroll_test_case_6470(num_iterations: usize) -> Ssa { + brillig_unroll_test_case_6470_with_params("u32", "0", &format!("{num_iterations}")) + } + + fn brillig_unroll_test_case_6470_with_params(idx_type: &str, lower: &str, upper: &str) -> Ssa { let src = format!( " // After `static_assert` and `assert_constant`: @@ -1461,18 +1496,18 @@ mod tests { inc_rc v3 v4 = allocate -> &mut [u64; 6] store v3 at v4 - jmp b1(u32 0) - b1(v1: u32): - v7 = lt v1, u32 {num_iterations} + jmp b1({idx_type} {lower}) + b1(v1: {idx_type}): + v7 = lt v1, {idx_type} {upper} jmpif v7 then: b3, else: b2 b3(): v9 = load v4 -> [u64; 6] v10 = array_get v0, index v1 -> u64 v12 = add v10, u64 1 v13 = array_set v9, index v1, value v12 - v15 = add v1, u32 1 + v15 = add v1, {idx_type} 1 store v13 at v4 - v16 = add v1, u32 1 // duplicate + v16 = add v1, {idx_type} 1 // duplicate jmp b1(v16) b2(): v8 = load v4 -> [u64; 6] diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs index 39378d334df..9a10f4e1b5c 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs @@ -45,7 +45,7 @@ pub(crate) const SSA_WORD_SIZE: u32 = 32; /// Generates SSA for the given monomorphized program. /// /// This function will generate the SSA but does not perform any optimizations on it. -pub(crate) fn generate_ssa(program: Program) -> Result { +pub fn generate_ssa(program: Program) -> Result { // see which parameter has call_data/return_data attribute let is_databus = DataBusBuilder::is_databus(&program.main_function_signature); @@ -534,10 +534,11 @@ impl FunctionContext<'_> { self.builder.set_location(for_expr.end_range_location); let end_index = self.codegen_non_tuple_expression(&for_expr.end_range)?; - if let (Some(start_constant), Some(end_constant)) = ( - self.builder.current_function.dfg.get_numeric_constant(start_index), - self.builder.current_function.dfg.get_numeric_constant(end_index), - ) { + let range_bound = |id| self.builder.current_function.dfg.get_integer_constant(id); + + if let (Some(start_constant), Some(end_constant)) = + (range_bound(start_index), range_bound(end_index)) + { // If we can determine that the loop contains zero iterations then there's no need to codegen the loop. if start_constant >= end_constant { return Ok(Self::unit_value()); @@ -625,7 +626,7 @@ impl FunctionContext<'_> { /// jmp while_entry() /// while_entry: /// v0 = ... codegen cond ... - /// jmpif v0, then: while_body, else: while_end + /// jmpif v0, then: while_body, else: while_end /// while_body(): /// v3 = ... codegen body ... /// jmp while_entry() diff --git a/test_programs/execution_success/regression_8009/Nargo.toml b/test_programs/execution_success/regression_8009/Nargo.toml new file mode 100644 index 00000000000..9c1e28f204c --- /dev/null +++ b/test_programs/execution_success/regression_8009/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "regression_8009" +version = "0.1.0" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/regression_8009/Prover.toml b/test_programs/execution_success/regression_8009/Prover.toml new file mode 100644 index 00000000000..35445cec952 --- /dev/null +++ b/test_programs/execution_success/regression_8009/Prover.toml @@ -0,0 +1,3 @@ +start = -51675949543456665 +end = -1 +return = 0 diff --git a/test_programs/execution_success/regression_8009/src/main.nr b/test_programs/execution_success/regression_8009/src/main.nr new file mode 100644 index 00000000000..a412f81fd71 --- /dev/null +++ b/test_programs/execution_success/regression_8009/src/main.nr @@ -0,0 +1,9 @@ +unconstrained fn main(start: i64, end: i64) -> pub u32 { + let start = (start % 5); + let end = (end % 5); + let mut sum = 0; + for i in start..end { + sum += 1; + } + sum +} diff --git a/test_programs/execution_success/regression_8009/stdout.txt b/test_programs/execution_success/regression_8009/stdout.txt new file mode 100644 index 00000000000..4620f639006 --- /dev/null +++ b/test_programs/execution_success/regression_8009/stdout.txt @@ -0,0 +1 @@ +[regression_8009] Circuit output: Field(0) diff --git a/test_programs/execution_success/regression_8011/Nargo.toml b/test_programs/execution_success/regression_8011/Nargo.toml new file mode 100644 index 00000000000..815e4a279bc --- /dev/null +++ b/test_programs/execution_success/regression_8011/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "regression_8011" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/regression_8011/Prover.toml b/test_programs/execution_success/regression_8011/Prover.toml new file mode 100644 index 00000000000..23badac2fd8 --- /dev/null +++ b/test_programs/execution_success/regression_8011/Prover.toml @@ -0,0 +1 @@ +return = 15 diff --git a/test_programs/execution_success/regression_8011/src/main.nr b/test_programs/execution_success/regression_8011/src/main.nr new file mode 100644 index 00000000000..e683b84ecd1 --- /dev/null +++ b/test_programs/execution_success/regression_8011/src/main.nr @@ -0,0 +1,26 @@ +unconstrained fn main() -> pub u32 { + let s1 = loop_with_negative_literal(); + let s2 = loop_with_u128_literal(); + assert_eq(s1, s2); + s1 +} + +fn loop_with_negative_literal() -> u32 { + let s: i64 = -5; + let e: i64 = 10; + let mut sum = 0; + for _ in s..e { + sum += 1; + } + sum +} + +fn loop_with_u128_literal() -> u32 { + let s: u128 = 170141183460469231731687303715884105715; + let e: u128 = 170141183460469231731687303715884105730; + let mut sum = 0; + for _ in s..e { + sum += 1; + } + sum +} diff --git a/test_programs/execution_success/regression_8011/stdout.txt b/test_programs/execution_success/regression_8011/stdout.txt new file mode 100644 index 00000000000..9bbe0c91cde --- /dev/null +++ b/test_programs/execution_success/regression_8011/stdout.txt @@ -0,0 +1 @@ +[regression_8011] Circuit output: Field(15) diff --git a/tooling/ast_fuzzer/Cargo.toml b/tooling/ast_fuzzer/Cargo.toml index 016a2db7302..d2815f7112d 100644 --- a/tooling/ast_fuzzer/Cargo.toml +++ b/tooling/ast_fuzzer/Cargo.toml @@ -32,4 +32,5 @@ noir_fuzzer.workspace = true [dev-dependencies] arbtest.workspace = true +insta.workspace = true rand.workspace = true diff --git a/tooling/ast_fuzzer/src/program/expr.rs b/tooling/ast_fuzzer/src/program/expr.rs index 33b94517009..60a5f0a2a33 100644 --- a/tooling/ast_fuzzer/src/program/expr.rs +++ b/tooling/ast_fuzzer/src/program/expr.rs @@ -141,7 +141,7 @@ pub(crate) fn gen_range( let e = (Field::from(e.unsigned_abs()), e < 0); (s, e) } - _ => unreachable!("invalid bit size for range: {integer_bit_size}"), + _ => unreachable!("invalid bit size for range: {integer_bit_size} (signed)"), } } else { let (s, e) = match integer_bit_size { @@ -173,7 +173,14 @@ pub(crate) fn gen_range( let e = Field::from(e); (s, e) } - _ => unreachable!("invalid bit size for range: {integer_bit_size}"), + HundredTwentyEight => { + let s = u128::arbitrary(u)?; + let e = s.saturating_add(u.choose_index(max_size)? as u128); + let s = Field::from(s); + let e = Field::from(e); + (s, e) + } + _ => unreachable!("invalid bit size for range: {integer_bit_size} (unsigned)"), }; ((s, false), (e, false)) } @@ -222,13 +229,13 @@ pub(crate) fn ident_inner( } } -/// 32-bit unsigned int literal, used in indexing arrays. -fn positive_int_literal(value: V, typ: Type) -> Expression +/// Integer literal, can be positive or negative depending on type. +pub(crate) fn int_literal(value: V, is_negative: bool, typ: Type) -> Expression where FieldElement: From, { Expression::Literal(Literal::Integer( - SignedField { field: FieldElement::from(value), is_negative: false }, + SignedField { field: FieldElement::from(value), is_negative }, typ, Location::dummy(), )) @@ -236,7 +243,7 @@ where /// 32-bit unsigned int literal, used in indexing arrays. pub(crate) fn u32_literal(value: u32) -> Expression { - positive_int_literal(value, types::U32) + int_literal(value, false, types::U32) } /// Create a variable. @@ -287,7 +294,7 @@ pub(crate) fn index_modulo(idx: Expression, len: u32) -> Expression { /// Take an integer expression and make sure it's no larger than `max_size`. pub(crate) fn range_modulo(lhs: Expression, typ: Type, max_size: usize) -> Expression { - modulo(lhs, positive_int_literal(max_size as u64, typ)) + modulo(lhs, int_literal(max_size as u64, false, typ)) } /// Make a modulo expression. diff --git a/tooling/ast_fuzzer/src/program/func.rs b/tooling/ast_fuzzer/src/program/func.rs index 70d4595bc04..4d7b15e2dde 100644 --- a/tooling/ast_fuzzer/src/program/func.rs +++ b/tooling/ast_fuzzer/src/program/func.rs @@ -785,10 +785,16 @@ impl<'a> FunctionContext<'a> { /// Generate a `for` loop. fn gen_for(&mut self, u: &mut Unstructured) -> arbitrary::Result { - // The index can be signed or unsigned int, 8 to 64 bits, + // The index can be signed or unsigned int, 8 to 128 bits, except i128. + let bit_size = + u.choose(&[8, 16, 32, 64, 128]).map(|s| IntegerBitSize::try_from(*s).unwrap())?; let idx_type = Type::Integer( - if bool::arbitrary(u)? { Signedness::Signed } else { Signedness::Unsigned }, - u.choose(&[8, 16, 32, 64]).map(|s| IntegerBitSize::try_from(*s).unwrap())?, + if bit_size == IntegerBitSize::HundredTwentyEight || bool::arbitrary(u)? { + Signedness::Unsigned + } else { + Signedness::Signed + }, + bit_size, ); let (start_range, end_range) = if self.unconstrained() && bool::arbitrary(u)? { diff --git a/tooling/ast_fuzzer/src/program/mod.rs b/tooling/ast_fuzzer/src/program/mod.rs index 8877db80ae5..476911776df 100644 --- a/tooling/ast_fuzzer/src/program/mod.rs +++ b/tooling/ast_fuzzer/src/program/mod.rs @@ -24,6 +24,9 @@ mod scope; mod types; pub(crate) mod visitor; +#[cfg(test)] +mod tests; + /// Generate an arbitrary monomorphized AST. pub fn arb_program(u: &mut Unstructured, config: Config) -> arbitrary::Result { let mut ctx = Context::new(config); @@ -332,17 +335,3 @@ impl std::fmt::Display for DisplayAstAsNoir<'_> { printer.print_program(self.0, f) } } - -#[cfg(test)] -mod tests { - use crate::program::make_name; - - #[test] - fn test_make_name() { - for (i, n) in - [(0, "a"), (1, "b"), (24, "y"), (25, "z"), (26, "ba"), (27, "bb"), (26 * 2 + 3, "cd")] - { - assert_eq!(make_name(i, false), n, "{i} should be {n}"); - } - } -} diff --git a/tooling/ast_fuzzer/src/program/tests.rs b/tooling/ast_fuzzer/src/program/tests.rs new file mode 100644 index 00000000000..d7f1c4dff50 --- /dev/null +++ b/tooling/ast_fuzzer/src/program/tests.rs @@ -0,0 +1,94 @@ +use nargo::errors::Location; +use noirc_evaluator::{assert_ssa_snapshot, ssa::ssa_gen}; +use noirc_frontend::{ + ast::IntegerBitSize, + monomorphization::ast::{ + Expression, For, FuncId, Function, InlineType, LocalId, Program, Type, + }, + shared::Visibility, +}; + +#[test] +fn test_make_name() { + use crate::program::make_name; + + for (i, n) in + [(0, "a"), (1, "b"), (24, "y"), (25, "z"), (26, "ba"), (27, "bb"), (26 * 2 + 3, "cd")] + { + assert_eq!(make_name(i, false), n, "{i} should be {n}"); + } +} + +/// Put a body in a `fn main() { }` and compile it into the initial SSA. +fn generate_ssa_from_body(body: Expression) -> ssa_gen::Ssa { + let func = Function { + id: FuncId(0), + name: "main".to_string(), + parameters: Vec::new(), + body, + return_type: Type::Unit, + unconstrained: false, + inline_type: InlineType::Inline, + func_sig: (Vec::new(), None), + }; + + let sigs = vec![func.func_sig.clone()]; + + let program = Program { + functions: vec![func], + main_function_signature: sigs[0].clone(), + function_signatures: sigs, + return_location: None, + return_visibility: Visibility::Private, + globals: Default::default(), + debug_variables: Default::default(), + debug_functions: Default::default(), + debug_types: Default::default(), + }; + + ssa_gen::generate_ssa(program).unwrap() +} + +/// Test the SSA we get when we use negative range literals with modulo. +#[test] +fn test_modulo_of_negative_literals_in_range() { + use super::expr::{int_literal, range_modulo}; + + let max_size = 5; + let index_type = + Type::Integer(noirc_frontend::shared::Signedness::Signed, IntegerBitSize::SixtyFour); + + let start_range = + range_modulo(int_literal(9u64, true, index_type.clone()), index_type.clone(), max_size); + let end_range = + range_modulo(int_literal(1u64, true, index_type.clone()), index_type.clone(), max_size); + + let body = Expression::For(For { + index_variable: LocalId(0), + index_name: "idx".to_string(), + index_type, + start_range: Box::new(start_range), + end_range: Box::new(end_range), + block: Box::new(Expression::Break), + start_range_location: Location::dummy(), + end_range_location: Location::dummy(), + }); + + let ssa = generate_ssa_from_body(body); + + // The lower bound is -4 (-9 % 5), represented as a field by subtracting it from u64::MAX. + assert_ssa_snapshot!(ssa, @r" + acir(inline) fn main f0 { + b0(): + jmp b1(i64 18446744073709551612) + b1(v0: i64): + v3 = lt v0, i64 18446744073709551615 + jmpif v3 then: b2, else: b3 + b2(): + v5 = unchecked_add v0, i64 1 + jmp b3() + b3(): + return + } + "); +} diff --git a/tooling/nargo_cli/tests/execute.rs b/tooling/nargo_cli/tests/execute.rs index 5a5dc8fbc1a..deb61e99897 100644 --- a/tooling/nargo_cli/tests/execute.rs +++ b/tooling/nargo_cli/tests/execute.rs @@ -160,6 +160,11 @@ mod tests { println!( "stdout does not match expected output. Expected:\n{expected_stdout}\n\nActual:\n{stdout}" ); + if expected_stdout.is_empty() && !stdout_path.exists() { + println!( + "Hint: set the OVERWRITE_TEST_OUTPUT env var to establish a stdout.txt" + ) + } assert_eq!(stdout, expected_stdout); } } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap new file mode 100644 index 00000000000..8ebfeb1d652 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap @@ -0,0 +1,62 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "start", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + }, + { + "name": "end", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1YTU/bQBDdtTd2nDQNbU9V1VNV9VBVsotdh1NbtYA4c0JcsAiRQOI/5KcTw4z8MoyNgHVAiJWsXXuf37z58NiJNTcjWB2W1g6uycGYPzSnjxuZR660T53Wo04LOoNbCxCPa23/kuZEYOr90KPzibDrk3+W5mVi1odn/dsJcPbA/5P5XT/8aUw8/5fr/EbYDQVO3uMAswuYXYGZ0BrrkHl4D+uR7x+uji3TrN+Z5p567IEd5k4En+fa+tVz7rMPLfrrMaY4zIWvWCfOn5aC+See+MvF+uC8DYlvQPzSpszt2378TdnWVPBLmxb0ov6PNEer4xOtub6x500B97kDZxXcpnIyMt05cc8sJw70ov4vEMOvItZjo+fkWwfOKTjWGNF5CBoxn2OBfwMx5OtDWI+ET4z/Dhp+AIfPumjLQyT4pc1I+MjvmgDwkgPxA4UfvxPinvx9aG8KhJ6nfg4C0Iv6C5rr2Je0vqs37XTgAgX32pvu15t+Qwz/ili39aZ/HTin4Dbdm/ZBwwFwvITeZBV+/E5jPu2b1rbM9QiVa7Kv9PVbYEvxw23Gdpa0xNwX/wQ0Mz+/X2qbh8LPxJOOmTiX9WZMUz+oTX77DRW87cCzb9gXY8DguwzxxxCTI1pPFXtcI2PYHyj7mr+h0d/vmr9RCz4W+hl/QnN9fkFrra5jYW8A+rR8cF3ep46uuZYNztfzUs6aP3rCZROH0NweDvYRf07nI/CD58fU+6KsssV2taiKaj7PT6v3gr8eWDu+7edFVZ5WZZbt5NlZnhV32b8C59X6eaUUAAA=", + "debug_symbols": "ldfBisIwEIDhd8m5h6STTNq+yrJI1SiF0kqtC4v47qaiIKWX/yJE5ifiVwpzN8e0v5133XAar6b5uZt+PLRzNw75dH8UZj91fd+dd99fG7t8uOo1f720w3K8zu00myb6wqThaJpKcn3q+mSaYB+/hXE1my8tnHdwvoTzAuc9nA9wXuF8hPPQt4S+An0F+gr0Fegr0Fegr0Bfgb4CfQX6eujroa+Hvh76eujroa+Hvn7T11n3Dpyt1kWFi5oWweLC4aLEheDC4yLgQnGBzQM2D9hcsblic8Xmis0Vmys2V2yu2FyxuWLziM0jNo/YPGLziM3jtnlZfwqx60JxEXFR0aLa/q9C+SlCWBceFwEXiovtZ1f1U0S/KmpH76hLfIfgwuMi4EJxEVnxyKe/durafZ/eK+PpNhy+Nsj5/5JWy+RlGg/peJvSslZ+bZTLO8ZZWzgb8k9x7nXUfKzyPfmuJw==", + "file_map": { + "50": { + "source": "unconstrained fn main(start: i64, end: i64) -> pub u32 {\n let start = (start % 5);\n let end = (end % 5);\n let mut sum = 0;\n for i in start..end {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_false_inliner_0.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_false_inliner_0.snap new file mode 100644 index 00000000000..8ebfeb1d652 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_false_inliner_0.snap @@ -0,0 +1,62 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "start", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + }, + { + "name": "end", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1YTU/bQBDdtTd2nDQNbU9V1VNV9VBVsotdh1NbtYA4c0JcsAiRQOI/5KcTw4z8MoyNgHVAiJWsXXuf37z58NiJNTcjWB2W1g6uycGYPzSnjxuZR660T53Wo04LOoNbCxCPa23/kuZEYOr90KPzibDrk3+W5mVi1odn/dsJcPbA/5P5XT/8aUw8/5fr/EbYDQVO3uMAswuYXYGZ0BrrkHl4D+uR7x+uji3TrN+Z5p567IEd5k4En+fa+tVz7rMPLfrrMaY4zIWvWCfOn5aC+See+MvF+uC8DYlvQPzSpszt2378TdnWVPBLmxb0ov6PNEer4xOtub6x500B97kDZxXcpnIyMt05cc8sJw70ov4vEMOvItZjo+fkWwfOKTjWGNF5CBoxn2OBfwMx5OtDWI+ET4z/Dhp+AIfPumjLQyT4pc1I+MjvmgDwkgPxA4UfvxPinvx9aG8KhJ6nfg4C0Iv6C5rr2Je0vqs37XTgAgX32pvu15t+Qwz/ili39aZ/HTin4Dbdm/ZBwwFwvITeZBV+/E5jPu2b1rbM9QiVa7Kv9PVbYEvxw23Gdpa0xNwX/wQ0Mz+/X2qbh8LPxJOOmTiX9WZMUz+oTX77DRW87cCzb9gXY8DguwzxxxCTI1pPFXtcI2PYHyj7mr+h0d/vmr9RCz4W+hl/QnN9fkFrra5jYW8A+rR8cF3ep46uuZYNztfzUs6aP3rCZROH0NweDvYRf07nI/CD58fU+6KsssV2taiKaj7PT6v3gr8eWDu+7edFVZ5WZZbt5NlZnhV32b8C59X6eaUUAAA=", + "debug_symbols": "ldfBisIwEIDhd8m5h6STTNq+yrJI1SiF0kqtC4v47qaiIKWX/yJE5ifiVwpzN8e0v5133XAar6b5uZt+PLRzNw75dH8UZj91fd+dd99fG7t8uOo1f720w3K8zu00myb6wqThaJpKcn3q+mSaYB+/hXE1my8tnHdwvoTzAuc9nA9wXuF8hPPQt4S+An0F+gr0Fegr0Fegr0Bfgb4CfQX6eujroa+Hvh76eujroa+Hvn7T11n3Dpyt1kWFi5oWweLC4aLEheDC4yLgQnGBzQM2D9hcsblic8Xmis0Vmys2V2yu2FyxuWLziM0jNo/YPGLziM3jtnlZfwqx60JxEXFR0aLa/q9C+SlCWBceFwEXiovtZ1f1U0S/KmpH76hLfIfgwuMi4EJxEVnxyKe/durafZ/eK+PpNhy+Nsj5/5JWy+RlGg/peJvSslZ+bZTLO8ZZWzgb8k9x7nXUfKzyPfmuJw==", + "file_map": { + "50": { + "source": "unconstrained fn main(start: i64, end: i64) -> pub u32 {\n let start = (start % 5);\n let end = (end % 5);\n let mut sum = 0;\n for i in start..end {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_false_inliner_9223372036854775807.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_false_inliner_9223372036854775807.snap new file mode 100644 index 00000000000..8ebfeb1d652 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_false_inliner_9223372036854775807.snap @@ -0,0 +1,62 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "start", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + }, + { + "name": "end", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1YTU/bQBDdtTd2nDQNbU9V1VNV9VBVsotdh1NbtYA4c0JcsAiRQOI/5KcTw4z8MoyNgHVAiJWsXXuf37z58NiJNTcjWB2W1g6uycGYPzSnjxuZR660T53Wo04LOoNbCxCPa23/kuZEYOr90KPzibDrk3+W5mVi1odn/dsJcPbA/5P5XT/8aUw8/5fr/EbYDQVO3uMAswuYXYGZ0BrrkHl4D+uR7x+uji3TrN+Z5p567IEd5k4En+fa+tVz7rMPLfrrMaY4zIWvWCfOn5aC+See+MvF+uC8DYlvQPzSpszt2378TdnWVPBLmxb0ov6PNEer4xOtub6x500B97kDZxXcpnIyMt05cc8sJw70ov4vEMOvItZjo+fkWwfOKTjWGNF5CBoxn2OBfwMx5OtDWI+ET4z/Dhp+AIfPumjLQyT4pc1I+MjvmgDwkgPxA4UfvxPinvx9aG8KhJ6nfg4C0Iv6C5rr2Je0vqs37XTgAgX32pvu15t+Qwz/ili39aZ/HTin4Dbdm/ZBwwFwvITeZBV+/E5jPu2b1rbM9QiVa7Kv9PVbYEvxw23Gdpa0xNwX/wQ0Mz+/X2qbh8LPxJOOmTiX9WZMUz+oTX77DRW87cCzb9gXY8DguwzxxxCTI1pPFXtcI2PYHyj7mr+h0d/vmr9RCz4W+hl/QnN9fkFrra5jYW8A+rR8cF3ep46uuZYNztfzUs6aP3rCZROH0NweDvYRf07nI/CD58fU+6KsssV2taiKaj7PT6v3gr8eWDu+7edFVZ5WZZbt5NlZnhV32b8C59X6eaUUAAA=", + "debug_symbols": "ldfBisIwEIDhd8m5h6STTNq+yrJI1SiF0kqtC4v47qaiIKWX/yJE5ifiVwpzN8e0v5133XAar6b5uZt+PLRzNw75dH8UZj91fd+dd99fG7t8uOo1f720w3K8zu00myb6wqThaJpKcn3q+mSaYB+/hXE1my8tnHdwvoTzAuc9nA9wXuF8hPPQt4S+An0F+gr0Fegr0Fegr0Bfgb4CfQX6eujroa+Hvh76eujroa+Hvn7T11n3Dpyt1kWFi5oWweLC4aLEheDC4yLgQnGBzQM2D9hcsblic8Xmis0Vmys2V2yu2FyxuWLziM0jNo/YPGLziM3jtnlZfwqx60JxEXFR0aLa/q9C+SlCWBceFwEXiovtZ1f1U0S/KmpH76hLfIfgwuMi4EJxEVnxyKe/durafZ/eK+PpNhy+Nsj5/5JWy+RlGg/peJvSslZ+bZTLO8ZZWzgb8k9x7nXUfKzyPfmuJw==", + "file_map": { + "50": { + "source": "unconstrained fn main(start: i64, end: i64) -> pub u32 {\n let start = (start % 5);\n let end = (end % 5);\n let mut sum = 0;\n for i in start..end {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap new file mode 100644 index 00000000000..8ebfeb1d652 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap @@ -0,0 +1,62 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "start", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + }, + { + "name": "end", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1YTU/bQBDdtTd2nDQNbU9V1VNV9VBVsotdh1NbtYA4c0JcsAiRQOI/5KcTw4z8MoyNgHVAiJWsXXuf37z58NiJNTcjWB2W1g6uycGYPzSnjxuZR660T53Wo04LOoNbCxCPa23/kuZEYOr90KPzibDrk3+W5mVi1odn/dsJcPbA/5P5XT/8aUw8/5fr/EbYDQVO3uMAswuYXYGZ0BrrkHl4D+uR7x+uji3TrN+Z5p567IEd5k4En+fa+tVz7rMPLfrrMaY4zIWvWCfOn5aC+See+MvF+uC8DYlvQPzSpszt2378TdnWVPBLmxb0ov6PNEer4xOtub6x500B97kDZxXcpnIyMt05cc8sJw70ov4vEMOvItZjo+fkWwfOKTjWGNF5CBoxn2OBfwMx5OtDWI+ET4z/Dhp+AIfPumjLQyT4pc1I+MjvmgDwkgPxA4UfvxPinvx9aG8KhJ6nfg4C0Iv6C5rr2Je0vqs37XTgAgX32pvu15t+Qwz/ili39aZ/HTin4Dbdm/ZBwwFwvITeZBV+/E5jPu2b1rbM9QiVa7Kv9PVbYEvxw23Gdpa0xNwX/wQ0Mz+/X2qbh8LPxJOOmTiX9WZMUz+oTX77DRW87cCzb9gXY8DguwzxxxCTI1pPFXtcI2PYHyj7mr+h0d/vmr9RCz4W+hl/QnN9fkFrra5jYW8A+rR8cF3ep46uuZYNztfzUs6aP3rCZROH0NweDvYRf07nI/CD58fU+6KsssV2taiKaj7PT6v3gr8eWDu+7edFVZ5WZZbt5NlZnhV32b8C59X6eaUUAAA=", + "debug_symbols": "ldfBisIwEIDhd8m5h6STTNq+yrJI1SiF0kqtC4v47qaiIKWX/yJE5ifiVwpzN8e0v5133XAar6b5uZt+PLRzNw75dH8UZj91fd+dd99fG7t8uOo1f720w3K8zu00myb6wqThaJpKcn3q+mSaYB+/hXE1my8tnHdwvoTzAuc9nA9wXuF8hPPQt4S+An0F+gr0Fegr0Fegr0Bfgb4CfQX6eujroa+Hvh76eujroa+Hvn7T11n3Dpyt1kWFi5oWweLC4aLEheDC4yLgQnGBzQM2D9hcsblic8Xmis0Vmys2V2yu2FyxuWLziM0jNo/YPGLziM3jtnlZfwqx60JxEXFR0aLa/q9C+SlCWBceFwEXiovtZ1f1U0S/KmpH76hLfIfgwuMi4EJxEVnxyKe/durafZ/eK+PpNhy+Nsj5/5JWy+RlGg/peJvSslZ+bZTLO8ZZWzgb8k9x7nXUfKzyPfmuJw==", + "file_map": { + "50": { + "source": "unconstrained fn main(start: i64, end: i64) -> pub u32 {\n let start = (start % 5);\n let end = (end % 5);\n let mut sum = 0;\n for i in start..end {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_true_inliner_0.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_true_inliner_0.snap new file mode 100644 index 00000000000..8ebfeb1d652 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_true_inliner_0.snap @@ -0,0 +1,62 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "start", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + }, + { + "name": "end", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1YTU/bQBDdtTd2nDQNbU9V1VNV9VBVsotdh1NbtYA4c0JcsAiRQOI/5KcTw4z8MoyNgHVAiJWsXXuf37z58NiJNTcjWB2W1g6uycGYPzSnjxuZR660T53Wo04LOoNbCxCPa23/kuZEYOr90KPzibDrk3+W5mVi1odn/dsJcPbA/5P5XT/8aUw8/5fr/EbYDQVO3uMAswuYXYGZ0BrrkHl4D+uR7x+uji3TrN+Z5p567IEd5k4En+fa+tVz7rMPLfrrMaY4zIWvWCfOn5aC+See+MvF+uC8DYlvQPzSpszt2378TdnWVPBLmxb0ov6PNEer4xOtub6x500B97kDZxXcpnIyMt05cc8sJw70ov4vEMOvItZjo+fkWwfOKTjWGNF5CBoxn2OBfwMx5OtDWI+ET4z/Dhp+AIfPumjLQyT4pc1I+MjvmgDwkgPxA4UfvxPinvx9aG8KhJ6nfg4C0Iv6C5rr2Je0vqs37XTgAgX32pvu15t+Qwz/ili39aZ/HTin4Dbdm/ZBwwFwvITeZBV+/E5jPu2b1rbM9QiVa7Kv9PVbYEvxw23Gdpa0xNwX/wQ0Mz+/X2qbh8LPxJOOmTiX9WZMUz+oTX77DRW87cCzb9gXY8DguwzxxxCTI1pPFXtcI2PYHyj7mr+h0d/vmr9RCz4W+hl/QnN9fkFrra5jYW8A+rR8cF3ep46uuZYNztfzUs6aP3rCZROH0NweDvYRf07nI/CD58fU+6KsssV2taiKaj7PT6v3gr8eWDu+7edFVZ5WZZbt5NlZnhV32b8C59X6eaUUAAA=", + "debug_symbols": "ldfBisIwEIDhd8m5h6STTNq+yrJI1SiF0kqtC4v47qaiIKWX/yJE5ifiVwpzN8e0v5133XAar6b5uZt+PLRzNw75dH8UZj91fd+dd99fG7t8uOo1f720w3K8zu00myb6wqThaJpKcn3q+mSaYB+/hXE1my8tnHdwvoTzAuc9nA9wXuF8hPPQt4S+An0F+gr0Fegr0Fegr0Bfgb4CfQX6eujroa+Hvh76eujroa+Hvn7T11n3Dpyt1kWFi5oWweLC4aLEheDC4yLgQnGBzQM2D9hcsblic8Xmis0Vmys2V2yu2FyxuWLziM0jNo/YPGLziM3jtnlZfwqx60JxEXFR0aLa/q9C+SlCWBceFwEXiovtZ1f1U0S/KmpH76hLfIfgwuMi4EJxEVnxyKe/durafZ/eK+PpNhy+Nsj5/5JWy+RlGg/peJvSslZ+bZTLO8ZZWzgb8k9x7nXUfKzyPfmuJw==", + "file_map": { + "50": { + "source": "unconstrained fn main(start: i64, end: i64) -> pub u32 {\n let start = (start % 5);\n let end = (end % 5);\n let mut sum = 0;\n for i in start..end {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_true_inliner_9223372036854775807.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_true_inliner_9223372036854775807.snap new file mode 100644 index 00000000000..8ebfeb1d652 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8009/execute__tests__force_brillig_true_inliner_9223372036854775807.snap @@ -0,0 +1,62 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [ + { + "name": "start", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + }, + { + "name": "end", + "type": { + "kind": "integer", + "sign": "signed", + "width": 64 + }, + "visibility": "private" + } + ], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/+1YTU/bQBDdtTd2nDQNbU9V1VNV9VBVsotdh1NbtYA4c0JcsAiRQOI/5KcTw4z8MoyNgHVAiJWsXXuf37z58NiJNTcjWB2W1g6uycGYPzSnjxuZR660T53Wo04LOoNbCxCPa23/kuZEYOr90KPzibDrk3+W5mVi1odn/dsJcPbA/5P5XT/8aUw8/5fr/EbYDQVO3uMAswuYXYGZ0BrrkHl4D+uR7x+uji3TrN+Z5p567IEd5k4En+fa+tVz7rMPLfrrMaY4zIWvWCfOn5aC+See+MvF+uC8DYlvQPzSpszt2378TdnWVPBLmxb0ov6PNEer4xOtub6x500B97kDZxXcpnIyMt05cc8sJw70ov4vEMOvItZjo+fkWwfOKTjWGNF5CBoxn2OBfwMx5OtDWI+ET4z/Dhp+AIfPumjLQyT4pc1I+MjvmgDwkgPxA4UfvxPinvx9aG8KhJ6nfg4C0Iv6C5rr2Je0vqs37XTgAgX32pvu15t+Qwz/ili39aZ/HTin4Dbdm/ZBwwFwvITeZBV+/E5jPu2b1rbM9QiVa7Kv9PVbYEvxw23Gdpa0xNwX/wQ0Mz+/X2qbh8LPxJOOmTiX9WZMUz+oTX77DRW87cCzb9gXY8DguwzxxxCTI1pPFXtcI2PYHyj7mr+h0d/vmr9RCz4W+hl/QnN9fkFrra5jYW8A+rR8cF3ep46uuZYNztfzUs6aP3rCZROH0NweDvYRf07nI/CD58fU+6KsssV2taiKaj7PT6v3gr8eWDu+7edFVZ5WZZbt5NlZnhV32b8C59X6eaUUAAA=", + "debug_symbols": "ldfBisIwEIDhd8m5h6STTNq+yrJI1SiF0kqtC4v47qaiIKWX/yJE5ifiVwpzN8e0v5133XAar6b5uZt+PLRzNw75dH8UZj91fd+dd99fG7t8uOo1f720w3K8zu00myb6wqThaJpKcn3q+mSaYB+/hXE1my8tnHdwvoTzAuc9nA9wXuF8hPPQt4S+An0F+gr0Fegr0Fegr0Bfgb4CfQX6eujroa+Hvh76eujroa+Hvn7T11n3Dpyt1kWFi5oWweLC4aLEheDC4yLgQnGBzQM2D9hcsblic8Xmis0Vmys2V2yu2FyxuWLziM0jNo/YPGLziM3jtnlZfwqx60JxEXFR0aLa/q9C+SlCWBceFwEXiovtZ1f1U0S/KmpH76hLfIfgwuMi4EJxEVnxyKe/durafZ/eK+PpNhy+Nsj5/5JWy+RlGg/peJvSslZ+bZTLO8ZZWzgb8k9x7nXUfKzyPfmuJw==", + "file_map": { + "50": { + "source": "unconstrained fn main(start: i64, end: i64) -> pub u32 {\n let start = (start % 5);\n let end = (end % 5);\n let mut sum = 0;\n for i in start..end {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap new file mode 100644 index 00000000000..784addfac26 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_false_inliner_-9223372036854775808.snap @@ -0,0 +1,43 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/9VWzU6DQBBeykKLtWmjL6AXve4KFDyYYKwXE+PFg4mntZXn4NGFZDZMxwFaAaNfQnaWnX7zszNDHVHDgVWKfTjiADgt795hDWCdoHO3fDLYq37QAbE7JH+qonXAxDeg/2EAnM44/Mryj5R/NQWex6Lmx7FYu7PyOUXyEuRFy+/H9L282zhAnEPzl9DnDf7b2Co8FKPYVpZ/Mw6/nsM9Xv7CXZUIFyR/GNwcchkdXIvXIC8YPYHOaD1LEu9ItRMtiL0mH9vidVG89ygm0REvvkMPyZhTgtzU7x7Rv4DV5k0SPzPYq544Q7yC2JqLuu9kMbz9JFXK2nWLOg9czUp0jvWvYH/SEEf2Qz/zxOg8NLmJzW4XbQ3NU4UJyhPubVoX1C/K47ZwrxguOwO5nuoV8z4+uNrrw09gLL83Dr/m5pHNlV/xi/08zgbyIyV764MvakjGN2y/eqaMvmzRt7F5SN9HOlN0jvVTlJM1yEvRPKvm6Nxlzrl4XfH9e7Qp+Hh9Rh/zeUT/DtYqH28grxiffOIf9oW7D1uXh9bRX5kBld8Z7LtqNclbEXIz4Bj+tP34hpsBx/B3oHMGPKH3tIc80fx/hvbQC+J8Bvk/9dArrH16iMvXoT1k72Ho73gUm2RrEq1vI/0Z6bjrO/4FDs9oNO0PAAA=", + "debug_symbols": "ldbbioUgFAbgd/G6C11q6n6VYdh0sE0QFR0GhujdR4fdJsSb/yYw/o8FK7V1sNbX++vZj920ssfXwYapqbZ+GsPqOAtWL/0w9K/n/TXj8SHK//w6V2Ncrlu1bOyhecH82LKHsUF3/eDju/O7YMKAeQvmHZYnDuYFmKdc3sl3XgiTAokChQKNghIFBgXZryzkR0iXCocKyWEhUKGyNUhfgrRKhYAFwSLbXTJ0CSNT4VChOSwELLI7nay6hKNUlHANA9ewsHCoKDksBCwIFtnuqo9QVqfCwMKiwqj8DX2dD83T82Hy/yShL0HpLjEOrWE5WsMKWBAsJCwULDQmzrD6qZa+qgf/Hj+6fWxu08j2O/tkMJmXqfHtvvg4otymk9j1cF9LG0eD2FBrC8dDjVDnDw==", + "file_map": { + "50": { + "source": "unconstrained fn main() -> pub u32 {\n let s1 = loop_with_negative_literal();\n let s2 = loop_with_u128_literal();\n assert_eq(s1, s2);\n s1\n}\n\nfn loop_with_negative_literal() -> u32 {\n let s: i64 = -5;\n let e: i64 = 10;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n\nfn loop_with_u128_literal() -> u32 {\n let s: u128 = 170141183460469231731687303715884105715;\n let e: u128 = 170141183460469231731687303715884105730;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_false_inliner_0.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_false_inliner_0.snap new file mode 100644 index 00000000000..321ac2661d5 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_false_inliner_0.snap @@ -0,0 +1,43 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/7VWzU7DMAx21nZrGdMQXDhxReJCw1pauDAJDiDxEmGjz7FHpwVb9Uya/SWWqiTN18/2Fyepgt4UtjFsm4I9TDnefWKbYTti81H7LHGcn2Y6E3598td5UWaW/DzGv8iQU4Xhz4k/kP75BHneNj0/z4X8pu1zzvoz7M8c34eMvV3bImOcvvlb01cD8Xc2RR1emQ4cC7CtI29BxEw2EroFyiu/cORFvmM2F5/gu9m2L+JPPPELM8Q/DqOdJv5JmPg11ZES/IA5XYt1OvMURy3GFEMKvcWW2Lh/Bf19wfGJA0+5JQyfMkzG5jn+mWlyg/05/K9dqnGf+3Of/cO/72Jf4njXOlSN0xa2/XMIf+2efrDV9yH8O8xa36RVt5a37D2fS6CvASViAzZHeM0477A/h+H7TYlxjFyynpTwR/h7bEOf3ZeMF4Qv19kxZflHjvz5fo8s+LHA0/4cD+BToRfhH7Ht5j+wb9tXqfAXsfhs9TBxaGGrM9eZ4dKE4/fRJLbkJDV5wfZQTfjPv+2MdmkydLf8cm16nK8aruq/u6WzaNPrwNcVhP9E4N9xzO8Sns/yyDibyuhmYRpTmvW6WBm51zqjdZgG8F+UplqZSuunQn8Xutzl/wdvYFtnCQ4AAA==", + "debug_symbols": "tdbbaoQwEAbgd8m1FzlNovsqpSwe4hIQFQ+FIr57TVkXSZeCyH8jJMx8gUlMZmGVK+bH3bd1N7Lbx8Karswn37XbaFkTVgy+afzjfpxmPHyE/o0f+7wNw3HKh4ndiCfMtRW72XTLrn3jwtya/AmUpJ6RkvQx9DNhgnC0wdEWRsuLtbZyp62KacLRBkdbGK34NTrVO53JmBbv6GzfdyHs/7Z+2Tql2JZAWwHt7JpNfA8lHv82+mJNSNBuy/iY6Lc1EeqFqyzO0Kcz6HSGOZ0BrD9xXP1JAG3guSEFtDXQJqCdwm5zymC3ucE9FEbgaImjFY7WIHrdRl/54POicc+Wt57b8tABT9+9i5rhfuhKV82DC23xoSMOB8LYxMrQDYYttCqxtK2xrfMD", + "file_map": { + "50": { + "source": "unconstrained fn main() -> pub u32 {\n let s1 = loop_with_negative_literal();\n let s2 = loop_with_u128_literal();\n assert_eq(s1, s2);\n s1\n}\n\nfn loop_with_negative_literal() -> u32 {\n let s: i64 = -5;\n let e: i64 = 10;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n\nfn loop_with_u128_literal() -> u32 {\n let s: u128 = 170141183460469231731687303715884105715;\n let e: u128 = 170141183460469231731687303715884105730;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_false_inliner_9223372036854775807.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_false_inliner_9223372036854775807.snap new file mode 100644 index 00000000000..321ac2661d5 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_false_inliner_9223372036854775807.snap @@ -0,0 +1,43 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/7VWzU7DMAx21nZrGdMQXDhxReJCw1pauDAJDiDxEmGjz7FHpwVb9Uya/SWWqiTN18/2Fyepgt4UtjFsm4I9TDnefWKbYTti81H7LHGcn2Y6E3598td5UWaW/DzGv8iQU4Xhz4k/kP75BHneNj0/z4X8pu1zzvoz7M8c34eMvV3bImOcvvlb01cD8Xc2RR1emQ4cC7CtI29BxEw2EroFyiu/cORFvmM2F5/gu9m2L+JPPPELM8Q/DqOdJv5JmPg11ZES/IA5XYt1OvMURy3GFEMKvcWW2Lh/Bf19wfGJA0+5JQyfMkzG5jn+mWlyg/05/K9dqnGf+3Of/cO/72Jf4njXOlSN0xa2/XMIf+2efrDV9yH8O8xa36RVt5a37D2fS6CvASViAzZHeM0477A/h+H7TYlxjFyynpTwR/h7bEOf3ZeMF4Qv19kxZflHjvz5fo8s+LHA0/4cD+BToRfhH7Ht5j+wb9tXqfAXsfhs9TBxaGGrM9eZ4dKE4/fRJLbkJDV5wfZQTfjPv+2MdmkydLf8cm16nK8aruq/u6WzaNPrwNcVhP9E4N9xzO8Sns/yyDibyuhmYRpTmvW6WBm51zqjdZgG8F+UplqZSuunQn8Xutzl/wdvYFtnCQ4AAA==", + "debug_symbols": "tdbbaoQwEAbgd8m1FzlNovsqpSwe4hIQFQ+FIr57TVkXSZeCyH8jJMx8gUlMZmGVK+bH3bd1N7Lbx8Karswn37XbaFkTVgy+afzjfpxmPHyE/o0f+7wNw3HKh4ndiCfMtRW72XTLrn3jwtya/AmUpJ6RkvQx9DNhgnC0wdEWRsuLtbZyp62KacLRBkdbGK34NTrVO53JmBbv6GzfdyHs/7Z+2Tql2JZAWwHt7JpNfA8lHv82+mJNSNBuy/iY6Lc1EeqFqyzO0Kcz6HSGOZ0BrD9xXP1JAG3guSEFtDXQJqCdwm5zymC3ucE9FEbgaImjFY7WIHrdRl/54POicc+Wt57b8tABT9+9i5rhfuhKV82DC23xoSMOB8LYxMrQDYYttCqxtK2xrfMD", + "file_map": { + "50": { + "source": "unconstrained fn main() -> pub u32 {\n let s1 = loop_with_negative_literal();\n let s2 = loop_with_u128_literal();\n assert_eq(s1, s2);\n s1\n}\n\nfn loop_with_negative_literal() -> u32 {\n let s: i64 = -5;\n let e: i64 = 10;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n\nfn loop_with_u128_literal() -> u32 {\n let s: u128 = 170141183460469231731687303715884105715;\n let e: u128 = 170141183460469231731687303715884105730;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap new file mode 100644 index 00000000000..784addfac26 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_true_inliner_-9223372036854775808.snap @@ -0,0 +1,43 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/9VWzU6DQBBeykKLtWmjL6AXve4KFDyYYKwXE+PFg4mntZXn4NGFZDZMxwFaAaNfQnaWnX7zszNDHVHDgVWKfTjiADgt795hDWCdoHO3fDLYq37QAbE7JH+qonXAxDeg/2EAnM44/Mryj5R/NQWex6Lmx7FYu7PyOUXyEuRFy+/H9L282zhAnEPzl9DnDf7b2Co8FKPYVpZ/Mw6/nsM9Xv7CXZUIFyR/GNwcchkdXIvXIC8YPYHOaD1LEu9ItRMtiL0mH9vidVG89ygm0REvvkMPyZhTgtzU7x7Rv4DV5k0SPzPYq544Q7yC2JqLuu9kMbz9JFXK2nWLOg9czUp0jvWvYH/SEEf2Qz/zxOg8NLmJzW4XbQ3NU4UJyhPubVoX1C/K47ZwrxguOwO5nuoV8z4+uNrrw09gLL83Dr/m5pHNlV/xi/08zgbyIyV764MvakjGN2y/eqaMvmzRt7F5SN9HOlN0jvVTlJM1yEvRPKvm6Nxlzrl4XfH9e7Qp+Hh9Rh/zeUT/DtYqH28grxiffOIf9oW7D1uXh9bRX5kBld8Z7LtqNclbEXIz4Bj+tP34hpsBx/B3oHMGPKH3tIc80fx/hvbQC+J8Bvk/9dArrH16iMvXoT1k72Ho73gUm2RrEq1vI/0Z6bjrO/4FDs9oNO0PAAA=", + "debug_symbols": "ldbbioUgFAbgd/G6C11q6n6VYdh0sE0QFR0GhujdR4fdJsSb/yYw/o8FK7V1sNbX++vZj920ssfXwYapqbZ+GsPqOAtWL/0w9K/n/TXj8SHK//w6V2Ncrlu1bOyhecH82LKHsUF3/eDju/O7YMKAeQvmHZYnDuYFmKdc3sl3XgiTAokChQKNghIFBgXZryzkR0iXCocKyWEhUKGyNUhfgrRKhYAFwSLbXTJ0CSNT4VChOSwELLI7nay6hKNUlHANA9ewsHCoKDksBCwIFtnuqo9QVqfCwMKiwqj8DX2dD83T82Hy/yShL0HpLjEOrWE5WsMKWBAsJCwULDQmzrD6qZa+qgf/Hj+6fWxu08j2O/tkMJmXqfHtvvg4otymk9j1cF9LG0eD2FBrC8dDjVDnDw==", + "file_map": { + "50": { + "source": "unconstrained fn main() -> pub u32 {\n let s1 = loop_with_negative_literal();\n let s2 = loop_with_u128_literal();\n assert_eq(s1, s2);\n s1\n}\n\nfn loop_with_negative_literal() -> u32 {\n let s: i64 = -5;\n let e: i64 = 10;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n\nfn loop_with_u128_literal() -> u32 {\n let s: u128 = 170141183460469231731687303715884105715;\n let e: u128 = 170141183460469231731687303715884105730;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_true_inliner_0.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_true_inliner_0.snap new file mode 100644 index 00000000000..321ac2661d5 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_true_inliner_0.snap @@ -0,0 +1,43 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/7VWzU7DMAx21nZrGdMQXDhxReJCw1pauDAJDiDxEmGjz7FHpwVb9Uya/SWWqiTN18/2Fyepgt4UtjFsm4I9TDnefWKbYTti81H7LHGcn2Y6E3598td5UWaW/DzGv8iQU4Xhz4k/kP75BHneNj0/z4X8pu1zzvoz7M8c34eMvV3bImOcvvlb01cD8Xc2RR1emQ4cC7CtI29BxEw2EroFyiu/cORFvmM2F5/gu9m2L+JPPPELM8Q/DqOdJv5JmPg11ZES/IA5XYt1OvMURy3GFEMKvcWW2Lh/Bf19wfGJA0+5JQyfMkzG5jn+mWlyg/05/K9dqnGf+3Of/cO/72Jf4njXOlSN0xa2/XMIf+2efrDV9yH8O8xa36RVt5a37D2fS6CvASViAzZHeM0477A/h+H7TYlxjFyynpTwR/h7bEOf3ZeMF4Qv19kxZflHjvz5fo8s+LHA0/4cD+BToRfhH7Ht5j+wb9tXqfAXsfhs9TBxaGGrM9eZ4dKE4/fRJLbkJDV5wfZQTfjPv+2MdmkydLf8cm16nK8aruq/u6WzaNPrwNcVhP9E4N9xzO8Sns/yyDibyuhmYRpTmvW6WBm51zqjdZgG8F+UplqZSuunQn8Xutzl/wdvYFtnCQ4AAA==", + "debug_symbols": "tdbbaoQwEAbgd8m1FzlNovsqpSwe4hIQFQ+FIr57TVkXSZeCyH8jJMx8gUlMZmGVK+bH3bd1N7Lbx8Karswn37XbaFkTVgy+afzjfpxmPHyE/o0f+7wNw3HKh4ndiCfMtRW72XTLrn3jwtya/AmUpJ6RkvQx9DNhgnC0wdEWRsuLtbZyp62KacLRBkdbGK34NTrVO53JmBbv6GzfdyHs/7Z+2Tql2JZAWwHt7JpNfA8lHv82+mJNSNBuy/iY6Lc1EeqFqyzO0Kcz6HSGOZ0BrD9xXP1JAG3guSEFtDXQJqCdwm5zymC3ucE9FEbgaImjFY7WIHrdRl/54POicc+Wt57b8tABT9+9i5rhfuhKV82DC23xoSMOB8LYxMrQDYYttCqxtK2xrfMD", + "file_map": { + "50": { + "source": "unconstrained fn main() -> pub u32 {\n let s1 = loop_with_negative_literal();\n let s2 = loop_with_u128_literal();\n assert_eq(s1, s2);\n s1\n}\n\nfn loop_with_negative_literal() -> u32 {\n let s: i64 = -5;\n let e: i64 = 10;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n\nfn loop_with_u128_literal() -> u32 {\n let s: u128 = 170141183460469231731687303715884105715;\n let e: u128 = 170141183460469231731687303715884105730;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +} diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_true_inliner_9223372036854775807.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_true_inliner_9223372036854775807.snap new file mode 100644 index 00000000000..321ac2661d5 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_8011/execute__tests__force_brillig_true_inliner_9223372036854775807.snap @@ -0,0 +1,43 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: artifact +--- +{ + "noir_version": "[noir_version]", + "hash": "[hash]", + "abi": { + "parameters": [], + "return_type": { + "abi_type": { + "kind": "integer", + "sign": "unsigned", + "width": 32 + }, + "visibility": "public" + }, + "error_types": { + "5019202896831570965": { + "error_kind": "string", + "string": "attempt to add with overflow" + }, + "17843811134343075018": { + "error_kind": "string", + "string": "Stack too deep" + } + } + }, + "bytecode": "H4sIAAAAAAAA/7VWzU7DMAx21nZrGdMQXDhxReJCw1pauDAJDiDxEmGjz7FHpwVb9Uya/SWWqiTN18/2Fyepgt4UtjFsm4I9TDnefWKbYTti81H7LHGcn2Y6E3598td5UWaW/DzGv8iQU4Xhz4k/kP75BHneNj0/z4X8pu1zzvoz7M8c34eMvV3bImOcvvlb01cD8Xc2RR1emQ4cC7CtI29BxEw2EroFyiu/cORFvmM2F5/gu9m2L+JPPPELM8Q/DqOdJv5JmPg11ZES/IA5XYt1OvMURy3GFEMKvcWW2Lh/Bf19wfGJA0+5JQyfMkzG5jn+mWlyg/05/K9dqnGf+3Of/cO/72Jf4njXOlSN0xa2/XMIf+2efrDV9yH8O8xa36RVt5a37D2fS6CvASViAzZHeM0477A/h+H7TYlxjFyynpTwR/h7bEOf3ZeMF4Qv19kxZflHjvz5fo8s+LHA0/4cD+BToRfhH7Ht5j+wb9tXqfAXsfhs9TBxaGGrM9eZ4dKE4/fRJLbkJDV5wfZQTfjPv+2MdmkydLf8cm16nK8aruq/u6WzaNPrwNcVhP9E4N9xzO8Sns/yyDibyuhmYRpTmvW6WBm51zqjdZgG8F+UplqZSuunQn8Xutzl/wdvYFtnCQ4AAA==", + "debug_symbols": "tdbbaoQwEAbgd8m1FzlNovsqpSwe4hIQFQ+FIr57TVkXSZeCyH8jJMx8gUlMZmGVK+bH3bd1N7Lbx8Karswn37XbaFkTVgy+afzjfpxmPHyE/o0f+7wNw3HKh4ndiCfMtRW72XTLrn3jwtya/AmUpJ6RkvQx9DNhgnC0wdEWRsuLtbZyp62KacLRBkdbGK34NTrVO53JmBbv6GzfdyHs/7Z+2Tql2JZAWwHt7JpNfA8lHv82+mJNSNBuy/iY6Lc1EeqFqyzO0Kcz6HSGOZ0BrD9xXP1JAG3guSEFtDXQJqCdwm5zymC3ucE9FEbgaImjFY7WIHrdRl/54POicc+Wt57b8tABT9+9i5rhfuhKV82DC23xoSMOB8LYxMrQDYYttCqxtK2xrfMD", + "file_map": { + "50": { + "source": "unconstrained fn main() -> pub u32 {\n let s1 = loop_with_negative_literal();\n let s2 = loop_with_u128_literal();\n assert_eq(s1, s2);\n s1\n}\n\nfn loop_with_negative_literal() -> u32 {\n let s: i64 = -5;\n let e: i64 = 10;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n\nfn loop_with_u128_literal() -> u32 {\n let s: u128 = 170141183460469231731687303715884105715;\n let e: u128 = 170141183460469231731687303715884105730;\n let mut sum = 0;\n for _ in s..e {\n sum += 1;\n }\n sum\n}\n", + "path": "" + } + }, + "names": [ + "main" + ], + "brillig_names": [ + "main" + ] +}