Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vastly improves coverage spans for macros #84582

Merged
merged 5 commits into from
May 1, 2021
Merged

Conversation

richkadel
Copy link
Contributor

@richkadel richkadel commented Apr 26, 2021

Fixes: #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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 26, 2021
@rust-log-analyzer

This comment has been minimized.

@richkadel richkadel force-pushed the issue-84561 branch 2 times, most recently from b76f133 to 2d72f54 Compare April 26, 2021 10:11
@rust-log-analyzer

This comment has been minimized.

@richkadel richkadel changed the title Drop branching blocks with same span as expanded macro Vastly improves coverage spans for macros Apr 26, 2021
@scole66
Copy link

scole66 commented Apr 27, 2021

Also fixes #82853, I believe.

@richkadel
Copy link
Contributor Author

@tmandry I moved the spanview debug output ICE fix to this PR instead of the Eq #[no_coverage] PR since this one also caused the problem (during debugging only), and this PR should land much more quickly, pending your review.

Thanks!

@richkadel
Copy link
Contributor Author

@tmandry - Great review comments. I resolved the simple requests. Check out my replies (and changes, where relevant).

Thanks!

@richkadel
Copy link
Contributor Author

(To be a little more clear, I addressed all of your comments. I just marked the simple ones resolved, to reduce the clutter on this page.)

@tmandry
Copy link
Member

tmandry commented Apr 29, 2021

Looks good, thanks for making those changes!

@bors r+

@bors
Copy link
Contributor

bors commented Apr 29, 2021

📌 Commit fd85fd3 has been approved by tmandry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 29, 2021
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`
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 29, 2021
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``
jackh726 added a commit to jackh726/rust that referenced this pull request Apr 29, 2021
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````
jackh726 added a commit to jackh726/rust that referenced this pull request Apr 29, 2021
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`````
@jackh726
Copy link
Member

Possibly failed in #84720 (comment)

@bors rollup=iffy

@richkadel
Copy link
Contributor Author

Possibly failed in #84720 (comment)

@bors rollup=iffy

Oh, darn. This test output changed after the new #[no_coverage] attribute was added a couple of days ago,

The Eq no longer shows 0 coverage.

But this PR was uploaded before the Eq coverage issue was fixed.

Will fix.

     2|       |
     3|       |// expect-exit-status-101
     4|     21|#[derive(PartialEq, Eq)]
-                                  ^0
   ------------------

@richkadel
Copy link
Contributor Author

@bors r-

I may have found one more edge case, plus I'm not sure if I need to re-bless one other test result.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 30, 2021
self.prev_mut().span = self.prev().span.with_lo(right_cutoff);
self.prev_original_span = self.prev().span;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line updating prev_original_span to match the mutated self.prev().span has been wrong for a long time. It's clear, now, that the original_span should never be mutated, and this was always a bug.

I think recent changes elsewhere may have exposed this bug, but even so, it still occurs very rarely.

I added some tests to try to replicate the failures I saw when compiling a very large codebase, but it's very hard to replicate. (It seems to occur when calling a macro that contains a closure and returns a Result, checked with the ? try operator. But even that is not enough to replicate the problem. It also requires that the macro code branches, and that it produces just the right order of dominator relationship between basic blocks, with just the right nested but equal spans.

The bug is clear to me even if the specific situation leading up to that bug is not as clear. I validated this against the code that triggered the error (at least 3 instances) and removing this line corrected the problem, allowing the codebase to compile to completion.

@richkadel
Copy link
Contributor Author

r? @tmandry - can you take a quick look and re-approve / re-submit to bors?

@richkadel
Copy link
Contributor Author

@rustbot label -S-waiting-on-author +S-waiting-on-review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 30, 2021
@tmandry
Copy link
Member

tmandry commented Apr 30, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Apr 30, 2021

📌 Commit 0312bf5 has been approved by tmandry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 30, 2021
@bors
Copy link
Contributor

bors commented May 1, 2021

⌛ Testing commit 0312bf5 with merge 1c2c6b6...

@bors
Copy link
Contributor

bors commented May 1, 2021

☀️ Test successful - checks-actions
Approved by: tmandry
Pushing 1c2c6b6 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 1, 2021
@bors bors merged commit 1c2c6b6 into rust-lang:master May 1, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

function-like macros, esp. with internal branching, produce unintuitive coverage results
8 participants