diff --git a/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs b/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs index 490dc9c0ed7..85cb1d8dc66 100644 --- a/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs +++ b/compiler/noirc_frontend/src/hir/comptime/interpreter/builtin.rs @@ -215,6 +215,9 @@ impl Interpreter<'_, '_> { "type_def_add_attribute" => type_def_add_attribute(interner, arguments, location), "type_def_add_generic" => type_def_add_generic(interner, arguments, location), "type_def_as_type" => type_def_as_type(interner, arguments, location), + "type_def_as_type_with_generics" => { + type_def_as_type_with_generics(interner, arguments, return_type, location) + } "type_def_eq" => type_def_eq(arguments, location), "type_def_fields" => type_def_fields(interner, arguments, location, call_stack), "type_def_fields_as_written" => { @@ -474,6 +477,31 @@ fn type_def_as_type( Ok(Value::Type(Type::DataType(type_def_rc, generics))) } +/// `fn as_type_with_generics(self, generics: [Type]) -> Option` +fn type_def_as_type_with_generics( + interner: &NodeInterner, + arguments: Vec<(Value, Location)>, + return_type: Type, + location: Location, +) -> IResult { + let (type_def, generics) = check_two_arguments(arguments, location)?; + let type_id = get_type_id(type_def)?; + let type_def_rc = interner.get_type(type_id); + let type_def = type_def_rc.borrow(); + + let generics_location = generics.1; + let (generics, _) = get_slice(interner, generics)?; + let generics = try_vecmap(generics, |generic| get_type((generic, generics_location)))?; + + let correct_generic_count = type_def.generics.len() == generics.len(); + drop(type_def); + + let type_result = + correct_generic_count.then(|| Value::Type(Type::DataType(type_def_rc, generics))); + + Ok(option(return_type, type_result, location)) +} + /// fn generics(self) -> [(Type, `Option`)] fn type_def_generics( interner: &NodeInterner, diff --git a/compiler/noirc_frontend/src/hir/comptime/value.rs b/compiler/noirc_frontend/src/hir/comptime/value.rs index 1551d6d3862..08065fd613b 100644 --- a/compiler/noirc_frontend/src/hir/comptime/value.rs +++ b/compiler/noirc_frontend/src/hir/comptime/value.rs @@ -367,7 +367,6 @@ impl Value { location: Location, ) -> IResult { let typ = self.get_type().into_owned(); - let expression = match self { Value::Unit => HirExpression::Literal(HirLiteral::Unit), Value::Bool(value) => HirExpression::Literal(HirLiteral::Bool(value)), diff --git a/docs/docs/noir/standard_library/meta/struct_def.md b/docs/docs/noir/standard_library/meta/struct_def.md index 69ec2dac6f1..c9b680f0c78 100644 --- a/docs/docs/noir/standard_library/meta/struct_def.md +++ b/docs/docs/noir/standard_library/meta/struct_def.md @@ -39,6 +39,13 @@ Example: Returns this type definition as a type in the source program. If this definition has any generics, the generics are also included as-is. +### as_type_with_generics + +#include_code as_type_with_generics noir_stdlib/src/meta/type_def.nr rust + +Returns a type from this type definition using the given generic arguments. Returns `Option::none()` +if an incorrect amount of generic arguments are given for this type. + ### generics #include_code generics noir_stdlib/src/meta/type_def.nr rust diff --git a/noir_stdlib/src/meta/type_def.nr b/noir_stdlib/src/meta/type_def.nr index 0cb20407bd2..bdadf3da4b2 100644 --- a/noir_stdlib/src/meta/type_def.nr +++ b/noir_stdlib/src/meta/type_def.nr @@ -12,12 +12,23 @@ impl TypeDefinition { // docs:end:add_generic /// Return a syntactic version of this type definition as a type. - /// For example, `as_type(quote { type Foo { ... } })` would return `Foo` + /// For example, `type Foo { ... })` would return `Foo` when called with this method. #[builtin(type_def_as_type)] // docs:start:as_type pub comptime fn as_type(self) -> Type {} // docs:end:as_type + /// Return this type applied to the given generic arguments. + /// For example, given `type Foo { ... })` could be applied to `&[quote[i32].as_type(), quote[Field].as_type()]` + /// to return `Foo`. + /// + /// If an incorrect number of generic arguments are given, this function will return None. + /// Otherwise, this function returns Some with the resulting type inside. + #[builtin(type_def_as_type_with_generics)] + // docs:start:as_type_with_generics + pub comptime fn as_type_with_generics(self, generics: [Type]) -> Option {} + // docs:end:as_type_with_generics + #[builtin(type_def_has_named_attribute)] // docs:start:has_named_attribute pub comptime fn has_named_attribute(self, name: str) -> bool {} diff --git a/test_programs/compile_success_empty/comptime_struct_definition/src/main.nr b/test_programs/compile_success_empty/comptime_struct_definition/src/main.nr index bc975c90b3f..883a134b976 100644 --- a/test_programs/compile_success_empty/comptime_struct_definition/src/main.nr +++ b/test_programs/compile_success_empty/comptime_struct_definition/src/main.nr @@ -77,5 +77,14 @@ fn main() { assert_eq(visibility1, quote {}); assert_eq(visibility2, quote {}); + + // Test TypeDefinition::as_type_with_generics + let i32_type = quote [i32].as_type(); + + let applied = struct_def.as_type_with_generics(&[i32_type, i32_type, i32_type]); + let invalid = struct_def.as_type_with_generics(&[i32_type, i32_type]); // invalid generic count + + assert_eq(applied.unwrap(), quote [MyType].as_type()); + assert(invalid.is_none()); } } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/arithmetic_generics/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/arithmetic_generics/execute__tests__expanded.snap index 50c3b901872..c0a8e0f5019 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/arithmetic_generics/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/arithmetic_generics/execute__tests__expanded.snap @@ -24,8 +24,8 @@ fn split_first(array: [T; N]) -> (T, [T; N - 1]) { fn push(array: [Field; N], element: Field) -> [Field; N + 1] { let mut result: [Field; N + 1] = std::mem::zeroed(); { - let i_4521: u32 = array.len(); - result[i_4521] = element; + let i_4524: u32 = array.len(); + result[i_4524] = element; }; for i in 0_u32..array.len() { result[i] = array[i]; diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/assign_mutation_in_lvalue/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/assign_mutation_in_lvalue/execute__tests__expanded.snap index e749a2e1d71..e3c0edb531b 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/assign_mutation_in_lvalue/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/assign_mutation_in_lvalue/execute__tests__expanded.snap @@ -10,11 +10,11 @@ fn main() { fn bug() { let mut a: ([Field; 2], Field) = ([1_Field, 2_Field], 3_Field); { - let i_4490: u32 = { + let i_4493: u32 = { a = ([4_Field, 5_Field], 6_Field); 1_u32 }; - a.0[i_4490] = 7_Field; + a.0[i_4493] = 7_Field; }; assert(a == ([4_Field, 7_Field], 6_Field)); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/numeric_generics/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/numeric_generics/execute__tests__expanded.snap index 4d7154ea327..afbd5876496 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/numeric_generics/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/numeric_generics/execute__tests__expanded.snap @@ -27,8 +27,8 @@ impl MyStruct { fn insert(mut self, index: Field, elem: Field) -> Self { assert((index as u64) < (S as u64)); { - let i_4504: u32 = index as u32; - self.data[i_4504] = elem; + let i_4507: u32 = index as u32; + self.data[i_4507] = elem; }; self } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/numeric_generics_explicit/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/numeric_generics_explicit/execute__tests__expanded.snap index eee1f8cc318..2224a10fd65 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/numeric_generics_explicit/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/numeric_generics_explicit/execute__tests__expanded.snap @@ -36,8 +36,8 @@ impl MyStruct { fn insert(mut self, index: Field, elem: Field) -> Self { assert((index as u32) < S); { - let i_4522: u32 = index as u32; - self.data[i_4522] = elem; + let i_4525: u32 = index as u32; + self.data[i_4525] = elem; }; self } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_bignum/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_bignum/execute__tests__expanded.snap index 29f79966808..cccb4b5b044 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_bignum/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_bignum/execute__tests__expanded.snap @@ -53,8 +53,8 @@ unconstrained fn shl(shift: u32) -> [u64; 6] { result[num_shifted_limbs] = 1_u64 << limb_shift; for i in 1_u32..6_u32 - num_shifted_limbs { { - let i_4511: u32 = i + num_shifted_limbs; - result[i_4511] = 0_u64; + let i_4514: u32 = i + num_shifted_limbs; + result[i_4514] = 0_u64; } } result diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/serialize_1/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/serialize_1/execute__tests__expanded.snap index aac4fa2f914..b4e7b24456e 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/serialize_1/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/serialize_1/execute__tests__expanded.snap @@ -25,8 +25,8 @@ where } for i in 0_u32..b.len() { { - let i_4513: u32 = i + a.len(); - array[i_4513] = b[i]; + let i_4516: u32 = i + a.len(); + array[i_4516] = b[i]; } } array diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/serialize_4/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/serialize_4/execute__tests__expanded.snap index 288540bd756..0c1a76b6445 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/serialize_4/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/serialize_4/execute__tests__expanded.snap @@ -25,8 +25,8 @@ where } for i in 0_u32..b.len() { { - let i_4513: u32 = i + a.len(); - array[i_4513] = b[i]; + let i_4516: u32 = i + a.len(); + array[i_4516] = b[i]; } } array diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/ram_blowup_regression/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/ram_blowup_regression/execute__tests__expanded.snap index 7a3d2d3996a..5c6ab0048d9 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/ram_blowup_regression/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/ram_blowup_regression/execute__tests__expanded.snap @@ -29,8 +29,8 @@ fn main(tx_effects_hash_input: [Field; 256]) -> pub Field { let input_as_bytes: [u8; 32] = tx_effects_hash_input[offset].to_be_bytes(); for byte_index in 0_u32..32_u32 { { - let i_4505: u32 = (offset * 32_u32) + byte_index; - hash_input_flattened[i_4505] = input_as_bytes[byte_index]; + let i_4508: u32 = (offset * 32_u32) + byte_index; + hash_input_flattened[i_4508] = input_as_bytes[byte_index]; } } } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/aes128_encrypt/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/aes128_encrypt/execute__tests__expanded.snap index b740e3fa500..74c2289c1e9 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/aes128_encrypt/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/aes128_encrypt/execute__tests__expanded.snap @@ -18,8 +18,8 @@ unconstrained fn decode_hex(s: str) -> [u8; M] { for i in 0_u32..N { if (i % 2_u32) != 0_u32 { continue; }; { - let i_4505: u32 = i / 2_u32; - result[i_4505] = + let i_4508: u32 = i / 2_u32; + result[i_4508] = (decode_ascii(as_bytes[i]) * 16_u8) + decode_ascii(as_bytes[i + 1_u32]); } } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/array_dedup_regression/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/array_dedup_regression/execute__tests__expanded.snap index 9f6a3be8e59..4c917f022d5 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/array_dedup_regression/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/array_dedup_regression/execute__tests__expanded.snap @@ -7,8 +7,8 @@ unconstrained fn main(x: u32) { for i in 0_u32..5_u32 { let mut a2: [Field; 5] = [1_Field, 2_Field, 3_Field, 4_Field, 5_Field]; { - let i_4492: u32 = x + i; - a2[i_4492] = 128_Field; + let i_4495: u32 = x + i; + a2[i_4495] = 128_Field; }; println(a2); if i != 0_u32 { diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/array_dynamic_blackbox_input/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/array_dynamic_blackbox_input/execute__tests__expanded.snap index 29cd7003cf4..94e3d69acc7 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/array_dynamic_blackbox_input/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/array_dynamic_blackbox_input/execute__tests__expanded.snap @@ -17,12 +17,12 @@ fn compute_root(leaf: [u8; 32], path: [u8; 64], _index: u32, root: [u8; 32]) { let b: u32 = if is_right { 0_u32 } else { 32_u32 }; for j in 0_u32..32_u32 { { - let i_4506: u32 = j + a; - hash_input[i_4506] = current[j]; + let i_4509: u32 = j + a; + hash_input[i_4509] = current[j]; }; { - let i_4507: u32 = j + b; - hash_input[i_4507] = path[offset + j]; + let i_4510: u32 = j + b; + hash_input[i_4510] = path[offset + j]; } } current = std::hash::blake3(hash_input); diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/array_dynamic_nested_blackbox_input/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/array_dynamic_nested_blackbox_input/execute__tests__expanded.snap index acd105b33c6..1ceb95fe299 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/array_dynamic_nested_blackbox_input/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/array_dynamic_nested_blackbox_input/execute__tests__expanded.snap @@ -14,13 +14,13 @@ struct Foo { fn main(mut x: [Foo; 3], y: pub u32, hash_result: pub [u8; 32]) { { - let i_4491: u32 = y - 1_u32; - x[i_4491].bar.inner = [106_u8, 107_u8, 10_u8]; + let i_4494: u32 = y - 1_u32; + x[i_4494].bar.inner = [106_u8, 107_u8, 10_u8]; }; let mut hash_input: [u8; 3] = x[y - 1_u32].bar.inner; { - let i_4493: u32 = y - 1_u32; - hash_input[i_4493] = 0_u8; + let i_4496: u32 = y - 1_u32; + hash_input[i_4496] = 0_u8; }; let hash: [u8; 32] = std::hash::blake3(hash_input); assert(hash == hash_result); diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/brillig_cow/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/brillig_cow/execute__tests__expanded.snap index 7ef05e00dfe..133fac96b30 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/brillig_cow/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/brillig_cow/execute__tests__expanded.snap @@ -22,8 +22,8 @@ fn modify_in_inlined_constrained(original: [Field; 5], index: u32) -> ExecutionR modified[index] = 27_Field; let modified_once: [Field; 5] = modified; { - let i_4503: u32 = index + 1_u32; - modified[i_4503] = 27_Field; + let i_4506: u32 = index + 1_u32; + modified[i_4506] = 27_Field; }; ExecutionResult { original: original, modified_once: modified_once, modified_twice: modified } } @@ -33,8 +33,8 @@ unconstrained fn modify_in_unconstrained(original: [Field; 5], index: u32) -> Ex modified[index] = 27_Field; let modified_once: [Field; 5] = modified; { - let i_4506: u32 = index + 1_u32; - modified[i_4506] = 27_Field; + let i_4509: u32 = index + 1_u32; + modified[i_4509] = 27_Field; }; ExecutionResult { original: original, modified_once: modified_once, modified_twice: modified } } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/brillig_cow_regression/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/brillig_cow_regression/execute__tests__expanded.snap index e23e7e7db69..d767286a359 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/brillig_cow_regression/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/brillig_cow_regression/execute__tests__expanded.snap @@ -155,33 +155,33 @@ unconstrained fn main(kernel_data: DataToHash) -> pub [Field; 2] { let mut offset: u32 = 0_u32; for j in 0_u32..MAX_NOTE_HASHES_PER_TX { { - let i_4515: u32 = offset + j; - tx_effects_hash_inputs[i_4515] = new_note_hashes[j]; + let i_4518: u32 = offset + j; + tx_effects_hash_inputs[i_4518] = new_note_hashes[j]; } } offset = offset + MAX_NOTE_HASHES_PER_TX; for j in 0_u32..MAX_NULLIFIERS_PER_TX { { - let i_4517: u32 = offset + j; - tx_effects_hash_inputs[i_4517] = new_nullifiers[j]; + let i_4520: u32 = offset + j; + tx_effects_hash_inputs[i_4520] = new_nullifiers[j]; } } offset = offset + MAX_NULLIFIERS_PER_TX; for j in 0_u32..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX { { - let i_4519: u32 = offset + (j * 2_u32); - tx_effects_hash_inputs[i_4519] = public_data_update_requests[j].leaf_slot; + let i_4522: u32 = offset + (j * 2_u32); + tx_effects_hash_inputs[i_4522] = public_data_update_requests[j].leaf_slot; }; { - let i_4520: u32 = (offset + (j * 2_u32)) + 1_u32; - tx_effects_hash_inputs[i_4520] = public_data_update_requests[j].new_value; + let i_4523: u32 = (offset + (j * 2_u32)) + 1_u32; + tx_effects_hash_inputs[i_4523] = public_data_update_requests[j].new_value; } } offset = offset + (MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * 2_u32); for j in 0_u32..MAX_L2_TO_L1_MSGS_PER_TX { { - let i_4522: u32 = offset + j; - tx_effects_hash_inputs[i_4522] = l2ToL1Msgs[j]; + let i_4525: u32 = offset + j; + tx_effects_hash_inputs[i_4525] = l2ToL1Msgs[j]; } } offset = offset + MAX_L2_TO_L1_MSGS_PER_TX; @@ -191,21 +191,21 @@ unconstrained fn main(kernel_data: DataToHash) -> pub [Field; 2] { let new_contracts: [NewContractData; 1] = kernel_data.new_contracts; tx_effects_hash_inputs[offset] = new_contracts[0_u32].contract_address; { - let i_4525: u32 = offset + 1_u32; - tx_effects_hash_inputs[i_4525] = new_contracts[0_u32].portal_contract_address; + let i_4528: u32 = offset + 1_u32; + tx_effects_hash_inputs[i_4528] = new_contracts[0_u32].portal_contract_address; }; offset = offset + (MAX_NEW_CONTRACTS_PER_TX * 2_u32); for j in 0_u32..NUM_FIELDS_PER_SHA256 { { - let i_4527: u32 = offset + j; - tx_effects_hash_inputs[i_4527] = encryptedLogsHash[j]; + let i_4530: u32 = offset + j; + tx_effects_hash_inputs[i_4530] = encryptedLogsHash[j]; } } offset = offset + (NUM_ENCRYPTED_LOGS_HASHES_PER_TX * NUM_FIELDS_PER_SHA256); for j in 0_u32..NUM_FIELDS_PER_SHA256 { { - let i_4529: u32 = offset + j; - tx_effects_hash_inputs[i_4529] = unencryptedLogsHash[j]; + let i_4532: u32 = offset + j; + tx_effects_hash_inputs[i_4532] = unencryptedLogsHash[j]; } } offset = offset + (NUM_UNENCRYPTED_LOGS_HASHES_PER_TX * NUM_FIELDS_PER_SHA256); @@ -215,8 +215,8 @@ unconstrained fn main(kernel_data: DataToHash) -> pub [Field; 2] { let input_as_bytes: [u8; 32] = tx_effects_hash_inputs[offset].to_be_bytes(); for byte_index in 0_u32..32_u32 { { - let i_4534: u32 = (offset * 32_u32) + byte_index; - hash_input_flattened[i_4534] = input_as_bytes[byte_index]; + let i_4537: u32 = (offset * 32_u32) + byte_index; + hash_input_flattened[i_4537] = input_as_bytes[byte_index]; } } } @@ -225,11 +225,11 @@ unconstrained fn main(kernel_data: DataToHash) -> pub [Field; 2] { tx_effects_hash_inputs[TX_EFFECT_HASH_FULL_FIELDS + log_field_index].to_be_bytes(); for byte_index in 0_u32..16_u32 { { - let i_4538: u32 = ( + let i_4541: u32 = ( (TX_EFFECT_HASH_FULL_FIELDS * 32_u32) + (log_field_index * 16_u32) ) + byte_index; - hash_input_flattened[i_4538] = input_as_bytes[byte_index]; + hash_input_flattened[i_4541] = input_as_bytes[byte_index]; } } } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/conditional_1/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/conditional_1/execute__tests__expanded.snap index 3bc6ba4c5f5..8b17ca30e85 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/conditional_1/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/conditional_1/execute__tests__expanded.snap @@ -27,8 +27,8 @@ fn main(a: u32, mut c: [u32; 4], x: [u8; 5], result: pub [u8; 32]) { if i_u32 == a { for j in 0_u32..4_u32 { { - let i_4504: u32 = i + j; - data[i_4504] = c[(4_u32 - 1_u32) - j]; + let i_4507: u32 = i + j; + data[i_4507] = c[(4_u32 - 1_u32) - j]; }; for k in 0_u32..4_u32 { ba = ba + data[k]; diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/databus_two_calldata/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/databus_two_calldata/execute__tests__expanded.snap index 5f89e87ad5e..f6a67456f09 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/databus_two_calldata/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/databus_two_calldata/execute__tests__expanded.snap @@ -9,8 +9,8 @@ fn main(mut x: [u32; 4], y: [u32; 3], z: [u32; 4]) -> return_data [u32; 4] { result[idx] = y[idx] + z[idx]; } { - let i_4494: u32 = x[3_u32]; - result[i_4494] = z[x[3_u32]]; + let i_4497: u32 = x[3_u32]; + result[i_4497] = z[x[3_u32]]; }; result } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/encrypted_log_regression/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/encrypted_log_regression/execute__tests__expanded.snap index 44f6c4b8084..1afaadb67da 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/encrypted_log_regression/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/encrypted_log_regression/execute__tests__expanded.snap @@ -39,15 +39,15 @@ fn compute_encrypted_log( if flag { for i in 0_u32..EPH_PK_SIZE { { - let i_4507: u32 = offset + i; - encrypted_bytes[i_4507] = eph_pk_bytes[i]; + let i_4510: u32 = offset + i; + encrypted_bytes[i_4510] = eph_pk_bytes[i]; } } offset = offset + EPH_PK_SIZE; for i in 0_u32..HEADER_SIZE { { - let i_4509: u32 = offset + i; - encrypted_bytes[i_4509] = incoming_header_ciphertext[i]; + let i_4512: u32 = offset + i; + encrypted_bytes[i_4512] = incoming_header_ciphertext[i]; } } offset = offset + HEADER_SIZE; @@ -56,8 +56,8 @@ fn compute_encrypted_log( assert(size == incoming_body_ciphertext.len(), "ciphertext length mismatch"); for i in 0_u32..size { { - let i_4512: u32 = offset + i; - encrypted_bytes[i_4512] = incoming_body_ciphertext[i]; + let i_4515: u32 = offset + i; + encrypted_bytes[i_4515] = incoming_body_ciphertext[i]; } } }; diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/nested_array_dynamic/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/nested_array_dynamic/execute__tests__expanded.snap index a6da2620a58..7253980977c 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/nested_array_dynamic/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/nested_array_dynamic/execute__tests__expanded.snap @@ -35,13 +35,13 @@ fn main(mut x: [Foo; 4], y: pub u32) { assert(x[3_u32].a == 50_Field); if y == 2_u32 { { - let i_4490: u32 = y - 1_u32; - x[i_4490].b = [50_Field, 51_Field, 52_Field]; + let i_4493: u32 = y - 1_u32; + x[i_4493].b = [50_Field, 51_Field, 52_Field]; } } else { { - let i_4491: u32 = y - 1_u32; - x[i_4491].b = [100_Field, 101_Field, 102_Field]; + let i_4494: u32 = y - 1_u32; + x[i_4494].b = [100_Field, 101_Field, 102_Field]; } }; assert(x[2_u32].b == [100_Field, 101_Field, 102_Field]); @@ -60,39 +60,39 @@ fn main(mut x: [Foo; 4], y: pub u32) { assert(foo_parents[1_u32].foos[1_u32].b == [5_Field, 6_Field, 21_Field]); if y == 2_u32 { { - let i_4495: u32 = y - 2_u32; - let i_4496: u32 = y - 2_u32; - foo_parents[i_4495].foos[i_4496].b = [10_Field, 9_Field, 8_Field]; + let i_4498: u32 = y - 2_u32; + let i_4499: u32 = y - 2_u32; + foo_parents[i_4498].foos[i_4499].b = [10_Field, 9_Field, 8_Field]; } } else { { - let i_4497: u32 = y - 2_u32; - let i_4498: u32 = y - 2_u32; - foo_parents[i_4497].foos[i_4498].b = [20_Field, 19_Field, 18_Field]; + let i_4500: u32 = y - 2_u32; + let i_4501: u32 = y - 2_u32; + foo_parents[i_4500].foos[i_4501].b = [20_Field, 19_Field, 18_Field]; } }; assert(foo_parents[1_u32].foos[1_u32].b == [20_Field, 19_Field, 18_Field]); assert(foo_parents[1_u32].foos[1_u32].b[2_u32] == 18_Field); if y == 3_u32 { - { - let i_4499: u32 = y - 2_u32; - let i_4500: u32 = y - 2_u32; - let i_4501: u32 = y - 1_u32; - foo_parents[i_4499].foos[i_4500].b[i_4501] = 5000_Field; - } - } else { { let i_4502: u32 = y - 2_u32; let i_4503: u32 = y - 2_u32; let i_4504: u32 = y - 1_u32; - foo_parents[i_4502].foos[i_4503].b[i_4504] = 1000_Field; + foo_parents[i_4502].foos[i_4503].b[i_4504] = 5000_Field; + } + } else { + { + let i_4505: u32 = y - 2_u32; + let i_4506: u32 = y - 2_u32; + let i_4507: u32 = y - 1_u32; + foo_parents[i_4505].foos[i_4506].b[i_4507] = 1000_Field; } }; assert(foo_parents[1_u32].foos[1_u32].b[2_u32] == 5000_Field); { - let i_4505: u32 = y - 2_u32; - let i_4506: u32 = y - 3_u32; - foo_parents[i_4505].foos[i_4506].b = foo_parents[y - 2_u32].foos[y - 2_u32].b; + let i_4508: u32 = y - 2_u32; + let i_4509: u32 = y - 3_u32; + foo_parents[i_4508].foos[i_4509].b = foo_parents[y - 2_u32].foos[y - 2_u32].b; }; assert(foo_parents[1_u32].foos[0_u32].b == [20_Field, 19_Field, 5000_Field]); } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/nested_array_in_slice/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/nested_array_in_slice/execute__tests__expanded.snap index 74a453746ee..0c0e2698457 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/nested_array_in_slice/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/nested_array_in_slice/execute__tests__expanded.snap @@ -48,25 +48,25 @@ fn main(y: u32) { assert(x[y].bar.inner == [109_Field, 110_Field, 111_Field]); if y != 2_u32 { { - let i_4494: u32 = y - 2_u32; - x[i_4494].a = 50_Field; + let i_4497: u32 = y - 2_u32; + x[i_4497].a = 50_Field; } } else { { - let i_4495: u32 = y - 2_u32; - x[i_4495].a = 100_Field; + let i_4498: u32 = y - 2_u32; + x[i_4498].a = 100_Field; } }; assert(x[y - 2_u32].a == 50_Field); if y == 2_u32 { { - let i_4496: u32 = y - 1_u32; - x[i_4496].b = [50_Field, 51_Field, 52_Field]; + let i_4499: u32 = y - 1_u32; + x[i_4499].b = [50_Field, 51_Field, 52_Field]; } } else { { - let i_4497: u32 = y - 1_u32; - x[i_4497].b = [100_Field, 101_Field, 102_Field]; + let i_4500: u32 = y - 1_u32; + x[i_4500].b = [100_Field, 101_Field, 102_Field]; } }; assert(x[2_u32].b == [100_Field, 101_Field, 102_Field]); diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_1144_1169_2399_6609/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_1144_1169_2399_6609/execute__tests__expanded.snap index cede3fd9a45..7c5a5aede8a 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/regression_1144_1169_2399_6609/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_1144_1169_2399_6609/execute__tests__expanded.snap @@ -36,12 +36,12 @@ fn compact_decode(input: [u8; N], length: Field) -> ([U4; 16], Field if (i as u32) < (length as u32) { let x: u8 = input[i]; { - let i_4516: u32 = (2_u32 * i) - 1_u32; - nibble[i_4516] = U4::from_u8(x >> 4_u8); + let i_4519: u32 = (2_u32 * i) - 1_u32; + nibble[i_4519] = U4::from_u8(x >> 4_u8); }; { - let i_4517: u32 = 2_u32 * i; - nibble[i_4517] = U4::from_u8(x & 15_u8); + let i_4520: u32 = 2_u32 * i; + nibble[i_4520] = U4::from_u8(x & 15_u8); } } } @@ -50,12 +50,12 @@ fn compact_decode(input: [u8; N], length: Field) -> ([U4; 16], Field if (i as u32) < ((length as u32) - 1_u32) { let x: u8 = input[i + 1_u32]; { - let i_4520: u32 = 2_u32 * i; - nibble[i_4520] = U4::from_u8(x >> 4_u8); + let i_4523: u32 = 2_u32 * i; + nibble[i_4523] = U4::from_u8(x >> 4_u8); }; { - let i_4521: u32 = (2_u32 * i) + 1_u32; - nibble[i_4521] = U4::from_u8(x & 15_u8); + let i_4524: u32 = (2_u32 * i) + 1_u32; + nibble[i_4524] = U4::from_u8(x & 15_u8); } } } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_1/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_1/execute__tests__expanded.snap index 2ebc7f2bdba..45312288b72 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_1/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_1/execute__tests__expanded.snap @@ -16,8 +16,8 @@ impl BoundedVec4 { pub fn push(&mut self, elem: Field) { { - let i_4510: u32 = self.len; - self.storage[i_4510] = elem; + let i_4513: u32 = self.len; + self.storage[i_4513] = elem; }; self.len = self.len + 1_u32; } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_2/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_2/execute__tests__expanded.snap index f65b333600d..cf3253b6bf3 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_2/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_2/execute__tests__expanded.snap @@ -16,8 +16,8 @@ impl BoundedVec4 { pub fn push(&mut self, elem: Field) { { - let i_4510: u32 = self.len; - self.storage[i_4510] = elem; + let i_4513: u32 = self.len; + self.storage[i_4513] = elem; }; self.len = self.len + 1_u32; } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_capacity_tracker/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_capacity_tracker/execute__tests__expanded.snap index 9babc53101e..e35e4b5954f 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/regression_capacity_tracker/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_capacity_tracker/execute__tests__expanded.snap @@ -8,13 +8,13 @@ fn main(expected: pub Field, first: Field, input: [Field; 20]) { assert(hasher_slice[0_u32] == expected); if (expected as u32) > 10_u32 { { - let i_4492: u32 = (expected - 10_Field) as u32; - hasher_slice[i_4492] = 100_Field; + let i_4495: u32 = (expected - 10_Field) as u32; + hasher_slice[i_4495] = 100_Field; } } else { { - let i_4493: u32 = expected as u32; - hasher_slice[i_4493] = 100_Field; + let i_4496: u32 = expected as u32; + hasher_slice[i_4496] = 100_Field; } }; assert(hasher_slice[0_u32] == expected); diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/slice_dynamic_index/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/slice_dynamic_index/execute__tests__expanded.snap index 6f8e8df7c63..3eff010af53 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/slice_dynamic_index/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/slice_dynamic_index/execute__tests__expanded.snap @@ -36,8 +36,8 @@ fn dynamic_slice_index_set_if(mut slice: [Field], x: u32, y: u32) { assert(slice[x] == 4_Field); slice[x] = slice[x] - 2_Field; { - let i_4536: u32 = x - 1_u32; - slice[i_4536] = slice[x]; + let i_4539: u32 = x - 1_u32; + slice[i_4539] = slice[x]; } } else { slice[x] = 0_Field; @@ -56,8 +56,8 @@ fn dynamic_slice_index_set_else(mut slice: [Field], x: u32, y: u32) { assert(slice[x] == 4_Field); slice[x] = slice[x] - 2_Field; { - let i_4537: u32 = x - 1_u32; - slice[i_4537] = slice[x]; + let i_4540: u32 = x - 1_u32; + slice[i_4540] = slice[x]; } } else { slice[x] = 0_Field; diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/slice_dynamic_insert/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/slice_dynamic_insert/execute__tests__expanded.snap index 713a35d08c1..81d11e8a19c 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/slice_dynamic_insert/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/slice_dynamic_insert/execute__tests__expanded.snap @@ -21,8 +21,8 @@ fn insert(x: u32, array: [Field; 5]) { fn insert_dynamic_array(x: u32, array: [Field; 5]) { let mut value_to_insert: [Field; 5] = array; { - let i_4500: u32 = x - 1_u32; - value_to_insert[i_4500] = 10_Field; + let i_4503: u32 = x - 1_u32; + value_to_insert[i_4503] = 10_Field; }; let mut slice: [[Field; 5]] = &[array, array, array]; slice = slice.insert(x - 3_u32, value_to_insert);