mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Prefer plain trait definitions over macros for salsa
This commit is contained in:
parent
e059feadef
commit
3874681cb6
7 changed files with 37 additions and 33 deletions
|
@ -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<generics::LifetimeParamData>;
|
||||
impl_intern_value_trivial!(LifetimeParamId);
|
||||
impl InternValueTrivial for LifetimeParamId {}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum ItemContainerId {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<CallableDefId> for ModuleDefId {
|
||||
fn from(def: CallableDefId) -> ModuleDefId {
|
||||
|
|
|
@ -98,26 +98,27 @@ impl<A: InternValue + Eq + Hash + Debug + Clone, B: InternValue + Eq + Hash + De
|
|||
}
|
||||
}
|
||||
|
||||
/// Implement [`InternValue`] trivially, that is without actually mapping at all.
|
||||
#[macro_export]
|
||||
macro_rules! impl_intern_value_trivial {
|
||||
($($ty:ty),*) => {
|
||||
$(
|
||||
impl $crate::InternValue for $ty {
|
||||
type Key = $ty;
|
||||
#[inline]
|
||||
fn into_key(&self) -> Self::Key {
|
||||
self.clone()
|
||||
}
|
||||
#[inline]
|
||||
fn with_key<F: FnOnce(&Self::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<V: InternValueTrivial> InternValue for V {
|
||||
type Key = Self;
|
||||
#[inline]
|
||||
fn into_key(&self) -> Self::Key {
|
||||
self.clone()
|
||||
}
|
||||
#[inline]
|
||||
fn with_key<F: FnOnce(&Self::Key) -> T, T>(&self, f: F) -> T {
|
||||
f(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl InternValueTrivial for String {}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Slot<V> {
|
||||
/// DatabaseKeyIndex for this slot.
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue