Skip to content

Commit cb59028

Browse files
committed
w
1 parent 5cb6ad1 commit cb59028

File tree

3 files changed

+22
-17
lines changed
  • compiler
    • rustc_next_trait_solver/src/solve/eval_ctxt
    • rustc_type_ir/src

3 files changed

+22
-17
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,10 @@ where
264264

265265
pub(super) fn step_kind_for_source(&self, source: GoalSource) -> PathKind {
266266
match (self.current_goal_kind, source) {
267-
(
268-
CurrentGoalKind::CoinductiveTrait,
269-
GoalSource::ImplWhereBound | GoalSource::NormalizeImplWhereBound,
270-
) => PathKind::Coinductive,
267+
(_, GoalSource::NormalizeGoal(step_kind)) => step_kind,
268+
(CurrentGoalKind::CoinductiveTrait, GoalSource::ImplWhereBound) => {
269+
PathKind::Coinductive
270+
}
271271
_ => PathKind::Inductive,
272272
}
273273
}
@@ -1120,14 +1120,11 @@ where
11201120
for_goal_source: GoalSource,
11211121
param_env: I::ParamEnv,
11221122
) -> Self {
1123-
let normalization_goal_source = match for_goal_source {
1124-
GoalSource::ImplWhereBound => GoalSource::NormalizeImplWhereBound,
1125-
_ => GoalSource::Misc,
1126-
};
1123+
let step_kind = ecx.step_kind_for_source(for_goal_source);
11271124
ReplaceAliasWithInfer {
11281125
ecx,
11291126
param_env,
1130-
normalization_goal_source,
1127+
normalization_goal_source: GoalSource::NormalizeGoal(step_kind),
11311128
cache: Default::default(),
11321129
}
11331130
}

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use std::marker::PhantomData;
1919

2020
use derive_where::derive_where;
2121
use rustc_index::{Idx, IndexVec};
22+
#[cfg(feature = "nightly")]
23+
use rustc_macros::HashStable_NoContext;
2224
use tracing::debug;
2325

2426
use crate::data_structures::HashMap;
@@ -109,7 +111,8 @@ pub trait Delegate {
109111
/// In the initial iteration of a cycle, we do not yet have a provisional
110112
/// result. In the case we return an initial provisional result depending
111113
/// on the kind of cycle.
112-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
114+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
115+
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
113116
pub enum PathKind {
114117
Coinductive,
115118
Inductive,
@@ -716,7 +719,9 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
716719
path_from_head,
717720
result,
718721
} = entry;
719-
if heads.highest_cycle_head() != head {
722+
if heads.highest_cycle_head() == head {
723+
heads.remove_highest_cycle_head()
724+
} else {
720725
return true;
721726
}
722727

@@ -737,7 +742,6 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
737742
// Merge the cycle heads of the provisional cache entry and the
738743
// popped head. If the popped cycle head was a root, discard all
739744
// provisional cache entries which depend on it.
740-
heads.remove_highest_cycle_head();
741745
heads.merge(&stack_entry.heads);
742746
let Some(head) = heads.opt_highest_cycle_head() else {
743747
return false;

compiler/rustc_type_ir/src/solve/mod.rs

Lines changed: 9 additions & 5 deletions
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,14 @@ 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+
83+
/// In case normalizing aliases in nested goals cycles, eagerly normalizing these
84+
/// aliases in the context of the parent may incorrectly change the cycle kind.
85+
/// Normalizing aliases in goals therefore tracks the original path kind for this
86+
/// nested goal.
87+
///
88+
/// This is necessary for tests/ui/sized/coinductive-1.rs to compile.
89+
NormalizeGoal(PathKind),
8690
}
8791

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

0 commit comments

Comments
 (0)