@@ -10,7 +10,6 @@ use rustc_data_structures::graph;
10
10
use rustc_index:: bit_set:: DenseBitSet ;
11
11
use rustc_index:: { Idx , IndexVec } ;
12
12
use rustc_middle:: mir:: coverage:: Op ;
13
- use smallvec:: SmallVec ;
14
13
15
14
use crate :: coverage:: counters:: iter_nodes:: IterNodes ;
16
15
use crate :: coverage:: counters:: union_find:: { FrozenUnionFind , UnionFind } ;
@@ -100,26 +99,20 @@ impl<Node: Idx> MergedNodeFlowGraph<Node> {
100
99
builder. visit_node ( node) ;
101
100
}
102
101
103
- NodeCounters { counter_exprs : builder. finish ( ) }
102
+ NodeCounters { counter_terms : builder. finish ( ) }
104
103
}
105
104
}
106
105
107
106
/// End result of allocating physical counters and counter expressions for the
108
107
/// nodes of a graph.
109
108
#[ derive( Debug ) ]
110
109
pub ( crate ) struct NodeCounters < Node : Idx > {
111
- counter_exprs : IndexVec < Node , CounterExprVec < Node > > ,
112
- }
113
-
114
- impl < Node : Idx > NodeCounters < Node > {
115
110
/// For the given node, returns the finished list of terms that represent
116
111
/// its physical counter or counter expression. Always non-empty.
117
112
///
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
119
114
/// 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 > > > ,
123
116
}
124
117
125
118
#[ derive( Debug ) ]
@@ -146,9 +139,6 @@ pub(crate) struct CounterTerm<Node> {
146
139
pub ( crate ) node : Node ,
147
140
}
148
141
149
- /// Stores the list of counter terms that make up a node's counter expression.
150
- type CounterExprVec < Node > = SmallVec < [ CounterTerm < Node > ; 2 ] > ;
151
-
152
142
#[ derive( Debug ) ]
153
143
struct SpantreeBuilder < ' a , Node : Idx > {
154
144
graph : & ' a MergedNodeFlowGraph < Node > ,
@@ -163,7 +153,7 @@ struct SpantreeBuilder<'a, Node: Idx> {
163
153
yank_buffer : Vec < Node > ,
164
154
/// An in-progress counter expression for each node. Each expression is
165
155
/// 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 > > > ,
167
157
}
168
158
169
159
impl < ' a , Node : Idx > SpantreeBuilder < ' a , Node > {
@@ -174,7 +164,7 @@ impl<'a, Node: Idx> SpantreeBuilder<'a, Node> {
174
164
is_unvisited : DenseBitSet :: new_filled ( num_nodes) ,
175
165
span_edges : IndexVec :: from_fn_n ( |_| None , num_nodes) ,
176
166
yank_buffer : vec ! [ ] ,
177
- counter_exprs : IndexVec :: from_fn_n ( |_| SmallVec :: new ( ) , num_nodes) ,
167
+ counter_terms : IndexVec :: from_fn_n ( |_| vec ! [ ] , num_nodes) ,
178
168
}
179
169
}
180
170
@@ -268,8 +258,8 @@ impl<'a, Node: Idx> SpantreeBuilder<'a, Node> {
268
258
// `this_supernode`.
269
259
270
260
// 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 } ) ;
273
263
274
264
// Walk the spantree from `this.successor` back to `this`. For each
275
265
// spantree edge along the way, add this node's physical counter to
@@ -279,7 +269,7 @@ impl<'a, Node: Idx> SpantreeBuilder<'a, Node> {
279
269
let & SpantreeEdge { is_reversed, claiming_node, span_parent } =
280
270
self . span_edges [ curr] . as_ref ( ) . unwrap ( ) ;
281
271
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 } ) ;
283
273
284
274
curr = span_parent;
285
275
}
@@ -288,8 +278,8 @@ impl<'a, Node: Idx> SpantreeBuilder<'a, Node> {
288
278
289
279
/// Asserts that all nodes have been visited, and returns the computed
290
280
/// 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 ;
293
283
assert ! ( is_unvisited. is_empty( ) , "some nodes were never visited: {is_unvisited:?}" ) ;
294
284
debug_assert ! (
295
285
span_edges
@@ -298,9 +288,9 @@ impl<'a, Node: Idx> SpantreeBuilder<'a, Node> {
298
288
"only supernodes can have a span edge" ,
299
289
) ;
300
290
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 " ,
303
293
) ;
304
- counter_exprs
294
+ counter_terms
305
295
}
306
296
}
0 commit comments