Skip to content

Commit

Permalink
feat: Only link the debug crate when instrumenting code for the debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Jan 23, 2024
1 parent ca45375 commit c701728
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
24 changes: 16 additions & 8 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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));
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tooling/debugger/ignored-tests.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
array_sort
assign_ex
bit_shifts_comptime
brillig_cow
brillig_nested_arrays
brillig_references
Expand All @@ -12,6 +11,5 @@ nested_array_dynamic
nested_array_in_slice
nested_arrays_from_brillig
references
signed_comparison
simple_2d_array
to_bytes_integration
3 changes: 2 additions & 1 deletion tooling/nargo/src/ops/compile.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -105,6 +105,7 @@ pub fn compile_program_with_debug_state(
debug_state: DebugState,
) -> CompilationResult<CompiledProgram> {
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) =
Expand Down

0 comments on commit c701728

Please sign in to comment.