diff --git a/crates/hir-def/src/lib.rs b/crates/hir-def/src/lib.rs index b1f97f2bb9..0dcd9129d6 100644 --- a/crates/hir-def/src/lib.rs +++ b/crates/hir-def/src/lib.rs @@ -73,7 +73,7 @@ use std::{ use base_db::{ impl_intern_key, - salsa::{self, impl_intern_value_trivial}, + salsa::{self, InternValueTrivial}, CrateId, }; use hir_expand::{ @@ -187,7 +187,7 @@ pub trait ItemTreeLoc { macro_rules! impl_intern { ($id:ident, $loc:ident, $intern:ident, $lookup:ident) => { impl_intern_key!($id); - impl_intern_value_trivial!($loc); + impl InternValueTrivial for $loc {} impl_intern_lookup!(DefDatabase, $id, $loc, $intern, $lookup); }; } @@ -535,7 +535,7 @@ pub struct TypeOrConstParamId { pub parent: GenericDefId, pub local_id: LocalTypeOrConstParamId, } -impl_intern_value_trivial!(TypeOrConstParamId); +impl InternValueTrivial for TypeOrConstParamId {} /// A TypeOrConstParamId with an invariant that it actually belongs to a type #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -597,7 +597,7 @@ pub struct LifetimeParamId { pub local_id: LocalLifetimeParamId, } pub type LocalLifetimeParamId = Idx; -impl_intern_value_trivial!(LifetimeParamId); +impl InternValueTrivial for LifetimeParamId {} #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum ItemContainerId { diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs index 8859b47e4c..ec0716c5fa 100644 --- a/crates/hir-expand/src/lib.rs +++ b/crates/hir-expand/src/lib.rs @@ -31,7 +31,7 @@ use triomphe::Arc; use std::{fmt, hash::Hash}; -use base_db::{salsa::impl_intern_value_trivial, CrateId, FileId}; +use base_db::{salsa::InternValueTrivial, CrateId, FileId}; use either::Either; use span::{ Edition, ErasedFileAstId, FileAstId, FileRange, HirFileIdRepr, Span, SpanAnchor, @@ -173,7 +173,7 @@ pub struct MacroCallLoc { pub kind: MacroCallKind, pub ctxt: SyntaxContextId, } -impl_intern_value_trivial!(MacroCallLoc); +impl InternValueTrivial for MacroCallLoc {} #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct MacroDefId { diff --git a/crates/hir-ty/src/db.rs b/crates/hir-ty/src/db.rs index 90bf46b505..000871ed52 100644 --- a/crates/hir-ty/src/db.rs +++ b/crates/hir-ty/src/db.rs @@ -5,7 +5,7 @@ use std::sync; use base_db::{ impl_intern_key, - salsa::{self, impl_intern_value_trivial}, + salsa::{self, InternValueTrivial}, CrateId, Upcast, }; use hir_def::{ @@ -298,7 +298,8 @@ impl_intern_key!(InternedClosureId); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct InternedClosure(pub DefWithBodyId, pub ExprId); -impl_intern_value_trivial!(InternedClosure); + +impl InternValueTrivial for InternedClosure {} #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct InternedCoroutineId(salsa::InternId); @@ -306,7 +307,7 @@ impl_intern_key!(InternedCoroutineId); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct InternedCoroutine(pub DefWithBodyId, pub ExprId); -impl_intern_value_trivial!(InternedCoroutine); +impl InternValueTrivial for InternedCoroutine {} /// This exists just for Chalk, because Chalk just has a single `FnDefId` where /// we have different IDs for struct and enum variant constructors. diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs index 26a839f0e9..9d596e957b 100644 --- a/crates/hir-ty/src/lib.rs +++ b/crates/hir-ty/src/lib.rs @@ -52,7 +52,7 @@ use std::{ hash::{BuildHasherDefault, Hash}, }; -use base_db::salsa::impl_intern_value_trivial; +use base_db::salsa::InternValueTrivial; use chalk_ir::{ fold::{Shift, TypeFoldable}, interner::HasInterner, @@ -606,7 +606,7 @@ pub enum ImplTraitId { AssociatedTypeImplTrait(hir_def::TypeAliasId, ImplTraitIdx), AsyncBlockTypeImplTrait(hir_def::DefWithBodyId, ExprId), } -impl_intern_value_trivial!(ImplTraitId); +impl InternValueTrivial for ImplTraitId {} #[derive(PartialEq, Eq, Debug, Hash)] pub struct ImplTraits { diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index d3e79541ab..2e100d5c55 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -11,7 +11,7 @@ use std::{ }; use base_db::{ - salsa::{impl_intern_value_trivial, Cycle}, + salsa::{Cycle, InternValueTrivial}, CrateId, }; use chalk_ir::{ @@ -1965,7 +1965,9 @@ pub enum CallableDefId { StructId(StructId), EnumVariantId(EnumVariantId), } -impl_intern_value_trivial!(CallableDefId); + +impl InternValueTrivial for CallableDefId {} + impl_from!(FunctionId, StructId, EnumVariantId for CallableDefId); impl From for ModuleDefId { fn from(def: CallableDefId) -> ModuleDefId { diff --git a/crates/salsa/src/interned.rs b/crates/salsa/src/interned.rs index bfa9cc0591..eef8bcc814 100644 --- a/crates/salsa/src/interned.rs +++ b/crates/salsa/src/interned.rs @@ -98,26 +98,27 @@ impl { - $( - impl $crate::InternValue for $ty { - type Key = $ty; - #[inline] - fn into_key(&self) -> Self::Key { - self.clone() - } - #[inline] - fn with_key T, T>(&self, f: F) -> T { - f(self) - } - } - )* - }; +pub trait InternValueTrivial +where + Self: Eq + Hash + Debug + Clone, +{ } -impl_intern_value_trivial!(String); + +/// Implement [`InternValue`] trivially, that is without actually mapping at all. +impl InternValue for V { + type Key = Self; + #[inline] + fn into_key(&self) -> Self::Key { + self.clone() + } + #[inline] + fn with_key T, T>(&self, f: F) -> T { + f(self) + } +} + +impl InternValueTrivial for String {} + #[derive(Debug)] struct Slot { /// DatabaseKeyIndex for this slot. diff --git a/crates/salsa/src/lib.rs b/crates/salsa/src/lib.rs index 9219a55634..d81fca05e5 100644 --- a/crates/salsa/src/lib.rs +++ b/crates/salsa/src/lib.rs @@ -40,7 +40,7 @@ use std::panic::{self, UnwindSafe}; pub use crate::durability::Durability; pub use crate::intern_id::InternId; -pub use crate::interned::{InternKey, InternValue}; +pub use crate::interned::{InternKey, InternValue, InternValueTrivial}; pub use crate::runtime::Runtime; pub use crate::runtime::RuntimeId; pub use crate::storage::Storage;