rustc/ty: improve allocations
This commit is contained in:
parent
029e2618d0
commit
e153103c38
@ -87,11 +87,7 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
|
||||
}
|
||||
ret.root_ids.extend(old_ret.drain());
|
||||
|
||||
for id in next_forest.root_ids {
|
||||
if ret.contains(tcx, id) {
|
||||
next_ret.push(id);
|
||||
}
|
||||
}
|
||||
next_ret.extend(next_forest.root_ids.into_iter().filter(|&id| ret.contains(tcx, id)));
|
||||
|
||||
mem::swap(&mut next_ret, &mut ret.root_ids);
|
||||
next_ret.drain();
|
||||
@ -107,11 +103,7 @@ impl<'a, 'gcx, 'tcx> DefIdForest {
|
||||
let mut ret = DefIdForest::empty();
|
||||
let mut next_ret = SmallVec::new();
|
||||
for next_forest in iter {
|
||||
for id in ret.root_ids.drain() {
|
||||
if !next_forest.contains(tcx, id) {
|
||||
next_ret.push(id);
|
||||
}
|
||||
}
|
||||
next_ret.extend(ret.root_ids.drain().filter(|&id| !next_forest.contains(tcx, id)));
|
||||
|
||||
for id in next_forest.root_ids {
|
||||
if !next_ret.contains(&id) {
|
||||
|
@ -388,7 +388,7 @@ fn remove_cycle<'tcx>(
|
||||
|
||||
// Find the queries in the cycle which are
|
||||
// connected to queries outside the cycle
|
||||
let entry_points: Vec<Lrc<QueryJob<'tcx>>> = stack.iter().filter_map(|query| {
|
||||
let entry_points = stack.iter().filter_map(|query| {
|
||||
// Mark all the other queries in the cycle as already visited
|
||||
let mut visited = FxHashSet::from_iter(stack.iter().filter_map(|q| {
|
||||
if q.1.as_ptr() != query.1.as_ptr() {
|
||||
@ -403,12 +403,12 @@ fn remove_cycle<'tcx>(
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}).collect();
|
||||
});
|
||||
|
||||
// Deterministically pick an entry point
|
||||
// FIXME: Sort this instead
|
||||
let mut hcx = tcx.create_stable_hashing_context();
|
||||
let entry_point = entry_points.iter().min_by_key(|q| {
|
||||
let entry_point = entry_points.min_by_key(|q| {
|
||||
let mut stable_hasher = StableHasher::<u64>::new();
|
||||
q.info.query.hash_stable(&mut hcx, &mut stable_hasher);
|
||||
stable_hasher.finish()
|
||||
|
@ -254,23 +254,19 @@ impl<'sess> OnDiskCache<'sess> {
|
||||
})?;
|
||||
|
||||
// Encode diagnostics
|
||||
let diagnostics_index = {
|
||||
let mut diagnostics_index = EncodedDiagnosticsIndex::new();
|
||||
|
||||
for (dep_node_index, diagnostics) in self.current_diagnostics
|
||||
.borrow()
|
||||
.iter() {
|
||||
let diagnostics_index: EncodedDiagnosticsIndex = self.current_diagnostics.borrow()
|
||||
.iter()
|
||||
.map(|(dep_node_index, diagnostics)|
|
||||
{
|
||||
let pos = AbsoluteBytePos::new(encoder.position());
|
||||
// Let's make sure we get the expected type here:
|
||||
let diagnostics: &EncodedDiagnostics = diagnostics;
|
||||
let dep_node_index =
|
||||
SerializedDepNodeIndex::new(dep_node_index.index());
|
||||
let dep_node_index = SerializedDepNodeIndex::new(dep_node_index.index());
|
||||
encoder.encode_tagged(dep_node_index, diagnostics)?;
|
||||
diagnostics_index.push((dep_node_index, pos));
|
||||
}
|
||||
|
||||
diagnostics_index
|
||||
};
|
||||
Ok((dep_node_index, pos))
|
||||
})
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
let interpret_alloc_index = {
|
||||
let mut interpret_alloc_index = Vec::new();
|
||||
@ -282,6 +278,7 @@ impl<'sess> OnDiskCache<'sess> {
|
||||
// otherwise, abort
|
||||
break;
|
||||
}
|
||||
interpret_alloc_index.reserve(new_n);
|
||||
for idx in n..new_n {
|
||||
let id = encoder.interpret_allocs_inverse[idx];
|
||||
let pos = encoder.position() as u32;
|
||||
|
@ -709,14 +709,19 @@ macro_rules! define_queries_inner {
|
||||
|
||||
// We use try_lock here since we are only called from the
|
||||
// deadlock handler, and this shouldn't be locked
|
||||
$(for v in self.$name.try_lock().unwrap().active.values() {
|
||||
match *v {
|
||||
QueryResult::Started(ref job) => jobs.push(job.clone()),
|
||||
_ => (),
|
||||
$(
|
||||
jobs.extend(
|
||||
self.$name.try_lock().unwrap().active.values().filter_map(|v|
|
||||
if let QueryResult::Started(ref job) = *v {
|
||||
Some(job.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})*
|
||||
)
|
||||
);
|
||||
)*
|
||||
|
||||
return jobs;
|
||||
jobs
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user