Skip to content

Commit 6bc9eba

Browse files
(debug): Adding debug information for test runner and optimization
1 parent bbee75a commit 6bc9eba

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cairo-lang-lowering/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ salsa.workspace = true
2828
serde = { workspace = true, default-features = true }
2929
starknet-types-core.workspace = true
3030
thiserror.workspace = true
31+
tracing = { workspace = true, features = ["log"] }
32+
3133

3234
[dev-dependencies]
3335
cairo-lang-plugins = { path = "../cairo-lang-plugins" }

crates/cairo-lang-lowering/src/optimizations/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/// Macro for debug logging with "optimization" target.
2+
#[allow(unused)]
3+
macro_rules! debug {
4+
($($arg:tt)*) => {
5+
tracing::debug!(target: "optimization", $($arg)*)
6+
};
7+
}
8+
#[allow(unused_imports)]
9+
pub(crate) use debug;
10+
11+
/// Macro for trace logging with "optimization" target.
12+
#[allow(unused)]
13+
macro_rules! trace {
14+
($($arg:tt)*) => {
15+
tracing::trace!(target: "optimization", $($arg)*)
16+
};
17+
}
18+
#[allow(unused_imports)]
19+
pub(crate) use trace;
20+
121
pub mod branch_inversion;
222
pub mod cancel_ops;
323
pub mod config;

crates/cairo-lang-lowering/src/optimizations/strategy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ impl<'db> OptimizationPhase<'db> {
6969
function: ConcreteFunctionWithBodyId<'db>,
7070
lowered: &mut Lowered<'db>,
7171
) -> Maybe<()> {
72+
debug!("Applying optimization: {self:?}");
73+
7274
match self {
7375
OptimizationPhase::ApplyInlining { enable_const_folding } => {
7476
apply_inlining(db, function, lowered, enable_const_folding)?

crates/cairo-lang-test-utils/src/parse_test_file.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ pub fn dump_to_test_file(
102102
for (test_name, test) in tests {
103103
let mut tag_strings = vec![TAG_PREFIX.to_string() + &test_name];
104104
for (tag, content) in test.attributes {
105-
tag_strings.push(
106-
TAG_PREFIX.to_string()
107-
+ &tag
108-
+ if content.is_empty() { "" } else { "\n" }
109-
+ &content,
110-
);
105+
if tag != "test_name" {
106+
tag_strings.push(
107+
TAG_PREFIX.to_string()
108+
+ &tag
109+
+ if content.is_empty() { "" } else { "\n" }
110+
+ &content,
111+
);
112+
}
111113
}
112114
test_strings.push(tag_strings.join("\n\n"));
113115
}
@@ -139,8 +141,11 @@ impl TestBuilder {
139141
}
140142

141143
fn set_test_name(&mut self, line: String, line_num: usize) {
142-
self.current_test_name = Some(line);
143-
self.current_test = Some(Test { attributes: OrderedHashMap::default(), line_num });
144+
self.current_test_name = Some(line.clone());
145+
self.current_test = Some(Test {
146+
attributes: OrderedHashMap::from([("test_name".to_string(), line)]),
147+
line_num,
148+
});
144149
}
145150

146151
fn add_content_line(&mut self, line: String) {

0 commit comments

Comments
 (0)