@@ -10,7 +10,6 @@ use rustc_data_structures::graph;
1010use rustc_index:: bit_set:: DenseBitSet ;
1111use rustc_index:: { Idx , IndexVec } ;
1212use rustc_middle:: mir:: coverage:: Op ;
13- use smallvec:: SmallVec ;
1413
1514use crate :: coverage:: counters:: iter_nodes:: IterNodes ;
1615use crate :: coverage:: counters:: union_find:: { FrozenUnionFind , UnionFind } ;
@@ -100,26 +99,20 @@ impl<Node: Idx> MergedNodeFlowGraph<Node> {
10099 builder. visit_node ( node) ;
101100 }
102101
103- NodeCounters { counter_exprs : builder. finish ( ) }
102+ NodeCounters { counter_terms : builder. finish ( ) }
104103 }
105104}
106105
107106/// End result of allocating physical counters and counter expressions for the
108107/// nodes of a graph.
109108#[ derive( Debug ) ]
110109pub ( crate ) struct NodeCounters < Node : Idx > {
111- counter_exprs : IndexVec < Node , CounterExprVec < Node > > ,
112- }
113-
114- impl < Node : Idx > NodeCounters < Node > {
115110 /// For the given node, returns the finished list of terms that represent
116111 /// its physical counter or counter expression. Always non-empty.
117112 ///
118- /// If a node was given a physical counter, its "expression" will contain
113+ /// If a node was given a physical counter, the term list will contain
119114 /// that counter as its sole element.
120- pub ( crate ) fn counter_expr ( & self , this : Node ) -> & [ CounterTerm < Node > ] {
121- self . counter_exprs [ this] . as_slice ( )
122- }
115+ pub ( crate ) counter_terms : IndexVec < Node , Vec < CounterTerm < Node > > > ,
123116}
124117
125118#[ derive( Debug ) ]
@@ -146,9 +139,6 @@ pub(crate) struct CounterTerm<Node> {
146139 pub ( crate ) node : Node ,
147140}
148141
149- /// Stores the list of counter terms that make up a node's counter expression.
150- type CounterExprVec < Node > = SmallVec < [ CounterTerm < Node > ; 2 ] > ;
151-
152142#[ derive( Debug ) ]
153143struct SpantreeBuilder < ' a , Node : Idx > {
154144 graph : & ' a MergedNodeFlowGraph < Node > ,
@@ -163,7 +153,7 @@ struct SpantreeBuilder<'a, Node: Idx> {
163153 yank_buffer : Vec < Node > ,
164154 /// An in-progress counter expression for each node. Each expression is
165155 /// initially empty, and will be filled in as relevant nodes are visited.
166- counter_exprs : IndexVec < Node , CounterExprVec < Node > > ,
156+ counter_terms : IndexVec < Node , Vec < CounterTerm < Node > > > ,
167157}
168158
169159impl < ' a , Node : Idx > SpantreeBuilder < ' a , Node > {
@@ -174,7 +164,7 @@ impl<'a, Node: Idx> SpantreeBuilder<'a, Node> {
174164 is_unvisited : DenseBitSet :: new_filled ( num_nodes) ,
175165 span_edges : IndexVec :: from_fn_n ( |_| None , num_nodes) ,
176166 yank_buffer : vec ! [ ] ,
177- counter_exprs : IndexVec :: from_fn_n ( |_| SmallVec :: new ( ) , num_nodes) ,
167+ counter_terms : IndexVec :: from_fn_n ( |_| vec ! [ ] , num_nodes) ,
178168 }
179169 }
180170
@@ -268,8 +258,8 @@ impl<'a, Node: Idx> SpantreeBuilder<'a, Node> {
268258 // `this_supernode`.
269259
270260 // Instead of setting `this.measure = true` as in the original paper,
271- // we just add the node's ID to its own "expression" .
272- self . counter_exprs [ this] . push ( CounterTerm { node : this, op : Op :: Add } ) ;
261+ // we just add the node's ID to its own list of terms .
262+ self . counter_terms [ this] . push ( CounterTerm { node : this, op : Op :: Add } ) ;
273263
274264 // Walk the spantree from `this.successor` back to `this`. For each
275265 // spantree edge along the way, add this node's physical counter to
@@ -279,7 +269,7 @@ impl<'a, Node: Idx> SpantreeBuilder<'a, Node> {
279269 let & SpantreeEdge { is_reversed, claiming_node, span_parent } =
280270 self . span_edges [ curr] . as_ref ( ) . unwrap ( ) ;
281271 let op = if is_reversed { Op :: Subtract } else { Op :: Add } ;
282- self . counter_exprs [ claiming_node] . push ( CounterTerm { node : this, op } ) ;
272+ self . counter_terms [ claiming_node] . push ( CounterTerm { node : this, op } ) ;
283273
284274 curr = span_parent;
285275 }
@@ -288,8 +278,8 @@ impl<'a, Node: Idx> SpantreeBuilder<'a, Node> {
288278
289279 /// Asserts that all nodes have been visited, and returns the computed
290280 /// counter expressions (made up of physical counters) for each node.
291- fn finish ( self ) -> IndexVec < Node , CounterExprVec < Node > > {
292- let Self { graph, is_unvisited, span_edges, yank_buffer : _, counter_exprs } = self ;
281+ fn finish ( self ) -> IndexVec < Node , Vec < CounterTerm < Node > > > {
282+ let Self { graph, is_unvisited, span_edges, yank_buffer : _, counter_terms } = self ;
293283 assert ! ( is_unvisited. is_empty( ) , "some nodes were never visited: {is_unvisited:?}" ) ;
294284 debug_assert ! (
295285 span_edges
@@ -298,9 +288,9 @@ impl<'a, Node: Idx> SpantreeBuilder<'a, Node> {
298288 "only supernodes can have a span edge" ,
299289 ) ;
300290 debug_assert ! (
301- counter_exprs . iter( ) . all( |expr | !expr . is_empty( ) ) ,
302- "after visiting all nodes, every node should have a non-empty expression " ,
291+ counter_terms . iter( ) . all( |terms | !terms . is_empty( ) ) ,
292+ "after visiting all nodes, every node should have at least one term " ,
303293 ) ;
304- counter_exprs
294+ counter_terms
305295 }
306296}
0 commit comments