From 7519c3e2a6cc1ceaeb11b541acb677778a295ab8 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 18 May 2024 06:27:08 -0400 Subject: [PATCH] extend IdentityInterner to be based on LookupId --- .../salsa-2022-macros/src/tracked_fn.rs | 4 ++-- components/salsa-2022/src/interned.rs | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index cbc1211f..0e67af52 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -431,7 +431,7 @@ fn fn_configuration(args: &FnArgs, item_fn: &syn::ItemFn) -> Configuration { let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db); let __ingredients = <_ as salsa::storage::HasIngredientsFor<#fn_ty>>::ingredient(__jar); - let #key_var = __ingredients.intern_map.data(__id).clone(); + let #key_var = __ingredients.intern_map.data_with_db(__id, __db).clone(); #recovery_fn(__db, __cycle, #key_splat) } }; @@ -463,7 +463,7 @@ fn fn_configuration(args: &FnArgs, item_fn: &syn::ItemFn) -> Configuration { let (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db); let __ingredients = <_ as salsa::storage::HasIngredientsFor<#fn_ty>>::ingredient(__jar); - let #key_var = __ingredients.intern_map.data(__id).clone(); + let #key_var = __ingredients.intern_map.data_with_db(__id, __db).clone(); #inner_fn_name(__db, #key_splat) } }; diff --git a/components/salsa-2022/src/interned.rs b/components/salsa-2022/src/interned.rs index 6c276145..295b6adc 100644 --- a/components/salsa-2022/src/interned.rs +++ b/components/salsa-2022/src/interned.rs @@ -4,7 +4,7 @@ use std::hash::Hash; use std::marker::PhantomData; use crate::durability::Durability; -use crate::id::AsId; +use crate::id::{AsId, LookupId}; use crate::ingredient::{fmt_index, IngredientRequiresReset}; use crate::key::DependencyIndex; use crate::plumbing::transmute_lifetime; @@ -141,10 +141,20 @@ where unsafe { transmute_lifetime(self, &**r) } } + /// Lookup the data for an interned value based on its id. + /// Rarely used since end-users generally carry a struct with a pointer directly + /// to the interned item. pub fn data<'db>(&'db self, id: Id) -> &'db C::Data<'db> { self.interned_value(id).data() } + /// Variant of `data` that takes a (unnecessary) database argument. + /// This exists because tracked functions sometimes use true interning and sometimes use + /// [`IdentityInterner`][], which requires the database argument. + pub fn data_with_db<'db, DB: ?Sized>(&'db self, id: Id, _db: &'db DB) -> &'db C::Data<'db> { + self.data(id) + } + pub fn reset(&mut self, revision: Revision) { assert!(revision > self.reset_at); self.reset_at = revision; @@ -242,8 +252,12 @@ where id.as_id() } - pub fn data<'db>(&'db self, id: crate::Id) -> C::Data<'db> { - >::from_id(id) + pub fn data_with_db<'db, DB>(&'db self, id: crate::Id, db: &'db DB) -> C::Data<'db> + where + DB: ?Sized, + C::Data<'db>: LookupId<&'db DB>, + { + >::lookup_id(id, db) } }