@@ -25,15 +25,21 @@ pub(super) fn make_bcb_counters(
2525 graph : & CoverageGraph ,
2626 bcb_needs_counter : & DenseBitSet < BasicCoverageBlock > ,
2727) -> CoverageCounters {
28+ // Create the derived graphs that are necessary for subsequent steps.
2829 let balanced_graph = BalancedFlowGraph :: for_graph ( graph, |n| !graph[ n] . is_out_summable ) ;
2930 let merged_graph = MergedNodeFlowGraph :: for_balanced_graph ( & balanced_graph) ;
3031
32+ // Use those graphs to determine which nodes get physical counters, and how
33+ // to compute the execution counts of other nodes from those counters.
3134 let nodes = make_node_counter_priority_list ( graph, balanced_graph) ;
3235 let node_counters = merged_graph. make_node_counters ( & nodes) ;
3336
37+ // Convert the counters into a form suitable for embedding into MIR.
3438 transcribe_counters ( & node_counters, bcb_needs_counter)
3539}
3640
41+ /// Arranges the nodes in `balanced_graph` into a list, such that earlier nodes
42+ /// take priority in being given a counter expression instead of a physical counter.
3743fn make_node_counter_priority_list (
3844 graph : & CoverageGraph ,
3945 balanced_graph : BalancedFlowGraph < & CoverageGraph > ,
@@ -67,13 +73,17 @@ fn make_node_counter_priority_list(
6773 nodes
6874}
6975
76+ // Converts node counters into a form suitable for embedding into MIR.
7077fn transcribe_counters (
7178 old : & NodeCounters < BasicCoverageBlock > ,
7279 bcb_needs_counter : & DenseBitSet < BasicCoverageBlock > ,
7380) -> CoverageCounters {
7481 let mut new = CoverageCounters :: with_num_bcbs ( bcb_needs_counter. domain_size ( ) ) ;
7582
7683 for bcb in bcb_needs_counter. iter ( ) {
84+ // Our counter-creation algorithm doesn't guarantee that a counter
85+ // expression starts or ends with a positive term, so partition the
86+ // counters into "positive" and "negative" lists for easier handling.
7787 let ( mut pos, mut neg) : ( Vec < _ > , Vec < _ > ) =
7888 old. counter_expr ( bcb) . iter ( ) . partition_map ( |& CounterTerm { node, op } | match op {
7989 Op :: Add => Either :: Left ( node) ,
@@ -89,6 +99,10 @@ fn transcribe_counters(
8999 neg = vec ! [ ] ;
90100 }
91101
102+ // These intermediate sorts are not strictly necessary, but were helpful
103+ // in reducing churn when switching to the current counter-creation scheme.
104+ // They also help to slightly decrease the overall size of the expression
105+ // table, due to more subexpressions being shared.
92106 pos. sort ( ) ;
93107 neg. sort ( ) ;
94108
@@ -98,6 +112,7 @@ fn transcribe_counters(
98112 let mut pos = new_counters_for_sites ( pos) ;
99113 let mut neg = new_counters_for_sites ( neg) ;
100114
115+ // These sorts are also not strictly necessary; see above.
101116 pos. sort ( ) ;
102117 neg. sort ( ) ;
103118
0 commit comments