diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 1d0e4d4ef66..c9c03089b84 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -109,6 +109,7 @@ pub fn file_manager_with_stdlib(root: &Path) -> FileManager { let mut file_manager = FileManager::new(root); add_stdlib_source_to_file_manager(&mut file_manager); + add_debug_source_to_file_manager(&mut file_manager); file_manager } @@ -123,7 +124,11 @@ fn add_stdlib_source_to_file_manager(file_manager: &mut FileManager) { for (path, source) in stdlib_paths_with_source { file_manager.add_file_with_source_canonical_path(Path::new(&path), source); } +} +/// Adds the source code of the debug crate needed to support instrumentation to +/// track variables values +fn add_debug_source_to_file_manager(file_manager: &mut FileManager) { // Adds the synthetic debug module for instrumentation into the file manager let path_to_debug_lib_file = Path::new(DEBUG_CRATE_NAME).join("lib.nr"); file_manager.add_file_with_contents(&path_to_debug_lib_file, &create_prologue_program(8)); @@ -141,23 +146,26 @@ pub fn prepare_crate(context: &mut Context, file_name: &Path) -> CrateId { .expect("stdlib file id is expected to be present"); let std_crate_id = context.crate_graph.add_stdlib(std_file_id); - let path_to_debug_lib_file = Path::new(DEBUG_CRATE_NAME).join("lib.nr"); - let debug_file_id = context - .file_manager - .name_to_id(path_to_debug_lib_file) - .expect("debug module is expected to be present"); - let debug_crate_id = context.crate_graph.add_crate(debug_file_id); - let root_file_id = context.file_manager.name_to_id(file_name.to_path_buf()).unwrap_or_else(|| panic!("files are expected to be added to the FileManager before reaching the compiler file_path: {file_name:?}")); let root_crate_id = context.crate_graph.add_crate_root(root_file_id); add_dep(context, root_crate_id, std_crate_id, STD_CRATE_NAME.parse().unwrap()); - add_dep(context, root_crate_id, debug_crate_id, DEBUG_CRATE_NAME.parse().unwrap()); root_crate_id } +pub fn link_to_debug_crate(context: &mut Context, root_crate_id: CrateId) { + let path_to_debug_lib_file = Path::new(DEBUG_CRATE_NAME).join("lib.nr"); + let debug_file_id = context + .file_manager + .name_to_id(path_to_debug_lib_file) + .expect("debug source is expected to be present in file manager"); + let debug_crate_id = context.crate_graph.add_crate(debug_file_id); + + add_dep(context, root_crate_id, debug_crate_id, DEBUG_CRATE_NAME.parse().unwrap()); +} + // Adds the file from the file system at `Path` to the crate graph pub fn prepare_dependency(context: &mut Context, file_name: &Path) -> CrateId { let root_file_id = context diff --git a/tooling/debugger/ignored-tests.txt b/tooling/debugger/ignored-tests.txt index a9aeb44051f..f84712e20e0 100644 --- a/tooling/debugger/ignored-tests.txt +++ b/tooling/debugger/ignored-tests.txt @@ -1,6 +1,5 @@ array_sort assign_ex -bit_shifts_comptime brillig_cow brillig_nested_arrays brillig_references @@ -12,6 +11,5 @@ nested_array_dynamic nested_array_in_slice nested_arrays_from_brillig references -signed_comparison simple_2d_array to_bytes_integration diff --git a/tooling/nargo/src/ops/compile.rs b/tooling/nargo/src/ops/compile.rs index 247e731bb1a..db7cfa53cf7 100644 --- a/tooling/nargo/src/ops/compile.rs +++ b/tooling/nargo/src/ops/compile.rs @@ -1,6 +1,6 @@ use acvm::ExpressionWidth; use fm::FileManager; -use noirc_driver::{CompilationResult, CompileOptions, CompiledContract, CompiledProgram}; +use noirc_driver::{CompilationResult, CompileOptions, CompiledContract, CompiledProgram, link_to_debug_crate}; use noirc_frontend::debug::DebugState; use noirc_frontend::hir::ParsedFiles; @@ -105,6 +105,7 @@ pub fn compile_program_with_debug_state( debug_state: DebugState, ) -> CompilationResult { let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package); + link_to_debug_crate(&mut context, crate_id); context.debug_state = debug_state; let (program, warnings) =