Skip to content

Commit

Permalink
[pointer][invariant] Remove AliasingMapping
Browse files Browse the repository at this point in the history
We previously used these to model `UnsafeCell` agreement, but that only
works when we support an `Inaccessible` aliasing invariant, which we
don't anymore. Future commits will use a different mechanism to model
`UnsafeCell` agreement. There is no other circumstance under which a
pointer can change its aliasing model.

Makes progress on #1122, #1866

gherrit-pr-id: I1ac2ae177a235083e33b09fc848423220d3da042
  • Loading branch information
joshlf committed Oct 18, 2024
1 parent 4bd33fb commit ac629d9
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions src/pointer/invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ pub trait Aliasing: Sealed {
/// Aliasing>::Variance<'a, T>` to inherit this variance.
#[doc(hidden)]
type Variance<'a, T: 'a + ?Sized>;

#[doc(hidden)]
type MappedTo<M: AliasingMapping>: Aliasing;
}

/// The alignment invariant of a [`Ptr`][super::Ptr].
Expand Down Expand Up @@ -113,7 +110,6 @@ impl Aliasing for Inaccessible {
//
// [1] https://doc.rust-lang.org/1.81.0/reference/subtyping.html#variance
type Variance<'a, T: 'a + ?Sized> = &'a T;
type MappedTo<M: AliasingMapping> = M::FromInaccessible;
}

/// The `Ptr<'a, T>` adheres to the aliasing rules of a `&'a T`.
Expand All @@ -128,7 +124,6 @@ pub enum Shared {}
impl Aliasing for Shared {
const IS_EXCLUSIVE: bool = false;
type Variance<'a, T: 'a + ?Sized> = &'a T;
type MappedTo<M: AliasingMapping> = M::FromShared;
}
impl Reference for Shared {}

Expand All @@ -141,7 +136,6 @@ pub enum Exclusive {}
impl Aliasing for Exclusive {
const IS_EXCLUSIVE: bool = true;
type Variance<'a, T: 'a + ?Sized> = &'a mut T;
type MappedTo<M: AliasingMapping> = M::FromExclusive;
}
impl Reference for Exclusive {}

Expand Down Expand Up @@ -257,23 +251,6 @@ pub use mapping::*;
mod mapping {
use super::*;

/// A mapping from one [`Aliasing`] type to another.
///
/// An `AliasingMapping` is a type-level map which maps one `Aliasing` type
/// to another. It is always "total" in the sense of having a mapping for
/// any `A: Aliasing`.
///
/// Given `A: Aliasing` and `M: AliasingMapping`, `M` can be applied to `A`
/// as [`MappedAliasing<A, M>`](MappedAliasing).
///
/// Mappings are used by [`Ptr`](crate::Ptr) conversion methods to preserve
/// or modify invariants as required by each method's semantics.
pub trait AliasingMapping {
type FromInaccessible: Aliasing;
type FromShared: Aliasing;
type FromExclusive: Aliasing;
}

/// A mapping from one [`Alignment`] type to another.
///
/// An `AlignmentMapping` is a type-level map which maps one `Alignment`
Expand Down Expand Up @@ -308,10 +285,6 @@ mod mapping {
type FromValid: Validity;
}

/// The application of the [`AliasingMapping`] `M` to the [`Aliasing`] `A`.
#[allow(type_alias_bounds)]
pub type MappedAliasing<A: Aliasing, M: AliasingMapping> = A::MappedTo<M>;

/// The application of the [`AlignmentMapping`] `M` to the [`Alignment`] `A`.
#[allow(type_alias_bounds)]
pub type MappedAlignment<A: Alignment, M: AlignmentMapping> = A::MappedTo<M>;
Expand All @@ -320,14 +293,6 @@ mod mapping {
#[allow(type_alias_bounds)]
pub type MappedValidity<V: Validity, M: ValidityMapping> = V::MappedTo<M>;

impl<FromInaccessible: Aliasing, FromShared: Aliasing, FromExclusive: Aliasing> AliasingMapping
for ((Inaccessible, FromInaccessible), (Shared, FromShared), (Exclusive, FromExclusive))
{
type FromInaccessible = FromInaccessible;
type FromShared = FromShared;
type FromExclusive = FromExclusive;
}

impl<FromUnknown: Alignment, FromAligned: Alignment> AlignmentMapping
for ((Unknown, FromUnknown), (Shared, FromAligned))
{
Expand Down

0 comments on commit ac629d9

Please sign in to comment.