Skip to content

Commit

Permalink
w
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Feb 21, 2025
1 parent 5cb6ad1 commit cb59028
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
15 changes: 6 additions & 9 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ where

pub(super) fn step_kind_for_source(&self, source: GoalSource) -> PathKind {
match (self.current_goal_kind, source) {
(
CurrentGoalKind::CoinductiveTrait,
GoalSource::ImplWhereBound | GoalSource::NormalizeImplWhereBound,
) => PathKind::Coinductive,
(_, GoalSource::NormalizeGoal(step_kind)) => step_kind,
(CurrentGoalKind::CoinductiveTrait, GoalSource::ImplWhereBound) => {
PathKind::Coinductive
}
_ => PathKind::Inductive,
}
}
Expand Down Expand Up @@ -1120,14 +1120,11 @@ where
for_goal_source: GoalSource,
param_env: I::ParamEnv,
) -> Self {
let normalization_goal_source = match for_goal_source {
GoalSource::ImplWhereBound => GoalSource::NormalizeImplWhereBound,
_ => GoalSource::Misc,
};
let step_kind = ecx.step_kind_for_source(for_goal_source);
ReplaceAliasWithInfer {
ecx,
param_env,
normalization_goal_source,
normalization_goal_source: GoalSource::NormalizeGoal(step_kind),
cache: Default::default(),
}
}
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_type_ir/src/search_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use std::marker::PhantomData;

use derive_where::derive_where;
use rustc_index::{Idx, IndexVec};
#[cfg(feature = "nightly")]
use rustc_macros::HashStable_NoContext;
use tracing::debug;

use crate::data_structures::HashMap;
Expand Down Expand Up @@ -109,7 +111,8 @@ pub trait Delegate {
/// In the initial iteration of a cycle, we do not yet have a provisional
/// result. In the case we return an initial provisional result depending
/// on the kind of cycle.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))]
pub enum PathKind {
Coinductive,
Inductive,
Expand Down Expand Up @@ -716,7 +719,9 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
path_from_head,
result,
} = entry;
if heads.highest_cycle_head() != head {
if heads.highest_cycle_head() == head {
heads.remove_highest_cycle_head()
} else {
return true;
}

Expand All @@ -737,7 +742,6 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
// Merge the cycle heads of the provisional cache entry and the
// popped head. If the popped cycle head was a root, discard all
// provisional cache entries which depend on it.
heads.remove_highest_cycle_head();
heads.merge(&stack_entry.heads);
let Some(head) = heads.opt_highest_cycle_head() else {
return false;
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_type_ir/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use derive_where::derive_where;
use rustc_macros::{HashStable_NoContext, TyDecodable, TyEncodable};
use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic};

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

pub type CanonicalInput<I, T = <I as Interner>::Predicate> =
Expand Down Expand Up @@ -68,11 +69,6 @@ pub enum GoalSource {
/// FIXME(-Znext-solver=coinductive): Explain how and why this
/// changes whether cycles are coinductive.
ImplWhereBound,
/// When eagerly replacing aliases with impl where-bounds, we also
/// have to consider these normalization goals to be coinductive.
///
/// This is necessary for tests/ui/sized/coinductive-1.rs to compile.
NormalizeImplWhereBound,
/// Const conditions that need to hold for `~const` alias bounds to hold.
///
/// FIXME(-Znext-solver=coinductive): Are these even coinductive?
Expand All @@ -83,6 +79,14 @@ pub enum GoalSource {
/// This is used in two places: projecting to an opaque whose hidden type
/// is already registered in the opaque type storage, and for rigid projections.
AliasWellFormed,

/// In case normalizing aliases in nested goals cycles, eagerly normalizing these
/// aliases in the context of the parent may incorrectly change the cycle kind.
/// Normalizing aliases in goals therefore tracks the original path kind for this
/// nested goal.
///
/// This is necessary for tests/ui/sized/coinductive-1.rs to compile.
NormalizeGoal(PathKind),
}

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

0 comments on commit cb59028

Please # to comment.