Skip to content

Commit fd5ba80

Browse files
committed
Do not alias fields of tracked_struct Values when updating
1 parent 393cf7c commit fd5ba80

File tree

5 files changed

+143
-149
lines changed

5 files changed

+143
-149
lines changed

src/input.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,12 @@ where
281281
C: Configuration,
282282
{
283283
#[inline(always)]
284-
unsafe fn memos(&self, _current_revision: Revision) -> &crate::table::memo::MemoTable {
285-
&self.memos
284+
unsafe fn memos(
285+
this: *const Self,
286+
_current_revision: Revision,
287+
) -> *const crate::table::memo::MemoTable {
288+
// SAFETY: Caller obligation demands this pointer to be valid.
289+
unsafe { &raw const (*this).memos }
286290
}
287291

288292
#[inline(always)]

src/interned.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,15 @@ where
451451
C: Configuration,
452452
{
453453
#[inline(always)]
454-
unsafe fn memos(&self, _current_revision: Revision) -> &MemoTable {
455-
&self.memos
454+
unsafe fn memos(
455+
this: *const Self,
456+
_current_revision: Revision,
457+
) -> *const crate::table::memo::MemoTable {
458+
unsafe { &raw const (*this).memos }
456459
}
457460

458461
#[inline(always)]
459-
fn memos_mut(&mut self) -> &mut MemoTable {
462+
fn memos_mut(&mut self) -> &mut crate::table::memo::MemoTable {
460463
&mut self.memos
461464
}
462465
}

src/table.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,26 @@ pub(crate) trait Slot: Any + Send + Sync {
3636
/// # Safety condition
3737
///
3838
/// The current revision MUST be the current revision of the database containing this slot.
39-
unsafe fn memos(&self, current_revision: Revision) -> &MemoTable;
39+
unsafe fn memos(slot: *const Self, current_revision: Revision) -> *const MemoTable;
4040

4141
/// Mutably access the [`MemoTable`] for this slot.
4242
fn memos_mut(&mut self) -> &mut MemoTable;
4343
}
4444

4545
/// [Slot::memos]
46-
type SlotMemosFnRaw = unsafe fn(*const (), current_revision: Revision) -> *const MemoTable;
46+
type SlotMemosFnErased = unsafe fn(*const (), current_revision: Revision) -> *const MemoTable;
4747
/// [Slot::memos]
48-
type SlotMemosFn<T> = unsafe fn(&T, current_revision: Revision) -> &MemoTable;
48+
type SlotMemosFn<T> = unsafe fn(*const T, current_revision: Revision) -> *const MemoTable;
4949
/// [Slot::memos_mut]
50-
type SlotMemosMutFnRaw = unsafe fn(*mut ()) -> *mut MemoTable;
50+
type SlotMemosMutFnErased = unsafe fn(*mut ()) -> *mut MemoTable;
5151
/// [Slot::memos_mut]
5252
type SlotMemosMutFn<T> = fn(&mut T) -> &mut MemoTable;
5353

5454
struct SlotVTable {
5555
layout: Layout,
5656
/// [`Slot`] methods
57-
memos: SlotMemosFnRaw,
58-
memos_mut: SlotMemosMutFnRaw,
57+
memos: SlotMemosFnErased,
58+
memos_mut: SlotMemosMutFnErased,
5959
/// A drop impl to call when the own page drops
6060
/// SAFETY: The caller is required to supply a correct data pointer to a `Box<PageDataEntry<T>>` and initialized length,
6161
/// and correct memo types.
@@ -78,10 +78,10 @@ impl SlotVTable {
7878
},
7979
layout: Layout::new::<T>(),
8080
// SAFETY: The signatures are compatible
81-
memos: unsafe { mem::transmute::<SlotMemosFn<T>, SlotMemosFnRaw>(T::memos) },
81+
memos: unsafe { mem::transmute::<SlotMemosFn<T>, SlotMemosFnErased>(T::memos) },
8282
// SAFETY: The signatures are compatible
8383
memos_mut: unsafe {
84-
mem::transmute::<SlotMemosMutFn<T>, SlotMemosMutFnRaw>(T::memos_mut)
84+
mem::transmute::<SlotMemosMutFn<T>, SlotMemosMutFnErased>(T::memos_mut)
8585
},
8686
}
8787
}

0 commit comments

Comments
 (0)