Skip to content

Commit

Permalink
the coolest beans
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Aug 12, 2024
1 parent ad501b4 commit 73f0823
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_next_trait_solver/src/solve/search_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ where
inspect.is_noop()
}

const DIVIDE_AVAILABLE_DEPTH_ON_OVERFLOW: usize = 4;
fn recursion_limit(cx: I) -> usize {
cx.recursion_limit()
}
Expand Down
26 changes: 15 additions & 11 deletions compiler/rustc_type_ir/src/search_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub trait Delegate {
type ProofTreeBuilder;
fn inspect_is_noop(inspect: &mut Self::ProofTreeBuilder) -> bool;

const DIVIDE_AVAILABLE_DEPTH_ON_OVERFLOW: usize;
fn recursion_limit(cx: Self::Cx) -> usize;

fn initial_provisional_result(
Expand Down Expand Up @@ -150,7 +151,7 @@ impl AvailableDepth {
}

Some(if last.encountered_overflow {
AvailableDepth(last.available_depth.0 / 2)
AvailableDepth(last.available_depth.0 / D::DIVIDE_AVAILABLE_DEPTH_ON_OVERFLOW)
} else {
AvailableDepth(last.available_depth.0 - 1)
})
Expand Down Expand Up @@ -306,7 +307,7 @@ struct StackEntry<X: Cx> {
/// goals still on the stack.
#[derive_where(Debug; X: Cx)]
struct ProvisionalCacheEntry<X: Cx> {
is_sus: bool,
encountered_overflow: bool,
heads: CycleHeads,
path_from_head: CycleKind,
nested_goals: NestedGoals<X>,
Expand Down Expand Up @@ -421,7 +422,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
self.provisional_cache.retain(|&input, entries| {
entries.retain_mut(|entry| {
let ProvisionalCacheEntry {
is_sus: _,
encountered_overflow: _,
heads,
path_from_head,
nested_goals,
Expand Down Expand Up @@ -544,10 +545,9 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
debug_assert!(validate_cache.is_none());
let entry = self.provisional_cache.entry(input).or_default();
let StackEntry { heads, nested_goals, encountered_overflow, .. } = final_entry;
let is_sus = encountered_overflow;
let path_from_head = Self::stack_path_kind(cx, &self.stack, heads.highest_cycle_head());
entry.push(ProvisionalCacheEntry {
is_sus,
encountered_overflow,
heads,
path_from_head,
nested_goals,
Expand Down Expand Up @@ -606,14 +606,18 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
debug!(?input, ?path_from_global_entry, ?entries, "candidate_is_applicable");
// A provisional cache entry is applicable if the path to
// its highest cycle head is equal to the expected path.
for ProvisionalCacheEntry {
is_sus: _,
heads,
for &ProvisionalCacheEntry {
encountered_overflow,
ref heads,
path_from_head,
nested_goals: _,
result: _,
} in entries.iter().filter(|e| !e.is_sus)
} in entries.iter()
{
if encountered_overflow {
continue;
}

let head = heads.highest_cycle_head();
let full_path = if Self::stack_coinductive_from(cx, stack, head) {
path_from_global_entry
Expand Down Expand Up @@ -707,15 +711,15 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {

let entries = self.provisional_cache.get(&input)?;
for &ProvisionalCacheEntry {
is_sus,
encountered_overflow,
ref heads,
path_from_head,
ref nested_goals,
result,
} in entries
{
let head = heads.highest_cycle_head();
if is_sus {
if encountered_overflow {
let last = self.stack.raw.last().unwrap();
if !last.heads.opt_lowest_cycle_head().is_some_and(|lowest| lowest <= head) {
continue;
Expand Down

0 comments on commit 73f0823

Please sign in to comment.