Skip to content

Commit

Permalink
rustc/ty: improve stack shifting and remove related allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Oct 5, 2018
1 parent 0ee6b54 commit 7ad21a8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/librustc/ty/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ impl<'tcx> QueryJob<'tcx> {
let mut cycle = Vec::new();

while let Some(job) = current_job {
cycle.insert(0, job.info.clone());
cycle.push(job.info.clone());

if ptr::eq(&*job, self) {
cycle.reverse();

// This is the end of the cycle
// The span entry we included was for the usage
// of the cycle itself, and not part of the cycle
Expand Down Expand Up @@ -368,13 +370,11 @@ fn remove_cycle<'tcx>(
// Reverse the stack so earlier entries require later entries
stack.reverse();

// Extract the spans and queries into separate arrays
let mut spans: Vec<_> = stack.iter().map(|e| e.0).collect();
let queries = stack.into_iter().map(|e| e.1);
// The stack is a vector of pairs of spans and queries
let (mut spans, queries): (Vec<_>, Vec<_>) = stack.into_iter().unzip();

// Shift the spans so that queries are matched with the span for their waitee
let last = spans.pop().unwrap();
spans.insert(0, last);
spans.rotate_right(1);

// Zip them back together
let mut stack: Vec<_> = spans.into_iter().zip(queries).collect();
Expand Down Expand Up @@ -414,10 +414,10 @@ fn remove_cycle<'tcx>(
stable_hasher.finish()
}).unwrap().as_ptr();

// Shift the stack until our entry point is first
while stack[0].1.as_ptr() != entry_point {
let last = stack.pop().unwrap();
stack.insert(0, last);
// Shift the stack so that our entry point is first
let entry_point_pos = stack.iter().position(|(_, query)| query.as_ptr() == entry_point);
if let Some(pos) = entry_point_pos {
stack.rotate_right(pos);
}

// Create the cycle error
Expand Down

0 comments on commit 7ad21a8

Please sign in to comment.