mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-15 01:39:25 +00:00
track outputs for the active record
This commit is contained in:
parent
b65207ccbc
commit
97e280ddd2
2 changed files with 20 additions and 9 deletions
|
@ -1,3 +1,5 @@
|
|||
use std::collections::BTreeSet;
|
||||
|
||||
use crate::{
|
||||
durability::Durability,
|
||||
hash::{FxHashSet, FxIndexMap, FxIndexSet},
|
||||
|
@ -34,8 +36,15 @@ pub(super) struct ActiveQuery {
|
|||
/// Otherwise it is 1 more than the current value (which is incremented).
|
||||
pub(super) disambiguator_map: FxIndexMap<u64, Disambiguator>,
|
||||
|
||||
/// Tracks entities created by this query.
|
||||
pub(super) entities_created: FxHashSet<DatabaseKeyIndex>,
|
||||
/// Tracks values written by this query. Could be...
|
||||
///
|
||||
/// * tracked structs created
|
||||
/// * invocations of `specify`
|
||||
/// * accumulators pushed to
|
||||
///
|
||||
/// We use a btree-set because we want to be able to
|
||||
/// extract the keys in sorted order.
|
||||
pub(super) outputs: BTreeSet<DatabaseKeyIndex>,
|
||||
}
|
||||
|
||||
impl ActiveQuery {
|
||||
|
@ -48,7 +57,7 @@ impl ActiveQuery {
|
|||
untracked_read: false,
|
||||
cycle: None,
|
||||
disambiguator_map: Default::default(),
|
||||
entities_created: Default::default(),
|
||||
outputs: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,13 +84,15 @@ impl ActiveQuery {
|
|||
self.changed_at = self.changed_at.max(revision);
|
||||
}
|
||||
|
||||
pub(super) fn add_entity_created(&mut self, entity: DatabaseKeyIndex) {
|
||||
let is_new = self.entities_created.insert(entity);
|
||||
/// Adds a key to our list of outputs.
|
||||
pub(super) fn add_output(&mut self, key: DatabaseKeyIndex) {
|
||||
let is_new = self.outputs.insert(key);
|
||||
assert!(is_new);
|
||||
}
|
||||
|
||||
pub(super) fn was_entity_created(&self, entity: DatabaseKeyIndex) -> bool {
|
||||
self.entities_created.contains(&entity)
|
||||
/// True if the given key was output by this query.
|
||||
pub(super) fn is_output(&self, key: DatabaseKeyIndex) -> bool {
|
||||
self.outputs.contains(&key)
|
||||
}
|
||||
|
||||
pub(crate) fn revisions(&self, runtime: &Runtime) -> QueryRevisions {
|
||||
|
|
|
@ -118,7 +118,7 @@ impl LocalState {
|
|||
pub(super) fn add_entity_created(&self, entity: DatabaseKeyIndex) {
|
||||
self.with_query_stack(|stack| {
|
||||
if let Some(top_query) = stack.last_mut() {
|
||||
top_query.add_entity_created(entity)
|
||||
top_query.add_output(entity)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ impl LocalState {
|
|||
pub(super) fn was_entity_created(&self, entity: DatabaseKeyIndex) -> bool {
|
||||
self.with_query_stack(|stack| {
|
||||
if let Some(top_query) = stack.last_mut() {
|
||||
top_query.was_entity_created(entity)
|
||||
top_query.is_output(entity)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue