From ae84c24cda68e967222848e97c980036c22d040e Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:07:05 +0000 Subject: [PATCH 01/14] chore: sync changes from aztec-packages --- .aztec-sync-commit | 2 +- Cargo.lock | 12 +- Cargo.toml | 1 - ...te_note_hash_and_optionally_a_nullifier.rs | 8 +- .../src/transforms/contract_interface.rs | 16 +-- aztec_macros/src/transforms/note_interface.rs | 14 +-- aztec_macros/src/utils/ast_utils.rs | 2 +- .../src/hir/resolution/import.rs | 52 ++------ docs/docs/how_to/how-to-oracles.md | 8 +- .../bench_eddsa_poseidon/src/main.nr | 4 +- .../bench_poseidon_hash_100/src/main.nr | 2 +- .../bench_poseidon_hash_30/src/main.nr | 2 +- .../benchmarks/bench_sha256/src/main.nr | 1 - .../benchmarks/bench_sha256_100/src/main.nr | 3 +- .../benchmarks/bench_sha256_30/src/main.nr | 3 +- .../negate_unsigned/src/main.nr | 1 + .../non_comptime_local_fn_call/Nargo.toml | 7 -- .../non_comptime_local_fn_call/src/main.nr | 9 -- .../orphaned_trait_impl/src/main.nr | 2 +- .../restricted_bit_sizes/src/main.nr | 2 - .../turbofish_generic_count/src/main.nr | 1 + .../abi_attribute/Nargo.toml | 6 - .../abi_attribute/src/main.nr | 9 -- .../impl_where_clause/Nargo.toml | 7 -- .../impl_where_clause/src/main.nr | 34 ------ .../Nargo.toml | 2 +- .../src/main.nr | 0 .../intrinsic_die/src/main.nr | 1 + .../numeric_generics/src/main.nr | 1 + .../numeric_generics_explicit/Nargo.toml | 7 -- .../numeric_generics_explicit/src/main.nr | 111 ------------------ .../reexports/src/main.nr | 2 +- .../regression_4635/src/main.nr | 2 +- .../trait_generics/src/main.nr | 2 +- .../workspace_reexport_bug/binary/src/main.nr | 2 +- .../workspace_reexport_bug/library/src/lib.nr | 2 +- .../div_by_zero_numerator_witness/src/main.nr | 1 + .../diamond_deps_0/src/main.nr | 6 +- .../execution_success/hashmap/src/main.nr | 1 - .../regression_4088/src/main.nr | 4 +- .../regression_4124/src/main.nr | 4 +- .../execution_success/slices/src/main.nr | 8 -- .../traits_in_crates_1/crate1/src/lib.nr | 2 +- .../traits_in_crates_1/src/main.nr | 2 +- .../traits_in_crates_2/crate2/src/lib.nr | 2 +- .../traits_in_crates_2/src/main.nr | 2 +- .../should_fail_mismatch/src/main.nr | 17 ++- .../test_libraries/diamond_deps_1/src/lib.nr | 2 +- .../test_libraries/reexporting_lib/src/lib.nr | 4 +- tooling/acvm_cli/Cargo.toml | 2 +- tooling/nargo_cli/Cargo.toml | 9 +- tooling/nargo_fmt/tests/expected/contract.nr | 4 +- tooling/nargo_fmt/tests/expected/fn.nr | 4 - tooling/nargo_fmt/tests/expected/impl.nr | 6 - tooling/nargo_fmt/tests/expected/let.nr | 8 +- tooling/nargo_fmt/tests/input/contract.nr | 4 +- tooling/nargo_fmt/tests/input/fn.nr | 5 - tooling/nargo_fmt/tests/input/impl.nr | 6 - tooling/nargo_fmt/tests/input/let.nr | 8 +- 59 files changed, 100 insertions(+), 351 deletions(-) delete mode 100644 test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml delete mode 100644 test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr delete mode 100644 test_programs/compile_success_contract/abi_attribute/Nargo.toml delete mode 100644 test_programs/compile_success_contract/abi_attribute/src/main.nr delete mode 100644 test_programs/compile_success_empty/impl_where_clause/Nargo.toml delete mode 100644 test_programs/compile_success_empty/impl_where_clause/src/main.nr rename test_programs/compile_success_empty/{trait_impl_with_where_clause => impl_with_where_clause}/Nargo.toml (58%) rename test_programs/compile_success_empty/{trait_impl_with_where_clause => impl_with_where_clause}/src/main.nr (100%) delete mode 100644 test_programs/compile_success_empty/numeric_generics_explicit/Nargo.toml delete mode 100644 test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr diff --git a/.aztec-sync-commit b/.aztec-sync-commit index d1e571cab5c..0e17b00d0d2 100644 --- a/.aztec-sync-commit +++ b/.aztec-sync-commit @@ -1 +1 @@ -9be0ad6b41a69c35ad9737d60da7a16300b87642 +ed815a3713fc311056a8bd0a616945f12d9be2a8 diff --git a/Cargo.lock b/Cargo.lock index 0511d4e75ce..d2afe025c69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3416,9 +3416,9 @@ dependencies = [ [[package]] name = "proptest" -version = "1.3.1" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c003ac8c77cb07bb74f5f198bce836a689bcd5a42574612bf14d17bfd08c20e" +checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ "bit-set", "bit-vec", @@ -3428,7 +3428,7 @@ dependencies = [ "rand 0.8.5", "rand_chacha 0.3.1", "rand_xorshift", - "regex-syntax 0.7.4", + "regex-syntax 0.8.2", "rusty-fork", "tempfile", "unarray", @@ -3676,12 +3676,6 @@ version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" -[[package]] -name = "regex-syntax" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" - [[package]] name = "regex-syntax" version = "0.8.2" diff --git a/Cargo.toml b/Cargo.toml index f180af01bdf..8cd5defa121 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -149,7 +149,6 @@ rand = "0.8.5" proptest = "1.2.0" proptest-derive = "0.4.0" - im = { version = "15.1", features = ["serde"] } tracing = "0.1.40" tracing-web = "0.1.3" diff --git a/aztec_macros/src/transforms/compute_note_hash_and_optionally_a_nullifier.rs b/aztec_macros/src/transforms/compute_note_hash_and_optionally_a_nullifier.rs index 40fde39a06f..30c0f63a2d4 100644 --- a/aztec_macros/src/transforms/compute_note_hash_and_optionally_a_nullifier.rs +++ b/aztec_macros/src/transforms/compute_note_hash_and_optionally_a_nullifier.rs @@ -176,7 +176,7 @@ fn generate_compute_note_hash_and_optionally_a_nullifier_source( format!( " unconstrained fn compute_note_hash_and_optionally_a_nullifier( - contract_address: aztec::protocol_types::address::AztecAddress, + contract_address: dep::aztec::protocol_types::address::AztecAddress, nonce: Field, storage_slot: Field, note_type_id: Field, @@ -194,7 +194,7 @@ fn generate_compute_note_hash_and_optionally_a_nullifier_source( let if_statements: Vec = note_types.iter().map(|note_type| format!( "if (note_type_id == {0}::get_note_type_id()) {{ - aztec::note::utils::compute_note_hash_and_optionally_a_nullifier({0}::deserialize_content, note_header, compute_nullifier, serialized_note) + dep::aztec::note::utils::compute_note_hash_and_optionally_a_nullifier({0}::deserialize_content, note_header, compute_nullifier, serialized_note) }}" , note_type)).collect(); @@ -208,14 +208,14 @@ fn generate_compute_note_hash_and_optionally_a_nullifier_source( format!( " unconstrained fn compute_note_hash_and_optionally_a_nullifier( - contract_address: aztec::protocol_types::address::AztecAddress, + contract_address: dep::aztec::protocol_types::address::AztecAddress, nonce: Field, storage_slot: Field, note_type_id: Field, compute_nullifier: bool, serialized_note: [Field; {}], ) -> pub [Field; 4] {{ - let note_header = aztec::prelude::NoteHeader::new(contract_address, nonce, storage_slot); + let note_header = dep::aztec::prelude::NoteHeader::new(contract_address, nonce, storage_slot); {} }}", diff --git a/aztec_macros/src/transforms/contract_interface.rs b/aztec_macros/src/transforms/contract_interface.rs index f22cfaca075..ed451fdd998 100644 --- a/aztec_macros/src/transforms/contract_interface.rs +++ b/aztec_macros/src/transforms/contract_interface.rs @@ -30,8 +30,8 @@ use crate::utils::{ // for i in 0..third_arg.len() { // args_acc = args_acc.append(third_arg[i].serialize().as_slice()); // } -// let args_hash = aztec::hash::hash_args(args_acc); -// assert(args_hash == aztec::oracle::arguments::pack_arguments(args_acc)); +// let args_hash = dep::aztec::hash::hash_args(args_acc); +// assert(args_hash == dep::aztec::oracle::arguments::pack_arguments(args_acc)); // PublicCallInterface { // target_contract: self.target_contract, // selector: FunctionSelector::from_signature("SELECTOR_PLACEHOLDER"), @@ -57,7 +57,7 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call let fn_return_type: noirc_frontend::ast::UnresolvedType = func.return_type(); let fn_selector = format!( - "aztec::protocol_types::abis::function_selector::FunctionSelector::from_signature(\"{}\")", + "dep::aztec::protocol_types::abis::function_selector::FunctionSelector::from_signature(\"{}\")", SELECTOR_PLACEHOLDER ); @@ -137,8 +137,8 @@ pub fn stub_function(aztec_visibility: &str, func: &NoirFunction, is_static_call format!( "let mut args_acc: [Field] = &[]; {} - let args_hash = aztec::hash::hash_args(args_acc); - assert(args_hash == aztec::oracle::arguments::pack_arguments(args_acc));", + let args_hash = dep::aztec::hash::hash_args(args_acc); + assert(args_hash == dep::aztec::oracle::arguments::pack_arguments(args_acc));", call_args ) } else { @@ -234,14 +234,14 @@ pub fn generate_contract_interface( let contract_interface = format!( " struct {0} {{ - target_contract: aztec::protocol_types::address::AztecAddress + target_contract: dep::aztec::protocol_types::address::AztecAddress }} impl {0} {{ {1} pub fn at( - target_contract: aztec::protocol_types::address::AztecAddress + target_contract: dep::aztec::protocol_types::address::AztecAddress ) -> Self {{ Self {{ target_contract }} }} @@ -255,7 +255,7 @@ pub fn generate_contract_interface( #[contract_library_method] pub fn at( - target_contract: aztec::protocol_types::address::AztecAddress + target_contract: dep::aztec::protocol_types::address::AztecAddress ) -> {0} {{ {0} {{ target_contract }} }} diff --git a/aztec_macros/src/transforms/note_interface.rs b/aztec_macros/src/transforms/note_interface.rs index b6d837d9384..b4e219164bd 100644 --- a/aztec_macros/src/transforms/note_interface.rs +++ b/aztec_macros/src/transforms/note_interface.rs @@ -272,7 +272,7 @@ fn generate_note_get_header( ) -> Result { let function_source = format!( " - fn get_header(note: {}) -> aztec::note::note_header::NoteHeader {{ + fn get_header(note: {}) -> dep::aztec::note::note_header::NoteHeader {{ note.{} }} ", @@ -303,7 +303,7 @@ fn generate_note_set_header( ) -> Result { let function_source = format!( " - fn set_header(self: &mut {}, header: aztec::note::note_header::NoteHeader) {{ + fn set_header(self: &mut {}, header: dep::aztec::note::note_header::NoteHeader) {{ self.{} = header; }} ", @@ -493,7 +493,7 @@ fn generate_note_properties_fn( // Automatically generate the method to compute the note's content hash as: // fn compute_note_content_hash(self: NoteType) -> Field { -// aztec::hash::pedersen_hash(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH) +// dep::aztec::hash::pedersen_hash(self.serialize_content(), dep::aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH) // } // fn generate_compute_note_content_hash( @@ -503,7 +503,7 @@ fn generate_compute_note_content_hash( let function_source = format!( " fn compute_note_content_hash(self: {}) -> Field {{ - aztec::hash::pedersen_hash(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH) + dep::aztec::hash::pedersen_hash(self.serialize_content(), dep::aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH) }} ", note_type @@ -562,7 +562,7 @@ fn generate_note_properties_struct_source( .iter() .filter_map(|(field_name, _)| { if field_name != note_header_field_name { - Some(format!("{}: aztec::note::note_getter_options::PropertySelector", field_name)) + Some(format!("{field_name}: dep::aztec::note::note_getter_options::PropertySelector")) } else { None } @@ -590,7 +590,7 @@ fn generate_note_properties_fn_source( .filter_map(|(index, (field_name, _))| { if field_name != note_header_field_name { Some(format!( - "{}: aztec::note::note_getter_options::PropertySelector {{ index: {}, offset: 0, length: 32 }}", + "{}: dep::aztec::note::note_getter_options::PropertySelector {{ index: {}, offset: 0, length: 32 }}", field_name, index )) @@ -667,7 +667,7 @@ fn generate_note_deserialize_content_source( ) } } else { - format!("{}: aztec::note::note_header::NoteHeader::empty()", note_header_field_name) + format!("{note_header_field_name}: dep::aztec::note::note_header::NoteHeader::empty()") } }) .collect::>() diff --git a/aztec_macros/src/utils/ast_utils.rs b/aztec_macros/src/utils/ast_utils.rs index 4467c4bca4b..48b3b25747b 100644 --- a/aztec_macros/src/utils/ast_utils.rs +++ b/aztec_macros/src/utils/ast_utils.rs @@ -161,7 +161,7 @@ macro_rules! chained_dep { ( $base:expr $(, $tail:expr)* ) => { { let mut base_path = ident_path($base); - base_path.kind = PathKind::Plain; + base_path.kind = PathKind::Dep; $( base_path.segments.push(ident($tail)); )* diff --git a/compiler/noirc_frontend/src/hir/resolution/import.rs b/compiler/noirc_frontend/src/hir/resolution/import.rs index f3dae31e1e0..282ee8a23c2 100644 --- a/compiler/noirc_frontend/src/hir/resolution/import.rs +++ b/compiler/noirc_frontend/src/hir/resolution/import.rs @@ -88,15 +88,12 @@ pub fn resolve_import( import_directive: &ImportDirective, def_maps: &BTreeMap, ) -> Result { - let allow_contracts = - allow_referencing_contracts(def_maps, crate_id, import_directive.module_id); - let module_scope = import_directive.module_id; let NamespaceResolution { module_id: resolved_module, namespace: resolved_namespace, mut error, - } = resolve_path_to_ns(import_directive, crate_id, crate_id, def_maps, allow_contracts)?; + } = resolve_path_to_ns(import_directive, crate_id, crate_id, def_maps)?; let name = resolve_path_name(import_directive); @@ -129,20 +126,11 @@ pub fn resolve_import( }) } -fn allow_referencing_contracts( - def_maps: &BTreeMap, - krate: CrateId, - local_id: LocalModuleId, -) -> bool { - ModuleId { krate, local_id }.module(def_maps).is_contract -} - fn resolve_path_to_ns( import_directive: &ImportDirective, crate_id: CrateId, importing_crate: CrateId, def_maps: &BTreeMap, - allow_contracts: bool, ) -> NamespaceResolutionResult { let import_path = &import_directive.path.segments; let def_map = &def_maps[&crate_id]; @@ -150,13 +138,7 @@ fn resolve_path_to_ns( match import_directive.path.kind { crate::ast::PathKind::Crate => { // Resolve from the root of the crate - resolve_path_from_crate_root( - crate_id, - importing_crate, - import_path, - def_maps, - allow_contracts, - ) + resolve_path_from_crate_root(crate_id, importing_crate, import_path, def_maps) } crate::ast::PathKind::Plain => { // There is a possibility that the import path is empty @@ -168,7 +150,6 @@ fn resolve_path_to_ns( import_path, import_directive.module_id, def_maps, - allow_contracts, ); } @@ -177,13 +158,7 @@ fn resolve_path_to_ns( let first_segment = import_path.first().expect("ice: could not fetch first segment"); if current_mod.find_name(first_segment).is_none() { // Resolve externally when first segment is unresolved - return resolve_external_dep( - def_map, - import_directive, - def_maps, - allow_contracts, - importing_crate, - ); + return resolve_external_dep(def_map, import_directive, def_maps, importing_crate); } resolve_name_in_module( @@ -192,17 +167,12 @@ fn resolve_path_to_ns( import_path, import_directive.module_id, def_maps, - allow_contracts, ) } - crate::ast::PathKind::Dep => resolve_external_dep( - def_map, - import_directive, - def_maps, - allow_contracts, - importing_crate, - ), + crate::ast::PathKind::Dep => { + resolve_external_dep(def_map, import_directive, def_maps, importing_crate) + } } } @@ -212,7 +182,6 @@ fn resolve_path_from_crate_root( import_path: &[Ident], def_maps: &BTreeMap, - allow_contracts: bool, ) -> NamespaceResolutionResult { resolve_name_in_module( crate_id, @@ -220,7 +189,6 @@ fn resolve_path_from_crate_root( import_path, def_maps[&crate_id].root, def_maps, - allow_contracts, ) } @@ -230,7 +198,6 @@ fn resolve_name_in_module( import_path: &[Ident], starting_mod: LocalModuleId, def_maps: &BTreeMap, - allow_contracts: bool, ) -> NamespaceResolutionResult { let def_map = &def_maps[&krate]; let mut current_mod_id = ModuleId { krate, local_id: starting_mod }; @@ -293,10 +260,6 @@ fn resolve_name_in_module( return Err(PathResolutionError::Unresolved(current_segment.clone())); } - // Check if it is a contract and we're calling from a non-contract context - if current_mod.is_contract && !allow_contracts { - return Err(PathResolutionError::ExternalContractUsed(current_segment.clone())); - } current_ns = found_ns; } @@ -314,7 +277,6 @@ fn resolve_external_dep( current_def_map: &CrateDefMap, directive: &ImportDirective, def_maps: &BTreeMap, - allow_contracts: bool, importing_crate: CrateId, ) -> NamespaceResolutionResult { // Use extern_prelude to get the dep @@ -344,7 +306,7 @@ fn resolve_external_dep( is_prelude: false, }; - resolve_path_to_ns(&dep_directive, dep_module.krate, importing_crate, def_maps, allow_contracts) + resolve_path_to_ns(&dep_directive, dep_module.krate, importing_crate, def_maps) } // Issue an error if the given private function is being called from a non-child module, or diff --git a/docs/docs/how_to/how-to-oracles.md b/docs/docs/how_to/how-to-oracles.md index 2d2ed5c94b9..d6834c09c84 100644 --- a/docs/docs/how_to/how-to-oracles.md +++ b/docs/docs/how_to/how-to-oracles.md @@ -141,10 +141,10 @@ server.addMethod("resolve_function_call", async (params) => { if params.function !== "getSqrt" { throw Error("Unexpected foreign call") }; - const values = params.inputs[0].Array.map((field) => { + const values = params.inputs[0].map((field) => { return `${Math.sqrt(parseInt(field, 16))}`; }); - return { values: [{ Array: values }] }; + return { values }; }); ``` @@ -236,9 +236,9 @@ const foreignCallHandler = async (name, input) => { // notice that the "inputs" parameter contains *all* the inputs // in this case we to make the RPC request with the first parameter "numbers", which would be input[0] const oracleReturn = await client.request(name, [ - { Array: input[0].map((i) => i.toString("hex")) }, + input[0].map((i) => i.toString("hex")), ]); - return [oracleReturn.values[0].Array]; + return { values: oracleReturn }; }; // the rest of your NoirJS code diff --git a/test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr b/test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr index cb853e48c30..2e42c483360 100644 --- a/test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr +++ b/test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr @@ -1,4 +1,4 @@ -use std::eddsa::eddsa_poseidon_verify; +use std::eddsa::{eddsa_poseidon_verify}; fn main( msg: pub Field, @@ -9,4 +9,4 @@ fn main( s: Field ) -> pub bool { eddsa_poseidon_verify(pub_key_x, pub_key_y, s, r8_x, r8_y, msg) -} +} \ No newline at end of file diff --git a/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr b/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr index 1c9bbfe61bf..5fc9e313179 100644 --- a/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr +++ b/test_programs/benchmarks/bench_poseidon_hash_100/src/main.nr @@ -9,4 +9,4 @@ fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] { } results -} +} \ No newline at end of file diff --git a/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr b/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr index 3edb47e9f72..3e319d2b025 100644 --- a/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr +++ b/test_programs/benchmarks/bench_poseidon_hash_30/src/main.nr @@ -9,4 +9,4 @@ fn main(input: [[Field; 2]; SIZE]) -> pub [Field; SIZE] { } results -} +} \ No newline at end of file diff --git a/test_programs/benchmarks/bench_sha256/src/main.nr b/test_programs/benchmarks/bench_sha256/src/main.nr index fc873fb4afb..c94d359239d 100644 --- a/test_programs/benchmarks/bench_sha256/src/main.nr +++ b/test_programs/benchmarks/bench_sha256/src/main.nr @@ -1,4 +1,3 @@ -use dep::std; fn main(input: [u8; 2]) -> pub [u8; 32] { std::hash::sha256(input) diff --git a/test_programs/benchmarks/bench_sha256_100/src/main.nr b/test_programs/benchmarks/bench_sha256_100/src/main.nr index 6df856a83fc..48b7fbac93c 100644 --- a/test_programs/benchmarks/bench_sha256_100/src/main.nr +++ b/test_programs/benchmarks/bench_sha256_100/src/main.nr @@ -1,3 +1,4 @@ + global SIZE = 100; fn main(input: [[u8; 2]; SIZE]) -> pub [[u8; 32]; SIZE] { @@ -7,4 +8,4 @@ fn main(input: [[u8; 2]; SIZE]) -> pub [[u8; 32]; SIZE] { } results -} +} \ No newline at end of file diff --git a/test_programs/benchmarks/bench_sha256_30/src/main.nr b/test_programs/benchmarks/bench_sha256_30/src/main.nr index 220c1cfbbed..37c742f9667 100644 --- a/test_programs/benchmarks/bench_sha256_30/src/main.nr +++ b/test_programs/benchmarks/bench_sha256_30/src/main.nr @@ -1,3 +1,4 @@ + global SIZE = 30; fn main(input: [[u8; 2]; SIZE]) -> pub [[u8; 32]; SIZE] { @@ -7,4 +8,4 @@ fn main(input: [[u8; 2]; SIZE]) -> pub [[u8; 32]; SIZE] { } results -} +} \ No newline at end of file diff --git a/test_programs/compile_failure/negate_unsigned/src/main.nr b/test_programs/compile_failure/negate_unsigned/src/main.nr index 4d3c5abe5a4..af4802a4ce6 100644 --- a/test_programs/compile_failure/negate_unsigned/src/main.nr +++ b/test_programs/compile_failure/negate_unsigned/src/main.nr @@ -1,3 +1,4 @@ + fn main() { let var = -1 as u8; std::println(var); diff --git a/test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml b/test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml deleted file mode 100644 index 2597f0c4653..00000000000 --- a/test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "non_comptime_local_fn_call" -type = "bin" -authors = [""] -compiler_version = ">=0.31.0" - -[dependencies] diff --git a/test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr b/test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr deleted file mode 100644 index d75bb1a922a..00000000000 --- a/test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - comptime { - let _a = id(3); - } -} - -fn id(x: Field) -> Field { - x -} diff --git a/test_programs/compile_failure/orphaned_trait_impl/src/main.nr b/test_programs/compile_failure/orphaned_trait_impl/src/main.nr index dd04aa454b2..dfd88d8f074 100644 --- a/test_programs/compile_failure/orphaned_trait_impl/src/main.nr +++ b/test_programs/compile_failure/orphaned_trait_impl/src/main.nr @@ -1,4 +1,4 @@ -impl crate1::MyTrait for crate2::MyStruct { +impl dep::crate1::MyTrait for dep::crate2::MyStruct { } fn main(x: Field, y: pub Field) { diff --git a/test_programs/compile_failure/restricted_bit_sizes/src/main.nr b/test_programs/compile_failure/restricted_bit_sizes/src/main.nr index a3fea13cc3a..4298c2052a7 100644 --- a/test_programs/compile_failure/restricted_bit_sizes/src/main.nr +++ b/test_programs/compile_failure/restricted_bit_sizes/src/main.nr @@ -1,5 +1,3 @@ -use std::assert_constant; - fn main() -> pub u63 { 5 } diff --git a/test_programs/compile_failure/turbofish_generic_count/src/main.nr b/test_programs/compile_failure/turbofish_generic_count/src/main.nr index 4091b2f0581..a5f46adb6a5 100644 --- a/test_programs/compile_failure/turbofish_generic_count/src/main.nr +++ b/test_programs/compile_failure/turbofish_generic_count/src/main.nr @@ -1,3 +1,4 @@ + struct Bar { one: Field, two: Field, diff --git a/test_programs/compile_success_contract/abi_attribute/Nargo.toml b/test_programs/compile_success_contract/abi_attribute/Nargo.toml deleted file mode 100644 index 56fa88ccb68..00000000000 --- a/test_programs/compile_success_contract/abi_attribute/Nargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "abi_attribute" -type = "contract" -authors = [""] - -[dependencies] diff --git a/test_programs/compile_success_contract/abi_attribute/src/main.nr b/test_programs/compile_success_contract/abi_attribute/src/main.nr deleted file mode 100644 index d658823d519..00000000000 --- a/test_programs/compile_success_contract/abi_attribute/src/main.nr +++ /dev/null @@ -1,9 +0,0 @@ -contract Foo { - #[abi(foo)] - global foo: Field = 42; - - #[abi(bar)] - struct Bar { - inner: Field - } -} diff --git a/test_programs/compile_success_empty/impl_where_clause/Nargo.toml b/test_programs/compile_success_empty/impl_where_clause/Nargo.toml deleted file mode 100644 index 7d0d5f3513e..00000000000 --- a/test_programs/compile_success_empty/impl_where_clause/Nargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "impl_where_clause" -type = "bin" -authors = [""] -compiler_version = ">=0.31.0" - -[dependencies] \ No newline at end of file diff --git a/test_programs/compile_success_empty/impl_where_clause/src/main.nr b/test_programs/compile_success_empty/impl_where_clause/src/main.nr deleted file mode 100644 index 2f3223efaae..00000000000 --- a/test_programs/compile_success_empty/impl_where_clause/src/main.nr +++ /dev/null @@ -1,34 +0,0 @@ -struct MyStruct { - a: u32, - b: T, -} - -struct InnerStruct { - a: Field, - b: Field, -} - -trait MyEq { - fn my_eq(self, other: Self) -> bool; -} - -impl MyEq for InnerStruct { - fn my_eq(self, other: InnerStruct) -> bool { - (self.a == other.a) & (self.b == other.b) - } -} - -impl MyStruct where T: MyEq { - fn my_eq(self, other: Self) -> bool { - (self.a == other.a) & self.b.my_eq(other.b) - } -} - -fn main() { - let inner = InnerStruct { a: 1, b: 2 }; - let my_struct = MyStruct { a: 5, b: inner }; - assert(my_struct.my_eq(my_struct)); - - let mut my_struct_new = MyStruct { a: 5, b: InnerStruct { a: 10, b: 15 } }; - assert(my_struct_new.my_eq(my_struct_new)); -} diff --git a/test_programs/compile_success_empty/trait_impl_with_where_clause/Nargo.toml b/test_programs/compile_success_empty/impl_with_where_clause/Nargo.toml similarity index 58% rename from test_programs/compile_success_empty/trait_impl_with_where_clause/Nargo.toml rename to test_programs/compile_success_empty/impl_with_where_clause/Nargo.toml index 672569634ea..ef9bdce2640 100644 --- a/test_programs/compile_success_empty/trait_impl_with_where_clause/Nargo.toml +++ b/test_programs/compile_success_empty/impl_with_where_clause/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "trait_impl_with_where_clause" +name = "impl_with_where_clause" type = "bin" authors = [""] diff --git a/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr b/test_programs/compile_success_empty/impl_with_where_clause/src/main.nr similarity index 100% rename from test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr rename to test_programs/compile_success_empty/impl_with_where_clause/src/main.nr diff --git a/test_programs/compile_success_empty/intrinsic_die/src/main.nr b/test_programs/compile_success_empty/intrinsic_die/src/main.nr index 17aaf02c283..c6e269c155d 100644 --- a/test_programs/compile_success_empty/intrinsic_die/src/main.nr +++ b/test_programs/compile_success_empty/intrinsic_die/src/main.nr @@ -1,5 +1,6 @@ // This test checks that we perform dead-instruction-elimination on intrinsic functions. fn main(x: Field) { + let hash = std::hash::pedersen_commitment([x]); let g1_x = 0x0000000000000000000000000000000000000000000000000000000000000001; let g1_y = 0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c; let g1 = std::embedded_curve_ops::EmbeddedCurvePoint { x: g1_x, y: g1_y, is_infinite: false }; diff --git a/test_programs/compile_success_empty/numeric_generics/src/main.nr b/test_programs/compile_success_empty/numeric_generics/src/main.nr index 340c18c2a1d..1e03a382fed 100644 --- a/test_programs/compile_success_empty/numeric_generics/src/main.nr +++ b/test_programs/compile_success_empty/numeric_generics/src/main.nr @@ -36,3 +36,4 @@ fn foo(mut s: MyStruct<2+1>) -> MyStruct<10/2-2> { s.data[0] = s.data[0] + 1; s } + diff --git a/test_programs/compile_success_empty/numeric_generics_explicit/Nargo.toml b/test_programs/compile_success_empty/numeric_generics_explicit/Nargo.toml deleted file mode 100644 index bc3d43498db..00000000000 --- a/test_programs/compile_success_empty/numeric_generics_explicit/Nargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "numeric_generics_explicit" -type = "bin" -authors = [""] -compiler_version = ">=0.30.0" - -[dependencies] \ No newline at end of file diff --git a/test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr b/test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr deleted file mode 100644 index 7c4f7761ff6..00000000000 --- a/test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr +++ /dev/null @@ -1,111 +0,0 @@ -// Regression that a global of the same name does not trigger a duplicate definition error -global N = 1000; - -fn main() { - let a = id([1, 2]); - let b = id([1, 2, 3]); - - let itWorks1 = MyStruct { data: a }; - assert(itWorks1.data[1] == 2); - let itWorks2 = MyStruct { data: b }; - assert(itWorks2.data[1] == 2); - - let c = [1, 2]; - let itAlsoWorks = MyStruct { data: c }; - assert(itAlsoWorks.data[1] == 2); - - assert(foo(itWorks2).data[0] == itWorks2.data[0] + 1); - - double_numeric_generics_test(); - - let my_type = PublicStorage::read::(); - assert(my_type.a == 1); - assert(my_type.b == 2); - assert(my_type.c == 3); - - let foo = baz::<10>(); - assert(foo.data == [1; 10]); -} - -// Used in the signature of a function -fn id(x: [Field; I]) -> [Field; I] { - x -} - -// Used as a field of a struct -struct MyStruct { - data: [Field; S], -} - -// Used in an impl -impl MyStruct { - fn insert(mut self: Self, index: Field, elem: Field) -> Self { - // Regression test for numeric generics on impls - assert(index as u32 < S); - - self.data[index] = elem; - self - } -} - -fn foo(mut s: MyStruct<2+1>) -> MyStruct<10/2-2> { - s.data[0] = s.data[0] + 1; - s -} - -fn baz() -> MyStruct { - MyStruct { data: [1; N] } -} - -fn double() -> u32 { - // Used as an expression - N * 2 -} - -fn double_numeric_generics_test() { - // Example usage of a numeric generic arguments. - assert(double::<9>() == 18); - assert(double::<123>() == 246); - assert(double::<7 + 8>() == 30); -} - -struct MyType { - a: Field, - b: Field, - c: Field, -} - -impl Deserialize for MyType { - fn deserialize(fields: [Field; N]) -> Self { - MyType { a: fields[0], b: fields[1], c: fields[2] } - } -} - -trait Deserialize { - fn deserialize(fields: [Field; N]) -> Self; -} - -struct PublicStorage {} - -impl PublicStorage { - fn read() -> T where T: Deserialize { - // Used as a type within a function body - let mut fields: [Field; N] = [0; N]; - // Used a loop bound - for i in 0..N { - fields[i] = i as Field + 1; - } - T::deserialize(fields) - } -} - -// Check that we can thread numeric generics into nested structs -// and also that we can handle nested structs with numeric generics -// which are declared after the parent struct -struct NestedNumeric { - a: Field, - b: InnerNumeric -} -struct InnerNumeric { - inner: [u32; N], -} diff --git a/test_programs/compile_success_empty/reexports/src/main.nr b/test_programs/compile_success_empty/reexports/src/main.nr index 0fd65a33564..ed469ff77d0 100644 --- a/test_programs/compile_success_empty/reexports/src/main.nr +++ b/test_programs/compile_success_empty/reexports/src/main.nr @@ -1,4 +1,4 @@ -use reexporting_lib::{FooStruct, MyStruct, lib}; +use dep::reexporting_lib::{FooStruct, MyStruct, lib}; fn main() { let x: FooStruct = MyStruct { inner: 0 }; diff --git a/test_programs/compile_success_empty/regression_4635/src/main.nr b/test_programs/compile_success_empty/regression_4635/src/main.nr index 350b60ba3f7..23918e30785 100644 --- a/test_programs/compile_success_empty/regression_4635/src/main.nr +++ b/test_programs/compile_success_empty/regression_4635/src/main.nr @@ -8,7 +8,7 @@ impl FromField for Field { } } -trait Deserialize { +trait Deserialize { fn deserialize(fields: [Field; N]) -> Self; } diff --git a/test_programs/compile_success_empty/trait_generics/src/main.nr b/test_programs/compile_success_empty/trait_generics/src/main.nr index 56ce7e8970c..30b2e79d579 100644 --- a/test_programs/compile_success_empty/trait_generics/src/main.nr +++ b/test_programs/compile_success_empty/trait_generics/src/main.nr @@ -29,7 +29,7 @@ impl MyInto for Field { /// Serialize example -trait Serializable { +trait Serializable { fn serialize(self) -> [Field; N]; } diff --git a/test_programs/compile_success_empty/workspace_reexport_bug/binary/src/main.nr b/test_programs/compile_success_empty/workspace_reexport_bug/binary/src/main.nr index a4207794a8a..ab0ae9a48b8 100644 --- a/test_programs/compile_success_empty/workspace_reexport_bug/binary/src/main.nr +++ b/test_programs/compile_success_empty/workspace_reexport_bug/binary/src/main.nr @@ -1,2 +1,2 @@ -use library::ReExportMeFromAnotherLib; +use dep::library::ReExportMeFromAnotherLib; fn main(_x: ReExportMeFromAnotherLib) {} diff --git a/test_programs/compile_success_empty/workspace_reexport_bug/library/src/lib.nr b/test_programs/compile_success_empty/workspace_reexport_bug/library/src/lib.nr index e3a1539ea65..8e84662ed03 100644 --- a/test_programs/compile_success_empty/workspace_reexport_bug/library/src/lib.nr +++ b/test_programs/compile_success_empty/workspace_reexport_bug/library/src/lib.nr @@ -1,2 +1,2 @@ // Re-export -use library2::ReExportMeFromAnotherLib; +use dep::library2::ReExportMeFromAnotherLib; diff --git a/test_programs/execution_failure/div_by_zero_numerator_witness/src/main.nr b/test_programs/execution_failure/div_by_zero_numerator_witness/src/main.nr index 012e823b297..7c6cae4932e 100644 --- a/test_programs/execution_failure/div_by_zero_numerator_witness/src/main.nr +++ b/test_programs/execution_failure/div_by_zero_numerator_witness/src/main.nr @@ -1,3 +1,4 @@ + fn main(x: Field) { let a: Field = x / 0; std::println(a); diff --git a/test_programs/execution_success/diamond_deps_0/src/main.nr b/test_programs/execution_success/diamond_deps_0/src/main.nr index 690d6fc9fc8..ca95c6e0aa8 100644 --- a/test_programs/execution_success/diamond_deps_0/src/main.nr +++ b/test_programs/execution_success/diamond_deps_0/src/main.nr @@ -1,6 +1,6 @@ -use dep1::call_dep1_then_dep2; -use dep2::call_dep2; -use dep2::RESOLVE_THIS; +use dep::dep1::call_dep1_then_dep2; +use dep::dep2::call_dep2; +use dep::dep2::RESOLVE_THIS; fn main(x: Field, y: pub Field) -> pub Field { call_dep1_then_dep2(x, y) + call_dep2(x, y) + RESOLVE_THIS diff --git a/test_programs/execution_success/hashmap/src/main.nr b/test_programs/execution_success/hashmap/src/main.nr index 8cf70cc5970..56b13d6779b 100644 --- a/test_programs/execution_success/hashmap/src/main.nr +++ b/test_programs/execution_success/hashmap/src/main.nr @@ -3,7 +3,6 @@ mod utils; use std::collections::map::HashMap; use std::hash::BuildHasherDefault; use std::hash::poseidon2::Poseidon2Hasher; -use std::cmp::Eq; use utils::cut; diff --git a/test_programs/execution_success/regression_4088/src/main.nr b/test_programs/execution_success/regression_4088/src/main.nr index 12a7afca68c..9e4d7892fc3 100644 --- a/test_programs/execution_success/regression_4088/src/main.nr +++ b/test_programs/execution_success/regression_4088/src/main.nr @@ -1,4 +1,4 @@ -trait Serialize { +trait Serialize { fn serialize(self) -> [Field; N]; } @@ -12,7 +12,7 @@ impl Serialize<1> for ValueNote { } } -fn check(serialized_note: [Field; N]) { +fn check(serialized_note: [Field; N]) { assert(serialized_note[0] == 0); } diff --git a/test_programs/execution_success/regression_4124/src/main.nr b/test_programs/execution_success/regression_4124/src/main.nr index 6caea017798..2b0e65a0b6c 100644 --- a/test_programs/execution_success/regression_4124/src/main.nr +++ b/test_programs/execution_success/regression_4124/src/main.nr @@ -1,6 +1,6 @@ use std::option::Option; -trait MyDeserialize { +trait MyDeserialize { fn deserialize(fields: [Field; N]) -> Self; } @@ -10,7 +10,7 @@ impl MyDeserialize<1> for Field { } } -pub fn storage_read() -> [Field; N] { +pub fn storage_read() -> [Field; N] { std::unsafe::zeroed() } diff --git a/test_programs/execution_success/slices/src/main.nr b/test_programs/execution_success/slices/src/main.nr index 2bd4dbd97b0..8be79cdc3c4 100644 --- a/test_programs/execution_success/slices/src/main.nr +++ b/test_programs/execution_success/slices/src/main.nr @@ -45,14 +45,6 @@ fn main(x: Field, y: pub Field) { assert(append[0] == 1); assert(append[4] == 5); - let mapped = &[1, 2].map(|x| x + 1); - assert_eq(mapped, &[2, 3]); - - assert_eq(&[1, 2, 3].fold(0, |acc, x| acc + x), 6); - assert_eq(&[1, 2, 3].reduce(|acc, x| acc + x), 6); - assert(&[2, 4, 6].all(|x| x > 0)); - assert(&[2, 4, 6].any(|x| x > 5)); - regression_2083(); // The parameters to this function must come from witness values (inputs to main) regression_merge_slices(x, y); diff --git a/test_programs/execution_success/traits_in_crates_1/crate1/src/lib.nr b/test_programs/execution_success/traits_in_crates_1/crate1/src/lib.nr index e36a263093a..62dd5a2c111 100644 --- a/test_programs/execution_success/traits_in_crates_1/crate1/src/lib.nr +++ b/test_programs/execution_success/traits_in_crates_1/crate1/src/lib.nr @@ -2,7 +2,7 @@ trait MyTrait { fn Add10(&mut self); } -impl MyTrait for crate2::MyStruct { +impl MyTrait for dep::crate2::MyStruct { fn Add10(&mut self) { self.Q += 10; } diff --git a/test_programs/execution_success/traits_in_crates_1/src/main.nr b/test_programs/execution_success/traits_in_crates_1/src/main.nr index 2afec29ee1f..7ba2f63c5c0 100644 --- a/test_programs/execution_success/traits_in_crates_1/src/main.nr +++ b/test_programs/execution_success/traits_in_crates_1/src/main.nr @@ -1,5 +1,5 @@ fn main(x: Field, y: pub Field) { - let mut V = crate2::MyStruct { Q: x }; + let mut V = dep::crate2::MyStruct { Q: x }; V.Add10(); assert(V.Q == y); } diff --git a/test_programs/execution_success/traits_in_crates_2/crate2/src/lib.nr b/test_programs/execution_success/traits_in_crates_2/crate2/src/lib.nr index fe6a94a4a95..38870489131 100644 --- a/test_programs/execution_success/traits_in_crates_2/crate2/src/lib.nr +++ b/test_programs/execution_success/traits_in_crates_2/crate2/src/lib.nr @@ -2,7 +2,7 @@ struct MyStruct { Q: Field, } -impl crate1::MyTrait for MyStruct { +impl dep::crate1::MyTrait for MyStruct { fn Add10(&mut self) { self.Q += 10; } diff --git a/test_programs/execution_success/traits_in_crates_2/src/main.nr b/test_programs/execution_success/traits_in_crates_2/src/main.nr index 2afec29ee1f..7ba2f63c5c0 100644 --- a/test_programs/execution_success/traits_in_crates_2/src/main.nr +++ b/test_programs/execution_success/traits_in_crates_2/src/main.nr @@ -1,5 +1,5 @@ fn main(x: Field, y: pub Field) { - let mut V = crate2::MyStruct { Q: x }; + let mut V = dep::crate2::MyStruct { Q: x }; V.Add10(); assert(V.Q == y); } diff --git a/test_programs/noir_test_failure/should_fail_mismatch/src/main.nr b/test_programs/noir_test_failure/should_fail_mismatch/src/main.nr index 62e03c153ed..08a9234a752 100644 --- a/test_programs/noir_test_failure/should_fail_mismatch/src/main.nr +++ b/test_programs/noir_test_failure/should_fail_mismatch/src/main.nr @@ -2,9 +2,14 @@ fn test_different_string() { assert_eq(0, 1, "Different string"); } - -// The failure reason is a substring of the expected message, but it should be the other way around -#[test(should_fail_with = "Definitely Not equal!")] -fn test_wrong_expectation() { - assert_eq(0, 1, "Not equal"); -} \ No newline at end of file +// The assert message has a space +#[test(should_fail_with = "Not equal")] +fn test_with_extra_space() { + assert_eq(0, 1, "Not equal "); +} +// The assert message has a space +#[test(should_fail_with = "Not equal")] +fn test_runtime_mismatch() { + // We use a pedersen commitment here so that the assertion failure is only known at runtime. + assert_eq(std::hash::pedersen_commitment([27]).x, 0, "Not equal "); +} diff --git a/test_programs/test_libraries/diamond_deps_1/src/lib.nr b/test_programs/test_libraries/diamond_deps_1/src/lib.nr index d76ce5a05e9..60c001ec64e 100644 --- a/test_programs/test_libraries/diamond_deps_1/src/lib.nr +++ b/test_programs/test_libraries/diamond_deps_1/src/lib.nr @@ -1,4 +1,4 @@ -use dep2::call_dep2; +use dep::dep2::call_dep2; pub fn call_dep1_then_dep2(x: Field, y: Field) -> Field { call_dep2(x, y) diff --git a/test_programs/test_libraries/reexporting_lib/src/lib.nr b/test_programs/test_libraries/reexporting_lib/src/lib.nr index 1bced548304..f12dfe01ecd 100644 --- a/test_programs/test_libraries/reexporting_lib/src/lib.nr +++ b/test_programs/test_libraries/reexporting_lib/src/lib.nr @@ -1,3 +1,3 @@ -use exporting_lib::{MyStruct, FooStruct}; +use dep::exporting_lib::{MyStruct, FooStruct}; -use exporting_lib as lib; +use dep::exporting_lib as lib; diff --git a/tooling/acvm_cli/Cargo.toml b/tooling/acvm_cli/Cargo.toml index 1cfd1f3b270..a592f2d65f3 100644 --- a/tooling/acvm_cli/Cargo.toml +++ b/tooling/acvm_cli/Cargo.toml @@ -20,7 +20,7 @@ path = "src/main.rs" [dependencies] thiserror.workspace = true toml.workspace = true -color-eyre = "0.6.2" +color-eyre.workspace = true clap.workspace = true acvm.workspace = true nargo.workspace = true diff --git a/tooling/nargo_cli/Cargo.toml b/tooling/nargo_cli/Cargo.toml index b9d7d7e3e48..e0e54449a6f 100644 --- a/tooling/nargo_cli/Cargo.toml +++ b/tooling/nargo_cli/Cargo.toml @@ -43,11 +43,16 @@ prettytable-rs = "0.10" rayon = "1.8.0" thiserror.workspace = true tower.workspace = true -async-lsp = { workspace = true, features = ["client-monitor", "stdio", "tracing", "tokio"] } +async-lsp = { workspace = true, features = [ + "client-monitor", + "stdio", + "tracing", + "tokio", +] } const_format.workspace = true similar-asserts.workspace = true termcolor = "1.1.2" -color-eyre = "0.6.2" +color-eyre.workspace = true tokio = { version = "1.0", features = ["io-std", "rt"] } dap.workspace = true clap-markdown = { git = "https://github.com/noir-lang/clap-markdown", rev = "450d759532c88f0dba70891ceecdbc9ff8f25d2b", optional = true } diff --git a/tooling/nargo_fmt/tests/expected/contract.nr b/tooling/nargo_fmt/tests/expected/contract.nr index e3a5877725a..14b1af4a848 100644 --- a/tooling/nargo_fmt/tests/expected/contract.nr +++ b/tooling/nargo_fmt/tests/expected/contract.nr @@ -3,11 +3,11 @@ // Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. // Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. contract Benchmarking { - use aztec::protocol_types::abis::function_selector::FunctionSelector; + use dep::aztec::protocol_types::abis::function_selector::FunctionSelector; use value_note::{utils::{increment, decrement}, value_note::{VALUE_NOTE_LEN, ValueNote, ValueNoteMethods}}; - use aztec::{ + use dep::aztec::{ context::Context, note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader}, log::emit_unencrypted_log, state_vars::{Map, PublicMutable, PrivateSet}, types::type_serialization::field_serialization::{FieldSerializationMethods, FIELD_SERIALIZED_LEN}, diff --git a/tooling/nargo_fmt/tests/expected/fn.nr b/tooling/nargo_fmt/tests/expected/fn.nr index 4dde9a1b3ec..961e67faf1c 100644 --- a/tooling/nargo_fmt/tests/expected/fn.nr +++ b/tooling/nargo_fmt/tests/expected/fn.nr @@ -62,10 +62,6 @@ fn main( pub fn from_baz(x: [Field; crate::foo::MAGIC_NUMBER]) {} -fn id(x: [Field; I]) -> [Field; I] {} - -fn id_two(x: [Field; I]) -> [Field; I] {} - fn whitespace_before_generics(foo: T) {} fn more_whitespace_before_generics(foo: T) {} diff --git a/tooling/nargo_fmt/tests/expected/impl.nr b/tooling/nargo_fmt/tests/expected/impl.nr index 3c2fa42837a..ec734b57970 100644 --- a/tooling/nargo_fmt/tests/expected/impl.nr +++ b/tooling/nargo_fmt/tests/expected/impl.nr @@ -19,9 +19,3 @@ impl MyType { impl MyType { fn method(self) {} } - -impl MyStruct where T: MyEq { - fn my_eq(self, other: Self) -> bool { - (self.a == other.a) & self.b.my_eq(other.b) - } -} diff --git a/tooling/nargo_fmt/tests/expected/let.nr b/tooling/nargo_fmt/tests/expected/let.nr index 0edc0eaf922..7ff69e74306 100644 --- a/tooling/nargo_fmt/tests/expected/let.nr +++ b/tooling/nargo_fmt/tests/expected/let.nr @@ -51,10 +51,10 @@ fn let_() { let expr = MyExpr { /*A boolean literal (true, false).*/ kind: ExprKind::Bool(true) }; - let mut V = crate2::MyStruct { Q: x }; - let mut V = crate2::MyStruct {}; - let mut V = crate2::MyStruct {/*test*/}; - let mut V = crate2::MyStruct { + let mut V = dep::crate2::MyStruct { Q: x }; + let mut V = dep::crate2::MyStruct {}; + let mut V = dep::crate2::MyStruct {/*test*/}; + let mut V = dep::crate2::MyStruct { // sad }; } diff --git a/tooling/nargo_fmt/tests/input/contract.nr b/tooling/nargo_fmt/tests/input/contract.nr index e3a5877725a..14b1af4a848 100644 --- a/tooling/nargo_fmt/tests/input/contract.nr +++ b/tooling/nargo_fmt/tests/input/contract.nr @@ -3,11 +3,11 @@ // Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. // Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. contract Benchmarking { - use aztec::protocol_types::abis::function_selector::FunctionSelector; + use dep::aztec::protocol_types::abis::function_selector::FunctionSelector; use value_note::{utils::{increment, decrement}, value_note::{VALUE_NOTE_LEN, ValueNote, ValueNoteMethods}}; - use aztec::{ + use dep::aztec::{ context::Context, note::{note_getter_options::NoteGetterOptions, note_header::NoteHeader}, log::emit_unencrypted_log, state_vars::{Map, PublicMutable, PrivateSet}, types::type_serialization::field_serialization::{FieldSerializationMethods, FIELD_SERIALIZED_LEN}, diff --git a/tooling/nargo_fmt/tests/input/fn.nr b/tooling/nargo_fmt/tests/input/fn.nr index 16ed95a540d..03806b0fef9 100644 --- a/tooling/nargo_fmt/tests/input/fn.nr +++ b/tooling/nargo_fmt/tests/input/fn.nr @@ -45,11 +45,6 @@ fn main( pub fn from_baz(x: [Field; crate::foo::MAGIC_NUMBER]) {} -fn id< T , let I : Field > ( x : [ Field ; I ] ) -> [Field; I ] { } - -fn id_two(x: [Field ; I]) -> [ Field; I] {} - fn whitespace_before_generics < T > (foo: T) {} fn more_whitespace_before_generics < diff --git a/tooling/nargo_fmt/tests/input/impl.nr b/tooling/nargo_fmt/tests/input/impl.nr index 4ca838c2964..ea909dfad44 100644 --- a/tooling/nargo_fmt/tests/input/impl.nr +++ b/tooling/nargo_fmt/tests/input/impl.nr @@ -19,9 +19,3 @@ fn method(self) {} impl MyType { fn method(self) {} } - -impl MyStruct where T: MyEq { - fn my_eq(self, other: Self) -> bool { - (self.a == other.a) & self.b.my_eq(other.b) - } -} \ No newline at end of file diff --git a/tooling/nargo_fmt/tests/input/let.nr b/tooling/nargo_fmt/tests/input/let.nr index 16ce0a9d7f1..37cdc6655c7 100644 --- a/tooling/nargo_fmt/tests/input/let.nr +++ b/tooling/nargo_fmt/tests/input/let.nr @@ -26,10 +26,10 @@ kind: ExprKind::Bool(true), let expr = MyExpr {/*A boolean literal (true, false).*/kind: ExprKind::Bool(true),}; - let mut V = crate2::MyStruct { Q: x }; - let mut V = crate2::MyStruct {}; - let mut V = crate2::MyStruct {/*test*/}; - let mut V = crate2::MyStruct { + let mut V = dep::crate2::MyStruct { Q: x }; + let mut V = dep::crate2::MyStruct {}; + let mut V = dep::crate2::MyStruct {/*test*/}; + let mut V = dep::crate2::MyStruct { // sad }; } From 0c1a7f3a8c05958ecabf63f3bbd54d9015a1627c Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:09:31 +0000 Subject: [PATCH 02/14] chore: restore formatter tests --- tooling/nargo_fmt/tests/expected/fn.nr | 4 ++++ tooling/nargo_fmt/tests/expected/impl.nr | 6 ++++++ tooling/nargo_fmt/tests/input/fn.nr | 5 +++++ tooling/nargo_fmt/tests/input/impl.nr | 6 ++++++ 4 files changed, 21 insertions(+) diff --git a/tooling/nargo_fmt/tests/expected/fn.nr b/tooling/nargo_fmt/tests/expected/fn.nr index 961e67faf1c..4dde9a1b3ec 100644 --- a/tooling/nargo_fmt/tests/expected/fn.nr +++ b/tooling/nargo_fmt/tests/expected/fn.nr @@ -62,6 +62,10 @@ fn main( pub fn from_baz(x: [Field; crate::foo::MAGIC_NUMBER]) {} +fn id(x: [Field; I]) -> [Field; I] {} + +fn id_two(x: [Field; I]) -> [Field; I] {} + fn whitespace_before_generics(foo: T) {} fn more_whitespace_before_generics(foo: T) {} diff --git a/tooling/nargo_fmt/tests/expected/impl.nr b/tooling/nargo_fmt/tests/expected/impl.nr index ec734b57970..006c7063b43 100644 --- a/tooling/nargo_fmt/tests/expected/impl.nr +++ b/tooling/nargo_fmt/tests/expected/impl.nr @@ -19,3 +19,9 @@ impl MyType { impl MyType { fn method(self) {} } + +impl MyStruct where T: MyEq { + fn my_eq(self, other: Self) -> bool { + (self.a == other.a) & self.b.my_eq(other.b) + } +} \ No newline at end of file diff --git a/tooling/nargo_fmt/tests/input/fn.nr b/tooling/nargo_fmt/tests/input/fn.nr index 03806b0fef9..16ed95a540d 100644 --- a/tooling/nargo_fmt/tests/input/fn.nr +++ b/tooling/nargo_fmt/tests/input/fn.nr @@ -45,6 +45,11 @@ fn main( pub fn from_baz(x: [Field; crate::foo::MAGIC_NUMBER]) {} +fn id< T , let I : Field > ( x : [ Field ; I ] ) -> [Field; I ] { } + +fn id_two(x: [Field ; I]) -> [ Field; I] {} + fn whitespace_before_generics < T > (foo: T) {} fn more_whitespace_before_generics < diff --git a/tooling/nargo_fmt/tests/input/impl.nr b/tooling/nargo_fmt/tests/input/impl.nr index ea909dfad44..4ca838c2964 100644 --- a/tooling/nargo_fmt/tests/input/impl.nr +++ b/tooling/nargo_fmt/tests/input/impl.nr @@ -19,3 +19,9 @@ fn method(self) {} impl MyType { fn method(self) {} } + +impl MyStruct where T: MyEq { + fn my_eq(self, other: Self) -> bool { + (self.a == other.a) & self.b.my_eq(other.b) + } +} \ No newline at end of file From 0b970e625c901b70a23b0d5cca63105cf6569673 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:09:57 +0000 Subject: [PATCH 03/14] chore: fmt --- aztec_macros/src/transforms/note_interface.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aztec_macros/src/transforms/note_interface.rs b/aztec_macros/src/transforms/note_interface.rs index b4e219164bd..c2dfb3d86d4 100644 --- a/aztec_macros/src/transforms/note_interface.rs +++ b/aztec_macros/src/transforms/note_interface.rs @@ -562,7 +562,9 @@ fn generate_note_properties_struct_source( .iter() .filter_map(|(field_name, _)| { if field_name != note_header_field_name { - Some(format!("{field_name}: dep::aztec::note::note_getter_options::PropertySelector")) + Some(format!( + "{field_name}: dep::aztec::note::note_getter_options::PropertySelector" + )) } else { None } @@ -667,7 +669,9 @@ fn generate_note_deserialize_content_source( ) } } else { - format!("{note_header_field_name}: dep::aztec::note::note_header::NoteHeader::empty()") + format!( + "{note_header_field_name}: dep::aztec::note::note_header::NoteHeader::empty()" + ) } }) .collect::>() From 1305be7abe3e3ee06f0eb5b9987b4b1fbb8b4cdd Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:12:09 +0000 Subject: [PATCH 04/14] chore: formatter tests --- tooling/nargo_fmt/tests/expected/impl.nr | 2 +- tooling/nargo_fmt/tests/input/impl.nr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tooling/nargo_fmt/tests/expected/impl.nr b/tooling/nargo_fmt/tests/expected/impl.nr index 006c7063b43..3c2fa42837a 100644 --- a/tooling/nargo_fmt/tests/expected/impl.nr +++ b/tooling/nargo_fmt/tests/expected/impl.nr @@ -24,4 +24,4 @@ impl MyStruct where T: MyEq { fn my_eq(self, other: Self) -> bool { (self.a == other.a) & self.b.my_eq(other.b) } -} \ No newline at end of file +} diff --git a/tooling/nargo_fmt/tests/input/impl.nr b/tooling/nargo_fmt/tests/input/impl.nr index 4ca838c2964..21ce6a2e175 100644 --- a/tooling/nargo_fmt/tests/input/impl.nr +++ b/tooling/nargo_fmt/tests/input/impl.nr @@ -24,4 +24,4 @@ impl MyStruct where T: MyEq { fn my_eq(self, other: Self) -> bool { (self.a == other.a) & self.b.my_eq(other.b) } -} \ No newline at end of file +} From e132c2b1f52d4d8d9e4061b5ca5522004c89d5bd Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:18:36 +0000 Subject: [PATCH 05/14] chore: revert changes to tests --- .../builtin_function_declaration/Nargo.toml | 6 +- .../builtin_function_declaration/src/main.nr | 17 ++- .../non_comptime_local_fn_call/Nargo.toml | 7 ++ .../non_comptime_local_fn_call/src/main.nr | 14 +++ .../abi_attribute/Nargo.toml | 6 + .../abi_attribute/src/main.nr | 9 ++ .../impl_where_clause/Nargo.toml | 6 + .../impl_where_clause/src/main.nr | 34 ++++++ .../numeric_generics_explicit/Nargo.toml | 6 + .../numeric_generics_explicit/src/main.nr | 111 ++++++++++++++++++ .../execution_success/slices/src/main.nr | 8 ++ .../should_fail_mismatch/src/main.nr | 17 +-- 12 files changed, 218 insertions(+), 23 deletions(-) create mode 100644 test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml create mode 100644 test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr create mode 100644 test_programs/compile_success_contract/abi_attribute/Nargo.toml create mode 100644 test_programs/compile_success_contract/abi_attribute/src/main.nr create mode 100644 test_programs/compile_success_empty/impl_where_clause/Nargo.toml create mode 100644 test_programs/compile_success_empty/impl_where_clause/src/main.nr create mode 100644 test_programs/compile_success_empty/numeric_generics_explicit/Nargo.toml create mode 100644 test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr diff --git a/test_programs/compile_failure/builtin_function_declaration/Nargo.toml b/test_programs/compile_failure/builtin_function_declaration/Nargo.toml index 3835292a6ba..cd000aa5f53 100644 --- a/test_programs/compile_failure/builtin_function_declaration/Nargo.toml +++ b/test_programs/compile_failure/builtin_function_declaration/Nargo.toml @@ -1,7 +1,7 @@ [package] -name = "builtin_function_declaration" +name = "non_comptime_local_fn_call" type = "bin" authors = [""] -compiler_version = ">=0.23.0" +compiler_version = ">=0.31.0" -[dependencies] +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_failure/builtin_function_declaration/src/main.nr b/test_programs/compile_failure/builtin_function_declaration/src/main.nr index ed376557371..7cbf4213425 100644 --- a/test_programs/compile_failure/builtin_function_declaration/src/main.nr +++ b/test_programs/compile_failure/builtin_function_declaration/src/main.nr @@ -1,10 +1,9 @@ -// This test prevents users from trying to create their own builtin functions as these should only exist in the stdlib. - -// This would otherwise be a perfectly valid declaration of the `to_le_bits` builtin function -#[builtin(to_le_bits)] -fn to_le_bits(_x: Field, _bit_size: u32) -> [u1] {} - -fn main(x: Field) -> pub u1 { - let bits = to_le_bits(x, 100); - bits[0] +fn main() { + comptime { + let _a = id(3); + } } + +fn id(x: Field) -> Field { + x +} \ No newline at end of file diff --git a/test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml b/test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml new file mode 100644 index 00000000000..c09fc417b55 --- /dev/null +++ b/test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "brillig_vec_to_acir" +type = "bin" +authors = [""] +compiler_version = ">=0.23.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr b/test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr new file mode 100644 index 00000000000..8f872f1b903 --- /dev/null +++ b/test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr @@ -0,0 +1,14 @@ +global DEPTH: Field = 40000; + +fn main(x: [u32; DEPTH], y: u32) { + let mut new_x = Vec::new(); + new_x = clear(x, y); +} + +unconstrained fn clear(x: [u32; DEPTH], y: u32) -> Vec { + let mut a = Vec::new(); + for i in 0..y { + a.push(x[i]); + } + a +} diff --git a/test_programs/compile_success_contract/abi_attribute/Nargo.toml b/test_programs/compile_success_contract/abi_attribute/Nargo.toml new file mode 100644 index 00000000000..9fcd61c235e --- /dev/null +++ b/test_programs/compile_success_contract/abi_attribute/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "abi_attribute" +type = "contract" +authors = [""] + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_success_contract/abi_attribute/src/main.nr b/test_programs/compile_success_contract/abi_attribute/src/main.nr new file mode 100644 index 00000000000..0c376b54686 --- /dev/null +++ b/test_programs/compile_success_contract/abi_attribute/src/main.nr @@ -0,0 +1,9 @@ +contract Foo { + #[abi(foo)] + global foo: Field = 42; + + #[abi(bar)] + struct Bar { + inner: Field + } +} \ No newline at end of file diff --git a/test_programs/compile_success_empty/impl_where_clause/Nargo.toml b/test_programs/compile_success_empty/impl_where_clause/Nargo.toml new file mode 100644 index 00000000000..58e774846cf --- /dev/null +++ b/test_programs/compile_success_empty/impl_where_clause/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "impl_where_clause" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/compile_success_empty/impl_where_clause/src/main.nr b/test_programs/compile_success_empty/impl_where_clause/src/main.nr new file mode 100644 index 00000000000..0fbda1db39b --- /dev/null +++ b/test_programs/compile_success_empty/impl_where_clause/src/main.nr @@ -0,0 +1,34 @@ +struct MyStruct { + a: u32, + b: T, +} + +struct InnerStruct { + a: Field, + b: Field, +} + +trait MyEq { + fn my_eq(self, other: Self) -> bool; +} + +impl MyEq for InnerStruct { + fn my_eq(self, other: InnerStruct) -> bool { + (self.a == other.a) & (self.b == other.b) + } +} + +impl MyStruct where T: MyEq { + fn my_eq(self, other: Self) -> bool { + (self.a == other.a) & self.b.my_eq(other.b) + } +} + +fn main() { + let inner = InnerStruct { a: 1, b: 2 }; + let my_struct = MyStruct { a: 5, b: inner }; + assert(my_struct.my_eq(my_struct)); + + let mut my_struct_new = MyStruct { a: 5, b: InnerStruct { a: 10, b: 15 } }; + assert(my_struct_new.my_eq(my_struct_new)); +} \ No newline at end of file diff --git a/test_programs/compile_success_empty/numeric_generics_explicit/Nargo.toml b/test_programs/compile_success_empty/numeric_generics_explicit/Nargo.toml new file mode 100644 index 00000000000..980e5db588a --- /dev/null +++ b/test_programs/compile_success_empty/numeric_generics_explicit/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "numeric_generics_explicit" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr b/test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr new file mode 100644 index 00000000000..b16c068d5f3 --- /dev/null +++ b/test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr @@ -0,0 +1,111 @@ +// Regression that a global of the same name does not trigger a duplicate definition error +global N = 1000; + +fn main() { + let a = id([1, 2]); + let b = id([1, 2, 3]); + + let itWorks1 = MyStruct { data: a }; + assert(itWorks1.data[1] == 2); + let itWorks2 = MyStruct { data: b }; + assert(itWorks2.data[1] == 2); + + let c = [1, 2]; + let itAlsoWorks = MyStruct { data: c }; + assert(itAlsoWorks.data[1] == 2); + + assert(foo(itWorks2).data[0] == itWorks2.data[0] + 1); + + double_numeric_generics_test(); + + let my_type = PublicStorage::read::(); + assert(my_type.a == 1); + assert(my_type.b == 2); + assert(my_type.c == 3); + + let foo = baz::<10>(); + assert(foo.data == [1; 10]); +} + +// Used in the signature of a function +fn id(x: [Field; I]) -> [Field; I] { + x +} + +// Used as a field of a struct +struct MyStruct { + data: [Field; S], +} + +// Used in an impl +impl MyStruct { + fn insert(mut self: Self, index: Field, elem: Field) -> Self { + // Regression test for numeric generics on impls + assert(index as u32 < S); + + self.data[index] = elem; + self + } +} + +fn foo(mut s: MyStruct<2+1>) -> MyStruct<10/2-2> { + s.data[0] = s.data[0] + 1; + s +} + +fn baz() -> MyStruct { + MyStruct { data: [1; N] } +} + +fn double() -> u32 { + // Used as an expression + N * 2 +} + +fn double_numeric_generics_test() { + // Example usage of a numeric generic arguments. + assert(double::<9>() == 18); + assert(double::<123>() == 246); + assert(double::<7 + 8>() == 30); +} + +struct MyType { + a: Field, + b: Field, + c: Field, +} + +impl Deserialize for MyType { + fn deserialize(fields: [Field; N]) -> Self { + MyType { a: fields[0], b: fields[1], c: fields[2] } + } +} + +trait Deserialize { + fn deserialize(fields: [Field; N]) -> Self; +} + +struct PublicStorage {} + +impl PublicStorage { + fn read() -> T where T: Deserialize { + // Used as a type within a function body + let mut fields: [Field; N] = [0; N]; + // Used a loop bound + for i in 0..N { + fields[i] = i as Field + 1; + } + T::deserialize(fields) + } +} + +// Check that we can thread numeric generics into nested structs +// and also that we can handle nested structs with numeric generics +// which are declared after the parent struct +struct NestedNumeric { + a: Field, + b: InnerNumeric +} +struct InnerNumeric { + inner: [u32; N], +} \ No newline at end of file diff --git a/test_programs/execution_success/slices/src/main.nr b/test_programs/execution_success/slices/src/main.nr index 8be79cdc3c4..2bd4dbd97b0 100644 --- a/test_programs/execution_success/slices/src/main.nr +++ b/test_programs/execution_success/slices/src/main.nr @@ -45,6 +45,14 @@ fn main(x: Field, y: pub Field) { assert(append[0] == 1); assert(append[4] == 5); + let mapped = &[1, 2].map(|x| x + 1); + assert_eq(mapped, &[2, 3]); + + assert_eq(&[1, 2, 3].fold(0, |acc, x| acc + x), 6); + assert_eq(&[1, 2, 3].reduce(|acc, x| acc + x), 6); + assert(&[2, 4, 6].all(|x| x > 0)); + assert(&[2, 4, 6].any(|x| x > 5)); + regression_2083(); // The parameters to this function must come from witness values (inputs to main) regression_merge_slices(x, y); diff --git a/test_programs/noir_test_failure/should_fail_mismatch/src/main.nr b/test_programs/noir_test_failure/should_fail_mismatch/src/main.nr index 08a9234a752..62e03c153ed 100644 --- a/test_programs/noir_test_failure/should_fail_mismatch/src/main.nr +++ b/test_programs/noir_test_failure/should_fail_mismatch/src/main.nr @@ -2,14 +2,9 @@ fn test_different_string() { assert_eq(0, 1, "Different string"); } -// The assert message has a space -#[test(should_fail_with = "Not equal")] -fn test_with_extra_space() { - assert_eq(0, 1, "Not equal "); -} -// The assert message has a space -#[test(should_fail_with = "Not equal")] -fn test_runtime_mismatch() { - // We use a pedersen commitment here so that the assertion failure is only known at runtime. - assert_eq(std::hash::pedersen_commitment([27]).x, 0, "Not equal "); -} + +// The failure reason is a substring of the expected message, but it should be the other way around +#[test(should_fail_with = "Definitely Not equal!")] +fn test_wrong_expectation() { + assert_eq(0, 1, "Not equal"); +} \ No newline at end of file From 98df27d39b8eac50a0f6796ebe67b466dcdb4d26 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:21:17 +0000 Subject: [PATCH 06/14] chore: more tests updates --- test_programs/compile_success_empty/intrinsic_die/src/main.nr | 1 - .../compile_success_empty/regression_4635/src/main.nr | 2 +- .../compile_success_empty/trait_generics/src/main.nr | 2 +- test_programs/execution_success/regression_4088/src/main.nr | 4 ++-- test_programs/execution_success/regression_4124/src/main.nr | 4 ++-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/test_programs/compile_success_empty/intrinsic_die/src/main.nr b/test_programs/compile_success_empty/intrinsic_die/src/main.nr index c6e269c155d..17aaf02c283 100644 --- a/test_programs/compile_success_empty/intrinsic_die/src/main.nr +++ b/test_programs/compile_success_empty/intrinsic_die/src/main.nr @@ -1,6 +1,5 @@ // This test checks that we perform dead-instruction-elimination on intrinsic functions. fn main(x: Field) { - let hash = std::hash::pedersen_commitment([x]); let g1_x = 0x0000000000000000000000000000000000000000000000000000000000000001; let g1_y = 0x0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c; let g1 = std::embedded_curve_ops::EmbeddedCurvePoint { x: g1_x, y: g1_y, is_infinite: false }; diff --git a/test_programs/compile_success_empty/regression_4635/src/main.nr b/test_programs/compile_success_empty/regression_4635/src/main.nr index 23918e30785..350b60ba3f7 100644 --- a/test_programs/compile_success_empty/regression_4635/src/main.nr +++ b/test_programs/compile_success_empty/regression_4635/src/main.nr @@ -8,7 +8,7 @@ impl FromField for Field { } } -trait Deserialize { +trait Deserialize { fn deserialize(fields: [Field; N]) -> Self; } diff --git a/test_programs/compile_success_empty/trait_generics/src/main.nr b/test_programs/compile_success_empty/trait_generics/src/main.nr index 30b2e79d579..efa731978fc 100644 --- a/test_programs/compile_success_empty/trait_generics/src/main.nr +++ b/test_programs/compile_success_empty/trait_generics/src/main.nr @@ -15,7 +15,7 @@ trait MyInto { fn into(self) -> T; } -impl MyInto<[U; N]> for [T; N] where T: MyInto { +impl MyInto<[U; N]> for [T; N] where T: MyInto { fn into(self) -> [U; N] { self.map(|x: T| x.into()) } diff --git a/test_programs/execution_success/regression_4088/src/main.nr b/test_programs/execution_success/regression_4088/src/main.nr index 9e4d7892fc3..12a7afca68c 100644 --- a/test_programs/execution_success/regression_4088/src/main.nr +++ b/test_programs/execution_success/regression_4088/src/main.nr @@ -1,4 +1,4 @@ -trait Serialize { +trait Serialize { fn serialize(self) -> [Field; N]; } @@ -12,7 +12,7 @@ impl Serialize<1> for ValueNote { } } -fn check(serialized_note: [Field; N]) { +fn check(serialized_note: [Field; N]) { assert(serialized_note[0] == 0); } diff --git a/test_programs/execution_success/regression_4124/src/main.nr b/test_programs/execution_success/regression_4124/src/main.nr index 2b0e65a0b6c..6caea017798 100644 --- a/test_programs/execution_success/regression_4124/src/main.nr +++ b/test_programs/execution_success/regression_4124/src/main.nr @@ -1,6 +1,6 @@ use std::option::Option; -trait MyDeserialize { +trait MyDeserialize { fn deserialize(fields: [Field; N]) -> Self; } @@ -10,7 +10,7 @@ impl MyDeserialize<1> for Field { } } -pub fn storage_read() -> [Field; N] { +pub fn storage_read() -> [Field; N] { std::unsafe::zeroed() } From 72f0ca4c4e81e59c32fad0abfff13bfd4a2c2237 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:21:44 +0000 Subject: [PATCH 07/14] chore: update --- test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr b/test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr index 2e42c483360..2d38f5b1063 100644 --- a/test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr +++ b/test_programs/benchmarks/bench_eddsa_poseidon/src/main.nr @@ -1,4 +1,4 @@ -use std::eddsa::{eddsa_poseidon_verify}; +use std::eddsa::eddsa_poseidon_verify; fn main( msg: pub Field, From b15eacb0c7fcfb2879ebf88ed68c967777d1237a Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:23:01 +0000 Subject: [PATCH 08/14] chore: f --- .../compile_success_empty/impl_where_clause/src/main.nr | 2 +- .../compile_success_empty/numeric_generics_explicit/src/main.nr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test_programs/compile_success_empty/impl_where_clause/src/main.nr b/test_programs/compile_success_empty/impl_where_clause/src/main.nr index 0fbda1db39b..2f3223efaae 100644 --- a/test_programs/compile_success_empty/impl_where_clause/src/main.nr +++ b/test_programs/compile_success_empty/impl_where_clause/src/main.nr @@ -31,4 +31,4 @@ fn main() { let mut my_struct_new = MyStruct { a: 5, b: InnerStruct { a: 10, b: 15 } }; assert(my_struct_new.my_eq(my_struct_new)); -} \ No newline at end of file +} diff --git a/test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr b/test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr index b16c068d5f3..7c4f7761ff6 100644 --- a/test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr +++ b/test_programs/compile_success_empty/numeric_generics_explicit/src/main.nr @@ -108,4 +108,4 @@ struct NestedNumeric { } struct InnerNumeric { inner: [u32; N], -} \ No newline at end of file +} From 2d42048e36397fe3a3a9347aa92323a3d16f4880 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:25:15 +0000 Subject: [PATCH 09/14] chore: fix --- .../builtin_function_declaration/src/main.nr | 15 ++++++++------- .../non_comptime_local_fn_call/src/main.nr | 19 +++++++------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/test_programs/compile_failure/builtin_function_declaration/src/main.nr b/test_programs/compile_failure/builtin_function_declaration/src/main.nr index 7cbf4213425..473b5405691 100644 --- a/test_programs/compile_failure/builtin_function_declaration/src/main.nr +++ b/test_programs/compile_failure/builtin_function_declaration/src/main.nr @@ -1,9 +1,10 @@ -fn main() { - comptime { - let _a = id(3); - } -} +// This test prevents users from trying to create their own builtin functions as these should only exist in the stdlib. -fn id(x: Field) -> Field { - x +// This would otherwise be a perfectly valid declaration of the `to_le_bits` builtin function +#[builtin(to_le_bits)] +fn to_le_bits(_x: Field, _bit_size: u32) -> [u1] {} + +fn main(x: Field) -> pub u1 { + let bits = to_le_bits(x, 100); + bits[0] } \ No newline at end of file diff --git a/test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr b/test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr index 8f872f1b903..7cbf4213425 100644 --- a/test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr +++ b/test_programs/compile_failure/non_comptime_local_fn_call/src/main.nr @@ -1,14 +1,9 @@ -global DEPTH: Field = 40000; - -fn main(x: [u32; DEPTH], y: u32) { - let mut new_x = Vec::new(); - new_x = clear(x, y); -} - -unconstrained fn clear(x: [u32; DEPTH], y: u32) -> Vec { - let mut a = Vec::new(); - for i in 0..y { - a.push(x[i]); +fn main() { + comptime { + let _a = id(3); } - a } + +fn id(x: Field) -> Field { + x +} \ No newline at end of file From f55ad6dfc296a72d11403c319deeb19810f55df6 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:25:54 +0000 Subject: [PATCH 10/14] fix --- .../compile_failure/builtin_function_declaration/Nargo.toml | 2 +- .../compile_failure/non_comptime_local_fn_call/Nargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test_programs/compile_failure/builtin_function_declaration/Nargo.toml b/test_programs/compile_failure/builtin_function_declaration/Nargo.toml index cd000aa5f53..80312a7aec1 100644 --- a/test_programs/compile_failure/builtin_function_declaration/Nargo.toml +++ b/test_programs/compile_failure/builtin_function_declaration/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "non_comptime_local_fn_call" +name = "builtin_function_declaration" type = "bin" authors = [""] compiler_version = ">=0.31.0" diff --git a/test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml b/test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml index c09fc417b55..4ea2b75aa85 100644 --- a/test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml +++ b/test_programs/compile_failure/non_comptime_local_fn_call/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "brillig_vec_to_acir" +name = "non_comptime_local_fn_call" type = "bin" authors = [""] compiler_version = ">=0.23.0" From 0fd7867adc5ca1fb29ee6549b4fa9eb00e55ec92 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:27:55 +0000 Subject: [PATCH 11/14] f --- test_programs/compile_success_empty/trait_generics/src/main.nr | 2 +- .../{impl_where_clause => trait_impl_where_clause}/Nargo.toml | 2 +- .../{impl_where_clause => trait_impl_where_clause}/src/main.nr | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename test_programs/compile_success_empty/{impl_where_clause => trait_impl_where_clause}/Nargo.toml (62%) rename test_programs/compile_success_empty/{impl_where_clause => trait_impl_where_clause}/src/main.nr (100%) diff --git a/test_programs/compile_success_empty/trait_generics/src/main.nr b/test_programs/compile_success_empty/trait_generics/src/main.nr index efa731978fc..15591f2f2ea 100644 --- a/test_programs/compile_success_empty/trait_generics/src/main.nr +++ b/test_programs/compile_success_empty/trait_generics/src/main.nr @@ -29,7 +29,7 @@ impl MyInto for Field { /// Serialize example -trait Serializable { +trait Serializable { fn serialize(self) -> [Field; N]; } diff --git a/test_programs/compile_success_empty/impl_where_clause/Nargo.toml b/test_programs/compile_success_empty/trait_impl_where_clause/Nargo.toml similarity index 62% rename from test_programs/compile_success_empty/impl_where_clause/Nargo.toml rename to test_programs/compile_success_empty/trait_impl_where_clause/Nargo.toml index 58e774846cf..d92f7425550 100644 --- a/test_programs/compile_success_empty/impl_where_clause/Nargo.toml +++ b/test_programs/compile_success_empty/trait_impl_where_clause/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "impl_where_clause" +name = "trait_impl_where_clause" type = "bin" authors = [""] diff --git a/test_programs/compile_success_empty/impl_where_clause/src/main.nr b/test_programs/compile_success_empty/trait_impl_where_clause/src/main.nr similarity index 100% rename from test_programs/compile_success_empty/impl_where_clause/src/main.nr rename to test_programs/compile_success_empty/trait_impl_where_clause/src/main.nr From d581722662e305d7b239284ba3a867a514925772 Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:31:13 +0000 Subject: [PATCH 12/14] . --- .../Nargo.toml | 2 +- .../src/main.nr | 0 .../trait_impl_with_where_clause/Nargo.toml | 6 +++++ .../trait_impl_with_where_clause/src/main.nr | 27 +++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) rename test_programs/compile_success_empty/{trait_impl_where_clause => impl_where_clause}/Nargo.toml (62%) rename test_programs/compile_success_empty/{trait_impl_where_clause => impl_where_clause}/src/main.nr (100%) create mode 100644 test_programs/compile_success_empty/trait_impl_with_where_clause/Nargo.toml create mode 100644 test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr diff --git a/test_programs/compile_success_empty/trait_impl_where_clause/Nargo.toml b/test_programs/compile_success_empty/impl_where_clause/Nargo.toml similarity index 62% rename from test_programs/compile_success_empty/trait_impl_where_clause/Nargo.toml rename to test_programs/compile_success_empty/impl_where_clause/Nargo.toml index d92f7425550..58e774846cf 100644 --- a/test_programs/compile_success_empty/trait_impl_where_clause/Nargo.toml +++ b/test_programs/compile_success_empty/impl_where_clause/Nargo.toml @@ -1,5 +1,5 @@ [package] -name = "trait_impl_where_clause" +name = "impl_where_clause" type = "bin" authors = [""] diff --git a/test_programs/compile_success_empty/trait_impl_where_clause/src/main.nr b/test_programs/compile_success_empty/impl_where_clause/src/main.nr similarity index 100% rename from test_programs/compile_success_empty/trait_impl_where_clause/src/main.nr rename to test_programs/compile_success_empty/impl_where_clause/src/main.nr diff --git a/test_programs/compile_success_empty/trait_impl_with_where_clause/Nargo.toml b/test_programs/compile_success_empty/trait_impl_with_where_clause/Nargo.toml new file mode 100644 index 00000000000..672569634ea --- /dev/null +++ b/test_programs/compile_success_empty/trait_impl_with_where_clause/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "trait_impl_with_where_clause" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr b/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr new file mode 100644 index 00000000000..7a93851ee55 --- /dev/null +++ b/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr @@ -0,0 +1,27 @@ +fn main() { + let array: [Field; 3] = [1, 2, 3]; + assert(array.my_eq(array)); + // Ensure this still works if we have to infer the type of the integer literals + let array = [1, 2, 3]; + assert(array.my_eq(array)); +} + +trait MyEq { + fn my_eq(self, other: Self) -> bool; +} + +impl MyEq for [T; 3] where T: MyEq { + fn my_eq(self, other: Self) -> bool { + let mut ret = true; + for i in 0 .. self.len() { + ret &= self[i].my_eq(other[i]); + } + ret + } +} + +impl MyEq for Field { + fn my_eq(self, other: Field) -> bool { + self == other + } +} \ No newline at end of file From 8a011f8d067861c7f3ebd1d4962c693a189af3cc Mon Sep 17 00:00:00 2001 From: TomAFrench Date: Thu, 27 Jun 2024 18:35:24 +0000 Subject: [PATCH 13/14] chore: fmt --- .../trait_impl_with_where_clause/src/main.nr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr b/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr index 7a93851ee55..780512f04dc 100644 --- a/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr +++ b/test_programs/compile_success_empty/trait_impl_with_where_clause/src/main.nr @@ -24,4 +24,4 @@ impl MyEq for Field { fn my_eq(self, other: Field) -> bool { self == other } -} \ No newline at end of file +} From b41a02cce101b63c82246050aafb5878497fb3b8 Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Thu, 27 Jun 2024 19:26:10 +0000 Subject: [PATCH 14/14] delete redundant test impl_with_where_clause that was renamed to trait_impl_with_where_clause --- .../impl_with_where_clause/Nargo.toml | 6 ----- .../impl_with_where_clause/src/main.nr | 27 ------------------- 2 files changed, 33 deletions(-) delete mode 100644 test_programs/compile_success_empty/impl_with_where_clause/Nargo.toml delete mode 100644 test_programs/compile_success_empty/impl_with_where_clause/src/main.nr diff --git a/test_programs/compile_success_empty/impl_with_where_clause/Nargo.toml b/test_programs/compile_success_empty/impl_with_where_clause/Nargo.toml deleted file mode 100644 index ef9bdce2640..00000000000 --- a/test_programs/compile_success_empty/impl_with_where_clause/Nargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "impl_with_where_clause" -type = "bin" -authors = [""] - -[dependencies] diff --git a/test_programs/compile_success_empty/impl_with_where_clause/src/main.nr b/test_programs/compile_success_empty/impl_with_where_clause/src/main.nr deleted file mode 100644 index 780512f04dc..00000000000 --- a/test_programs/compile_success_empty/impl_with_where_clause/src/main.nr +++ /dev/null @@ -1,27 +0,0 @@ -fn main() { - let array: [Field; 3] = [1, 2, 3]; - assert(array.my_eq(array)); - // Ensure this still works if we have to infer the type of the integer literals - let array = [1, 2, 3]; - assert(array.my_eq(array)); -} - -trait MyEq { - fn my_eq(self, other: Self) -> bool; -} - -impl MyEq for [T; 3] where T: MyEq { - fn my_eq(self, other: Self) -> bool { - let mut ret = true; - for i in 0 .. self.len() { - ret &= self[i].my_eq(other[i]); - } - ret - } -} - -impl MyEq for Field { - fn my_eq(self, other: Field) -> bool { - self == other - } -}