Skip to content

Commit 12c289b

Browse files
committed
box CandidateUsages
1 parent 32de28a commit 12c289b

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use std::collections::hash_map::Entry;
1616
use std::collections::{BTreeMap, btree_map};
1717
use std::fmt::Debug;
1818
use std::hash::Hash;
19+
use std::iter;
1920
use std::marker::PhantomData;
20-
use std::{iter, mem};
2121

2222
use derive_where::derive_where;
2323
#[cfg(feature = "nightly")]
@@ -229,16 +229,19 @@ impl Usages {
229229

230230
#[derive(Debug, Default)]
231231
pub struct CandidateUsages {
232-
usages: HashMap<StackDepth, Usages>,
232+
usages: Option<Box<HashMap<StackDepth, Usages>>>,
233233
}
234234
impl CandidateUsages {
235-
pub fn add_usages(&mut self, mut other: CandidateUsages) {
236-
if self.usages.is_empty() {
237-
mem::swap(self, &mut other);
238-
}
239-
#[allow(rustc::potential_query_instability)]
240-
for (head_index, head) in other.usages {
241-
self.usages.entry(head_index).or_default().add_usages(head);
235+
pub fn add_usages(&mut self, other: CandidateUsages) {
236+
if let Some(other_usages) = other.usages {
237+
if let Some(ref mut self_usages) = self.usages {
238+
#[allow(rustc::potential_query_instability)]
239+
for (head_index, head) in other_usages.into_iter() {
240+
self_usages.entry(head_index).or_default().add_usages(head);
241+
}
242+
} else {
243+
self.usages = Some(other_usages);
244+
}
242245
}
243246
}
244247
}
@@ -604,6 +607,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
604607
if let Some(candidate_usages) = &mut parent.candidate_usages {
605608
candidate_usages
606609
.usages
610+
.get_or_insert_default()
607611
.entry(head_index)
608612
.or_default()
609613
.add_usages(head.usages.compressed());
@@ -682,13 +686,15 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
682686
}
683687

684688
pub fn ignore_candidate_usages(&mut self, usages: CandidateUsages) {
685-
let (entry_index, entry) = self.stack.last_mut_with_index().unwrap();
686-
#[allow(rustc::potential_query_instability)]
687-
for (head_index, usages) in usages.usages {
688-
if head_index == entry_index {
689-
entry.usages.unwrap().ignore_usages(usages);
690-
} else {
691-
entry.heads.ignore_usages(head_index, usages);
689+
if let Some(usages) = usages.usages {
690+
let (entry_index, entry) = self.stack.last_mut_with_index().unwrap();
691+
#[allow(rustc::potential_query_instability)]
692+
for (head_index, usages) in usages.into_iter() {
693+
if head_index == entry_index {
694+
entry.usages.unwrap().ignore_usages(usages);
695+
} else {
696+
entry.heads.ignore_usages(head_index, usages);
697+
}
692698
}
693699
}
694700
}

compiler/rustc_type_ir/src/search_graph/stack.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ pub(super) struct StackEntry<X: Cx> {
2828
/// The available depth of a given goal, immutable.
2929
pub available_depth: AvailableDepth,
3030

31+
/// The maximum depth required while evaluating this goal.
32+
pub required_depth: usize,
33+
3134
/// Starts out as `None` and gets set when rerunning this
3235
/// goal in case we encounter a cycle.
3336
pub provisional_result: Option<X::Result>,
3437

35-
/// The maximum depth required while evaluating this goal.
36-
pub required_depth: usize,
37-
3838
/// All cycle heads this goal depends on. Lazily updated and only
3939
/// up-to date for the top of the stack.
4040
pub heads: CycleHeads,
@@ -45,7 +45,7 @@ pub(super) struct StackEntry<X: Cx> {
4545
/// Whether and how this goal has been used as the root of a cycle. Lazily updated.
4646
pub usages: Option<Usages>,
4747

48-
/// TODO
48+
// TODO
4949
pub candidate_usages: Option<CandidateUsages>,
5050

5151
/// The nested goals of this goal, see the doc comment of the type.

0 commit comments

Comments
 (0)