diff --git a/src/derived.rs b/src/derived.rs index 4d632282..aa972c30 100644 --- a/src/derived.rs +++ b/src/derived.rs @@ -205,6 +205,10 @@ where slot.sweep(revision_now, strategy); } } + fn purge(&self) { + self.lru_list.purge(); + *self.slot_map.write() = Default::default(); + } } impl LruQueryStorageOps for DerivedStorage diff --git a/src/input.rs b/src/input.rs index d9473a93..c7c8ddb0 100644 --- a/src/input.rs +++ b/src/input.rs @@ -162,6 +162,9 @@ where Q: Query, { fn sweep(&self, _runtime: &Runtime, _strategy: SweepStrategy) {} + fn purge(&self) { + *self.slots.write() = Default::default(); + } } impl InputQueryStorageOps for InputStorage diff --git a/src/interned.rs b/src/interned.rs index c0464680..ab1c5f30 100644 --- a/src/interned.rs +++ b/src/interned.rs @@ -407,6 +407,9 @@ where } }); } + fn purge(&self) { + *self.tables.write() = Default::default(); + } } impl QueryStorageOps for LookupInternedStorage @@ -505,6 +508,7 @@ where >, { fn sweep(&self, _: &Runtime, _strategy: SweepStrategy) {} + fn purge(&self) {} } impl Slot { diff --git a/src/lib.rs b/src/lib.rs index b3fe8b8f..6c175fde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -203,6 +203,7 @@ impl Default for DiscardWhat { pub struct SweepStrategy { discard_if: DiscardIf, discard_what: DiscardWhat, + shrink_to_fit: bool, } impl SweepStrategy { @@ -491,7 +492,18 @@ where { self.storage.sweep(self.db.salsa_runtime(), strategy); } -} + /// Completely clears the storage for this query. + /// + /// This method breaks internal invariants of salsa, so any further queries + /// might return nonsense results. It is useful only in very specific + /// circumstances -- for example, when one wants to observe which values + /// dropped together with the table + pub fn purge(&self) + where + Q::Storage: plumbing::QueryStorageMassOps, + { + self.storage.purge(); + }} /// Return value from [the `query_mut` method] on `Database`. /// Gives access to the `set` method, notably, that is used to diff --git a/src/lru.rs b/src/lru.rs index 22a10e97..4814bc51 100644 --- a/src/lru.rs +++ b/src/lru.rs @@ -131,6 +131,11 @@ where self.data.lock().record_use(node) } + + pub fn purge(&self) { + self.green_zone.store(0, Ordering::SeqCst); + *self.data.lock() = LruData::with_seed(LRU_SEED); + } } impl LruData diff --git a/src/plumbing.rs b/src/plumbing.rs index 036274b4..50532b85 100644 --- a/src/plumbing.rs +++ b/src/plumbing.rs @@ -66,6 +66,7 @@ pub trait DatabaseOps { pub trait QueryStorageMassOps { /// Discards memoized values that are not up to date with the current revision. fn sweep(&self, runtime: &Runtime, strategy: SweepStrategy); + fn purge(&self); } pub trait DatabaseKey: Clone + Debug + Eq + Hash {}