Skip to content

Commit 04b1111

Browse files
committed
Name index variables consistently.
Those with type `usize` are now called `i`, those with type `NodeIndex` are called `index`.
1 parent ca3766e commit 04b1111

File tree

1 file changed

+47
-50
lines changed
  • src/librustc_data_structures/obligation_forest

1 file changed

+47
-50
lines changed

src/librustc_data_structures/obligation_forest/mod.rs

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,15 @@ impl<O: ForestObligation> ObligationForest<O> {
295295
debug!("register_obligation_at({:?}, {:?}) - duplicate of {:?}!",
296296
obligation, parent, o.get());
297297
let node = &mut self.nodes[o.get().get()];
298-
if let Some(parent) = parent {
298+
if let Some(parent_index) = parent {
299299
// If the node is already in `waiting_cache`, it's already
300300
// been marked with a parent. (It's possible that parent
301301
// has been cleared by `apply_rewrites`, though.) So just
302302
// dump `parent` into `node.dependents`... unless it's
303303
// already in `node.dependents` or `node.parent`.
304-
if !node.dependents.contains(&parent) && Some(parent) != node.parent {
305-
node.dependents.push(parent);
304+
if !node.dependents.contains(&parent_index) &&
305+
Some(parent_index) != node.parent {
306+
node.dependents.push(parent_index);
306307
}
307308
}
308309
if let NodeState::Error = node.state.get() {
@@ -316,9 +317,8 @@ impl<O: ForestObligation> ObligationForest<O> {
316317
obligation, parent, self.nodes.len());
317318

318319
let obligation_tree_id = match parent {
319-
Some(p) => {
320-
let parent_node = &self.nodes[p.get()];
321-
parent_node.obligation_tree_id
320+
Some(parent_index) => {
321+
self.nodes[parent_index.get()].obligation_tree_id
322322
}
323323
None => self.obligation_tree_id_generator.next().unwrap()
324324
};
@@ -346,9 +346,9 @@ impl<O: ForestObligation> ObligationForest<O> {
346346
/// This cannot be done during a snapshot.
347347
pub fn to_errors<E: Clone>(&mut self, error: E) -> Vec<Error<O, E>> {
348348
let mut errors = vec![];
349-
for index in 0..self.nodes.len() {
350-
if let NodeState::Pending = self.nodes[index].state.get() {
351-
let backtrace = self.error_at(index);
349+
for i in 0..self.nodes.len() {
350+
if let NodeState::Pending = self.nodes[i].state.get() {
351+
let backtrace = self.error_at(i);
352352
errors.push(Error {
353353
error: error.clone(),
354354
backtrace,
@@ -393,16 +393,16 @@ impl<O: ForestObligation> ObligationForest<O> {
393393
let mut errors = vec![];
394394
let mut stalled = true;
395395

396-
for index in 0..self.nodes.len() {
397-
debug!("process_obligations: node {} == {:?}", index, self.nodes[index]);
396+
for i in 0..self.nodes.len() {
397+
debug!("process_obligations: node {} == {:?}", i, self.nodes[i]);
398398

399-
let result = match self.nodes[index] {
399+
let result = match self.nodes[i] {
400400
Node { ref state, ref mut obligation, .. } if state.get() == NodeState::Pending =>
401401
processor.process_obligation(obligation),
402402
_ => continue
403403
};
404404

405-
debug!("process_obligations: node {} got result {:?}", index, result);
405+
debug!("process_obligations: node {} got result {:?}", i, result);
406406

407407
match result {
408408
ProcessResult::Unchanged => {
@@ -411,23 +411,23 @@ impl<O: ForestObligation> ObligationForest<O> {
411411
ProcessResult::Changed(children) => {
412412
// We are not (yet) stalled.
413413
stalled = false;
414-
self.nodes[index].state.set(NodeState::Success);
414+
self.nodes[i].state.set(NodeState::Success);
415415

416416
for child in children {
417417
let st = self.register_obligation_at(
418418
child,
419-
Some(NodeIndex::new(index))
419+
Some(NodeIndex::new(i))
420420
);
421421
if let Err(()) = st {
422422
// error already reported - propagate it
423423
// to our node.
424-
self.error_at(index);
424+
self.error_at(i);
425425
}
426426
}
427427
}
428428
ProcessResult::Error(err) => {
429429
stalled = false;
430-
let backtrace = self.error_at(index);
430+
let backtrace = self.error_at(i);
431431
errors.push(Error {
432432
error: err,
433433
backtrace,
@@ -473,15 +473,15 @@ impl<O: ForestObligation> ObligationForest<O> {
473473

474474
debug!("process_cycles()");
475475

476-
for index in 0..self.nodes.len() {
476+
for i in 0..self.nodes.len() {
477477
// For rustc-benchmarks/inflate-0.1.0 this state test is extremely
478478
// hot and the state is almost always `Pending` or `Waiting`. It's
479479
// a win to handle the no-op cases immediately to avoid the cost of
480480
// the function call.
481-
let state = self.nodes[index].state.get();
481+
let state = self.nodes[i].state.get();
482482
match state {
483483
NodeState::Waiting | NodeState::Pending | NodeState::Done | NodeState::Error => {},
484-
_ => self.find_cycles_from_node(&mut stack, processor, index),
484+
_ => self.find_cycles_from_node(&mut stack, processor, i),
485485
}
486486
}
487487

@@ -491,24 +491,22 @@ impl<O: ForestObligation> ObligationForest<O> {
491491
self.scratch = Some(stack);
492492
}
493493

494-
fn find_cycles_from_node<P>(&self, stack: &mut Vec<usize>,
495-
processor: &mut P, index: usize)
494+
fn find_cycles_from_node<P>(&self, stack: &mut Vec<usize>, processor: &mut P, i: usize)
496495
where P: ObligationProcessor<Obligation=O>
497496
{
498-
let node = &self.nodes[index];
497+
let node = &self.nodes[i];
499498
let state = node.state.get();
500499
match state {
501500
NodeState::OnDfsStack => {
502-
let index =
503-
stack.iter().rposition(|n| *n == index).unwrap();
504-
processor.process_backedge(stack[index..].iter().map(GetObligation(&self.nodes)),
501+
let i = stack.iter().rposition(|n| *n == i).unwrap();
502+
processor.process_backedge(stack[i..].iter().map(GetObligation(&self.nodes)),
505503
PhantomData);
506504
}
507505
NodeState::Success => {
508506
node.state.set(NodeState::OnDfsStack);
509-
stack.push(index);
510-
for dependent in node.parent.iter().chain(node.dependents.iter()) {
511-
self.find_cycles_from_node(stack, processor, dependent.get());
507+
stack.push(i);
508+
for index in node.parent.iter().chain(node.dependents.iter()) {
509+
self.find_cycles_from_node(stack, processor, index.get());
512510
}
513511
stack.pop();
514512
node.state.set(NodeState::Done);
@@ -525,33 +523,32 @@ impl<O: ForestObligation> ObligationForest<O> {
525523

526524
/// Returns a vector of obligations for `p` and all of its
527525
/// ancestors, putting them into the error state in the process.
528-
fn error_at(&mut self, p: usize) -> Vec<O> {
526+
fn error_at(&mut self, mut i: usize) -> Vec<O> {
529527
let mut error_stack = self.scratch.take().unwrap();
530528
let mut trace = vec![];
531529

532-
let mut n = p;
533530
loop {
534-
self.nodes[n].state.set(NodeState::Error);
535-
trace.push(self.nodes[n].obligation.clone());
536-
error_stack.extend(self.nodes[n].dependents.iter().map(|x| x.get()));
531+
let node = &self.nodes[i];
532+
node.state.set(NodeState::Error);
533+
trace.push(node.obligation.clone());
534+
error_stack.extend(node.dependents.iter().map(|index| index.get()));
537535

538-
// loop to the parent
539-
match self.nodes[n].parent {
540-
Some(q) => n = q.get(),
536+
// Loop to the parent.
537+
match node.parent {
538+
Some(parent_index) => i = parent_index.get(),
541539
None => break
542540
}
543541
}
544542

545543
while let Some(i) = error_stack.pop() {
546-
match self.nodes[i].state.get() {
544+
let node = &self.nodes[i];
545+
match node.state.get() {
547546
NodeState::Error => continue,
548547
_ => self.nodes[i].state.set(NodeState::Error),
549548
}
550549

551-
let node = &self.nodes[i];
552-
553550
error_stack.extend(
554-
node.parent.iter().chain(node.dependents.iter()).map(|x| x.get())
551+
node.parent.iter().chain(node.dependents.iter()).map(|index| index.get())
555552
);
556553
}
557554

@@ -689,34 +686,34 @@ impl<O: ForestObligation> ObligationForest<O> {
689686

690687
for node in &mut self.nodes {
691688
if let Some(index) = node.parent {
692-
let new_index = node_rewrites[index.get()];
693-
if new_index >= nodes_len {
689+
let new_i = node_rewrites[index.get()];
690+
if new_i >= nodes_len {
694691
// parent dead due to error
695692
node.parent = None;
696693
} else {
697-
node.parent = Some(NodeIndex::new(new_index));
694+
node.parent = Some(NodeIndex::new(new_i));
698695
}
699696
}
700697

701698
let mut i = 0;
702699
while i < node.dependents.len() {
703-
let new_index = node_rewrites[node.dependents[i].get()];
704-
if new_index >= nodes_len {
700+
let new_i = node_rewrites[node.dependents[i].get()];
701+
if new_i >= nodes_len {
705702
node.dependents.swap_remove(i);
706703
} else {
707-
node.dependents[i] = NodeIndex::new(new_index);
704+
node.dependents[i] = NodeIndex::new(new_i);
708705
i += 1;
709706
}
710707
}
711708
}
712709

713710
let mut kill_list = vec![];
714711
for (predicate, index) in &mut self.waiting_cache {
715-
let new_index = node_rewrites[index.get()];
716-
if new_index >= nodes_len {
712+
let new_i = node_rewrites[index.get()];
713+
if new_i >= nodes_len {
717714
kill_list.push(predicate.clone());
718715
} else {
719-
*index = NodeIndex::new(new_index);
716+
*index = NodeIndex::new(new_i);
720717
}
721718
}
722719

0 commit comments

Comments
 (0)