From d22a0e7ac7de40c4bb765285724d585f0397f474 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 4 Jul 2023 09:32:21 +0000 Subject: [PATCH 1/9] fix: do not process relative dependencies twice --- crates/fm/src/lib.rs | 44 +++++++++++++++++++++++--- crates/noirc_driver/src/lib.rs | 8 +++++ crates/noirc_frontend/src/graph/mod.rs | 8 ++++- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/crates/fm/src/lib.rs b/crates/fm/src/lib.rs index cc87129fc0d..ad6c3d1fd23 100644 --- a/crates/fm/src/lib.rs +++ b/crates/fm/src/lib.rs @@ -10,6 +10,7 @@ pub use file_map::{File, FileId, FileMap}; use std::{ collections::HashMap, + fs, path::{Path, PathBuf}, }; @@ -20,6 +21,8 @@ pub const FILE_EXTENSION: &str = "nr"; /// which the compiler starts at, and the others. /// This is so that submodules of the root, can live alongside the /// root file as files. +// TODO(Maddiaa): remove derivations +#[derive(Clone, Copy, Debug)] pub enum FileType { Root, Normal, @@ -38,12 +41,21 @@ pub struct FileManager { impl FileManager { // XXX: Maybe use a AsRef here, for API ergonomics pub fn add_file(&mut self, path_to_file: &Path, file_type: FileType) -> Option { - let source = file_reader::read_file_to_string(path_to_file).ok()?; + // Handle both relative file paths and std/lib virtual paths. + let base = Path::new(".").canonicalize().unwrap(); // Should never fail (TODO: test wasm) + let res = path_to_file.canonicalize().unwrap_or(path_to_file.to_path_buf()); + let resolved_path = res.strip_prefix(base).unwrap_or(&res); + + // Check that the resolved path already exists in the file map, if it is, we return it. + let path_to_file = virtualize_path(resolved_path, file_type); + if let Some(file_id) = self.path_to_id.get(&path_to_file) { + return Some(*file_id); + } - let file_id = self.file_map.add_file(path_to_file.to_path_buf().into(), source); - let path_to_file = virtualize_path(path_to_file, file_type); + // Otherwise we add the file + let source = file_reader::read_file_to_string(&resolved_path).ok()?; + let file_id = self.file_map.add_file(resolved_path.to_path_buf().into(), source); self.register_path(file_id, path_to_file); - Some(file_id) } @@ -177,4 +189,28 @@ mod tests { // Now check for files in it's subdirectory fm.resolve_path(sub_dir_file_id, "foo").unwrap(); } + + /// Tests that two identical files that have different paths are treated as the same file + /// e.g. if we start in the dir ./src and have a file ../../foo.nr + /// that should be treated as the same file as ../ starting in ./ + /// they should both resolve to ../foo.nr + #[test] + fn path_resolve_modules_with_different_paths_as_same_file() { + let mut fm = FileManager::default(); + + // Create a lib.nr file at the root. + let dir = tempdir().unwrap(); + let sub_dir = TempDir::new_in(&dir).unwrap(); + let sub_sub_dir = TempDir::new_in(&sub_dir).unwrap(); + let file_path = dummy_file_path(&dir, "lib.nr"); + + // Create another file in a subdirectory with a convoluted path + let second_file_path = dummy_file_path(&sub_sub_dir, "./../../lib.nr"); + + // Add both files to the file manager + let file_id = fm.add_file(&file_path, FileType::Root).unwrap(); + let second_file_id = fm.add_file(&second_file_path, FileType::Root).unwrap(); + + assert_eq!(file_id, second_file_id); + } } diff --git a/crates/noirc_driver/src/lib.rs b/crates/noirc_driver/src/lib.rs index c09ffe6b43c..74f0db45ee7 100644 --- a/crates/noirc_driver/src/lib.rs +++ b/crates/noirc_driver/src/lib.rs @@ -122,9 +122,13 @@ impl Driver { root_file: P, crate_type: CrateType, ) -> CrateId { + // TODO(Maddiaa): recognise the same crate here + let dir_path = root_file.as_ref().to_path_buf(); let root_file_id = self.context.file_manager.add_file(&dir_path, FileType::Root).unwrap(); + dbg!(root_file_id); + // The first crate is always the local crate assert!(self.context.crate_graph.number_of_crates() != 0); @@ -143,6 +147,9 @@ impl Driver { panic!("crates cannot depend on binaries. {crate_name:?} is a binary crate") } + // dbg!("note"); + dbg!(this_crate, depends_on, crate_name.clone()); + dbg!("\n"); self.context .crate_graph .add_dep(this_crate, crate_name, depends_on) @@ -158,6 +165,7 @@ impl Driver { .filter(|crate_id| *crate_id != dep_to_propagate) .collect(); + dbg!("note"); for crate_id in crate_ids { self.context .crate_graph diff --git a/crates/noirc_frontend/src/graph/mod.rs b/crates/noirc_frontend/src/graph/mod.rs index 47426606da1..2c845a1ca65 100644 --- a/crates/noirc_frontend/src/graph/mod.rs +++ b/crates/noirc_frontend/src/graph/mod.rs @@ -83,7 +83,13 @@ impl CrateGraph { pub fn add_crate_root(&mut self, crate_type: CrateType, file_id: FileId) -> CrateId { let mut roots_with_file_id = self.arena.iter().filter(|(_, crate_data)| crate_data.root_file_id == file_id); - assert!(roots_with_file_id.next().is_none(), "you cannot add the same file id twice"); + + let next_file_id = roots_with_file_id.next(); + if next_file_id.is_some() { + return next_file_id.unwrap().0; + } + + assert!(next_file_id.is_none(), "you cannot add the same file id twice"); let data = CrateData { root_file_id: file_id, crate_type, dependencies: Vec::new() }; let crate_id = CrateId(self.arena.len()); From de0748ac3b4c6f4401e1786139764fc7ae1928c0 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 4 Jul 2023 09:44:14 +0000 Subject: [PATCH 2/9] fmt --- crates/fm/src/lib.rs | 3 --- crates/noirc_driver/src/lib.rs | 8 -------- crates/noirc_frontend/src/graph/mod.rs | 2 +- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/crates/fm/src/lib.rs b/crates/fm/src/lib.rs index ad6c3d1fd23..195e140c021 100644 --- a/crates/fm/src/lib.rs +++ b/crates/fm/src/lib.rs @@ -10,7 +10,6 @@ pub use file_map::{File, FileId, FileMap}; use std::{ collections::HashMap, - fs, path::{Path, PathBuf}, }; @@ -21,8 +20,6 @@ pub const FILE_EXTENSION: &str = "nr"; /// which the compiler starts at, and the others. /// This is so that submodules of the root, can live alongside the /// root file as files. -// TODO(Maddiaa): remove derivations -#[derive(Clone, Copy, Debug)] pub enum FileType { Root, Normal, diff --git a/crates/noirc_driver/src/lib.rs b/crates/noirc_driver/src/lib.rs index 74f0db45ee7..c09ffe6b43c 100644 --- a/crates/noirc_driver/src/lib.rs +++ b/crates/noirc_driver/src/lib.rs @@ -122,13 +122,9 @@ impl Driver { root_file: P, crate_type: CrateType, ) -> CrateId { - // TODO(Maddiaa): recognise the same crate here - let dir_path = root_file.as_ref().to_path_buf(); let root_file_id = self.context.file_manager.add_file(&dir_path, FileType::Root).unwrap(); - dbg!(root_file_id); - // The first crate is always the local crate assert!(self.context.crate_graph.number_of_crates() != 0); @@ -147,9 +143,6 @@ impl Driver { panic!("crates cannot depend on binaries. {crate_name:?} is a binary crate") } - // dbg!("note"); - dbg!(this_crate, depends_on, crate_name.clone()); - dbg!("\n"); self.context .crate_graph .add_dep(this_crate, crate_name, depends_on) @@ -165,7 +158,6 @@ impl Driver { .filter(|crate_id| *crate_id != dep_to_propagate) .collect(); - dbg!("note"); for crate_id in crate_ids { self.context .crate_graph diff --git a/crates/noirc_frontend/src/graph/mod.rs b/crates/noirc_frontend/src/graph/mod.rs index 2c845a1ca65..5d980df1df7 100644 --- a/crates/noirc_frontend/src/graph/mod.rs +++ b/crates/noirc_frontend/src/graph/mod.rs @@ -86,7 +86,7 @@ impl CrateGraph { let next_file_id = roots_with_file_id.next(); if next_file_id.is_some() { - return next_file_id.unwrap().0; + return *next_file_id.unwrap().0; } assert!(next_file_id.is_none(), "you cannot add the same file id twice"); From dd1686957d297f948caa749c0d6c27666645aaec Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 4 Jul 2023 10:08:00 +0000 Subject: [PATCH 3/9] chore(clippy): fix finds in flake check --- crates/fm/src/lib.rs | 4 ++-- crates/noirc_frontend/src/graph/mod.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fm/src/lib.rs b/crates/fm/src/lib.rs index 195e140c021..c19481c17c4 100644 --- a/crates/fm/src/lib.rs +++ b/crates/fm/src/lib.rs @@ -40,7 +40,7 @@ impl FileManager { pub fn add_file(&mut self, path_to_file: &Path, file_type: FileType) -> Option { // Handle both relative file paths and std/lib virtual paths. let base = Path::new(".").canonicalize().unwrap(); // Should never fail (TODO: test wasm) - let res = path_to_file.canonicalize().unwrap_or(path_to_file.to_path_buf()); + let res = path_to_file.canonicalize().unwrap_or_else(|_| path_to_file.to_path_buf()); let resolved_path = res.strip_prefix(base).unwrap_or(&res); // Check that the resolved path already exists in the file map, if it is, we return it. @@ -50,7 +50,7 @@ impl FileManager { } // Otherwise we add the file - let source = file_reader::read_file_to_string(&resolved_path).ok()?; + let source = file_reader::read_file_to_string(resolved_path).ok()?; let file_id = self.file_map.add_file(resolved_path.to_path_buf().into(), source); self.register_path(file_id, path_to_file); Some(file_id) diff --git a/crates/noirc_frontend/src/graph/mod.rs b/crates/noirc_frontend/src/graph/mod.rs index 5d980df1df7..1241561c03e 100644 --- a/crates/noirc_frontend/src/graph/mod.rs +++ b/crates/noirc_frontend/src/graph/mod.rs @@ -85,8 +85,8 @@ impl CrateGraph { self.arena.iter().filter(|(_, crate_data)| crate_data.root_file_id == file_id); let next_file_id = roots_with_file_id.next(); - if next_file_id.is_some() { - return *next_file_id.unwrap().0; + if let Some(file_id) = next_file_id { + return *file_id.0; } assert!(next_file_id.is_none(), "you cannot add the same file id twice"); From 4ed842c1f978e63a9867aec646c61e6bc43accd3 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 4 Jul 2023 13:16:26 +0000 Subject: [PATCH 4/9] fix: update unwrap to expect @ludamad --- crates/fm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fm/src/lib.rs b/crates/fm/src/lib.rs index c19481c17c4..c97e90ad16f 100644 --- a/crates/fm/src/lib.rs +++ b/crates/fm/src/lib.rs @@ -39,7 +39,7 @@ impl FileManager { // XXX: Maybe use a AsRef here, for API ergonomics pub fn add_file(&mut self, path_to_file: &Path, file_type: FileType) -> Option { // Handle both relative file paths and std/lib virtual paths. - let base = Path::new(".").canonicalize().unwrap(); // Should never fail (TODO: test wasm) + let base = Path::new(".").canonicalize().expect("Base path canonicalize failed"); // Should never fail let res = path_to_file.canonicalize().unwrap_or_else(|_| path_to_file.to_path_buf()); let resolved_path = res.strip_prefix(base).unwrap_or(&res); From 21d4132bfa4826ceeacd51a47db5071bfe57162d Mon Sep 17 00:00:00 2001 From: vezenovm Date: Tue, 4 Jul 2023 10:46:12 +0000 Subject: [PATCH 5/9] move file id none assert check --- crates/noirc_frontend/src/graph/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/noirc_frontend/src/graph/mod.rs b/crates/noirc_frontend/src/graph/mod.rs index 1241561c03e..69640e0349e 100644 --- a/crates/noirc_frontend/src/graph/mod.rs +++ b/crates/noirc_frontend/src/graph/mod.rs @@ -85,12 +85,12 @@ impl CrateGraph { self.arena.iter().filter(|(_, crate_data)| crate_data.root_file_id == file_id); let next_file_id = roots_with_file_id.next(); + assert!(next_file_id.is_none(), "you cannot add the same file id twice"); + if let Some(file_id) = next_file_id { return *file_id.0; } - assert!(next_file_id.is_none(), "you cannot add the same file id twice"); - let data = CrateData { root_file_id: file_id, crate_type, dependencies: Vec::new() }; let crate_id = CrateId(self.arena.len()); let prev = self.arena.insert(crate_id, data); From a15a5a67fe9302a75fd751923c0ec4f97025be4c Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 4 Jul 2023 13:47:43 +0000 Subject: [PATCH 6/9] test: add comprehensive regression test --- crates/nargo_cli/tests/test_data/diamond_deps_0/Nargo.toml | 7 +++++++ .../nargo_cli/tests/test_data/diamond_deps_0/Prover.toml | 3 +++ .../nargo_cli/tests/test_data/diamond_deps_0/src/main.nr | 7 +++++++ crates/nargo_cli/tests/test_data/diamond_deps_1/Nargo.toml | 6 ++++++ crates/nargo_cli/tests/test_data/diamond_deps_1/src/lib.nr | 5 +++++ crates/nargo_cli/tests/test_data/diamond_deps_2/Nargo.toml | 5 +++++ crates/nargo_cli/tests/test_data/diamond_deps_2/src/lib.nr | 6 ++++++ crates/noirc_frontend/src/graph/mod.rs | 2 -- 8 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 crates/nargo_cli/tests/test_data/diamond_deps_0/Nargo.toml create mode 100644 crates/nargo_cli/tests/test_data/diamond_deps_0/Prover.toml create mode 100644 crates/nargo_cli/tests/test_data/diamond_deps_0/src/main.nr create mode 100644 crates/nargo_cli/tests/test_data/diamond_deps_1/Nargo.toml create mode 100644 crates/nargo_cli/tests/test_data/diamond_deps_1/src/lib.nr create mode 100644 crates/nargo_cli/tests/test_data/diamond_deps_2/Nargo.toml create mode 100644 crates/nargo_cli/tests/test_data/diamond_deps_2/src/lib.nr diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_0/Nargo.toml b/crates/nargo_cli/tests/test_data/diamond_deps_0/Nargo.toml new file mode 100644 index 00000000000..fffedf870f9 --- /dev/null +++ b/crates/nargo_cli/tests/test_data/diamond_deps_0/Nargo.toml @@ -0,0 +1,7 @@ +[package] +authors = [""] +compiler_version = "0.7.1" + +[dependencies] +dep1 = { path = "../diamond_deps_1" } +dep2 = { path = "../diamond_deps_2" } \ No newline at end of file diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_0/Prover.toml b/crates/nargo_cli/tests/test_data/diamond_deps_0/Prover.toml new file mode 100644 index 00000000000..a713241e7dd --- /dev/null +++ b/crates/nargo_cli/tests/test_data/diamond_deps_0/Prover.toml @@ -0,0 +1,3 @@ +x = 1 +y = 1 +return = 5 \ No newline at end of file diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_0/src/main.nr b/crates/nargo_cli/tests/test_data/diamond_deps_0/src/main.nr new file mode 100644 index 00000000000..f01491171bb --- /dev/null +++ b/crates/nargo_cli/tests/test_data/diamond_deps_0/src/main.nr @@ -0,0 +1,7 @@ +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 +} \ No newline at end of file diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_1/Nargo.toml b/crates/nargo_cli/tests/test_data/diamond_deps_1/Nargo.toml new file mode 100644 index 00000000000..1241b147d83 --- /dev/null +++ b/crates/nargo_cli/tests/test_data/diamond_deps_1/Nargo.toml @@ -0,0 +1,6 @@ +[package] +authors = [""] +compiler_version = "0.7.1" + +[dependencies] +dep2 = { path = "../diamond_deps_2" } \ No newline at end of file diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_1/src/lib.nr b/crates/nargo_cli/tests/test_data/diamond_deps_1/src/lib.nr new file mode 100644 index 00000000000..cecb2715104 --- /dev/null +++ b/crates/nargo_cli/tests/test_data/diamond_deps_1/src/lib.nr @@ -0,0 +1,5 @@ +use dep::dep2::call_dep2; + +fn call_dep1_then_dep2(x : Field, y : Field) -> Field { + call_dep2(x, y) +} diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_2/Nargo.toml b/crates/nargo_cli/tests/test_data/diamond_deps_2/Nargo.toml new file mode 100644 index 00000000000..7cae77988e3 --- /dev/null +++ b/crates/nargo_cli/tests/test_data/diamond_deps_2/Nargo.toml @@ -0,0 +1,5 @@ +[package] +authors = [""] +compiler_version = "0.7.1" + +[dependencies] \ No newline at end of file diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_2/src/lib.nr b/crates/nargo_cli/tests/test_data/diamond_deps_2/src/lib.nr new file mode 100644 index 00000000000..f7745efd679 --- /dev/null +++ b/crates/nargo_cli/tests/test_data/diamond_deps_2/src/lib.nr @@ -0,0 +1,6 @@ +global RESOLVE_THIS = 3; + + +fn call_dep2(x : Field, y : Field) -> Field { + x + y +} diff --git a/crates/noirc_frontend/src/graph/mod.rs b/crates/noirc_frontend/src/graph/mod.rs index 69640e0349e..1968c9ae142 100644 --- a/crates/noirc_frontend/src/graph/mod.rs +++ b/crates/noirc_frontend/src/graph/mod.rs @@ -85,8 +85,6 @@ impl CrateGraph { self.arena.iter().filter(|(_, crate_data)| crate_data.root_file_id == file_id); let next_file_id = roots_with_file_id.next(); - assert!(next_file_id.is_none(), "you cannot add the same file id twice"); - if let Some(file_id) = next_file_id { return *file_id.0; } From 9061c06d42705c0e3d8357006335ffdeb423087c Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 4 Jul 2023 14:11:54 +0000 Subject: [PATCH 7/9] review: remove un-required comment --- crates/fm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fm/src/lib.rs b/crates/fm/src/lib.rs index c97e90ad16f..b79a2b2c700 100644 --- a/crates/fm/src/lib.rs +++ b/crates/fm/src/lib.rs @@ -39,7 +39,7 @@ impl FileManager { // XXX: Maybe use a AsRef here, for API ergonomics pub fn add_file(&mut self, path_to_file: &Path, file_type: FileType) -> Option { // Handle both relative file paths and std/lib virtual paths. - let base = Path::new(".").canonicalize().expect("Base path canonicalize failed"); // Should never fail + let base = Path::new(".").canonicalize().expect("Base path canonicalize failed"); let res = path_to_file.canonicalize().unwrap_or_else(|_| path_to_file.to_path_buf()); let resolved_path = res.strip_prefix(base).unwrap_or(&res); From 677140895a0c77e0639ad89cd7ef4b3a6bd44871 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 4 Jul 2023 14:17:46 +0000 Subject: [PATCH 8/9] fix: move test libraries into another folder --- crates/nargo_cli/tests/test_data/diamond_deps_0/Nargo.toml | 4 ++-- .../{test_data => test_libraries}/diamond_deps_1/Nargo.toml | 0 .../{test_data => test_libraries}/diamond_deps_1/src/lib.nr | 0 .../{test_data => test_libraries}/diamond_deps_2/Nargo.toml | 0 .../{test_data => test_libraries}/diamond_deps_2/src/lib.nr | 0 5 files changed, 2 insertions(+), 2 deletions(-) rename crates/nargo_cli/tests/{test_data => test_libraries}/diamond_deps_1/Nargo.toml (100%) rename crates/nargo_cli/tests/{test_data => test_libraries}/diamond_deps_1/src/lib.nr (100%) rename crates/nargo_cli/tests/{test_data => test_libraries}/diamond_deps_2/Nargo.toml (100%) rename crates/nargo_cli/tests/{test_data => test_libraries}/diamond_deps_2/src/lib.nr (100%) diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_0/Nargo.toml b/crates/nargo_cli/tests/test_data/diamond_deps_0/Nargo.toml index fffedf870f9..d5094940130 100644 --- a/crates/nargo_cli/tests/test_data/diamond_deps_0/Nargo.toml +++ b/crates/nargo_cli/tests/test_data/diamond_deps_0/Nargo.toml @@ -3,5 +3,5 @@ authors = [""] compiler_version = "0.7.1" [dependencies] -dep1 = { path = "../diamond_deps_1" } -dep2 = { path = "../diamond_deps_2" } \ No newline at end of file +dep1 = { path = "../../test_libraries/diamond_deps_1" } +dep2 = { path = "../../test_libraries/diamond_deps_2" } \ No newline at end of file diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_1/Nargo.toml b/crates/nargo_cli/tests/test_libraries/diamond_deps_1/Nargo.toml similarity index 100% rename from crates/nargo_cli/tests/test_data/diamond_deps_1/Nargo.toml rename to crates/nargo_cli/tests/test_libraries/diamond_deps_1/Nargo.toml diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_1/src/lib.nr b/crates/nargo_cli/tests/test_libraries/diamond_deps_1/src/lib.nr similarity index 100% rename from crates/nargo_cli/tests/test_data/diamond_deps_1/src/lib.nr rename to crates/nargo_cli/tests/test_libraries/diamond_deps_1/src/lib.nr diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_2/Nargo.toml b/crates/nargo_cli/tests/test_libraries/diamond_deps_2/Nargo.toml similarity index 100% rename from crates/nargo_cli/tests/test_data/diamond_deps_2/Nargo.toml rename to crates/nargo_cli/tests/test_libraries/diamond_deps_2/Nargo.toml diff --git a/crates/nargo_cli/tests/test_data/diamond_deps_2/src/lib.nr b/crates/nargo_cli/tests/test_libraries/diamond_deps_2/src/lib.nr similarity index 100% rename from crates/nargo_cli/tests/test_data/diamond_deps_2/src/lib.nr rename to crates/nargo_cli/tests/test_libraries/diamond_deps_2/src/lib.nr From 653cb17ec5c6f081190a7a6e58be3cd1dc8f26db Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 4 Jul 2023 15:22:00 +0000 Subject: [PATCH 9/9] fix(test): same crate test should not panic --- crates/noirc_frontend/src/graph/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/noirc_frontend/src/graph/mod.rs b/crates/noirc_frontend/src/graph/mod.rs index 1968c9ae142..0e4a4c63518 100644 --- a/crates/noirc_frontend/src/graph/mod.rs +++ b/crates/noirc_frontend/src/graph/mod.rs @@ -236,7 +236,6 @@ mod tests { assert!(graph.add_dep(crate2, CrateName::new("crate3").unwrap(), crate3).is_ok()); } #[test] - #[should_panic] fn it_works2() { let file_ids = dummy_file_ids(3); let file_id_0 = file_ids[0]; @@ -245,7 +244,10 @@ mod tests { let mut graph = CrateGraph::default(); let _crate1 = graph.add_crate_root(CrateType::Library, file_id_0); let _crate2 = graph.add_crate_root(CrateType::Library, file_id_1); - let _crate3 = graph.add_crate_root(CrateType::Library, file_id_2); - let _crate3 = graph.add_crate_root(CrateType::Library, file_id_2); + + // Adding the same file, so the crate should be the same. + let crate3 = graph.add_crate_root(CrateType::Library, file_id_2); + let crate3_2 = graph.add_crate_root(CrateType::Library, file_id_2); + assert_eq!(crate3, crate3_2); } }