Skip to content

Commit adc1109

Browse files
committed
Add option to extract functions debug info to configs
commit-id:c5d50d84
1 parent 629eb65 commit adc1109

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

crates/cairo-lang-compiler/src/lib.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ pub struct CompilerConfig<'a> {
4646
/// Replaces Sierra IDs with human-readable ones.
4747
pub replace_ids: bool,
4848

49-
/// Adds a mapping used by [cairo-profiler](https://github.com/software-mansion/cairo-profiler) to
50-
/// [cairo_lang_sierra::debug_info::Annotations] in [cairo_lang_sierra::debug_info::DebugInfo].
49+
/// Adds a mapping used by [cairo-profiler](https://github.com/software-mansion/cairo-profiler)
50+
/// to [Annotations] in [DebugInfo].
5151
pub add_statements_functions: bool,
5252

53-
/// Adds a mapping used by [cairo-coverage](https://github.com/software-mansion/cairo-coverage) to
54-
/// [cairo_lang_sierra::debug_info::Annotations] in [cairo_lang_sierra::debug_info::DebugInfo].
53+
/// Adds a mapping used by [cairo-coverage](https://github.com/software-mansion/cairo-coverage)
54+
/// to [Annotations] in [DebugInfo].
5555
pub add_statements_code_locations: bool,
56+
57+
/// Adds a mapping used by [cairo-debugger](https://github.com/software-mansion-labs/cairo-debugger)
58+
/// to [Annotations] in [DebugInfo] in the compiled tests.
59+
pub add_functions_debug_info: bool,
5660
}
5761

5862
/// Compiles a Cairo project at the given path.
@@ -159,6 +163,10 @@ pub fn compile_prepared_db<'db>(
159163
replace_sierra_ids_in_program(db, &sierra_program_with_debug.program);
160164
}
161165

166+
let x =
167+
sierra_program_with_debug.debug_info.statements_locations.extract_statements_functions(db);
168+
eprintln!("{x:#?}");
169+
162170
Ok(sierra_program_with_debug)
163171
}
164172

@@ -346,6 +354,12 @@ pub fn compile_prepared_db_program_artifact_for_functions<'db>(
346354
))
347355
};
348356

357+
if compiler_config.add_functions_debug_info {
358+
annotations.extend(Annotations::from(
359+
sierra_program_with_debug.debug_info.functions_info.extract_serializable_debug_info(db),
360+
))
361+
}
362+
349363
let debug_info = DebugInfo {
350364
type_names: Default::default(),
351365
libfunc_names: Default::default(),

crates/cairo-lang-starknet/src/compile.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ fn compile_contract_with_prepared_and_checked_db<'db>(
167167
annotations.extend(Annotations::from(statements_functions))
168168
};
169169

170+
if compiler_config.add_functions_debug_info {
171+
annotations.extend(Annotations::from(
172+
debug_info.functions_info.extract_serializable_debug_info(db),
173+
))
174+
}
175+
170176
let abi_builder: Option<AbiBuilder<'db>> =
171177
AbiBuilder::from_submodule(db, contract.submodule_id, Default::default()).ok();
172178
let finalized_abi =

crates/cairo-lang-starknet/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub fn get_test_contract(example_file_name: &str) -> ContractClass {
8484
diagnostics_reporter,
8585
add_statements_functions: false,
8686
add_statements_code_locations: false,
87+
add_functions_debug_info: false,
8788
},
8889
)
8990
.expect("compile_path failed")

crates/cairo-lang-test-plugin/src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@ pub struct TestsCompilationConfig<'db> {
6565
/// If not defined, test crates will be searched.
6666
pub executable_crate_ids: Option<Vec<CrateId<'db>>>,
6767

68-
/// Adds a mapping used by [cairo-profiler](https://github.com/software-mansion/cairo-profiler) to
69-
/// [Annotations] in [DebugInfo] in the compiled tests.
68+
/// Adds a mapping used by [cairo-profiler](https://github.com/software-mansion/cairo-profiler)
69+
/// to [Annotations] in [DebugInfo] in the compiled tests.
7070
pub add_statements_functions: bool,
7171

72-
/// Adds a mapping used by [cairo-coverage](https://github.com/software-mansion/cairo-coverage) to
73-
/// [Annotations] in [DebugInfo] in the compiled tests.
72+
/// Adds a mapping used by [cairo-coverage](https://github.com/software-mansion/cairo-coverage)
73+
/// to [Annotations] in [DebugInfo] in the compiled tests.
7474
pub add_statements_code_locations: bool,
75+
76+
/// Adds a mapping used by [cairo-debugger](https://github.com/software-mansion-labs/cairo-debugger)
77+
/// to [Annotations] in [DebugInfo] in the compiled tests.
78+
pub add_functions_debug_info: bool,
7579
}
7680

7781
/// Runs Cairo compiler.
@@ -172,6 +176,12 @@ pub fn compile_test_prepared_db<'db>(
172176
))
173177
}
174178

179+
if tests_compilation_config.add_functions_debug_info {
180+
annotations.extend(Annotations::from(
181+
debug_info.functions_info.extract_serializable_debug_info(db),
182+
))
183+
}
184+
175185
let executables = collect_executables(db, executable_functions, &sierra_program);
176186
let named_tests = all_tests
177187
.into_iter()

crates/cairo-lang-test-runner/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl<'db> TestRunner<'db> {
7575
contract_declarations: None,
7676
contract_crate_ids: None,
7777
executable_crate_ids: None,
78+
add_functions_debug_info: false,
7879
},
7980
)?;
8081
Ok(Self { compiler, config, custom_hint_processor_factory: None })

crates/cairo-lang-test-runner/src/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fn test_compiled_serialization() {
2121
starknet: true,
2222
add_statements_functions: false,
2323
add_statements_code_locations: false,
24+
add_functions_debug_info: false,
2425
contract_declarations: None,
2526
contract_crate_ids: None,
2627
executable_crate_ids: None,

0 commit comments

Comments
 (0)