Skip to content

Commit 85fc606

Browse files
committed
u wu
1 parent 4bd3204 commit 85fc606

File tree

5 files changed

+41
-12
lines changed

5 files changed

+41
-12
lines changed

Diff for: compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ pub trait SolverDelegateEvalExt: SolverDelegate {
132132
generate_proof_tree: GenerateProofTree,
133133
) -> (Result<(bool, Certainty), NoSolution>, Option<inspect::GoalEvaluation<Self::Interner>>);
134134

135+
fn root_goal_may_hold_with_depth(
136+
&self,
137+
root_depth: usize,
138+
goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
139+
) -> bool;
140+
135141
// FIXME: This is only exposed because we need to use it in `analyse.rs`
136142
// which is not yet uplifted. Once that's done, we should remove this.
137143
fn evaluate_root_goal_raw(
@@ -159,11 +165,25 @@ where
159165
goal: Goal<I, I::Predicate>,
160166
generate_proof_tree: GenerateProofTree,
161167
) -> (Result<(bool, Certainty), NoSolution>, Option<inspect::GoalEvaluation<I>>) {
162-
EvalCtxt::enter_root(self, generate_proof_tree, |ecx| {
168+
EvalCtxt::enter_root(self, self.cx().recursion_limit(), generate_proof_tree, |ecx| {
163169
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal)
164170
})
165171
}
166172

173+
fn root_goal_may_hold_with_depth(
174+
&self,
175+
root_depth: usize,
176+
goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
177+
) -> bool {
178+
self.probe(|| {
179+
EvalCtxt::enter_root(self, root_depth, GenerateProofTree::No, |ecx| {
180+
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal)
181+
})
182+
.0
183+
})
184+
.is_ok()
185+
}
186+
167187
#[instrument(level = "debug", skip(self))]
168188
fn evaluate_root_goal_raw(
169189
&self,
@@ -173,7 +193,7 @@ where
173193
Result<(NestedNormalizationGoals<I>, bool, Certainty), NoSolution>,
174194
Option<inspect::GoalEvaluation<I>>,
175195
) {
176-
EvalCtxt::enter_root(self, generate_proof_tree, |ecx| {
196+
EvalCtxt::enter_root(self, self.cx().recursion_limit(), generate_proof_tree, |ecx| {
177197
ecx.evaluate_goal_raw(GoalEvaluationKind::Root, GoalSource::Misc, goal)
178198
})
179199
}
@@ -197,10 +217,11 @@ where
197217
/// over using this manually (such as [`SolverDelegateEvalExt::evaluate_root_goal`]).
198218
pub(super) fn enter_root<R>(
199219
delegate: &D,
220+
root_depth: usize,
200221
generate_proof_tree: GenerateProofTree,
201222
f: impl FnOnce(&mut EvalCtxt<'_, D>) -> R,
202223
) -> (R, Option<inspect::GoalEvaluation<I>>) {
203-
let mut search_graph = SearchGraph::new(delegate.solver_mode());
224+
let mut search_graph = SearchGraph::new(delegate.solver_mode(), root_depth);
204225

205226
let mut ecx = EvalCtxt {
206227
delegate,

Diff for: compiler/rustc_next_trait_solver/src/solve/search_graph.rs

-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ where
4040
}
4141

4242
const DIVIDE_AVAILABLE_DEPTH_ON_OVERFLOW: usize = 4;
43-
fn recursion_limit(cx: I) -> usize {
44-
cx.recursion_limit()
45-
}
4643

4744
fn initial_provisional_result(
4845
cx: I,

Diff for: compiler/rustc_trait_selection/src/solve.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod inspect;
66
mod normalize;
77
mod select;
88

9+
pub(crate) use delegate::SolverDelegate;
910
pub use fulfill::{FulfillmentCtxt, NextSolverError};
1011
pub(crate) use normalize::deeply_normalize_for_diagnostics;
1112
pub use normalize::{deeply_normalize, deeply_normalize_with_skipped_universes};

Diff for: compiler/rustc_trait_selection/src/traits/coherence.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_middle::ty::fast_reject::DeepRejectCtxt;
1919
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
2020
use rustc_middle::ty::{self, Ty, TyCtxt};
2121
pub use rustc_next_trait_solver::coherence::*;
22+
use rustc_next_trait_solver::solve::SolverDelegateEvalExt;
2223
use rustc_span::symbol::sym;
2324
use rustc_span::{DUMMY_SP, Span};
2425
use tracing::{debug, instrument, warn};
@@ -28,7 +29,7 @@ use crate::error_reporting::traits::suggest_new_overflow_limit;
2829
use crate::infer::InferOk;
2930
use crate::infer::outlives::env::OutlivesEnvironment;
3031
use crate::solve::inspect::{InspectGoal, ProofTreeInferCtxtExt, ProofTreeVisitor};
31-
use crate::solve::{deeply_normalize_for_diagnostics, inspect};
32+
use crate::solve::{deeply_normalize_for_diagnostics, inspect, SolverDelegate};
3233
use crate::traits::query::evaluate_obligation::InferCtxtExt;
3334
use crate::traits::select::IntercrateAmbiguityCause;
3435
use crate::traits::{
@@ -333,6 +334,13 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>(
333334
let infcx = selcx.infcx;
334335

335336
if infcx.next_trait_solver() {
337+
if !obligations.iter().all(|o| {
338+
<&SolverDelegate<'tcx>>::from(infcx)
339+
.root_goal_may_hold_with_depth(8, Goal::new(infcx.tcx, o.param_env, o.predicate))
340+
}) {
341+
return IntersectionHasImpossibleObligations::Yes;
342+
}
343+
336344
let ocx = ObligationCtxt::new_with_diagnostics(infcx);
337345
ocx.register_obligations(obligations.iter().cloned());
338346
let errors_and_ambiguities = ocx.select_all_or_error();

Diff for: compiler/rustc_type_ir/src/search_graph/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ pub trait Delegate {
8181
fn inspect_is_noop(inspect: &mut Self::ProofTreeBuilder) -> bool;
8282

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

8685
fn initial_provisional_result(
8786
cx: Self::Cx,
@@ -156,7 +155,7 @@ impl AvailableDepth {
156155
/// the remaining depth of all nested goals to prevent hangs
157156
/// in case there is exponential blowup.
158157
fn allowed_depth_for_nested<D: Delegate>(
159-
cx: D::Cx,
158+
root_depth: AvailableDepth,
160159
stack: &IndexVec<StackDepth, StackEntry<D::Cx>>,
161160
) -> Option<AvailableDepth> {
162161
if let Some(last) = stack.raw.last() {
@@ -170,7 +169,7 @@ impl AvailableDepth {
170169
AvailableDepth(last.available_depth.0 - 1)
171170
})
172171
} else {
173-
Some(AvailableDepth(D::recursion_limit(cx)))
172+
Some(root_depth)
174173
}
175174
}
176175

@@ -360,6 +359,7 @@ struct ProvisionalCacheEntry<X: Cx> {
360359

361360
pub struct SearchGraph<D: Delegate<Cx = X>, X: Cx = <D as Delegate>::Cx> {
362361
mode: SolverMode,
362+
root_depth: AvailableDepth,
363363
/// The stack of goals currently being computed.
364364
///
365365
/// An element is *deeper* in the stack if its index is *lower*.
@@ -374,9 +374,10 @@ pub struct SearchGraph<D: Delegate<Cx = X>, X: Cx = <D as Delegate>::Cx> {
374374
}
375375

376376
impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
377-
pub fn new(mode: SolverMode) -> SearchGraph<D> {
377+
pub fn new(mode: SolverMode, root_depth: usize) -> SearchGraph<D> {
378378
Self {
379379
mode,
380+
root_depth: AvailableDepth(root_depth),
380381
stack: Default::default(),
381382
provisional_cache: Default::default(),
382383
_marker: PhantomData,
@@ -460,7 +461,8 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
460461
inspect: &mut D::ProofTreeBuilder,
461462
mut evaluate_goal: impl FnMut(&mut Self, &mut D::ProofTreeBuilder) -> X::Result,
462463
) -> X::Result {
463-
let Some(available_depth) = AvailableDepth::allowed_depth_for_nested::<D>(cx, &self.stack)
464+
let Some(available_depth) =
465+
AvailableDepth::allowed_depth_for_nested::<D>(self.root_depth, &self.stack)
464466
else {
465467
return self.handle_overflow(cx, input, inspect);
466468
};

0 commit comments

Comments
 (0)