Skip to content

Commit 03a15c4

Browse files
committed
[pointer][invariant] Remove AliasingMapping, Inaccessible
We previously used `AliasingMapping`s and `Inaccessible` to model `UnsafeCell` agreement. This abuses the notion of a mapping since one doesn't ever actually want to change the aliasing of a pointer (and certainly not to `Inaccessible`) - really this was meant to model pointer casts which should never be performed. In addition to being an awkward fit, the presence of `Inaccessible` meant that code could not assume that any `Aliasing` invariant permitted reading, and so we had to add extra machinery to work around this. Future commits will use a different, simpler model for denoting `UnsafeCell` agreement or disagreement. While we're here, make `Read` slightly more permissive, implemented for `A: Aliasing, T: Immutable` rather than just `A: Reference, T: Immutable`. Makes progress on #1122, #1866 gherrit-pr-id: I1ac2ae177a235083e33b09fc848423220d3da042
1 parent 77846a9 commit 03a15c4

File tree

1 file changed

+6
-52
lines changed

1 file changed

+6
-52
lines changed

src/pointer/invariant.rs

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ impl<A: Aliasing, AA: Alignment, V: Validity> Invariants for (A, AA, V) {
5555
}
5656

5757
/// The aliasing invariant of a [`Ptr`][super::Ptr].
58+
///
59+
/// All aliasing invariants must permit reading from the bytes of a pointer's
60+
/// referent which are not covered by [`UnsafeCell`]s.
61+
///
62+
/// [`UnsafeCell`]: core::cell::UnsafeCell
5863
pub trait Aliasing: Sealed {
5964
/// Is `Self` [`Exclusive`]?
6065
#[doc(hidden)]
@@ -65,9 +70,6 @@ pub trait Aliasing: Sealed {
6570
/// Aliasing>::Variance<'a, T>` to inherit this variance.
6671
#[doc(hidden)]
6772
type Variance<'a, T: 'a + ?Sized>;
68-
69-
#[doc(hidden)]
70-
type MappedTo<M: AliasingMapping>: Aliasing;
7173
}
7274

7375
/// The alignment invariant of a [`Ptr`][super::Ptr].
@@ -100,22 +102,6 @@ impl Validity for Unknown {
100102
type MappedTo<M: ValidityMapping> = M::FromUnknown;
101103
}
102104

103-
/// The `Ptr<'a, T>` does not permit any reads or writes from or to its referent.
104-
pub enum Inaccessible {}
105-
106-
impl Aliasing for Inaccessible {
107-
const IS_EXCLUSIVE: bool = false;
108-
109-
// SAFETY: Inaccessible `Ptr`s permit neither reads nor writes, and so it
110-
// doesn't matter how long the referent actually lives. Thus, covariance is
111-
// fine (and is chosen because it is maximally permissive). Shared
112-
// references are covariant [1].
113-
//
114-
// [1] https://doc.rust-lang.org/1.81.0/reference/subtyping.html#variance
115-
type Variance<'a, T: 'a + ?Sized> = &'a T;
116-
type MappedTo<M: AliasingMapping> = M::FromInaccessible;
117-
}
118-
119105
/// The `Ptr<'a, T>` adheres to the aliasing rules of a `&'a T`.
120106
///
121107
/// The referent of a shared-aliased `Ptr` may be concurrently referenced by any
@@ -128,7 +114,6 @@ pub enum Shared {}
128114
impl Aliasing for Shared {
129115
const IS_EXCLUSIVE: bool = false;
130116
type Variance<'a, T: 'a + ?Sized> = &'a T;
131-
type MappedTo<M: AliasingMapping> = M::FromShared;
132117
}
133118
impl Reference for Shared {}
134119

@@ -141,7 +126,6 @@ pub enum Exclusive {}
141126
impl Aliasing for Exclusive {
142127
const IS_EXCLUSIVE: bool = true;
143128
type Variance<'a, T: 'a + ?Sized> = &'a mut T;
144-
type MappedTo<M: AliasingMapping> = M::FromExclusive;
145129
}
146130
impl Reference for Exclusive {}
147131

@@ -230,7 +214,7 @@ define_because!(
230214
pub BecauseImmutable
231215
);
232216
// SAFETY: `T: Immutable`.
233-
unsafe impl<A: Reference, T: ?Sized + crate::Immutable> Read<A, BecauseImmutable> for T {}
217+
unsafe impl<A: Aliasing, T: ?Sized + crate::Immutable> Read<A, BecauseImmutable> for T {}
234218

235219
use sealed::Sealed;
236220
mod sealed {
@@ -240,7 +224,6 @@ mod sealed {
240224

241225
impl Sealed for Unknown {}
242226

243-
impl Sealed for Inaccessible {}
244227
impl Sealed for Shared {}
245228
impl Sealed for Exclusive {}
246229

@@ -257,23 +240,6 @@ pub use mapping::*;
257240
mod mapping {
258241
use super::*;
259242

260-
/// A mapping from one [`Aliasing`] type to another.
261-
///
262-
/// An `AliasingMapping` is a type-level map which maps one `Aliasing` type
263-
/// to another. It is always "total" in the sense of having a mapping for
264-
/// any `A: Aliasing`.
265-
///
266-
/// Given `A: Aliasing` and `M: AliasingMapping`, `M` can be applied to `A`
267-
/// as [`MappedAliasing<A, M>`](MappedAliasing).
268-
///
269-
/// Mappings are used by [`Ptr`](crate::Ptr) conversion methods to preserve
270-
/// or modify invariants as required by each method's semantics.
271-
pub trait AliasingMapping {
272-
type FromInaccessible: Aliasing;
273-
type FromShared: Aliasing;
274-
type FromExclusive: Aliasing;
275-
}
276-
277243
/// A mapping from one [`Alignment`] type to another.
278244
///
279245
/// An `AlignmentMapping` is a type-level map which maps one `Alignment`
@@ -308,10 +274,6 @@ mod mapping {
308274
type FromValid: Validity;
309275
}
310276

311-
/// The application of the [`AliasingMapping`] `M` to the [`Aliasing`] `A`.
312-
#[allow(type_alias_bounds)]
313-
pub type MappedAliasing<A: Aliasing, M: AliasingMapping> = A::MappedTo<M>;
314-
315277
/// The application of the [`AlignmentMapping`] `M` to the [`Alignment`] `A`.
316278
#[allow(type_alias_bounds)]
317279
pub type MappedAlignment<A: Alignment, M: AlignmentMapping> = A::MappedTo<M>;
@@ -320,14 +282,6 @@ mod mapping {
320282
#[allow(type_alias_bounds)]
321283
pub type MappedValidity<V: Validity, M: ValidityMapping> = V::MappedTo<M>;
322284

323-
impl<FromInaccessible: Aliasing, FromShared: Aliasing, FromExclusive: Aliasing> AliasingMapping
324-
for ((Inaccessible, FromInaccessible), (Shared, FromShared), (Exclusive, FromExclusive))
325-
{
326-
type FromInaccessible = FromInaccessible;
327-
type FromShared = FromShared;
328-
type FromExclusive = FromExclusive;
329-
}
330-
331285
impl<FromUnknown: Alignment, FromAligned: Alignment> AlignmentMapping
332286
for ((Unknown, FromUnknown), (Shared, FromAligned))
333287
{

0 commit comments

Comments
 (0)