1+ use super :: counters;
2+
13use rustc_middle:: mir:: coverage:: * ;
24use rustc_middle:: mir:: visit:: Visitor ;
35use rustc_middle:: mir:: { Coverage , CoverageInfo , Location } ;
@@ -32,21 +34,16 @@ pub(crate) fn provide(providers: &mut Providers) {
3234/// safeguard, with `add_missing_operands` set to `true`, to find any other counter or expression
3335/// IDs referenced by expression operands, if not already seen.
3436///
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.
3941struct CoverageVisitor {
4042 info : CoverageInfo ,
4143 add_missing_operands : bool ,
4244}
4345
4446impl 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-
5047 #[ inline( always) ]
5148 fn update_num_counters ( & mut self , counter_id : u32 ) {
5249 self . info . num_counters = std:: cmp:: max ( self . info . num_counters , counter_id + 1 ) ;
@@ -62,7 +59,10 @@ impl CoverageVisitor {
6259 if operand_id >= self . info . num_counters {
6360 let operand_as_expression_index = u32:: MAX - operand_id;
6461 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.
6666 self . update_num_counters ( operand_id)
6767 } else {
6868 self . update_num_expressions ( operand_id)
0 commit comments