Skip to content

Commit 93078e8

Browse files
committed
yeet
1 parent 2783fc4 commit 93078e8

File tree

5 files changed

+82
-12
lines changed

5 files changed

+82
-12
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_type_ir::{
1313
self as ty, Interner, TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt as _,
1414
TypeVisitor, TypingMode, Upcast as _, elaborate,
1515
};
16-
use tracing::{debug, instrument};
16+
use tracing::{debug, instrument, debug_span};
1717

1818
use super::trait_goals::TraitGoalProvenVia;
1919
use super::{has_only_region_constraints, inspect};
@@ -958,13 +958,19 @@ where
958958
// If the trait goal has been proven by using the environment, we want to treat
959959
// aliases as rigid if there are no applicable projection bounds in the environment.
960960
if considered_candidates.is_empty() {
961+
let _span = debug_span!("inject_normalize_to_rigid_candidate");
962+
let _span = _span.enter();
961963
if let Ok(response) = inject_normalize_to_rigid_candidate(self) {
962964
considered_candidates.push(response);
963965
}
964966
}
965967

966968
if let Some(response) = self.try_merge_responses(&considered_candidates) {
967-
Ok(response)
969+
if response.value.certainty == Certainty::Yes && response.value.external_constraints.normalization_nested_goals.is_empty() {
970+
Ok(response)
971+
} else {
972+
self.flounder(&considered_candidates)
973+
}
968974
} else {
969975
self.flounder(&considered_candidates)
970976
}

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,19 @@ where
334334
(result, proof_tree)
335335
}
336336

337+
pub(super) fn with_capped_depth<R>(
338+
&mut self,
339+
max_depth: usize,
340+
f: impl FnOnce(&mut Self) -> R,
341+
) -> R {
342+
let info = self.search_graph.with_capped_depth_start(max_depth);
343+
let r = f(self);
344+
if let Some(info) = info {
345+
self.search_graph.with_capped_depth_end(info);
346+
}
347+
r
348+
}
349+
337350
/// Creates a nested evaluation context that shares the same search graph as the
338351
/// one passed in. This is suitable for evaluation, granted that the search graph
339352
/// has had the nested goal recorded on its stack. This method only be used by
@@ -594,15 +607,31 @@ where
594607
#[instrument(level = "trace", skip(self))]
595608
pub(super) fn try_evaluate_added_goals(&mut self) -> Result<Certainty, NoSolution> {
596609
let mut response = Ok(Certainty::overflow(false));
597-
for _ in 0..FIXPOINT_STEP_LIMIT {
598-
// FIXME: This match is a bit ugly, it might be nice to change the inspect
599-
// stuff to use a closure instead. which should hopefully simplify this a bit.
600-
match self.evaluate_added_goals_step() {
610+
for i in 0..FIXPOINT_STEP_LIMIT {
611+
debug!(?i, ?self.nested_goals, "try_evaluate_added_goals_step");
612+
let evaluate_step_result = if i == 0 {
613+
self.with_capped_depth(4, |this| this.evaluate_added_goals_step())
614+
} else {
615+
self.evaluate_added_goals_step()
616+
};
617+
match evaluate_step_result {
601618
Ok(Some(cert)) => {
602-
response = Ok(cert);
603-
break;
619+
if i == 0 {
620+
for (_, _, stalled_on) in &mut self.nested_goals {
621+
*stalled_on = None;
622+
}
623+
} else {
624+
response = Ok(cert);
625+
break;
626+
}
627+
}
628+
Ok(None) => {
629+
if i == 0 {
630+
for (_, _, stalled_on) in &mut self.nested_goals {
631+
*stalled_on = None;
632+
}
633+
}
604634
}
605-
Ok(None) => {}
606635
Err(NoSolution) => {
607636
response = Err(NoSolution);
608637
break;

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ where
255255
}
256256

257257
fn bail_with_ambiguity(&mut self, responses: &[CanonicalResponse<I>]) -> CanonicalResponse<I> {
258-
debug_assert!(responses.len() > 1);
258+
debug_assert!(responses.len() > 0);
259259
let maybe_cause = responses.iter().fold(MaybeCause::Ambiguity, |maybe_cause, response| {
260260
// Pull down the certainty of `Certainty::Yes` to ambiguity when combining
261261
// these responses, b/c we're combining more than one response and this we

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,12 @@ where
13801380
.map(|c| c.result)
13811381
.collect();
13821382
return if let Some(response) = self.try_merge_responses(&where_bounds) {
1383-
Ok((response, Some(TraitGoalProvenVia::ParamEnv)))
1383+
let proven_via = if response.value.certainty == Certainty::Yes {
1384+
Some(TraitGoalProvenVia::ParamEnv)
1385+
} else {
1386+
None
1387+
};
1388+
Ok((response, proven_via))
13841389
} else {
13851390
Ok((self.bail_with_ambiguity(&where_bounds), None))
13861391
};
@@ -1393,7 +1398,12 @@ where
13931398
.map(|c| c.result)
13941399
.collect();
13951400
return if let Some(response) = self.try_merge_responses(&alias_bounds) {
1396-
Ok((response, Some(TraitGoalProvenVia::AliasBound)))
1401+
let proven_via = if response.value.certainty == Certainty::Yes {
1402+
Some(TraitGoalProvenVia::AliasBound)
1403+
} else {
1404+
None
1405+
};
1406+
Ok((response, proven_via))
13971407
} else {
13981408
Ok((self.bail_with_ambiguity(&alias_bounds), None))
13991409
};

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::collections::hash_map::Entry;
1717
use std::fmt::Debug;
1818
use std::hash::Hash;
1919
use std::marker::PhantomData;
20+
use std::mem;
2021

2122
use derive_where::derive_where;
2223
#[cfg(feature = "nightly")]
@@ -521,6 +522,11 @@ enum UpdateParentGoalCtxt<'a, X: Cx> {
521522
ProvisionalCacheHit,
522523
}
523524

525+
pub struct WithCappedDepthInfo {
526+
encountered_overflow: bool,
527+
available_depth: AvailableDepth,
528+
}
529+
524530
impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
525531
pub fn new(root_depth: usize) -> SearchGraph<D> {
526532
Self {
@@ -594,6 +600,25 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
594600
stack.cycle_step_kinds(head).fold(step_kind_to_head, |curr, step| curr.extend(step))
595601
}
596602

603+
pub fn with_capped_depth_start(&mut self, max_depth: usize) -> Option<WithCappedDepthInfo> {
604+
let entry = self.stack.last_mut().unwrap();
605+
if max_depth < entry.available_depth.0 {
606+
let encountered_overflow = entry.encountered_overflow;
607+
let available_depth =
608+
mem::replace(&mut entry.available_depth, AvailableDepth(max_depth));
609+
Some(WithCappedDepthInfo { encountered_overflow, available_depth })
610+
} else {
611+
None
612+
}
613+
}
614+
615+
pub fn with_capped_depth_end(&mut self, info: WithCappedDepthInfo) {
616+
let entry = self.stack.last_mut().unwrap();
617+
entry.encountered_overflow = info.encountered_overflow;
618+
entry.available_depth = info.available_depth;
619+
self.provisional_cache.clear();
620+
}
621+
597622
/// Probably the most involved method of the whole solver.
598623
///
599624
/// While goals get computed via `D::compute_goal`, this function handles

0 commit comments

Comments
 (0)