Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pointer][invariant] Remove AliasingMapping, Inaccessible #1942

Open
wants to merge 1 commit into
base: Ifc49755af0d90eeefe7822d755d508403c266bda
Choose a base branch
from
Open
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
56 changes: 4 additions & 52 deletions src/pointer/invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ impl<A: Aliasing, AA: Alignment, V: Validity> Invariants for (A, AA, V) {
}

/// The aliasing invariant of a [`Ptr`][super::Ptr].
///
/// All aliasing invariants must permit reading from the bytes of a pointer's
/// referent which are not covered by [`UnsafeCell`]s.
pub trait Aliasing: Sealed {
/// Is `Self` [`Exclusive`]?
#[doc(hidden)]
Expand All @@ -65,9 +68,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 @@ -100,22 +100,6 @@ impl Validity for Unknown {
type MappedTo<M: ValidityMapping> = M::FromUnknown;
}

/// The `Ptr<'a, T>` does not permit any reads or writes from or to its referent.
pub enum Inaccessible {}

impl Aliasing for Inaccessible {
const IS_EXCLUSIVE: bool = false;

// SAFETY: Inaccessible `Ptr`s permit neither reads nor writes, and so it
// doesn't matter how long the referent actually lives. Thus, covariance is
// fine (and is chosen because it is maximally permissive). Shared
// references are covariant [1].
//
// [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`.
///
/// The referent of a shared-aliased `Ptr` may be concurrently referenced by any
Expand All @@ -128,7 +112,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 +124,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 @@ -230,7 +212,7 @@ define_because!(
pub BecauseImmutable
);
// SAFETY: `T: Immutable`.
unsafe impl<A: Reference, T: ?Sized + crate::Immutable> Read<A, BecauseImmutable> for T {}
unsafe impl<A: Aliasing, T: ?Sized + crate::Immutable> Read<A, BecauseImmutable> for T {}

use sealed::Sealed;
mod sealed {
Expand All @@ -240,7 +222,6 @@ mod sealed {

impl Sealed for Unknown {}

impl Sealed for Inaccessible {}
impl Sealed for Shared {}
impl Sealed for Exclusive {}

Expand All @@ -257,23 +238,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 +272,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 +280,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
Loading