Skip to content

Commit 6713fa7

Browse files
committed
Auto merge of #133502 - lcnr:rust4, r=<try>
[DO NOT MERGE] `-Znext-solver=globally` experiments
2 parents 57f772f + 05fcfc6 commit 6713fa7

15 files changed

Lines changed: 135 additions & 134 deletions

File tree

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,13 @@ fn check_new_solver_banned_features(sess: &Session, features: &Features) {
731731
.map(|feat| feat.attr_sp)
732732
{
733733
#[allow(rustc::symbol_intern_string_literal)]
734-
sess.dcx().emit_err(errors::IncompatibleFeatures {
735-
spans: vec![gce_span],
736-
f1: Symbol::intern("-Znext-solver=globally"),
737-
f2: sym::generic_const_exprs,
738-
});
734+
sess.dcx()
735+
.create_fatal(errors::IncompatibleFeatures {
736+
spans: vec![gce_span],
737+
f1: Symbol::intern("-Znext-solver=globally"),
738+
f2: sym::generic_const_exprs,
739+
})
740+
.with_code(rustc_errors::E0001)
741+
.emit();
739742
}
740743
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2699,7 +2699,7 @@ impl<'tcx> TyCtxt<'tcx> {
26992699
}
27002700

27012701
pub fn next_trait_solver_globally(self) -> bool {
2702-
self.sess.opts.unstable_opts.next_solver.globally
2702+
self.sess.opts.unstable_opts.next_solver.globally && !self.features().generic_const_exprs()
27032703
}
27042704

27052705
pub fn next_trait_solver_in_coherence(self) -> bool {

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ where
371371
_ecx: &mut EvalCtxt<'_, D>,
372372
_goal: Goal<I, Self>,
373373
) -> Result<Candidate<I>, NoSolution> {
374-
todo!("Iterator is not yet const")
374+
Err(NoSolution)
375375
}
376376

377377
fn consider_builtin_fused_iterator_candidate(

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ where
201201
span: I::Span,
202202
stalled_on: Option<GoalStalledOn<I>>,
203203
) -> Result<GoalEvaluation<I>, NoSolution> {
204-
EvalCtxt::enter_root(self, self.cx().recursion_limit(), span, |ecx| {
204+
EvalCtxt::enter_root(self, self.cx().recursion_limit() * 2, span, |ecx| {
205205
ecx.evaluate_goal(GoalSource::Misc, goal, stalled_on)
206206
})
207207
}
@@ -284,18 +284,10 @@ where
284284
// We currently only consider a cycle coinductive if it steps
285285
// into a where-clause of a coinductive trait.
286286
CurrentGoalKind::CoinductiveTrait => PathKind::Coinductive,
287-
// While normalizing via an impl does step into a where-clause of
288-
// an impl, accessing the associated item immediately steps out of
289-
// it again. This means cycles/recursive calls are not guarded
290-
// by impls used for normalization.
291-
//
292-
// See tests/ui/traits/next-solver/cycles/normalizes-to-is-not-productive.rs
293-
// for how this can go wrong.
294-
CurrentGoalKind::NormalizesTo => PathKind::Inductive,
295287
// We probably want to make all traits coinductive in the future,
296288
// so we treat cycles involving where-clauses of not-yet coinductive
297289
// traits as ambiguous for now.
298-
CurrentGoalKind::Misc => PathKind::Unknown,
290+
CurrentGoalKind::Misc | CurrentGoalKind::NormalizesTo => PathKind::Unknown,
299291
},
300292
// Relating types is always unproductive. If we were to map proof trees to
301293
// corecursive functions as explained in #136824, relating types never
@@ -1491,7 +1483,7 @@ pub fn evaluate_root_goal_for_proof_tree_raw_provider<
14911483
let mut inspect = inspect::ProofTreeBuilder::new();
14921484
let canonical_result = SearchGraph::<D>::evaluate_root_goal_for_proof_tree(
14931485
cx,
1494-
cx.recursion_limit(),
1486+
cx.recursion_limit() * 2,
14951487
canonical_goal,
14961488
&mut inspect,
14971489
);

compiler/rustc_next_trait_solver/src/solve/search_graph.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ where
9595
response_no_constraints(cx, input, Certainty::overflow(true))
9696
}
9797

98+
const FIXPOINT_OVERFLOW_AMBIGUITY_KIND: Certainty = Certainty::overflow(false);
9899
fn fixpoint_overflow_result(cx: I, input: CanonicalInput<I>) -> QueryResult<I> {
99-
response_no_constraints(cx, input, Certainty::overflow(false))
100+
response_no_constraints(cx, input, Self::FIXPOINT_OVERFLOW_AMBIGUITY_KIND)
100101
}
101102

102103
fn is_ambiguous_result(result: QueryResult<I>) -> Option<Certainty> {
@@ -111,14 +112,6 @@ where
111112
})
112113
}
113114

