Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ use rustc_data_structures::sync::Lock;

use crate::dep_graph::{DepContext, DepNodeIndex};

pub struct Cache<Key, Value> {
pub struct WithDepNodeCache<Key, Value> {
hashmap: Lock<FxHashMap<Key, WithDepNode<Value>>>,
}

impl<Key: Clone, Value: Clone> Clone for Cache<Key, Value> {
impl<Key: Clone, Value: Clone> Clone for WithDepNodeCache<Key, Value> {
fn clone(&self) -> Self {
Self { hashmap: Lock::new(self.hashmap.borrow().clone()) }
}
}

impl<Key, Value> Default for Cache<Key, Value> {
impl<Key, Value> Default for WithDepNodeCache<Key, Value> {
fn default() -> Self {
Self { hashmap: Default::default() }
}
}

impl<Key: Eq + Hash, Value: Clone> Cache<Key, Value> {
impl<Key: Eq + Hash, Value: Clone> WithDepNodeCache<Key, Value> {
pub fn get<Tcx: DepContext>(&self, key: &Key, tcx: Tcx) -> Option<Value> {
Some(self.hashmap.borrow().get(key)?.get(tcx))
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/resolution.html

pub mod cache;
pub mod query;
pub mod select;
pub mod solve;
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_middle/src/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def_id::DefId;
use rustc_macros::{HashStable, TypeVisitable};
use rustc_query_system::cache::Cache;
use rustc_type_ir::solve::AliasBoundKind;

use self::EvaluationResult::*;
use super::{SelectionError, SelectionResult};
use crate::traits::cache::WithDepNodeCache;
use crate::ty;

pub type SelectionCache<'tcx, ENV> =
Cache<(ENV, ty::TraitPredicate<'tcx>), SelectionResult<'tcx, SelectionCandidate<'tcx>>>;
pub type SelectionCache<'tcx, ENV> = WithDepNodeCache<
(ENV, ty::TraitPredicate<'tcx>),
SelectionResult<'tcx, SelectionCandidate<'tcx>>,
>;

pub type EvaluationCache<'tcx, ENV> = Cache<(ENV, ty::PolyTraitPredicate<'tcx>), EvaluationResult>;
pub type EvaluationCache<'tcx, ENV> =
WithDepNodeCache<(ENV, ty::PolyTraitPredicate<'tcx>), EvaluationResult>;

/// The selection process begins by considering all impls, where
/// clauses, and so forth that might resolve an obligation. Sometimes
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use rustc_hir::lang_items::LangItem;
use rustc_hir::limit::Limit;
use rustc_hir::{self as hir, HirId, Node, TraitCandidate, find_attr};
use rustc_index::IndexVec;
use rustc_query_system::cache::WithDepNode;
use rustc_query_system::dep_graph::DepNodeIndex;
use rustc_query_system::ich::StableHashingContext;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
Expand Down Expand Up @@ -71,6 +70,7 @@ use crate::query::plumbing::QuerySystem;
use crate::query::{IntoQueryParam, LocalCrate, Providers, TyCtxtAt};
use crate::thir::Thir;
use crate::traits;
use crate::traits::cache::WithDepNode;
use crate::traits::solve::{
self, CanonicalInput, ExternalConstraints, ExternalConstraintsData, PredefinedOpaques,
QueryResult, inspect,
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_query_system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![feature(min_specialization)]
// tidy-alphabetical-end

pub mod cache;
pub mod dep_graph;
mod error;
pub mod ich;
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3270,7 +3270,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
// Acquire is necessary for the success case to synchronise with `Arc::new_cyclic`, when the inner
// value can be initialized after `Weak` references have already been created. In that case, we
// expect to observe the fully initialized value.
if self.inner()?.strong.fetch_update(Acquire, Relaxed, checked_increment).is_ok() {
if self.inner()?.strong.try_update(Acquire, Relaxed, checked_increment).is_ok() {
// SAFETY: pointer is not null, verified in checked_increment
unsafe { Some(Arc::from_inner_in(self.ptr, self.alloc.clone())) }
} else {
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/alloc/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use crate::{cmp, ptr};
/// let mut allocated = 0;
/// if self
/// .remaining
/// .fetch_update(Relaxed, Relaxed, |mut remaining| {
/// .try_update(Relaxed, Relaxed, |mut remaining| {
/// if size > remaining {
/// return None;
/// }
Expand Down
5 changes: 2 additions & 3 deletions library/core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,6 @@ pub const fn unlikely(b: bool) -> bool {
/// # Examples
///
/// ```
/// #![feature(cold_path)]
/// use core::hint::cold_path;
///
/// fn foo(x: &[i32]) {
Expand All @@ -750,7 +749,6 @@ pub const fn unlikely(b: bool) -> bool {
/// than the branch:
///
/// ```
/// #![feature(cold_path)]
/// use core::hint::cold_path;
///
/// #[inline(always)]
Expand All @@ -777,7 +775,8 @@ pub const fn unlikely(b: bool) -> bool {
/// }
/// }
/// ```
#[unstable(feature = "cold_path", issue = "136873")]
#[stable(feature = "cold_path", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "cold_path", since = "CURRENT_RUSTC_VERSION")]
#[inline(always)]
pub const fn cold_path() {
crate::intrinsics::cold_path()
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ unsafe impl<T> SliceIndex<[T]> for Clamp<ops::RangeFrom<usize>> {
}

#[unstable(feature = "sliceindex_wrappers", issue = "146179")]
unsafe impl<T> SliceIndex<[T]> for Clamp<range::RangeTo<usize>> {
unsafe impl<T> SliceIndex<[T]> for Clamp<ops::RangeTo<usize>> {
type Output = [T];

fn get(self, slice: &[T]) -> Option<&Self::Output> {
Expand Down Expand Up @@ -408,7 +408,7 @@ unsafe impl<T> SliceIndex<[T]> for Clamp<ops::RangeToInclusive<usize>> {
}

#[unstable(feature = "sliceindex_wrappers", issue = "146179")]
unsafe impl<T> SliceIndex<[T]> for Clamp<range::RangeFull> {
unsafe impl<T> SliceIndex<[T]> for Clamp<ops::RangeFull> {
type Output = [T];

fn get(self, slice: &[T]) -> Option<&Self::Output> {
Expand Down
3 changes: 1 addition & 2 deletions library/core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ pub const unsafe fn assume(b: bool) {
/// Therefore, implementations must not require the user to uphold
/// any safety invariants.
///
/// This intrinsic does not have a stable counterpart.
#[unstable(feature = "core_intrinsics", issue = "none")]
/// The stabilized version of this intrinsic is [`core::hint::cold_path`].
#[rustc_intrinsic]
#[rustc_nounwind]
#[miri::intrinsic_fallback_is_spec]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub mod pat;
pub mod pin;
#[unstable(feature = "random", issue = "130703")]
pub mod random;
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
pub mod range;
pub mod result;
pub mod sync;
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/random.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Random value generation.

use crate::range::RangeFull;
use crate::ops::RangeFull;

/// A source of randomness.
#[unstable(feature = "random", issue = "130703")]
Expand Down
58 changes: 33 additions & 25 deletions library/core/src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,26 @@ mod iter;
#[unstable(feature = "new_range_api", issue = "125687")]
pub mod legacy;

use Bound::{Excluded, Included, Unbounded};
#[doc(inline)]
pub use iter::{RangeFromIter, RangeInclusiveIter, RangeIter};

#[doc(inline)]
pub use crate::iter::Step;
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
pub use iter::RangeInclusiveIter;
#[doc(inline)]
pub use crate::ops::{Bound, IntoBounds, OneSidedRange, RangeBounds, RangeFull, RangeTo};
#[unstable(feature = "new_range_api", issue = "125687")]
pub use iter::{RangeFromIter, RangeIter};

// FIXME(#125687): re-exports temporarily removed
// Because re-exports of stable items (Bound, RangeBounds, RangeFull, RangeTo)
// can't be made unstable.
//
// #[doc(inline)]
// #[unstable(feature = "new_range_api", issue = "125687")]
// pub use crate::iter::Step;
// #[doc(inline)]
// #[unstable(feature = "new_range_api", issue = "125687")]
// pub use crate::ops::{Bound, IntoBounds, OneSidedRange, RangeBounds, RangeFull, RangeTo};
use crate::iter::Step;
use crate::ops::Bound::{self, Excluded, Included, Unbounded};
use crate::ops::{IntoBounds, RangeBounds};

/// A (half-open) range bounded inclusively below and exclusively above
/// (`start..end` in a future edition).
Expand Down Expand Up @@ -226,25 +238,24 @@ impl<T> const From<legacy::Range<T>> for Range<T> {
/// The `start..=last` syntax is a `RangeInclusive`:
///
/// ```
/// #![feature(new_range_api)]
/// use core::range::RangeInclusive;
///
/// assert_eq!(RangeInclusive::from(3..=5), RangeInclusive { start: 3, last: 5 });
/// assert_eq!(3 + 4 + 5, RangeInclusive::from(3..=5).into_iter().sum());
/// ```
#[lang = "RangeInclusiveCopy"]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
pub struct RangeInclusive<Idx> {
/// The lower bound of the range (inclusive).
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
pub start: Idx,
/// The upper bound of the range (inclusive).
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
pub last: Idx,
}

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
impl<Idx: fmt::Debug> fmt::Debug for RangeInclusive<Idx> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
self.start.fmt(fmt)?;
Expand All @@ -260,7 +271,6 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
/// # Examples
///
/// ```
/// #![feature(new_range_api)]
/// use core::range::RangeInclusive;
///
/// assert!(!RangeInclusive::from(3..=5).contains(&2));
Expand All @@ -278,7 +288,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
/// assert!(!RangeInclusive::from(f32::NAN..=1.0).contains(&1.0));
/// ```
#[inline]
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
pub const fn contains<U>(&self, item: &U) -> bool
where
Expand All @@ -293,7 +303,6 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
/// # Examples
///
/// ```
/// #![feature(new_range_api)]
/// use core::range::RangeInclusive;
///
/// assert!(!RangeInclusive::from(3..=5).is_empty());
Expand All @@ -304,14 +313,13 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
/// The range is empty if either side is incomparable:
///
/// ```
/// #![feature(new_range_api)]
/// use core::range::RangeInclusive;
///
/// assert!(!RangeInclusive::from(3.0..=5.0).is_empty());
/// assert!( RangeInclusive::from(3.0..=f32::NAN).is_empty());
/// assert!( RangeInclusive::from(f32::NAN..=5.0).is_empty());
/// ```
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[inline]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
pub const fn is_empty(&self) -> bool
Expand All @@ -330,15 +338,14 @@ impl<Idx: Step> RangeInclusive<Idx> {
/// # Examples
///
/// ```
/// #![feature(new_range_api)]
/// use core::range::RangeInclusive;
///
/// let mut i = RangeInclusive::from(3..=8).iter().map(|n| n*n);
/// assert_eq!(i.next(), Some(9));
/// assert_eq!(i.next(), Some(16));
/// assert_eq!(i.next(), Some(25));
/// ```
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub fn iter(&self) -> RangeInclusiveIter<Idx> {
self.clone().into_iter()
Expand All @@ -354,7 +361,7 @@ impl RangeInclusive<usize> {
}
}

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
impl<T> const RangeBounds<T> for RangeInclusive<T> {
fn start_bound(&self) -> Bound<&T> {
Expand All @@ -371,7 +378,7 @@ impl<T> const RangeBounds<T> for RangeInclusive<T> {
/// If you need to use this implementation where `T` is unsized,
/// consider using the `RangeBounds` impl for a 2-tuple of [`Bound<&T>`][Bound],
/// i.e. replace `start..=end` with `(Bound::Included(start), Bound::Included(end))`.
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
impl<T> const RangeBounds<T> for RangeInclusive<&T> {
fn start_bound(&self) -> Bound<&T> {
Expand All @@ -382,24 +389,24 @@ impl<T> const RangeBounds<T> for RangeInclusive<&T> {
}
}

// #[unstable(feature = "range_into_bounds", issue = "136903")]
#[unstable(feature = "new_range_api", issue = "125687")]
// #[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[unstable(feature = "range_into_bounds", issue = "136903")]
#[rustc_const_unstable(feature = "const_range", issue = "none")]
impl<T> const IntoBounds<T> for RangeInclusive<T> {
fn into_bounds(self) -> (Bound<T>, Bound<T>) {
(Included(self.start), Included(self.last))
}
}

#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl<T> const From<RangeInclusive<T>> for legacy::RangeInclusive<T> {
#[inline]
fn from(value: RangeInclusive<T>) -> Self {
Self::new(value.start, value.last)
}
}
#[unstable(feature = "new_range_api", issue = "125687")]
#[stable(feature = "new_range_inclusive_api", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl<T> const From<legacy::RangeInclusive<T>> for RangeInclusive<T> {
#[inline]
Expand Down Expand Up @@ -650,12 +657,13 @@ impl<Idx: PartialOrd<Idx>> RangeToInclusive<Idx> {
}
}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<T> From<legacy::RangeToInclusive<T>> for RangeToInclusive<T> {
fn from(value: legacy::RangeToInclusive<T>) -> Self {
Self { last: value.end }
}
}

#[unstable(feature = "new_range_api", issue = "125687")]
impl<T> From<RangeToInclusive<T>> for legacy::RangeToInclusive<T> {
fn from(value: RangeToInclusive<T>) -> Self {
Self { end: value.last }
Expand Down
Loading
Loading