Skip to content

Commit e32af01

Browse files
Rollup merge of rust-lang#154712 - lqd:revert-149904, r=jieyouxu
Revert "`-Znext-solver` Remove the forced ambiguity hack from search graph" This PR reverts rust-lang#149904 as discussed and requested in https://rust-lang.zulipchat.com/#narrow/channel/326866-t-types.2Fnominated/topic/.23153910.3A.20Significant.20compilation.20time.20regression.20starting.20i.E2.80.A6. We would like a bit of time to investigate without pressure how rust-lang#149904 caused the compile time regression in rust-lang#153910, and the PR is in beta and release is approaching. When that is better understood, and we e.g. have a fix or decide to eat it, we'd want to re-land the original work. cc @ShoyuVanilla @lcnr
2 parents 963e695 + 22faa52 commit e32af01

2 files changed

Lines changed: 28 additions & 48 deletions

File tree

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,9 +926,10 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
926926
/// heads from the stack. This may not necessarily mean that we've actually
927927
/// reached a fixpoint for that cycle head, which impacts the way we rebase
928928
/// provisional cache entries.
929-
#[derive(Debug)]
930-
enum RebaseReason {
929+
#[derive_where(Debug; X: Cx)]
930+
enum RebaseReason<X: Cx> {
931931
NoCycleUsages,
932+
Ambiguity(X::AmbiguityInfo),
932933
Overflow,
933934
/// We've actually reached a fixpoint.
934935
///
@@ -965,7 +966,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
965966
&mut self,
966967
cx: X,
967968
stack_entry: &StackEntry<X>,
968-
rebase_reason: RebaseReason,
969+
rebase_reason: RebaseReason<X>,
969970
) {
970971
let popped_head_index = self.stack.next_index();
971972
// Rebasing decisions depend only on each provisional entry and the current stack state,
@@ -1046,6 +1047,9 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
10461047
// is not actually equal to the final provisional result. We
10471048
// need to discard the provisional cache entry in this case.
10481049
RebaseReason::NoCycleUsages => return false,
1050+
RebaseReason::Ambiguity(info) => {
1051+
*result = D::propagate_ambiguity(cx, input, info);
1052+
}
10491053
RebaseReason::Overflow => *result = D::fixpoint_overflow_result(cx, input),
10501054
RebaseReason::ReachedFixpoint(None) => {}
10511055
RebaseReason::ReachedFixpoint(Some(path_kind)) => {
@@ -1362,6 +1366,27 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
13621366
return EvaluationResult::finalize(stack_entry, encountered_overflow, result);
13631367
}
13641368

1369+
// If computing this goal results in ambiguity with no constraints,
1370+
// we do not rerun it. It's incredibly difficult to get a different
1371+
// response in the next iteration in this case. These changes would
1372+
// likely either be caused by incompleteness or can change the maybe
1373+
// cause from ambiguity to overflow. Returning ambiguity always
1374+
// preserves soundness and completeness even if the goal is be known
1375+
// to succeed or fail.
1376+
//
1377+
// This prevents exponential blowup affecting multiple major crates.
1378+
// As we only get to this branch if we haven't yet reached a fixpoint,
1379+
// we also taint all provisional cache entries which depend on the
1380+
// current goal.
1381+
if let Some(info) = D::is_ambiguous_result(result) {
1382+
self.rebase_provisional_cache_entries(
1383+
cx,
1384+
&stack_entry,
1385+
RebaseReason::Ambiguity(info),
1386+
);
1387+
return EvaluationResult::finalize(stack_entry, encountered_overflow, result);
1388+
};
1389+
13651390
// If we've reached the fixpoint step limit, we bail with overflow and taint all
13661391
// provisional cache entries which depend on the current goal.
13671392
i += 1;

tests/ui/traits/next-solver/global-where-bound-normalization.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)