Skip to content

fix: Do not alias fields of tracked_struct Values when updating #741

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,12 @@ where
C: Configuration,
{
#[inline(always)]
unsafe fn memos(&self, _current_revision: Revision) -> &crate::table::memo::MemoTable {
&self.memos
unsafe fn memos(
this: *const Self,
_current_revision: Revision,
) -> *const crate::table::memo::MemoTable {
// SAFETY: Caller obligation demands this pointer to be valid.
unsafe { &raw const (*this).memos }
}

#[inline(always)]
Expand Down
9 changes: 6 additions & 3 deletions src/interned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,15 @@ where
C: Configuration,
{
#[inline(always)]
unsafe fn memos(&self, _current_revision: Revision) -> &MemoTable {
&self.memos
unsafe fn memos(
this: *const Self,
_current_revision: Revision,
) -> *const crate::table::memo::MemoTable {
unsafe { &raw const (*this).memos }
}

#[inline(always)]
fn memos_mut(&mut self) -> &mut MemoTable {
fn memos_mut(&mut self) -> &mut crate::table::memo::MemoTable {
&mut self.memos
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ pub(crate) trait Slot: Any + Send + Sync {
/// # Safety condition
///
/// The current revision MUST be the current revision of the database containing this slot.
unsafe fn memos(&self, current_revision: Revision) -> &MemoTable;
unsafe fn memos(slot: *const Self, current_revision: Revision) -> *const MemoTable;

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

/// [Slot::memos]
type SlotMemosFnRaw = unsafe fn(*const (), current_revision: Revision) -> *const MemoTable;
type SlotMemosFnErased = unsafe fn(*const (), current_revision: Revision) -> *const MemoTable;
/// [Slot::memos]
type SlotMemosFn<T> = unsafe fn(&T, current_revision: Revision) -> &MemoTable;
type SlotMemosFn<T> = unsafe fn(*const T, current_revision: Revision) -> *const MemoTable;
/// [Slot::memos_mut]
type SlotMemosMutFnRaw = unsafe fn(*mut ()) -> *mut MemoTable;
type SlotMemosMutFnErased = unsafe fn(*mut ()) -> *mut MemoTable;
/// [Slot::memos_mut]
type SlotMemosMutFn<T> = fn(&mut T) -> &mut MemoTable;

struct SlotVTable {
layout: Layout,
/// [`Slot`] methods
memos: SlotMemosFnRaw,
memos_mut: SlotMemosMutFnRaw,
memos: SlotMemosFnErased,
memos_mut: SlotMemosMutFnErased,
/// A drop impl to call when the own page drops
/// SAFETY: The caller is required to supply a correct data pointer to a `Box<PageDataEntry<T>>` and initialized length,
/// and correct memo types.
Expand All @@ -78,10 +78,10 @@ impl SlotVTable {
},
layout: Layout::new::<T>(),
// SAFETY: The signatures are compatible
memos: unsafe { mem::transmute::<SlotMemosFn<T>, SlotMemosFnRaw>(T::memos) },
memos: unsafe { mem::transmute::<SlotMemosFn<T>, SlotMemosFnErased>(T::memos) },
// SAFETY: The signatures are compatible
memos_mut: unsafe {
mem::transmute::<SlotMemosMutFn<T>, SlotMemosMutFnRaw>(T::memos_mut)
mem::transmute::<SlotMemosMutFn<T>, SlotMemosMutFnErased>(T::memos_mut)
},
}
}
Expand Down
Loading
Loading