114-
fn propagate_ambiguity(
115-
cx: I,
116-
for_input: CanonicalInput<I>,
117-
certainty: Certainty,
118-
) -> QueryResult<I> {
119-
response_no_constraints(cx, for_input, certainty)
120-
}
121-
122115
fn compute_goal(
123116
search_graph: &mut SearchGraph<D>,
124117
cx: I,

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ pub struct NextSolverConfig {
996996
pub coherence: bool = true,
997997
/// Whether the new trait solver should be enabled everywhere.
998998
/// This is only `true` if `coherence` is also enabled.
999-
pub globally: bool = false,
999+
pub globally: bool = true,
10001000
}
10011001

10021002
#[derive(Clone)]

compiler/rustc_type_ir/src/interner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ impl<T, R, E> CollectAndApply<T, R> for Result<T, E> {
558558
impl<I: Interner> search_graph::Cx for I {
559559
type Input = CanonicalInput<I>;
560560
type Result = QueryResult<I>;
561-
type AmbiguityInfo = Certainty;
561+
type AmbiguityKind = Certainty;
562562

563563
type DepNodeIndex = I::DepNodeIndex;
564564
type Tracked<T: Debug + Clone> = I::Tracked<T>;

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub use global_cache::GlobalCache;
4040
pub trait Cx: Copy {
4141
type Input: Debug + Eq + Hash + Copy;
4242
type Result: Debug + Eq + Hash + Copy;
43-
type AmbiguityInfo: Debug + Eq + Hash + Copy;
43+
type AmbiguityKind: Debug + Eq + Hash + Copy;
4444

4545
type DepNodeIndex;
4646
type Tracked<T: Debug + Clone>: Debug;
@@ -92,19 +92,16 @@ pub trait Delegate: Sized {
9292
cx: Self::Cx,
9393
input: <Self::Cx as Cx>::Input,
9494
) -> <Self::Cx as Cx>::Result;
95+
96+
const FIXPOINT_OVERFLOW_AMBIGUITY_KIND: <Self::Cx as Cx>::AmbiguityKind;
9597
fn fixpoint_overflow_result(
9698
cx: Self::Cx,
9799
input: <Self::Cx as Cx>::Input,
98100
) -> <Self::Cx as Cx>::Result;
99101

100102
fn is_ambiguous_result(
101103
result: <Self::Cx as Cx>::Result,
102-
) -> Option<<Self::Cx as Cx>::AmbiguityInfo>;
103-
fn propagate_ambiguity(
104-
cx: Self::Cx,
105-
for_input: <Self::Cx as Cx>::Input,
106-
ambiguity_info: <Self::Cx as Cx>::AmbiguityInfo,
107-
) -> <Self::Cx as Cx>::Result;
104+
) -> Option<<Self::Cx as Cx>::AmbiguityKind>;
108105

109106
fn compute_goal(
110107
search_graph: &mut SearchGraph<Self>,
@@ -929,8 +926,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
929926
#[derive_where(Debug; X: Cx)]
930927
enum RebaseReason<X: Cx> {
931928
NoCycleUsages,
932-
Ambiguity(X::AmbiguityInfo),
933-
Overflow,
929+
Ambiguity(X::AmbiguityKind),
934930
/// We've actually reached a fixpoint.
935931
///
936932
/// This either happens in the first evaluation step for the cycle head.
@@ -961,10 +957,9 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
961957
/// cache entries to also be ambiguous. This causes some undesirable ambiguity for nested
962958
/// goals whose result doesn't actually depend on this cycle head, but that's acceptable
963959
/// to me.
964-
#[instrument(level = "trace", skip(self, cx))]
960+
#[instrument(level = "trace", skip(self))]
965961
fn rebase_provisional_cache_entries(
966962
&mut self,
967-
cx: X,
968963
stack_entry: &StackEntry<X>,
969964
rebase_reason: RebaseReason<X>,
970965
) {
@@ -1039,18 +1034,22 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
10391034
}
10401035

10411036
// The provisional cache entry does depend on the provisional result
1042-
// of the popped cycle head. We need to mutate the result of our
1043-
// provisional cache entry in case we did not reach a fixpoint.
1037+
// of the popped cycle head. In case we didn't actually reach a fixpoint,
1038+
// we must not keep potentially incorrect provisional cache entries around.
10441039
match rebase_reason {
10451040
// If the cycle head does not actually depend on itself, then
10461041
// the provisional result used by the provisional cache entry
10471042
// is not actually equal to the final provisional result. We
10481043
// need to discard the provisional cache entry in this case.
10491044
RebaseReason::NoCycleUsages => return false,
1050-
RebaseReason::Ambiguity(info) => {
1051-
*result = D::propagate_ambiguity(cx, input, info);
1045+
// If we avoid rerunning a goal due to ambiguity, we only keep provisional
1046+
// results which depend on that cycle head if these are already ambiguous
1047+
// themselves.
1048+
RebaseReason::Ambiguity(kind) => {
1049+
if !D::is_ambiguous_result(*result).is_some_and(|k| k == kind) {
1050+
return false;
1051+
}
10521052
}
1053-
RebaseReason::Overflow => *result = D::fixpoint_overflow_result(cx, input),
10541053
RebaseReason::ReachedFixpoint(None) => {}
10551054
RebaseReason::ReachedFixpoint(Some(path_kind)) => {
10561055
if !popped_head.usages.is_single(path_kind) {
@@ -1352,17 +1351,12 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
13521351
// final result is equal to the initial response for that case.
13531352
if let Ok(fixpoint) = self.reached_fixpoint(&stack_entry, usages, result) {
13541353
self.rebase_provisional_cache_entries(
1355-
cx,
13561354
&stack_entry,
13571355
RebaseReason::ReachedFixpoint(fixpoint),
13581356
);
13591357
return EvaluationResult::finalize(stack_entry, encountered_overflow, result);
13601358
} else if usages.is_empty() {
1361-
self.rebase_provisional_cache_entries(
1362-
cx,
1363-
&stack_entry,
1364-
RebaseReason::NoCycleUsages,
1365-
);
1359+
self.rebase_provisional_cache_entries(&stack_entry, RebaseReason::NoCycleUsages);
13661360
return EvaluationResult::finalize(stack_entry, encountered_overflow, result);
13671361
}
13681362

@@ -1371,19 +1365,15 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
13711365
// response in the next iteration in this case. These changes would
13721366
// likely either be caused by incompleteness or can change the maybe
13731367
// 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.
1368+
// preserves soundness and completeness even if the goal could
1369+
// otherwise succeed or fail.
13761370
//
13771371
// This prevents exponential blowup affecting multiple major crates.
13781372
// As we only get to this branch if we haven't yet reached a fixpoint,
13791373
// we also taint all provisional cache entries which depend on the
13801374
// 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-
);
1375+
if let Some(kind) = D::is_ambiguous_result(result) {
1376+
self.rebase_provisional_cache_entries(&stack_entry, RebaseReason::Ambiguity(kind));
13871377
return EvaluationResult::finalize(stack_entry, encountered_overflow, result);
13881378
};
13891379

@@ -1393,7 +1383,10 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
13931383
if i >= D::FIXPOINT_STEP_LIMIT {
13941384
debug!("canonical cycle overflow");
13951385
let result = D::fixpoint_overflow_result(cx, input);
1396-
self.rebase_provisional_cache_entries(cx, &stack_entry, RebaseReason::Overflow);
1386+
self.rebase_provisional_cache_entries(
1387+
&stack_entry,
1388+
RebaseReason::Ambiguity(D::FIXPOINT_OVERFLOW_AMBIGUITY_KIND),
1389+
);
13971390
return EvaluationResult::finalize(stack_entry, encountered_overflow, result);
13981391
}
13991392

tests/ui/specialization/min_specialization/next-solver-region-resolution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ trait Foo {
1010
trait Baz {}
1111

1212
impl<'a, T> Foo for &'a T //~ ERROR not all trait items implemented, missing: `Item`
13-
//~| ERROR the trait bound `&'a T: Foo` is not satisfied
13+
//~| ERROR type annotations needed: cannot satisfy `&'a T: Foo`
1414
where
15-
Self::Item: 'a, //~ ERROR the trait bound `&'a T: Foo` is not satisfied
15+
Self::Item: 'a,
1616
{
1717
}
1818

tests/ui/specialization/min_specialization/next-solver-region-resolution.stderr

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,26 @@ LL | | where
1010
LL | | Self::Item: 'a,
1111
| |___________________^ missing `Item` in implementation
1212

13-
error[E0277]: the trait bound `&'a T: Foo` is not satisfied
13+
error[E0283]: type annotations needed: cannot satisfy `&'a T: Foo`
1414
--> $DIR/next-solver-region-resolution.rs:12:21
1515
|
1616
LL | impl<'a, T> Foo for &'a T
17-
| ^^^^^ the trait `Foo` is not implemented for `&'a T`
17+
| ^^^^^
1818
|
19-
help: the trait `Foo` is not implemented for `&'a _`
20-
but it is implemented for `&_`
19+
note: multiple `impl`s satisfying `&'a T: Foo` found
2120
--> $DIR/next-solver-region-resolution.rs:12:1
2221
|
2322
LL | / impl<'a, T> Foo for &'a T
2423
LL | |
2524
LL | | where
2625
LL | | Self::Item: 'a,
2726
| |___________________^
28-
29-
error[E0277]: the trait bound `&'a T: Foo` is not satisfied
30-
--> $DIR/next-solver-region-resolution.rs:15:17
31-
|
32-
LL | Self::Item: 'a,
33-
| ^^ the trait `Foo` is not implemented for `&'a T`
34-
|
35-
help: the trait `Foo` is not implemented for `&'a _`
36-
but it is implemented for `&_`
37-
--> $DIR/next-solver-region-resolution.rs:12:1
38-
|
39-
LL | / impl<'a, T> Foo for &'a T
27+
...
28+
LL | / impl<'a, T> Foo for &T
4029
LL | |
4130
LL | | where
42-
LL | | Self::Item: 'a,
43-
| |___________________^
31+
LL | | Self::Item: Baz,
32+
| |____________________^
4433

4534
error[E0046]: not all trait items implemented, missing: `Item`
4635
--> $DIR/next-solver-region-resolution.rs:19:1
@@ -63,7 +52,7 @@ LL | | where
6352
LL | | Self::Item: Baz,
6453
| |____________________^
6554

66-
error: aborting due to 5 previous errors
55+
error: aborting due to 4 previous errors
6756

68-
Some errors have detailed explanations: E0046, E0277.
57+
Some errors have detailed explanations: E0046, E0283.
6958
For more information about an error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)