@@ -3,7 +3,8 @@ use std::collections::VecDeque;
3
3
use rustc_data_structures:: fx:: FxIndexMap ;
4
4
use rustc_middle:: bug;
5
5
use rustc_middle:: mir:: coverage:: {
6
- BlockMarkerId , ConditionId , ConditionInfo , DecisionId , MCDCBranchSpan , MCDCDecisionSpan ,
6
+ BlockMarkerId , ConditionId , ConditionInfo , DecisionId , MCDCBranchMarkers , MCDCBranchSpan ,
7
+ MCDCDecisionSpan ,
7
8
} ;
8
9
use rustc_middle:: mir:: BasicBlock ;
9
10
use rustc_middle:: thir:: LogicalOp ;
@@ -29,6 +30,7 @@ struct BooleanDecisionCtx {
29
30
/// To construct condition evaluation tree.
30
31
decision_stack : VecDeque < ConditionInfo > ,
31
32
conditions : Vec < MCDCBranchSpan > ,
33
+ condition_id_counter : usize ,
32
34
}
33
35
34
36
impl BooleanDecisionCtx {
@@ -37,15 +39,20 @@ impl BooleanDecisionCtx {
37
39
id,
38
40
decision_info : MCDCDecisionSpan {
39
41
span : Span :: default ( ) ,
40
- num_conditions : 0 ,
41
42
end_markers : vec ! [ ] ,
42
43
decision_depth : 0 ,
43
44
} ,
44
45
decision_stack : VecDeque :: new ( ) ,
45
46
conditions : vec ! [ ] ,
47
+ condition_id_counter : 0 ,
46
48
}
47
49
}
48
50
51
+ fn next_condition_id ( & mut self ) -> ConditionId {
52
+ self . condition_id_counter += 1 ;
53
+ ConditionId :: from_usize ( self . condition_id_counter )
54
+ }
55
+
49
56
// At first we assign ConditionIds for each sub expression.
50
57
// If the sub expression is composite, re-assign its ConditionId to its LHS and generate a new ConditionId for its RHS.
51
58
//
@@ -89,14 +96,12 @@ impl BooleanDecisionCtx {
89
96
fn record_conditions ( & mut self , op : LogicalOp ) {
90
97
let parent_condition = self . decision_stack . pop_back ( ) . unwrap_or_default ( ) ;
91
98
let lhs_id = if parent_condition. condition_id == ConditionId :: NONE {
92
- self . decision_info . num_conditions += 1 ;
93
- ConditionId :: from ( self . decision_info . num_conditions )
99
+ ConditionId :: from ( self . next_condition_id ( ) )
94
100
} else {
95
101
parent_condition. condition_id
96
102
} ;
97
103
98
- self . decision_info . num_conditions += 1 ;
99
- let rhs_condition_id = ConditionId :: from ( self . decision_info . num_conditions ) ;
104
+ let rhs_condition_id = self . next_condition_id ( ) ;
100
105
101
106
let ( lhs, rhs) = match op {
102
107
LogicalOp :: And => {
@@ -147,13 +152,9 @@ impl BooleanDecisionCtx {
147
152
148
153
self . conditions . push ( MCDCBranchSpan {
149
154
span,
150
- condition_info : Some ( condition_info) ,
151
- true_marker,
152
- false_marker,
153
- decision_depth : 0 ,
155
+ condition_info,
156
+ markers : MCDCBranchMarkers :: Boolean ( true_marker, false_marker) ,
154
157
} ) ;
155
- // In case this decision had only one condition
156
- self . decision_info . num_conditions = self . decision_info . num_conditions . max ( 1 ) ;
157
158
}
158
159
159
160
fn is_finished ( & self ) -> bool {
@@ -250,7 +251,6 @@ struct MCDCTargetInfo {
250
251
impl MCDCTargetInfo {
251
252
fn set_depth ( & mut self , depth : u16 ) {
252
253
self . decision . decision_depth = depth;
253
- self . conditions . iter_mut ( ) . for_each ( |branch| branch. decision_depth = depth) ;
254
254
}
255
255
}
256
256
@@ -298,7 +298,9 @@ impl MCDCInfoBuilder {
298
298
}
299
299
300
300
fn append_normal_branches ( & mut self , mut branches : Vec < MCDCBranchSpan > ) {
301
- branches. iter_mut ( ) . for_each ( |branch| branch. condition_info = None ) ;
301
+ branches
302
+ . iter_mut ( )
303
+ . for_each ( |branch| branch. condition_info . condition_id = ConditionId :: NONE ) ;
302
304
self . normal_branch_spans . extend ( branches) ;
303
305
}
304
306
0 commit comments