@@ -20,7 +20,7 @@ pub(crate) struct BranchInfoBuilder {
2020 /// Maps condition expressions to their enclosing `!`, for better instrumentation.
2121 nots : FxHashMap < ExprId , NotInfo > ,
2222
23- num_block_markers : usize ,
23+ markers : BlockMarkerGen ,
2424 branch_spans : Vec < BranchSpan > ,
2525
2626 mcdc_branch_spans : Vec < MCDCBranchSpan > ,
@@ -38,14 +38,43 @@ struct NotInfo {
3838 is_flipped : bool ,
3939}
4040
41+ #[ derive( Default ) ]
42+ struct BlockMarkerGen {
43+ num_block_markers : usize ,
44+ }
45+
46+ impl BlockMarkerGen {
47+ fn next_block_marker_id ( & mut self ) -> BlockMarkerId {
48+ let id = BlockMarkerId :: from_usize ( self . num_block_markers ) ;
49+ self . num_block_markers += 1 ;
50+ id
51+ }
52+
53+ fn inject_block_marker (
54+ & mut self ,
55+ cfg : & mut CFG < ' _ > ,
56+ source_info : SourceInfo ,
57+ block : BasicBlock ,
58+ ) -> BlockMarkerId {
59+ let id = self . next_block_marker_id ( ) ;
60+ let marker_statement = mir:: Statement {
61+ source_info,
62+ kind : mir:: StatementKind :: Coverage ( CoverageKind :: BlockMarker { id } ) ,
63+ } ;
64+ cfg. push ( block, marker_statement) ;
65+
66+ id
67+ }
68+ }
69+
4170impl BranchInfoBuilder {
4271 /// Creates a new branch info builder, but only if branch coverage instrumentation
4372 /// is enabled and `def_id` represents a function that is eligible for coverage.
4473 pub ( crate ) fn new_if_enabled ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> Option < Self > {
4574 if tcx. sess . instrument_coverage_branch ( ) && tcx. is_eligible_for_coverage ( def_id) {
4675 Some ( Self {
4776 nots : FxHashMap :: default ( ) ,
48- num_block_markers : 0 ,
77+ markers : BlockMarkerGen :: default ( ) ,
4978 branch_spans : vec ! [ ] ,
5079 mcdc_branch_spans : vec ! [ ] ,
5180 mcdc_decision_spans : vec ! [ ] ,
@@ -145,39 +174,16 @@ impl BranchInfoBuilder {
145174 true_block : BasicBlock ,
146175 false_block : BasicBlock ,
147176 ) {
148- let true_marker = self . inject_block_marker ( cfg, source_info, true_block) ;
149- let false_marker = self . inject_block_marker ( cfg, source_info, false_block) ;
177+ let true_marker = self . markers . inject_block_marker ( cfg, source_info, true_block) ;
178+ let false_marker = self . markers . inject_block_marker ( cfg, source_info, false_block) ;
150179
151180 self . branch_spans . push ( BranchSpan { span : source_info. span , true_marker, false_marker } ) ;
152181 }
153182
154- fn next_block_marker_id ( & mut self ) -> BlockMarkerId {
155- let id = BlockMarkerId :: from_usize ( self . num_block_markers ) ;
156- self . num_block_markers += 1 ;
157- id
158- }
159-
160- fn inject_block_marker (
161- & mut self ,
162- cfg : & mut CFG < ' _ > ,
163- source_info : SourceInfo ,
164- block : BasicBlock ,
165- ) -> BlockMarkerId {
166- let id = self . next_block_marker_id ( ) ;
167-
168- let marker_statement = mir:: Statement {
169- source_info,
170- kind : mir:: StatementKind :: Coverage ( CoverageKind :: BlockMarker { id } ) ,
171- } ;
172- cfg. push ( block, marker_statement) ;
173-
174- id
175- }
176-
177183 pub ( crate ) fn into_done ( self ) -> Option < Box < mir:: coverage:: BranchInfo > > {
178184 let Self {
179185 nots : _,
180- num_block_markers,
186+ markers : BlockMarkerGen { num_block_markers } ,
181187 branch_spans,
182188 mcdc_branch_spans,
183189 mcdc_decision_spans,
@@ -386,7 +392,7 @@ impl Builder<'_, '_> {
386392 // Separate path for handling branches when MC/DC is enabled.
387393 if branch_info. mcdc_state . is_some ( ) {
388394 let mut inject_block_marker =
389- |block| branch_info. inject_block_marker ( & mut self . cfg , source_info, block) ;
395+ |block| branch_info. markers . inject_block_marker ( & mut self . cfg , source_info, block) ;
390396 let true_marker = inject_block_marker ( then_block) ;
391397 let false_marker = inject_block_marker ( else_block) ;
392398 let ( decision_depth, condition_info) = branch_info
0 commit comments