Skip to content

Commit 908a6ad

Browse files
committed
gaming
1 parent b479ffb commit 908a6ad

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ where
740740
// We skip the goal itself as that one would cycle.
741741
let predicate: I::Predicate = trait_ref.upcast(cx);
742742
ecx.add_goals(
743-
GoalSource::Misc,
743+
GoalSource::CoherenceUnknowableSuper,
744744
elaborate::elaborate(cx, [predicate])
745745
.skip(1)
746746
.map(|predicate| goal.with(cx, predicate)),

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,11 @@ where
262262
self.delegate.typing_mode()
263263
}
264264

265+
#[instrument(level = "trace", skip(self), ret)]
265266
pub(super) fn step_kind_for_source(&self, source: GoalSource) -> PathKind {
266267
match source {
267-
GoalSource::ImplWhereBound | GoalSource::NormalizeImplWhereBound => {
268+
GoalSource::NormalizeGoal(path_kind) => path_kind,
269+
GoalSource::ImplWhereBound => {
268270
// We currently only consider a cycle coinductive if it steps
269271
// into a where-clause of a coinductive trait.
270272
//
@@ -276,6 +278,11 @@ where
276278
PathKind::Unknown
277279
}
278280
}
281+
// We treat checking super trait bounds for unknowable candidates as
282+
// unknown. Treating them is inductive would cause be unsound as it causes
283+
// tests/ui/traits/next-solver/coherence/ambiguity-causes-visitor-hang.rs
284+
// to compile.
285+
GoalSource::CoherenceUnknowableSuper => PathKind::Unknown,
279286
GoalSource::Misc
280287
| GoalSource::AliasBoundConstCondition
281288
| GoalSource::AliasWellFormed
@@ -1131,14 +1138,11 @@ where
11311138
for_goal_source: GoalSource,
11321139
param_env: I::ParamEnv,
11331140
) -> Self {
1134-
let normalization_goal_source = match for_goal_source {
1135-
GoalSource::ImplWhereBound => GoalSource::NormalizeImplWhereBound,
1136-
_ => GoalSource::Misc,
1137-
};
1141+
let step_kind = ecx.step_kind_for_source(for_goal_source);
11381142
ReplaceAliasWithInfer {
11391143
ecx,
11401144
param_env,
1141-
normalization_goal_source,
1145+
normalization_goal_source: GoalSource::NormalizeGoal(step_kind),
11421146
cache: Default::default(),
11431147
}
11441148
}

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,13 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
438438

439439
let obligation;
440440
match (child_mode, nested_goal.source()) {
441+
// We shouldn't really care about coherence unknowable candidates
442+
// as we never report fulfillment errors involving them. However, this
443+
// is still reachable when building the fulfillment errors.
444+
(_, GoalSource::CoherenceUnknowableSuper) => continue,
441445
(
442446
ChildMode::Trait(_) | ChildMode::Host(_),
443-
GoalSource::Misc | GoalSource::NormalizeImplWhereBound,
447+
GoalSource::Misc | GoalSource::NormalizeGoal(_),
444448
) => {
445449
continue;
446450
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use std::marker::PhantomData;
2020

2121
use derive_where::derive_where;
2222
use rustc_index::{Idx, IndexVec};
23+
#[cfg(feature = "nightly")]
24+
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
2325
use tracing::debug;
2426

2527
use crate::data_structures::HashMap;
@@ -110,7 +112,8 @@ pub trait Delegate {
110112
/// In the initial iteration of a cycle, we do not yet have a provisional
111113
/// result. In the case we return an initial provisional result depending
112114
/// on the kind of cycle.
113-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
115+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
116+
#[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))]
114117
pub enum PathKind {
115118
/// A path consisting of only inductive/unproductive steps.
116119
Inductive,

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

+12-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use derive_where::derive_where;
88
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
99
use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic};
1010

11+
use crate::search_graph::PathKind;
1112
use crate::{self as ty, Canonical, CanonicalVarValues, Interner, Upcast};
1213

1314
pub type CanonicalInput<I, T = <I as Interner>::Predicate> =
@@ -68,11 +69,6 @@ pub enum GoalSource {
6869
/// FIXME(-Znext-solver=coinductive): Explain how and why this
6970
/// changes whether cycles are coinductive.
7071
ImplWhereBound,
71-
/// When eagerly replacing aliases with impl where-bounds, we also
72-
/// have to consider these normalization goals to be coinductive.
73-
///
74-
/// This is necessary for tests/ui/sized/coinductive-1.rs to compile.
75-
NormalizeImplWhereBound,
7672
/// Const conditions that need to hold for `~const` alias bounds to hold.
7773
///
7874
/// FIXME(-Znext-solver=coinductive): Are these even coinductive?
@@ -83,6 +79,17 @@ pub enum GoalSource {
8379
/// This is used in two places: projecting to an opaque whose hidden type
8480
/// is already registered in the opaque type storage, and for rigid projections.
8581
AliasWellFormed,
82+
/// Proving super trait bounds while checking whether a trait or projection
83+
/// goal is unknowable.
84+
///
85+
/// We must not treat these as an inductive steps, see `EvalCtxt::step_kind_for_source`.
86+
CoherenceUnknowableSuper,
87+
/// In case normalizing aliases in nested goals cycles, eagerly normalizing these aliases
88+
/// in the context of the parent may incorrectly change the cycle kind. Normalizing
89+
/// aliases in goals therefore tracks the original path kind for this nested goal.
90+
///
91+
/// This is necessary for tests/ui/sized/coinductive-1.rs to compile.
92+
NormalizeGoal(PathKind),
8693
}
8794

8895
#[derive_where(Clone; I: Interner, Goal<I, P>: Clone)]

0 commit comments

Comments
 (0)