-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
MCDC coverage: support nested decision coverage #124255
MCDC coverage: support nested decision coverage #124255
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @cjgillot (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
Some changes occurred in coverage instrumentation. cc @Zalathar Some changes occurred in match lowering cc @Nadrieril Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in coverage tests. cc @Zalathar Some changes occurred in coverage instrumentation. cc @Zalathar Some changes occurred in coverage instrumentation. cc @Zalathar Some changes occurred in coverage instrumentation. cc @Zalathar |
@rustbot label +A-code-coverage |
@bors delegate=Zalathar |
This comment has been minimized.
This comment has been minimized.
7c1bedb
to
67b59f8
Compare
force pushed formatting |
☔ The latest upstream changes (presumably #124271) made this pull request unmergeable. Please resolve the merge conflicts. |
67b59f8
to
b231d4a
Compare
r? @Zalathar |
Failed to set assignee to
|
b231d4a
to
074938a
Compare
rebased on top of #124217 |
This comment has been minimized.
This comment has been minimized.
074938a
to
37cb490
Compare
The assignee has announced Zalathar as his delegate. So you could @ him once you prepared and he has full authority to approve this pr. |
4c59f9d
to
eb422d5
Compare
Thank you ! |
@RenjiSann Do you still have more tweaks to make, or are you ready for me to have another look at this? |
@Zalathar Nothing to add for now, you can take another look :) |
@@ -195,7 +206,7 @@ fn ensure_mcdc_parameters<'ll, 'tcx>( | |||
let fn_name = bx.get_pgo_func_name_var(instance); | |||
let hash = bx.const_u64(function_coverage_info.function_source_hash); | |||
let bitmap_bytes = bx.const_u32(function_coverage_info.mcdc_bitmap_bytes); | |||
let cond_bitmap = bx.mcdc_parameters(fn_name, hash, bitmap_bytes); | |||
let cond_bitmap = bx.mcdc_parameters(fn_name, hash, bitmap_bytes, 1_u32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should actually be 0, not 1. But since this is temporary code anyway, and the only effect is an extra unused bitmap, it's OK to not worry about it.
There are a couple of things I would like to see improved (e.g. in the handling of |
@RenjiSann Oh, another thing I want to mention is that if you're adding tests for changed behaviour, it's often a good idea to add and bless the tests before making the changes, and then bless them again in later commits, so that it's easy to see the exact before/after changes in test output. (In some cases this doesn't work, because the compiler would error or crash before the changes are made. But it's a good habit to get into.) |
…ons, r=oli-obk MCDC coverage: support nested decision coverage rust-lang#123409 provided the initial MCDC coverage implementation. As referenced in rust-lang#124144, it does not currently support "nested" decisions, like the following example : ```rust fn nested_if_in_condition(a: bool, b: bool, c: bool) { if a && if b || c { true } else { false } { say("yes"); } else { say("no"); } } ``` Note that there is an if-expression (`if b || c ...`) embedded inside a boolean expression in the decision of an outer if-expression. This PR proposes a workaround for this cases, by introducing a Decision context stack, and by handing several `temporary condition bitmaps` instead of just one. When instrumenting boolean expressions, if the current node is a leaf condition (i.e. not a `||`/`&&` logical operator nor a `!` not operator), we insert a new decision context, such that if there are more boolean expressions inside the condition, they are handled as separate expressions. On the codegen LLVM side, we allocate as many `temp_cond_bitmap`s as necessary to handle the maximum encountered decision depth.
@bors r=Zalathar |
💡 This pull request was already approved, no need to approve it again.
|
Will do ! thanks ! |
☀️ Test successful - checks-actions |
Finished benchmarking commit (7a58674): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 672.94s -> 671.855s (-0.16%) |
coverage: Clean up creation of MC/DC condition bitmaps This PR improves the code for creating and initializing [MC/DC](https://en.wikipedia.org/wiki/Modified_condition/decision_coverage) condition bitmap variables, as introduced by rust-lang#123409 and modified by rust-lang#124255. - The condition bitmap variables are now created eagerly at the start of per-function codegen, via a new `init_coverage` method in `CoverageInfoBuilderMethods`. This avoids having to retroactively create the bitmaps while doing codegen for an individual coverage statement. - As a result, we can now create and initialize those bitmaps using existing safe APIs, instead of having to perform our own unsafe call to `llvm::LLVMBuildAlloca`. - This PR also tweaks the way we count the number of condition bitmaps needed, by tracking the total number of bitmaps needed (max depth + 1), instead of only tracking the maximum depth. This reduces the potential for subtle off-by-one confusion.
Rollup merge of rust-lang#124555 - Zalathar:init-coverage, r=nnethercote coverage: Clean up creation of MC/DC condition bitmaps This PR improves the code for creating and initializing [MC/DC](https://en.wikipedia.org/wiki/Modified_condition/decision_coverage) condition bitmap variables, as introduced by rust-lang#123409 and modified by rust-lang#124255. - The condition bitmap variables are now created eagerly at the start of per-function codegen, via a new `init_coverage` method in `CoverageInfoBuilderMethods`. This avoids having to retroactively create the bitmaps while doing codegen for an individual coverage statement. - As a result, we can now create and initialize those bitmaps using existing safe APIs, instead of having to perform our own unsafe call to `llvm::LLVMBuildAlloca`. - This PR also tweaks the way we count the number of condition bitmaps needed, by tracking the total number of bitmaps needed (max depth + 1), instead of only tracking the maximum depth. This reduces the potential for subtle off-by-one confusion.
#123409 provided the initial MCDC coverage implementation.
As referenced in #124144, it does not currently support "nested" decisions, like the following example :
Note that there is an if-expression (
if b || c ...
) embedded inside a boolean expression in the decision of an outer if-expression.This PR proposes a workaround for this cases, by introducing a Decision context stack, and by handing several
temporary condition bitmaps
instead of just one.When instrumenting boolean expressions, if the current node is a leaf condition (i.e. not a
||
/&&
logical operator nor a!
not operator), we insert a new decision context, such that if there are more boolean expressions inside the condition, they are handled as separate expressions.On the codegen LLVM side, we allocate as many
temp_cond_bitmap
s as necessary to handle the maximum encountered decision depth.