fix accumulator: clear the outdated accumulated values

This commit is contained in:
XFFXFF 2022-09-25 00:24:16 +00:00
parent 1214610451
commit e7c7f386fe
6 changed files with 9 additions and 8 deletions

View file

@ -61,8 +61,10 @@ impl<Data: Clone> AccumulatorIngredient<Data> {
produced_at: current_revision,
});
// This is the first push in a new revision. Reset.
if accumulated_values.produced_at != current_revision {
// When we call `push' in a query, we will add the accumulator to the output of the query.
// If we find here that this accumulator is not the output of the query,
// we can say that the accumulated values we stored for this query is out of date.
if !runtime.is_output_of_active_query(self.dependency_index()) {
accumulated_values.values.truncate(0);
accumulated_values.produced_at = current_revision;
}

View file

@ -46,7 +46,8 @@ where
//
// Now, if We invoke Q3 first, We get one result for Q2, but if We invoke Q4 first, We get a different value. That's no good.
let database_key_index = key.database_key_index(db);
if !runtime.is_output_of_active_query(database_key_index) {
let dependency_index = database_key_index.into();
if !runtime.is_output_of_active_query(dependency_index) {
panic!("can only use `specfiy` on entities created during current query");
}

View file

@ -149,7 +149,7 @@ impl Runtime {
}
/// 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 {
pub(super) fn is_output_of_active_query(&self, entity: DependencyIndex) -> bool {
self.local_state.is_output(entity)
}

View file

@ -82,8 +82,7 @@ impl ActiveQuery {
}
/// True if the given key was output by this query.
pub(super) fn is_output(&self, key: DatabaseKeyIndex) -> bool {
let key: DependencyIndex = key.into();
pub(super) fn is_output(&self, key: DependencyIndex) -> bool {
self.input_outputs.contains(&(EdgeKind::Output, key))
}

View file

@ -190,7 +190,7 @@ impl LocalState {
})
}
pub(super) fn is_output(&self, entity: DatabaseKeyIndex) -> bool {
pub(super) fn is_output(&self, entity: DependencyIndex) -> bool {
self.with_query_stack(|stack| {
if let Some(top_query) = stack.last_mut() {
top_query.is_output(entity)

View file

@ -89,6 +89,5 @@ fn test1() {
[
"accumulated(List(Id { value: 1 }))",
"compute(List(Id { value: 1 }))",
"compute(List(Id { value: 2 }))",
]"#]]);
}