@@ -3,7 +3,8 @@ use std::collections::VecDeque;
33use rustc_data_structures:: fx:: FxIndexMap ;
44use rustc_middle:: bug;
55use rustc_middle:: mir:: coverage:: {
6- BlockMarkerId , ConditionId , ConditionInfo , DecisionId , MCDCBranchSpan , MCDCDecisionSpan ,
6+ BlockMarkerId , ConditionId , ConditionInfo , DecisionId , MCDCBranchMarkers , MCDCBranchSpan ,
7+ MCDCDecisionSpan ,
78} ;
89use rustc_middle:: mir:: BasicBlock ;
910use rustc_middle:: thir:: LogicalOp ;
@@ -29,6 +30,7 @@ struct BooleanDecisionCtx {
2930 /// To construct condition evaluation tree.
3031 decision_stack : VecDeque < ConditionInfo > ,
3132 conditions : Vec < MCDCBranchSpan > ,
33+ condition_id_counter : usize ,
3234}
3335
3436impl BooleanDecisionCtx {
@@ -37,15 +39,20 @@ impl BooleanDecisionCtx {
3739 id,
3840 decision_info : MCDCDecisionSpan {
3941 span : Span :: default ( ) ,
40- num_conditions : 0 ,
4142 end_markers : vec ! [ ] ,
4243 decision_depth : 0 ,
4344 } ,
4445 decision_stack : VecDeque :: new ( ) ,
4546 conditions : vec ! [ ] ,
47+ condition_id_counter : 0 ,
4648 }
4749 }
4850
51+ fn next_condition_id ( & mut self ) -> ConditionId {
52+ self . condition_id_counter += 1 ;
53+ ConditionId :: from_usize ( self . condition_id_counter )
54+ }
55+
4956 // At first we assign ConditionIds for each sub expression.
5057 // If the sub expression is composite, re-assign its ConditionId to its LHS and generate a new ConditionId for its RHS.
5158 //
@@ -89,14 +96,12 @@ impl BooleanDecisionCtx {
8996 fn record_conditions ( & mut self , op : LogicalOp ) {
9097 let parent_condition = self . decision_stack . pop_back ( ) . unwrap_or_default ( ) ;
9198 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 ( ) )
94100 } else {
95101 parent_condition. condition_id
96102 } ;
97103
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 ( ) ;
100105
101106 let ( lhs, rhs) = match op {
102107 LogicalOp :: And => {
@@ -147,13 +152,9 @@ impl BooleanDecisionCtx {
147152
148153 self . conditions . push ( MCDCBranchSpan {
149154 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) ,
154157 } ) ;
155- // In case this decision had only one condition
156- self . decision_info . num_conditions = self . decision_info . num_conditions . max ( 1 ) ;
157158 }
158159
159160 fn is_finished ( & self ) -> bool {
@@ -250,7 +251,6 @@ struct MCDCTargetInfo {
250251impl MCDCTargetInfo {
251252 fn set_depth ( & mut self , depth : u16 ) {
252253 self . decision . decision_depth = depth;
253- self . conditions . iter_mut ( ) . for_each ( |branch| branch. decision_depth = depth) ;
254254 }
255255}
256256
@@ -298,7 +298,9 @@ impl MCDCInfoBuilder {
298298 }
299299
300300 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 ) ;
302304 self . normal_branch_spans . extend ( branches) ;
303305 }
304306
0 commit comments