From 97e280ddd226ab1c935ba45a83d27f7fdf7160d4 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 10 Aug 2022 03:46:27 -0400 Subject: [PATCH] track outputs for the active record --- .../salsa-2022/src/runtime/active_query.rs | 25 +++++++++++++------ .../salsa-2022/src/runtime/local_state.rs | 4 +-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/components/salsa-2022/src/runtime/active_query.rs b/components/salsa-2022/src/runtime/active_query.rs index 02fa5c6f..4ef9c889 100644 --- a/components/salsa-2022/src/runtime/active_query.rs +++ b/components/salsa-2022/src/runtime/active_query.rs @@ -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, - /// Tracks entities created by this query. - pub(super) entities_created: FxHashSet, + /// 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, } 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 { diff --git a/components/salsa-2022/src/runtime/local_state.rs b/components/salsa-2022/src/runtime/local_state.rs index 785da66c..ab47a2b7 100644 --- a/components/salsa-2022/src/runtime/local_state.rs +++ b/components/salsa-2022/src/runtime/local_state.rs @@ -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 }