mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Merge pull request #19997 from Veykril/push-xltylvqtpwzx
Remove `InternedCallableDefId`
This commit is contained in:
commit
a497f4114c
@ -16,7 +16,8 @@ use crate::{
|
||||
ClosureId, DynTy, FnPointer, ImplTraitId, InEnvironment, Interner, Lifetime, ProjectionTy,
|
||||
QuantifiedWhereClause, Substitution, TraitRef, Ty, TyBuilder, TyKind, TypeFlags, WhereClause,
|
||||
db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id,
|
||||
from_placeholder_idx, generics::generics, to_chalk_trait_id, utils::ClosureSubst,
|
||||
from_placeholder_idx, generics::generics, mapping::ToChalk, to_chalk_trait_id,
|
||||
utils::ClosureSubst,
|
||||
};
|
||||
|
||||
pub trait TyExt {
|
||||
@ -190,10 +191,9 @@ impl TyExt for Ty {
|
||||
fn as_generic_def(&self, db: &dyn HirDatabase) -> Option<GenericDefId> {
|
||||
match *self.kind(Interner) {
|
||||
TyKind::Adt(AdtId(adt), ..) => Some(adt.into()),
|
||||
TyKind::FnDef(callable, ..) => Some(GenericDefId::from_callable(
|
||||
db,
|
||||
db.lookup_intern_callable_def(callable.into()),
|
||||
)),
|
||||
TyKind::FnDef(callable, ..) => {
|
||||
Some(GenericDefId::from_callable(db, ToChalk::from_chalk(db, callable)))
|
||||
}
|
||||
TyKind::AssociatedType(type_alias, ..) => Some(from_assoc_type_id(type_alias).into()),
|
||||
TyKind::Foreign(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()),
|
||||
_ => None,
|
||||
@ -202,7 +202,7 @@ impl TyExt for Ty {
|
||||
|
||||
fn callable_def(&self, db: &dyn HirDatabase) -> Option<CallableDefId> {
|
||||
match self.kind(Interner) {
|
||||
&TyKind::FnDef(def, ..) => Some(db.lookup_intern_callable_def(def.into())),
|
||||
&TyKind::FnDef(def, ..) => Some(ToChalk::from_chalk(db, def)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -236,9 +236,6 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
|
||||
fn trait_impls_in_deps(&self, krate: Crate) -> Arc<[Arc<TraitImpls>]>;
|
||||
|
||||
// Interned IDs for Chalk integration
|
||||
#[salsa::interned]
|
||||
fn intern_callable_def(&self, callable_def: CallableDefId) -> InternedCallableDefId;
|
||||
|
||||
#[salsa::interned]
|
||||
fn intern_type_or_const_param_id(
|
||||
&self,
|
||||
@ -347,7 +344,3 @@ impl_intern_key!(InternedClosureId, InternedClosure);
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct InternedCoroutine(pub DefWithBodyId, pub ExprId);
|
||||
impl_intern_key!(InternedCoroutineId, InternedCoroutine);
|
||||
|
||||
// This exists just for Chalk, because Chalk just has a single `FnDefId` where
|
||||
// we have different IDs for struct and enum variant constructors.
|
||||
impl_intern_key!(InternedCallableDefId, CallableDefId);
|
||||
|
@ -98,7 +98,7 @@ pub use lower::{
|
||||
ValueTyDefId, associated_type_shorthand_candidates, diagnostics::*,
|
||||
};
|
||||
pub use mapping::{
|
||||
from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, from_placeholder_idx,
|
||||
ToChalk, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, from_placeholder_idx,
|
||||
lt_from_placeholder_idx, lt_to_placeholder_idx, to_assoc_type_id, to_chalk_trait_id,
|
||||
to_foreign_def_id, to_placeholder_idx,
|
||||
};
|
||||
@ -542,7 +542,7 @@ impl CallableSig {
|
||||
}
|
||||
|
||||
pub fn from_def(db: &dyn HirDatabase, def: FnDefId, substs: &Substitution) -> CallableSig {
|
||||
let callable_def = db.lookup_intern_callable_def(def.into());
|
||||
let callable_def = ToChalk::from_chalk(db, def);
|
||||
let sig = db.callable_item_signature(callable_def);
|
||||
sig.substitute(Interner, substs)
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ use crate::{
|
||||
PlaceholderIndex, chalk_db, db::HirDatabase,
|
||||
};
|
||||
|
||||
pub(crate) trait ToChalk {
|
||||
pub trait ToChalk {
|
||||
type Chalk;
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk;
|
||||
fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self;
|
||||
@ -44,12 +44,12 @@ impl ToChalk for hir_def::ImplId {
|
||||
impl ToChalk for CallableDefId {
|
||||
type Chalk = FnDefId;
|
||||
|
||||
fn to_chalk(self, db: &dyn HirDatabase) -> FnDefId {
|
||||
db.intern_callable_def(self).into()
|
||||
fn to_chalk(self, _db: &dyn HirDatabase) -> FnDefId {
|
||||
chalk_ir::FnDefId(salsa::plumbing::AsId::as_id(&self))
|
||||
}
|
||||
|
||||
fn from_chalk(db: &dyn HirDatabase, fn_def_id: FnDefId) -> CallableDefId {
|
||||
db.lookup_intern_callable_def(fn_def_id.into())
|
||||
salsa::plumbing::FromIdWithDb::from_id(fn_def_id.0, db.zalsa())
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,18 +70,6 @@ impl ToChalk for TypeAliasAsValue {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FnDefId> for crate::db::InternedCallableDefId {
|
||||
fn from(fn_def_id: FnDefId) -> Self {
|
||||
Self::from_id(fn_def_id.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::db::InternedCallableDefId> for FnDefId {
|
||||
fn from(callable_def_id: crate::db::InternedCallableDefId) -> Self {
|
||||
chalk_ir::FnDefId(callable_def_id.as_id())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OpaqueTyId> for crate::db::InternedOpaqueTyId {
|
||||
fn from(id: OpaqueTyId) -> Self {
|
||||
FromId::from_id(id.0)
|
||||
|
@ -32,7 +32,7 @@ use triomphe::Arc;
|
||||
|
||||
use crate::{
|
||||
CallableDefId, ClosureId, ComplexMemoryMap, Const, ConstData, ConstScalar, FnDefId, Interner,
|
||||
MemoryMap, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt, TyKind,
|
||||
MemoryMap, Substitution, ToChalk, TraitEnvironment, Ty, TyBuilder, TyExt, TyKind,
|
||||
consteval::{ConstEvalError, intern_const_scalar, try_const_usize},
|
||||
db::{HirDatabase, InternedClosure},
|
||||
display::{ClosureStyle, DisplayTarget, HirDisplay},
|
||||
@ -2930,7 +2930,7 @@ pub fn render_const_using_debug_impl(
|
||||
let a2 = evaluator.heap_allocate(evaluator.ptr_size() * 2, evaluator.ptr_size())?;
|
||||
evaluator.write_memory(a2, &data.addr.to_bytes())?;
|
||||
let debug_fmt_fn_ptr = evaluator.vtable_map.id(TyKind::FnDef(
|
||||
db.intern_callable_def(debug_fmt_fn.into()).into(),
|
||||
CallableDefId::FunctionId(debug_fmt_fn).to_chalk(db),
|
||||
Substitution::from1(Interner, c.data(Interner).ty.clone()),
|
||||
)
|
||||
.intern(Interner));
|
||||
|
@ -297,11 +297,8 @@ impl MirLowerCtx<'_> {
|
||||
let result_ref = TyKind::Ref(mutability, error_lifetime(), result_ty).intern(Interner);
|
||||
let mut result: Place = self.temp(result_ref, current, span)?.into();
|
||||
let index_fn_op = Operand::const_zst(
|
||||
TyKind::FnDef(
|
||||
self.db.intern_callable_def(CallableDefId::FunctionId(index_fn.0)).into(),
|
||||
index_fn.1,
|
||||
)
|
||||
.intern(Interner),
|
||||
TyKind::FnDef(CallableDefId::FunctionId(index_fn.0).to_chalk(self.db), index_fn.1)
|
||||
.intern(Interner),
|
||||
);
|
||||
let Some(current) = self.lower_call(
|
||||
index_fn_op,
|
||||
@ -357,7 +354,7 @@ impl MirLowerCtx<'_> {
|
||||
.ok_or(MirLowerError::LangItemNotFound(trait_lang_item))?;
|
||||
let deref_fn_op = Operand::const_zst(
|
||||
TyKind::FnDef(
|
||||
self.db.intern_callable_def(CallableDefId::FunctionId(deref_fn)).into(),
|
||||
CallableDefId::FunctionId(deref_fn).to_chalk(self.db),
|
||||
Substitution::from1(Interner, source_ty),
|
||||
)
|
||||
.intern(Interner),
|
||||
|
@ -37,7 +37,7 @@ use hir_expand::{
|
||||
};
|
||||
use hir_ty::{
|
||||
Adjustment, AliasTy, InferenceResult, Interner, LifetimeElisionKind, ProjectionTy,
|
||||
Substitution, TraitEnvironment, Ty, TyExt, TyKind, TyLoweringContext,
|
||||
Substitution, ToChalk, TraitEnvironment, Ty, TyExt, TyKind, TyLoweringContext,
|
||||
diagnostics::{
|
||||
InsideUnsafeBlock, record_literal_missing_fields, record_pattern_missing_fields,
|
||||
unsafe_operations,
|
||||
@ -1169,8 +1169,7 @@ impl<'db> SourceAnalyzer<'db> {
|
||||
)
|
||||
}
|
||||
TyKind::FnDef(fn_id, subst) => {
|
||||
let fn_id = hir_ty::db::InternedCallableDefId::from(*fn_id);
|
||||
let fn_id = db.lookup_intern_callable_def(fn_id);
|
||||
let fn_id = ToChalk::from_chalk(db, *fn_id);
|
||||
let generic_def_id = match fn_id {
|
||||
CallableDefId::StructId(id) => id.into(),
|
||||
CallableDefId::FunctionId(id) => id.into(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user