2 use salsa
::{Database, SweepStrategy}
;
3 use std
::sync
::atomic
::{AtomicUsize, Ordering}
;
6 /// Query group for tests for how interned keys interact with GC.
7 #[salsa::query_group(Volatile)]
8 pub(crate) trait VolatileDatabase
: Database
{
10 fn atomic_cell(&self) -> Arc
<AtomicUsize
>;
12 /// Underlying volatile query.
13 fn volatile(&self) -> usize;
15 /// This just executes the intern query and returns the result.
16 fn repeat1(&self) -> usize;
18 /// Same as `repeat_intern1`. =)
19 fn repeat2(&self) -> usize;
22 fn volatile(db
: &impl VolatileDatabase
) -> usize {
23 db
.salsa_runtime().report_untracked_read();
24 db
.atomic_cell().load(Ordering
::SeqCst
)
27 fn repeat1(db
: &impl VolatileDatabase
) -> usize {
31 fn repeat2(db
: &impl VolatileDatabase
) -> usize {
36 fn consistency_no_gc() {
37 let mut db
= db
::DatabaseImpl
::default();
39 let cell
= Arc
::new(AtomicUsize
::new(22));
41 db
.set_atomic_cell(cell
.clone());
43 let v1
= db
.repeat1();
45 cell
.store(23, Ordering
::SeqCst
);
47 let v2
= db
.repeat2();
53 fn consistency_with_gc() {
54 let mut db
= db
::DatabaseImpl
::default();
56 let cell
= Arc
::new(AtomicUsize
::new(22));
58 db
.set_atomic_cell(cell
.clone());
60 let v1
= db
.repeat1();
62 cell
.store(23, Ordering
::SeqCst
);
63 db
.query(VolatileQuery
).sweep(
64 SweepStrategy
::default()
66 .sweep_all_revisions(),
69 let v2
= db
.repeat2();