Skip to content

Commit b589d8a

Browse files
feat(rewrite): instrument fn items inside macro_rules! definitions
add token-level scanner for fn patterns in macro_rules! templates. injects piano_runtime::enter() guards with stringify!($name) for metavar names and string literals for literal names. skips const fn, unsafe fn, extern fn. handles generic parameters, brace/paren/bracket delimiters, and fn inside impl blocks. activated when no --fn/--file/ --mod targets are specified via new instrument_macros parameter.
1 parent c9e603d commit b589d8a

File tree

4 files changed

+736
-26
lines changed

4 files changed

+736
-26
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ serde = { version = "1", features = ["derive"] }
2323
serde_json = "1"
2424
ignore = "0.4"
2525
tempfile = "3"
26+
proc-macro2 = "1.0.106"
2627

2728
[[bin]]
2829
name = "piano"

src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ fn build_project(
302302
}
303303

304304
// Rewrite each target file in staging.
305+
let instrument_macros = specs.is_empty();
305306
let mut all_concurrency: Vec<(String, String)> = Vec::new();
306307
for target in &targets {
307308
let target_set: HashSet<String> = target.functions.iter().cloned().collect();
@@ -314,9 +315,11 @@ fn build_project(
314315
})?;
315316

316317
let result =
317-
instrument_source(&source, &target_set).map_err(|source| Error::ParseError {
318-
path: staged_file.clone(),
319-
source,
318+
instrument_source(&source, &target_set, instrument_macros).map_err(|source| {
319+
Error::ParseError {
320+
path: staged_file.clone(),
321+
source,
322+
}
320323
})?;
321324

322325
all_concurrency.extend(result.concurrency);

0 commit comments

Comments
 (0)