1
+ use super :: counters;
2
+
1
3
use rustc_middle:: mir:: coverage:: * ;
2
4
use rustc_middle:: mir:: visit:: Visitor ;
3
5
use rustc_middle:: mir:: { Coverage , CoverageInfo , Location } ;
@@ -32,21 +34,16 @@ pub(crate) fn provide(providers: &mut Providers) {
32
34
/// safeguard, with `add_missing_operands` set to `true`, to find any other counter or expression
33
35
/// IDs referenced by expression operands, if not already seen.
34
36
///
35
- /// Ideally, every expression operand in the MIR will have a corresponding Counter or Expression,
36
- /// but since current or future MIR optimizations can theoretically optimize out segments of a
37
- /// MIR, it may not be possible to guarantee this, so the second pass ensures the `CoverageInfo`
38
- /// counts include all referenced IDs.
37
+ /// Ideally, each operand ID in a MIR `CoverageKind::Expression` will have a separate MIR `Coverage`
38
+ /// statement for the `Counter` or `Expression` with the referenced ID. but since current or future
39
+ /// MIR optimizations can theoretically optimize out segments of a MIR, it may not be possible to
40
+ /// guarantee this, so the second pass ensures the `CoverageInfo` counts include all referenced IDs.
39
41
struct CoverageVisitor {
40
42
info : CoverageInfo ,
41
43
add_missing_operands : bool ,
42
44
}
43
45
44
46
impl CoverageVisitor {
45
- // If an expression operand is encountered with an ID outside the range of known counters and
46
- // expressions, the only way to determine if the ID is a counter ID or an expression ID is to
47
- // assume a maximum possible counter ID value.
48
- const MAX_COUNTER_GUARD : u32 = ( u32:: MAX / 2 ) + 1 ;
49
-
50
47
#[ inline( always) ]
51
48
fn update_num_counters ( & mut self , counter_id : u32 ) {
52
49
self . info . num_counters = std:: cmp:: max ( self . info . num_counters , counter_id + 1 ) ;
@@ -62,7 +59,10 @@ impl CoverageVisitor {
62
59
if operand_id >= self . info . num_counters {
63
60
let operand_as_expression_index = u32:: MAX - operand_id;
64
61
if operand_as_expression_index >= self . info . num_expressions {
65
- if operand_id <= Self :: MAX_COUNTER_GUARD {
62
+ if operand_id <= counters:: MAX_COUNTER_GUARD {
63
+ // Since the complete range of counter and expression IDs is not known here, the
64
+ // only way to determine if the ID is a counter ID or an expression ID is to
65
+ // assume a maximum possible counter ID value.
66
66
self . update_num_counters ( operand_id)
67
67
} else {
68
68
self . update_num_expressions ( operand_id)
0 commit comments