-
Notifications
You must be signed in to change notification settings - Fork 12.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generalize search graph to enable fuzzing #127627
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me after nits and comments
809acd2
to
208d709
Compare
@bors r=compiler-errors rollup |
use crate::delegate::SolverDelegate; | ||
use crate::solve::inspect::{self, ProofTreeBuilder}; | ||
use crate::solve::{ | ||
CacheData, CanonicalInput, Certainty, QueryResult, SolverMode, FIXPOINT_STEP_LIMIT, | ||
}; | ||
|
||
#[derive(Copy, Clone, PartialEq, Eq, Debug)] | ||
pub struct SolverLimit(usize); | ||
|
||
rustc_index::newtype_index! { | ||
#[orderable] | ||
#[gate_rustc_only] | ||
pub struct StackDepth {} | ||
} | ||
|
||
bitflags::bitflags! { | ||
/// Whether and how this goal has been used as the root of a | ||
/// cycle. We track the kind of cycle as we're otherwise forced | ||
/// to always rerun at least once. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
struct HasBeenUsed: u8 { | ||
const INDUCTIVE_CYCLE = 1 << 0; | ||
const COINDUCTIVE_CYCLE = 1 << 1; | ||
} | ||
} | ||
|
||
#[derive(derivative::Derivative)] | ||
#[derivative(Debug(bound = ""))] | ||
struct StackEntry<I: Interner> { | ||
input: CanonicalInput<I>, | ||
|
||
available_depth: SolverLimit, | ||
|
||
/// The maximum depth reached by this stack entry, only up-to date | ||
/// for the top of the stack and lazily updated for the rest. | ||
reached_depth: StackDepth, | ||
|
||
/// Whether this entry is a non-root cycle participant. | ||
/// | ||
/// We must not move the result of non-root cycle participants to the | ||
/// global cache. We store the highest stack depth of a head of a cycle | ||
/// this goal is involved in. This necessary to soundly cache its | ||
/// provisional result. | ||
non_root_cycle_participant: Option<StackDepth>, | ||
|
||
encountered_overflow: bool, | ||
|
||
has_been_used: HasBeenUsed, | ||
|
||
/// We put only the root goal of a coinductive cycle into the global cache. | ||
/// | ||
/// If we were to use that result when later trying to prove another cycle | ||
/// participant, we can end up with unstable query results. | ||
/// | ||
/// See tests/ui/next-solver/coinduction/incompleteness-unstable-result.rs for | ||
/// an example of where this is needed. | ||
/// | ||
/// There can be multiple roots on the same stack, so we need to track | ||
/// cycle participants per root: | ||
/// ```plain | ||
/// A :- B | ||
/// B :- A, C | ||
/// C :- D | ||
/// D :- C | ||
/// ``` | ||
nested_goals: HashSet<CanonicalInput<I>>, | ||
/// Starts out as `None` and gets set when rerunning this | ||
/// goal in case we encounter a cycle. | ||
provisional_result: Option<QueryResult<I>>, | ||
} | ||
|
||
/// The provisional result for a goal which is not on the stack. | ||
#[derive(Debug)] | ||
struct DetachedEntry<I: Interner> { | ||
/// The head of the smallest non-trivial cycle involving this entry. | ||
/// | ||
/// Given the following rules, when proving `A` the head for | ||
/// the provisional entry of `C` would be `B`. | ||
/// ```plain | ||
/// A :- B | ||
/// B :- C | ||
/// C :- A + B + C | ||
/// ``` | ||
head: StackDepth, | ||
result: QueryResult<I>, | ||
} | ||
use rustc_type_ir::inherent::Predicate; | ||
use rustc_type_ir::search_graph::{self, CycleKind, UsageKind}; | ||
use rustc_type_ir::solve::{CanonicalInput, Certainty, QueryResult}; | ||
use rustc_type_ir::Interner; | ||
use std::marker::PhantomData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imports are still not cleaned up :(
head: StackDepth, | ||
result: QueryResult<I>, | ||
} | ||
use rustc_type_ir::inherent::Predicate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always just glob-import inherent::*
as a convention.
fully move it into `rustc_type_ir` and make it independent of `Interner`.
208d709
to
15f770b
Compare
I've fixed the imports. Ideally we'd enforce via lint at least that Would prefer if we try to keep these imports clean in general 🤔 I've tried very hard to clean them up in the process of uplifting and I think it does a lot to help the code maintainability. @bors r+ |
…r-errors generalize search graph to enable fuzzing I do not believe it to be feasible to correctly implement the search graph without fuzzing. This PR enables this by requiring a fuzzer to only implement three new traits: - `Cx`: implemented by all `I: Interner` - `ProofTreeBuilder`: implemented by `struct ProofTreeBuilder<D>` for all `D: SolverDelegate` - `Delegate`: implemented for a new `struct SearchGraphDelegate<D>` for all `D: SolverDelegate` It also moves the evaluation cache implementation into `rustc_type_ir`, requiring `Interner` to provide methods to create and access arbitrary `WithDepNode<T>` and to provide mutable access to a given `GlobalCache`. It otherwise does not change the API surface for users of the shared library. This change should not impact behavior in any way. r? `@compiler-errors`
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#124980 (Generalize `fn allocator` for Rc/Arc.) - rust-lang#126639 (Add AMX target-features and `x86_amx_intrinsics` feature flag) - rust-lang#126827 (Use pidfd_spawn for faster process spawning when a PidFd is requested) - rust-lang#127153 (Initial implementation of anonymous_pipe API) - rust-lang#127433 (Stabilize const_cstr_from_ptr (CStr::from_ptr, CStr::count_bytes)) - rust-lang#127552 (remove unnecessary `git` usages) - rust-lang#127613 (Update dist-riscv64-linux to binutils 2.40) - rust-lang#127627 (generalize search graph to enable fuzzing) - rust-lang#127648 (Lower timeout of CI jobs to 4 hours) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#124980 (Generalize `fn allocator` for Rc/Arc.) - rust-lang#126639 (Add AMX target-features and `x86_amx_intrinsics` feature flag) - rust-lang#126827 (Use pidfd_spawn for faster process spawning when a PidFd is requested) - rust-lang#127433 (Stabilize const_cstr_from_ptr (CStr::from_ptr, CStr::count_bytes)) - rust-lang#127552 (remove unnecessary `git` usages) - rust-lang#127613 (Update dist-riscv64-linux to binutils 2.40) - rust-lang#127627 (generalize search graph to enable fuzzing) - rust-lang#127648 (Lower timeout of CI jobs to 4 hours) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#127627 - lcnr:rustc_search_graph, r=compiler-errors generalize search graph to enable fuzzing I do not believe it to be feasible to correctly implement the search graph without fuzzing. This PR enables this by requiring a fuzzer to only implement three new traits: - `Cx`: implemented by all `I: Interner` - `ProofTreeBuilder`: implemented by `struct ProofTreeBuilder<D>` for all `D: SolverDelegate` - `Delegate`: implemented for a new `struct SearchGraphDelegate<D>` for all `D: SolverDelegate` It also moves the evaluation cache implementation into `rustc_type_ir`, requiring `Interner` to provide methods to create and access arbitrary `WithDepNode<T>` and to provide mutable access to a given `GlobalCache`. It otherwise does not change the API surface for users of the shared library. This change should not impact behavior in any way. r? ``@compiler-errors``
I do not believe it to be feasible to correctly implement the search graph without fuzzing. This PR enables this by requiring a fuzzer to only implement three new traits:
Cx
: implemented by allI: Interner
ProofTreeBuilder
: implemented bystruct ProofTreeBuilder<D>
for allD: SolverDelegate
Delegate
: implemented for a newstruct SearchGraphDelegate<D>
for allD: SolverDelegate
It also moves the evaluation cache implementation into
rustc_type_ir
, requiringInterner
to provide methods to create and access arbitraryWithDepNode<T>
and to provide mutable access to a givenGlobalCache
. It otherwise does not change the API surface for users of the shared library.This change should not impact behavior in any way.
r? @compiler-errors