extend IdentityInterner to be based on LookupId

This commit is contained in:
Niko Matsakis 2024-05-18 06:27:08 -04:00
parent ab70786536
commit 7519c3e2a6
2 changed files with 19 additions and 5 deletions

View file

@ -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 (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db);
let __ingredients = let __ingredients =
<_ as salsa::storage::HasIngredientsFor<#fn_ty>>::ingredient(__jar); <_ 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) #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 (__jar, __runtime) = <_ as salsa::storage::HasJar<#jar_ty>>::jar(__db);
let __ingredients = let __ingredients =
<_ as salsa::storage::HasIngredientsFor<#fn_ty>>::ingredient(__jar); <_ 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) #inner_fn_name(__db, #key_splat)
} }
}; };

View file

@ -4,7 +4,7 @@ use std::hash::Hash;
use std::marker::PhantomData; use std::marker::PhantomData;
use crate::durability::Durability; use crate::durability::Durability;
use crate::id::AsId; use crate::id::{AsId, LookupId};
use crate::ingredient::{fmt_index, IngredientRequiresReset}; use crate::ingredient::{fmt_index, IngredientRequiresReset};
use crate::key::DependencyIndex; use crate::key::DependencyIndex;
use crate::plumbing::transmute_lifetime; use crate::plumbing::transmute_lifetime;
@ -141,10 +141,20 @@ where
unsafe { transmute_lifetime(self, &**r) } 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> { pub fn data<'db>(&'db self, id: Id) -> &'db C::Data<'db> {
self.interned_value(id).data() 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) { pub fn reset(&mut self, revision: Revision) {
assert!(revision > self.reset_at); assert!(revision > self.reset_at);
self.reset_at = revision; self.reset_at = revision;
@ -242,8 +252,12 @@ where
id.as_id() id.as_id()
} }
pub fn data<'db>(&'db self, id: crate::Id) -> C::Data<'db> { pub fn data_with_db<'db, DB>(&'db self, id: crate::Id, db: &'db DB) -> C::Data<'db>
<C::Data<'db>>::from_id(id) where
DB: ?Sized,
C::Data<'db>: LookupId<&'db DB>,
{
<C::Data<'db>>::lookup_id(id, db)
} }
} }