mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-15 01:39:25 +00:00
generalize list of "entities created" to "outputs"
We will record each thing that gets *output* by the query. Use a btree-set so that we can get a sorted list. That will allow us to easily compare what is output between revisions. We will use that to clear stale values.
This commit is contained in:
parent
de2fb22a1c
commit
cbe7d371c9
5 changed files with 12 additions and 13 deletions
|
@ -27,7 +27,7 @@ where
|
|||
};
|
||||
|
||||
let entity_index = key.database_key_index(db);
|
||||
if !runtime.was_entity_created(entity_index) {
|
||||
if !runtime.is_output_of_active_query(entity_index) {
|
||||
panic!("can only use `set` on entities created during current query");
|
||||
}
|
||||
|
||||
|
|
|
@ -144,15 +144,15 @@ impl Runtime {
|
|||
}
|
||||
}
|
||||
|
||||
/// Adds `entity` to the lits of entities created by the current query.
|
||||
/// Panics if `entity` was already added.
|
||||
pub(crate) fn add_entity_created(&self, entity: DatabaseKeyIndex) {
|
||||
self.local_state.add_entity_created(entity);
|
||||
/// Adds `key` to the list of output created by the current query
|
||||
/// (if not already present).
|
||||
pub(crate) fn add_output(&self, key: DatabaseKeyIndex) {
|
||||
self.local_state.add_output(key);
|
||||
}
|
||||
|
||||
/// Check whether `entity` is contained the list of entities created by the current query.
|
||||
pub(super) fn was_entity_created(&self, entity: DatabaseKeyIndex) -> bool {
|
||||
self.local_state.was_entity_created(entity)
|
||||
/// Check whether `entity` is contained the list of outputs written by the current query.
|
||||
pub(super) fn is_output_of_active_query(&self, entity: DatabaseKeyIndex) -> bool {
|
||||
self.local_state.is_output(entity)
|
||||
}
|
||||
|
||||
/// Called when the active queries creates an index from the
|
||||
|
|
|
@ -86,8 +86,7 @@ impl ActiveQuery {
|
|||
|
||||
/// 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);
|
||||
self.outputs.insert(key);
|
||||
}
|
||||
|
||||
/// True if the given key was output by this query.
|
||||
|
|
|
@ -115,7 +115,7 @@ impl LocalState {
|
|||
})
|
||||
}
|
||||
|
||||
pub(super) fn add_entity_created(&self, entity: DatabaseKeyIndex) {
|
||||
pub(super) fn add_output(&self, entity: DatabaseKeyIndex) {
|
||||
self.with_query_stack(|stack| {
|
||||
if let Some(top_query) = stack.last_mut() {
|
||||
top_query.add_output(entity)
|
||||
|
@ -123,7 +123,7 @@ impl LocalState {
|
|||
})
|
||||
}
|
||||
|
||||
pub(super) fn was_entity_created(&self, entity: DatabaseKeyIndex) -> bool {
|
||||
pub(super) fn is_output(&self, entity: DatabaseKeyIndex) -> bool {
|
||||
self.with_query_stack(|stack| {
|
||||
if let Some(top_query) = stack.last_mut() {
|
||||
top_query.is_output(entity)
|
||||
|
|
|
@ -76,7 +76,7 @@ where
|
|||
data,
|
||||
};
|
||||
let result = self.interned.intern(runtime, entity_key);
|
||||
runtime.add_entity_created(self.database_key_index(result));
|
||||
runtime.add_output(self.database_key_index(result));
|
||||
result
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue