forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#84582 - richkadel:issue-84561, r=tmandry
Vastly improves coverage spans for macros Fixes: rust-lang#84561 This resolves problems where macros like `trace!(...)` would show zero coverage if tracing was disabled, and `assert_eq!(...)` would show zero coverage if the assertion did not fail, because only one coverage span was generated, for the branch. This PR started with an idea that I could just drop branching blocks with same span as expanded macro. (See the fixed issue for more details.) That did help, but it didn't resolve everything. I also needed to add a span specifically for the macro name (plus `!`) to ensure the macro gets coverage even if it's internal expansion adds conditional branching blocks that are retained, and would otherwise drop the outer span. Now that outer span is _only_ the `(argument, list)`, which can safely be dropped now), because the macro name has its own span. While testing, I also noticed the spanview debug output can cause an ICE on a function with no body. The workaround for this is included in this PR (separate commit). r? `@tmandry` cc? `@wesleywiser`
- Loading branch information
Showing
13 changed files
with
861 additions
and
68 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.closure_macro.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
1| |// compile-flags: --edition=2018 | ||
2| |#![feature(no_coverage)] | ||
3| | | ||
4| |macro_rules! bail { | ||
5| | ($msg:literal $(,)?) => { | ||
6| | if $msg.len() > 0 { | ||
7| | println!("no msg"); | ||
8| | } else { | ||
9| | println!($msg); | ||
10| | } | ||
11| | return Err(String::from($msg)); | ||
12| | }; | ||
13| |} | ||
14| | | ||
15| |macro_rules! on_error { | ||
16| | ($value:expr, $error_message:expr) => { | ||
17| 0| $value.or_else(|e| { | ||
18| 0| let message = format!($error_message, e); | ||
19| 0| if message.len() > 0 { | ||
20| 0| println!("{}", message); | ||
21| 0| Ok(String::from("ok")) | ||
22| | } else { | ||
23| 0| bail!("error"); | ||
24| | } | ||
25| 0| }) | ||
26| | }; | ||
27| |} | ||
28| | | ||
29| 1|fn load_configuration_files() -> Result<String, String> { | ||
30| 1| Ok(String::from("config")) | ||
31| 1|} | ||
32| | | ||
33| 1|pub fn main() -> Result<(), String> { | ||
34| 1| println!("Starting service"); | ||
35| 1| let config = on_error!(load_configuration_files(), "Error loading configs: {}")?; | ||
^0 | ||
36| | | ||
37| 1| let startup_delay_duration = String::from("arg"); | ||
38| 1| let _ = (config, startup_delay_duration); | ||
39| 1| Ok(()) | ||
40| 1|} | ||
|
83 changes: 83 additions & 0 deletions
83
src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.closure_macro_async.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
1| |// compile-flags: --edition=2018 | ||
2| |#![feature(no_coverage)] | ||
3| | | ||
4| |macro_rules! bail { | ||
5| | ($msg:literal $(,)?) => { | ||
6| | if $msg.len() > 0 { | ||
7| | println!("no msg"); | ||
8| | } else { | ||
9| | println!($msg); | ||
10| | } | ||
11| | return Err(String::from($msg)); | ||
12| | }; | ||
13| |} | ||
14| | | ||
15| |macro_rules! on_error { | ||
16| | ($value:expr, $error_message:expr) => { | ||
17| 0| $value.or_else(|e| { | ||
18| 0| let message = format!($error_message, e); | ||
19| 0| if message.len() > 0 { | ||
20| 0| println!("{}", message); | ||
21| 0| Ok(String::from("ok")) | ||
22| | } else { | ||
23| 0| bail!("error"); | ||
24| | } | ||
25| 0| }) | ||
26| | }; | ||
27| |} | ||
28| | | ||
29| 1|fn load_configuration_files() -> Result<String, String> { | ||
30| 1| Ok(String::from("config")) | ||
31| 1|} | ||
32| | | ||
33| 1|pub async fn test() -> Result<(), String> { | ||
34| 1| println!("Starting service"); | ||
35| 1| let config = on_error!(load_configuration_files(), "Error loading configs: {}")?; | ||
^0 | ||
36| | | ||
37| 1| let startup_delay_duration = String::from("arg"); | ||
38| 1| let _ = (config, startup_delay_duration); | ||
39| 1| Ok(()) | ||
40| 1|} | ||
41| | | ||
42| |#[no_coverage] | ||
43| |fn main() { | ||
44| | executor::block_on(test()); | ||
45| |} | ||
46| | | ||
47| |mod executor { | ||
48| | use core::{ | ||
49| | future::Future, | ||
50| | pin::Pin, | ||
51| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, | ||
52| | }; | ||
53| | | ||
54| | #[no_coverage] | ||
55| | pub fn block_on<F: Future>(mut future: F) -> F::Output { | ||
56| | let mut future = unsafe { Pin::new_unchecked(&mut future) }; | ||
57| | use std::hint::unreachable_unchecked; | ||
58| | static VTABLE: RawWakerVTable = RawWakerVTable::new( | ||
59| | | ||
60| | #[no_coverage] | ||
61| | |_| unsafe { unreachable_unchecked() }, // clone | ||
62| | | ||
63| | #[no_coverage] | ||
64| | |_| unsafe { unreachable_unchecked() }, // wake | ||
65| | | ||
66| | #[no_coverage] | ||
67| | |_| unsafe { unreachable_unchecked() }, // wake_by_ref | ||
68| | | ||
69| | #[no_coverage] | ||
70| | |_| (), | ||
71| | ); | ||
72| | let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; | ||
73| | let mut context = Context::from_waker(&waker); | ||
74| | | ||
75| | loop { | ||
76| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) { | ||
77| | break val; | ||
78| | } | ||
79| | } | ||
80| | } | ||
81| |} | ||
|
6 changes: 3 additions & 3 deletions
6
src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.inner_items.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.