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

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

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
9 changes: 4 additions & 5 deletions src/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ impl Attached {
// Already attached? Assert that the database has not changed.
// NOTE: It's important to use `addr_eq` here because `NonNull::eq`
// not only compares the address but also the type's metadata.
if !std::ptr::addr_eq(current_db.as_ptr(), new_db.as_ptr()) {
panic!(
"Cannot change database mid-query. current: {current_db:?}, new: {new_db:?}",
);
}
assert!(
std::ptr::addr_eq(current_db.as_ptr(), new_db.as_ptr()),
"Cannot change database mid-query. current: {current_db:?}, new: {new_db:?}"
);

Self { state: None }
} else {
Expand Down
11 changes: 7 additions & 4 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,18 @@ impl<C> Slot for Value<C>
where
C: Configuration,
{
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 {
unsafe { &raw const (*this).memos }
}

fn memos_mut(&mut self) -> &mut crate::table::memo::MemoTable {
&mut self.memos
}

unsafe fn syncs(&self, _current_revision: Revision) -> &SyncTable {
&self.syncs
unsafe fn syncs(this: *const Self, _current_revision: Revision) -> *const SyncTable {
unsafe { &raw const (*this).syncs }
}
}
13 changes: 8 additions & 5 deletions src/interned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,19 @@ impl<C> Slot for Value<C>
where
C: Configuration,
{
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 }
}

fn memos_mut(&mut self) -> &mut MemoTable {
fn memos_mut(&mut self) -> &mut crate::table::memo::MemoTable {
&mut self.memos
}

unsafe fn syncs(&self, _current_revision: Revision) -> &crate::table::sync::SyncTable {
&self.syncs
unsafe fn syncs(this: *const Self, _current_revision: Revision) -> *const SyncTable {
unsafe { &raw const (*this).syncs }
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ 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;
Expand All @@ -89,7 +89,7 @@ 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 syncs(&self, current_revision: Revision) -> &SyncTable;
unsafe fn syncs(slot: *const Self, current_revision: Revision) -> *const SyncTable;
}

unsafe impl<T: Slot> Send for Page<T> {}
Expand Down Expand Up @@ -333,15 +333,15 @@ impl<T: Slot> TablePage for Page<T> {
}

unsafe fn memos(&self, slot: SlotIndex, current_revision: Revision) -> &MemoTable {
unsafe { self.get(slot).memos(current_revision) }
unsafe { &*T::memos(self.get_raw(slot), current_revision) }
}

fn memos_mut(&mut self, slot: SlotIndex) -> &mut MemoTable {
self.get_mut(slot).memos_mut()
}

unsafe fn syncs(&self, slot: SlotIndex, current_revision: Revision) -> &SyncTable {
unsafe { self.get(slot).syncs(current_revision) }
unsafe { &*T::syncs(self.get_raw(slot), current_revision) }
}
}

Expand Down
Loading
Loading