@@ -128,23 +128,24 @@ struct ObligationTreeId(usize);
128
128
type ObligationTreeIdGenerator =
129
129
:: std:: iter:: Map < :: std:: ops:: RangeFrom < usize > , fn ( usize ) -> ObligationTreeId > ;
130
130
131
+ /// `usize` indices are used here and throughout this module, rather than
132
+ /// `rustc_index::newtype_index!` indices, because this code is hot enough
133
+ /// that the `u32`-to-`usize` conversions that would be required are
134
+ /// significant, and space considerations are not important.
135
+ type NodeIndex = usize ;
136
+
131
137
pub struct ObligationForest < O : ForestObligation > {
132
138
/// The list of obligations. In between calls to `process_obligations`,
133
139
/// this list only contains nodes in the `Pending` or `Waiting` state.
134
- ///
135
- /// `usize` indices are used here and throughout this module, rather than
136
- /// `rustc_index::newtype_index!` indices, because this code is hot enough
137
- /// that the `u32`-to-`usize` conversions that would be required are
138
- /// significant, and space considerations are not important.
139
140
nodes : Vec < Node < O > > ,
140
141
141
142
/// A cache of the nodes in `nodes`, indexed by predicate. Unfortunately,
142
143
/// its contents are not guaranteed to match those of `nodes`. See the
143
144
/// comments in `process_obligation` for details.
144
- active_cache : FxHashMap < O :: Predicate , Option < usize > > ,
145
+ active_cache : FxHashMap < O :: Predicate , Option < NodeIndex > > ,
145
146
146
147
/// A vector reused in compress(), to avoid allocating new vectors.
147
- node_rewrites : Vec < usize > ,
148
+ node_rewrites : Vec < NodeIndex > ,
148
149
149
150
obligation_tree_id_generator : ObligationTreeIdGenerator ,
150
151
@@ -165,12 +166,12 @@ struct Node<O> {
165
166
166
167
/// Obligations that depend on this obligation for their completion. They
167
168
/// must all be in a non-pending state.
168
- dependents : Vec < usize > ,
169
+ dependents : Vec < NodeIndex > ,
169
170
170
171
/// If true, dependents[0] points to a "parent" node, which requires
171
172
/// special treatment upon error but is otherwise treated the same.
172
173
/// (It would be more idiomatic to store the parent node in a separate
173
- /// `Option<usize >` field, but that slows down the common case of
174
+ /// `Option<NodeIndex >` field, but that slows down the common case of
174
175
/// iterating over the parent and other descendants together.)
175
176
has_parent : bool ,
176
177
@@ -179,7 +180,11 @@ struct Node<O> {
179
180
}
180
181
181
182
impl < O > Node < O > {
182
- fn new ( parent : Option < usize > , obligation : O , obligation_tree_id : ObligationTreeId ) -> Node < O > {
183
+ fn new (
184
+ parent : Option < NodeIndex > ,
185
+ obligation : O ,
186
+ obligation_tree_id : ObligationTreeId ,
187
+ ) -> Node < O > {
183
188
Node {
184
189
obligation,
185
190
state : Cell :: new ( NodeState :: Pending ) ,
@@ -301,7 +306,11 @@ impl<O: ForestObligation> ObligationForest<O> {
301
306
}
302
307
303
308
// Returns Err(()) if we already know this obligation failed.
304
- fn register_obligation_at ( & mut self , obligation : O , parent : Option < usize > ) -> Result < ( ) , ( ) > {
309
+ fn register_obligation_at (
310
+ & mut self ,
311
+ obligation : O ,
312
+ parent : Option < NodeIndex > ,
313
+ ) -> Result < ( ) , ( ) > {
305
314
match self . active_cache . entry ( obligation. as_predicate ( ) . clone ( ) ) {
306
315
Entry :: Occupied ( o) => {
307
316
let index = match o. get ( ) {
@@ -372,7 +381,7 @@ impl<O: ForestObligation> ObligationForest<O> {
372
381
. collect ( )
373
382
}
374
383
375
- fn insert_into_error_cache ( & mut self , index : usize ) {
384
+ fn insert_into_error_cache ( & mut self , index : NodeIndex ) {
376
385
let node = & self . nodes [ index] ;
377
386
self . error_cache
378
387
. entry ( node. obligation_tree_id )
@@ -462,8 +471,8 @@ impl<O: ForestObligation> ObligationForest<O> {
462
471
463
472
/// Returns a vector of obligations for `p` and all of its
464
473
/// ancestors, putting them into the error state in the process.
465
- fn error_at ( & self , mut index : usize ) -> Vec < O > {
466
- let mut error_stack: Vec < usize > = vec ! [ ] ;
474
+ fn error_at ( & self , mut index : NodeIndex ) -> Vec < O > {
475
+ let mut error_stack: Vec < NodeIndex > = vec ! [ ] ;
467
476
let mut trace = vec ! [ ] ;
468
477
469
478
loop {
@@ -555,8 +564,12 @@ impl<O: ForestObligation> ObligationForest<O> {
555
564
debug_assert ! ( stack. is_empty( ) ) ;
556
565
}
557
566
558
- fn find_cycles_from_node < P > ( & self , stack : & mut Vec < usize > , processor : & mut P , index : usize )
559
- where
567
+ fn find_cycles_from_node < P > (
568
+ & self ,
569
+ stack : & mut Vec < NodeIndex > ,
570
+ processor : & mut P ,
571
+ index : NodeIndex ,
572
+ ) where
560
573
P : ObligationProcessor < Obligation = O > ,
561
574
{
562
575
let node = & self . nodes [ index] ;
@@ -643,7 +656,7 @@ impl<O: ForestObligation> ObligationForest<O> {
643
656
if do_completed == DoCompleted :: Yes { Some ( removed_done_obligations) } else { None }
644
657
}
645
658
646
- fn apply_rewrites ( & mut self , node_rewrites : & [ usize ] ) {
659
+ fn apply_rewrites ( & mut self , node_rewrites : & [ NodeIndex ] ) {
647
660
let orig_nodes_len = node_rewrites. len ( ) ;
648
661
let remove_node_marker = orig_nodes_len + 1 ;
649
662
0 commit comments