Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_type_ir::search_graph::{CandidateHeadUsages, LowerAvailableDepth, Path
use rustc_type_ir::solve::{
AccessedOpaques, ExternalRegionConstraints, FetchEligibleAssocItemResponse, MaybeInfo,
NoSolutionOrRerunNonErased, OpaqueTypesJank, QueryResultOrRerunNonErased, RerunCondition,
RerunNonErased, RerunReason, RerunResultExt, SmallCopyList,
RerunNonErased, RerunReason, RerunResultExt, SmallCopySet,
};
use rustc_type_ir::{
self as ty, CanonicalVarValues, ClauseKind, InferCtxtLike, Interner, MayBeErased,
Expand Down Expand Up @@ -1732,7 +1732,7 @@ fn should_rerun_after_erased_canonicalization<I: Interner>(
parent_opaque_types: &[(OpaqueTypeKey<I>, I::Ty)],
) -> RerunDecision {
let parent_opaque_def_ids = parent_opaque_types.iter().map(|(key, _)| key.def_id.into());
let opaque_in_storage = |opaques: I::LocalDefIds, def_ids: SmallCopyList<_>| {
let opaque_in_storage = |opaques: I::LocalDefIds, def_ids: SmallCopySet<_>| {
if def_ids.as_ref().is_empty() {
RerunDecision::No
} else if opaques
Expand Down
18 changes: 11 additions & 7 deletions compiler/rustc_type_ir/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,21 @@ impl From<RerunNonErased> for NoSolutionOrRerunNonErased {
}
}

/// A small set of up to 3 `Copy` elements, used as an optimization in [`RerunCondition`].
/// The entire set can be `Copy`ed because of this requirement.
///
/// Set properties maintained using [`union`](SmallCopySet::union), which deduplicates values.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[derive(TypeVisitable_Generic, TypeFoldable_Generic, GenericTypeVisitable)]
#[cfg_attr(feature = "nightly", derive(StableHash_NoContext))]
pub enum SmallCopyList<T: Copy + Debug + Hash + Eq> {
pub enum SmallCopySet<T: Copy + Debug + Hash + Eq> {
Empty,
One([T; 1]),
Two([T; 2]),
Three([T; 3]),
}

impl<T: Copy + Debug + Hash + Eq> SmallCopyList<T> {
impl<T: Copy + Debug + Hash + Eq> SmallCopySet<T> {
fn empty() -> Self {
Self::Empty
}
Expand Down Expand Up @@ -127,7 +131,7 @@ impl<T: Copy + Debug + Hash + Eq> SmallCopyList<T> {
}
}

impl<T: Copy + Debug + Hash + Eq> AsRef<[T]> for SmallCopyList<T> {
impl<T: Copy + Debug + Hash + Eq> AsRef<[T]> for SmallCopySet<T> {
fn as_ref(&self) -> &[T] {
match self {
Self::Empty => &[],
Expand Down Expand Up @@ -165,12 +169,12 @@ pub enum RerunCondition<I: Interner> {
/// Note that this only reruns according to the condition *if* we are in [`TypingMode::Typeck`].
AnyOpaqueHasInferAsHidden,
/// Note: unconditionally reruns in postanalysis
OpaqueInStorage(SmallCopyList<I::LocalDefId>),
OpaqueInStorage(SmallCopySet<I::LocalDefId>),

/// Merges [`Self::AnyOpaqueHasInferAsHidden`] and [`Self::OpaqueInStorage`].
/// Note that just like the unmerged [`Self::OpaqueInStorage`], that part of the
/// condition only matters in [`TypingMode::Typeck`]
OpaqueInStorageOrAnyOpaqueHasInferAsHidden(SmallCopyList<I::LocalDefId>),
OpaqueInStorageOrAnyOpaqueHasInferAsHidden(SmallCopySet<I::LocalDefId>),

Always,
}
Expand Down Expand Up @@ -327,7 +331,7 @@ impl<I: Interner> AccessedOpaques<I> {
debug!("set rerun if post analysis");
self.update(AccessedOpaques {
reason: Some(reason),
rerun: RerunCondition::OpaqueInStorage(SmallCopyList::empty()),
rerun: RerunCondition::OpaqueInStorage(SmallCopySet::empty()),
})
}

Expand All @@ -339,7 +343,7 @@ impl<I: Interner> AccessedOpaques<I> {
debug!("set rerun if opaque type {defid:?} in storage");
self.update(AccessedOpaques {
reason: Some(reason),
rerun: RerunCondition::OpaqueInStorage(SmallCopyList::new(defid.into())),
rerun: RerunCondition::OpaqueInStorage(SmallCopySet::new(defid.into())),
})
}

Expand Down
Loading