Skip to content

Commit b0680ac

Browse files
committed
Do not alias fields of tracked_struct Values when updating
1 parent 9d2a978 commit b0680ac

File tree

6 files changed

+187
-171
lines changed

6 files changed

+187
-171
lines changed

src/attach.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ impl Attached {
4141
// Already attached? Assert that the database has not changed.
4242
// NOTE: It's important to use `addr_eq` here because `NonNull::eq`
4343
// not only compares the address but also the type's metadata.
44-
if !std::ptr::addr_eq(current_db.as_ptr(), new_db.as_ptr()) {
45-
panic!(
46-
"Cannot change database mid-query. current: {current_db:?}, new: {new_db:?}",
47-
);
48-
}
44+
assert!(
45+
std::ptr::addr_eq(current_db.as_ptr(), new_db.as_ptr()),
46+
"Cannot change database mid-query. current: {current_db:?}, new: {new_db:?}"
47+
);
4948

5049
Self { state: None }
5150
} else {

src/input.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,18 @@ impl<C> Slot for Value<C>
318318
where
319319
C: Configuration,
320320
{
321-
unsafe fn memos(&self, _current_revision: Revision) -> &crate::table::memo::MemoTable {
322-
&self.memos
321+
unsafe fn memos(
322+
this: *const Self,
323+
_current_revision: Revision,
324+
) -> *const crate::table::memo::MemoTable {
325+
unsafe { &raw const (*this).memos }
323326
}
324327

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

329-
unsafe fn syncs(&self, _current_revision: Revision) -> &SyncTable {
330-
&self.syncs
332+
unsafe fn syncs(this: *const Self, _current_revision: Revision) -> *const SyncTable {
333+
unsafe { &raw const (*this).syncs }
331334
}
332335
}

src/interned.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,19 @@ impl<C> Slot for Value<C>
354354
where
355355
C: Configuration,
356356
{
357-
unsafe fn memos(&self, _current_revision: Revision) -> &MemoTable {
358-
&self.memos
357+
unsafe fn memos(
358+
this: *const Self,
359+
_current_revision: Revision,
360+
) -> *const crate::table::memo::MemoTable {
361+
unsafe { &raw const (*this).memos }
359362
}
360363

361-
fn memos_mut(&mut self) -> &mut MemoTable {
364+
fn memos_mut(&mut self) -> &mut crate::table::memo::MemoTable {
362365
&mut self.memos
363366
}
364367

365-
unsafe fn syncs(&self, _current_revision: Revision) -> &crate::table::sync::SyncTable {
366-
&self.syncs
368+
unsafe fn syncs(this: *const Self, _current_revision: Revision) -> *const SyncTable {
369+
unsafe { &raw const (*this).syncs }
367370
}
368371
}
369372

src/table.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub(crate) trait Slot: Any + Send + Sync {
7979
/// # Safety condition
8080
///
8181
/// The current revision MUST be the current revision of the database containing this slot.
82-
unsafe fn memos(&self, current_revision: Revision) -> &MemoTable;
82+
unsafe fn memos(slot: *const Self, current_revision: Revision) -> *const MemoTable;
8383

8484
/// Mutably access the [`MemoTable`] for this slot.
8585
fn memos_mut(&mut self) -> &mut MemoTable;
@@ -89,7 +89,7 @@ pub(crate) trait Slot: Any + Send + Sync {
8989
/// # Safety condition
9090
///
9191
/// The current revision MUST be the current revision of the database containing this slot.
92-
unsafe fn syncs(&self, current_revision: Revision) -> &SyncTable;
92+
unsafe fn syncs(slot: *const Self, current_revision: Revision) -> *const SyncTable;
9393
}
9494

9595
unsafe impl<T: Slot> Send for Page<T> {}
@@ -333,15 +333,15 @@ impl<T: Slot> TablePage for Page<T> {
333333
}
334334

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

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

343343
unsafe fn syncs(&self, slot: SlotIndex, current_revision: Revision) -> &SyncTable {
344-
unsafe { self.get(slot).syncs(current_revision) }
344+
unsafe { &*T::syncs(self.get_raw(slot), current_revision) }
345345
}
346346
}
347347

0 commit comments

Comments
 (0)