Skip to content

Commit 8505bc5

Browse files
committed
support disabling the provisional cache for fuzzing
1 parent c093af0 commit 8505bc5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

compiler/rustc_next_trait_solver/src/solve/search_graph.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ where
2323
{
2424
type Cx = D::Interner;
2525

26+
const ENABLE_PROVISIONAL_CACHE: bool = true;
2627
type ValidationScope = Infallible;
2728
fn enter_validation_scope(
2829
_cx: Self::Cx,

compiler/rustc_type_ir/src/search_graph/mod.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ pub trait Cx: Copy {
4646

4747
pub trait Delegate {
4848
type Cx: Cx;
49+
/// Whether to use the provisional cache. Set to `false` by a fuzzer when
50+
/// validating the search graph.
51+
const ENABLE_PROVISIONAL_CACHE: bool;
4952
type ValidationScope;
5053
/// Returning `Some` disables the global cache for the current goal.
5154
///
@@ -525,12 +528,14 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
525528
} else if D::inspect_is_noop(inspect) {
526529
self.insert_global_cache(cx, input, final_entry, result, dep_node)
527530
}
528-
} else {
531+
} else if D::ENABLE_PROVISIONAL_CACHE {
529532
debug_assert!(validate_cache.is_none());
530533
let entry = self.provisional_cache.entry(input).or_default();
531534
let StackEntry { heads, nested_goals, .. } = final_entry;
532535
let path_from_head = Self::stack_path_kind(cx, &self.stack, heads.highest_cycle_head());
533536
entry.push(ProvisionalCacheEntry { heads, path_from_head, nested_goals, result });
537+
} else {
538+
debug_assert!(validate_cache.is_none());
534539
}
535540

536541
result
@@ -672,6 +677,10 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
672677
}
673678

674679
fn lookup_provisional_cache(&mut self, cx: X, input: X::Input) -> Option<X::Result> {
680+
if !D::ENABLE_PROVISIONAL_CACHE {
681+
return None;
682+
}
683+
675684
let entries = self.provisional_cache.get(&input)?;
676685
for &ProvisionalCacheEntry { ref heads, path_from_head, ref nested_goals, result } in
677686
entries

0 commit comments

Comments
 (0)