From 1ae6a7bbc52f8a45f295bb998c9be3684ee53edb Mon Sep 17 00:00:00 2001 From: XFFXFF <1247714429@qq.com> Date: Sat, 17 Sep 2022 07:09:39 +0800 Subject: [PATCH] use `Assigned` insread of `Field` and remove `Field` --- components/salsa-2022-macros/src/tracked_struct.rs | 2 +- components/salsa-2022/src/function/accumulated.rs | 3 +-- .../salsa-2022/src/function/maybe_changed_after.rs | 8 -------- components/salsa-2022/src/function/memo.rs | 3 +-- components/salsa-2022/src/function/specify.rs | 14 -------------- components/salsa-2022/src/runtime/local_state.rs | 6 +----- 6 files changed, 4 insertions(+), 32 deletions(-) diff --git a/components/salsa-2022-macros/src/tracked_struct.rs b/components/salsa-2022-macros/src/tracked_struct.rs index fd826d07..98f36cf9 100644 --- a/components/salsa-2022-macros/src/tracked_struct.rs +++ b/components/salsa-2022-macros/src/tracked_struct.rs @@ -158,7 +158,7 @@ impl TrackedStruct { let __ingredients = <#jar_ty as salsa::storage::HasIngredientsFor< #ident >>::ingredient(__jar); let __id = __ingredients.#struct_index.new_struct(__runtime, (#(#id_field_names,)*)); #( - __ingredients.#value_field_indices.specify_field(__db, __id, #value_field_names); + __ingredients.#value_field_indices.specify_and_record(__db, __id, #value_field_names); )* __id } diff --git a/components/salsa-2022/src/function/accumulated.rs b/components/salsa-2022/src/function/accumulated.rs index 58ef6ee5..ccb3a2a0 100644 --- a/components/salsa-2022/src/function/accumulated.rs +++ b/components/salsa-2022/src/function/accumulated.rs @@ -67,8 +67,7 @@ impl Stack { match origin { None | Some(QueryOrigin::Assigned(_)) - | Some(QueryOrigin::BaseInput) - | Some(QueryOrigin::Field) => {} + | Some(QueryOrigin::BaseInput) => {} Some(QueryOrigin::Derived(edges)) | Some(QueryOrigin::DerivedUntracked(edges)) => { for DependencyIndex { ingredient_index, diff --git a/components/salsa-2022/src/function/maybe_changed_after.rs b/components/salsa-2022/src/function/maybe_changed_after.rs index 391d7068..77f8e0e5 100644 --- a/components/salsa-2022/src/function/maybe_changed_after.rs +++ b/components/salsa-2022/src/function/maybe_changed_after.rs @@ -174,14 +174,6 @@ where // This value was `set` by the mutator thread -- ie, it's a base input and it cannot be out of date. return true; } - QueryOrigin::Field => { - // This value is the value of a field of some tracked struct S. - // The fact that we are here means that we are accessing fields from old revisions, which is not allowed. - panic!( - "accessing fields of tracked struct {:?} from older revisions", - std::any::type_name::<::SalsaStruct>() - ) - } QueryOrigin::DerivedUntracked(_) => { // Untracked inputs? Have to assume that it changed. return false; diff --git a/components/salsa-2022/src/function/memo.rs b/components/salsa-2022/src/function/memo.rs index 73c7c2c4..7c77ce8c 100644 --- a/components/salsa-2022/src/function/memo.rs +++ b/components/salsa-2022/src/function/memo.rs @@ -55,8 +55,7 @@ impl MemoMap { match memo.revisions.origin { QueryOrigin::Assigned(_) | QueryOrigin::DerivedUntracked(_) - | QueryOrigin::BaseInput - | QueryOrigin::Field => { + | QueryOrigin::BaseInput => { // Careful: Cannot evict memos whose values were // assigned as output of another query // or those with untracked inputs diff --git a/components/salsa-2022/src/function/specify.rs b/components/salsa-2022/src/function/specify.rs index 17a703d2..0c215383 100644 --- a/components/salsa-2022/src/function/specify.rs +++ b/components/salsa-2022/src/function/specify.rs @@ -91,19 +91,6 @@ where self.insert_memo(db, key, memo); } - /// Specify the value for `key` but do not record it is an output. - /// This is used for the value fields declared on a tracked struct. - /// They are different from other calls to specify because we KNOW they will be given a value by construction, - /// so recording them as an explicit output (and checking them for validity, etc) is pure overhead. - pub fn specify_field<'db>(&self, db: &'db DynDb<'db, C>, key: C::Key, value: C::Value) - where - C::Key: TrackedStructInDb>, - { - self.specify(db, key, value, |_| QueryOrigin::Field); - let database_key_index = self.database_key_index(key); - db.runtime().add_output(database_key_index.into()); - } - /// Specify the value for `key` *and* record that we did so. /// Used for explicit calls to `specify`, but not needed for pre-declared tracked struct fields. pub fn specify_and_record<'db>(&self, db: &'db DynDb<'db, C>, key: C::Key, value: C::Value) @@ -140,7 +127,6 @@ where // assigneed by `executor`. match memo.revisions.origin { QueryOrigin::Assigned(by_query) => assert_eq!(by_query, executor), - QueryOrigin::Field => {} _ => panic!( "expected a query assigned by `{:?}`, not `{:?}`", executor.debug(db), diff --git a/components/salsa-2022/src/runtime/local_state.rs b/components/salsa-2022/src/runtime/local_state.rs index 0897722e..e5359cb9 100644 --- a/components/salsa-2022/src/runtime/local_state.rs +++ b/components/salsa-2022/src/runtime/local_state.rs @@ -60,10 +60,6 @@ pub enum QueryOrigin { /// The `DatabaseKeyIndex` is the identity of the assigning query. Assigned(DatabaseKeyIndex), - /// This is the value field of a tracked struct. - /// These are different from `Assigned` because we know they will always be assigned a value and hence are never "out of date". - Field, - /// This value was set as a base input to the computation. BaseInput, @@ -86,7 +82,7 @@ impl QueryOrigin { QueryOrigin::Derived(edges) | QueryOrigin::DerivedUntracked(edges) => { &edges.input_outputs[edges.separator as usize..] } - QueryOrigin::Assigned(_) | QueryOrigin::BaseInput | QueryOrigin::Field => &[], + QueryOrigin::Assigned(_) | QueryOrigin::BaseInput => &[], }; slice.iter().copied()