Skip to content

Commit 0a74d46

Browse files
authored
Merge pull request #19997 from Veykril/push-xltylvqtpwzx
Remove `InternedCallableDefId`
2 parents e7fbbaf + 71f6663 commit 0a74d46

File tree

7 files changed

+19
-42
lines changed

7 files changed

+19
-42
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/chalk_ext.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use crate::{
1616
ClosureId, DynTy, FnPointer, ImplTraitId, InEnvironment, Interner, Lifetime, ProjectionTy,
1717
QuantifiedWhereClause, Substitution, TraitRef, Ty, TyBuilder, TyKind, TypeFlags, WhereClause,
1818
db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id,
19-
from_placeholder_idx, generics::generics, to_chalk_trait_id, utils::ClosureSubst,
19+
from_placeholder_idx, generics::generics, mapping::ToChalk, to_chalk_trait_id,
20+
utils::ClosureSubst,
2021
};
2122

2223
pub trait TyExt {
@@ -190,10 +191,9 @@ impl TyExt for Ty {
190191
fn as_generic_def(&self, db: &dyn HirDatabase) -> Option<GenericDefId> {
191192
match *self.kind(Interner) {
192193
TyKind::Adt(AdtId(adt), ..) => Some(adt.into()),
193-
TyKind::FnDef(callable, ..) => Some(GenericDefId::from_callable(
194-
db,
195-
db.lookup_intern_callable_def(callable.into()),
196-
)),
194+
TyKind::FnDef(callable, ..) => {
195+
Some(GenericDefId::from_callable(db, ToChalk::from_chalk(db, callable)))
196+
}
197197
TyKind::AssociatedType(type_alias, ..) => Some(from_assoc_type_id(type_alias).into()),
198198
TyKind::Foreign(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()),
199199
_ => None,
@@ -202,7 +202,7 @@ impl TyExt for Ty {
202202

203203
fn callable_def(&self, db: &dyn HirDatabase) -> Option<CallableDefId> {
204204
match self.kind(Interner) {
205-
&TyKind::FnDef(def, ..) => Some(db.lookup_intern_callable_def(def.into())),
205+
&TyKind::FnDef(def, ..) => Some(ToChalk::from_chalk(db, def)),
206206
_ => None,
207207
}
208208
}

src/tools/rust-analyzer/crates/hir-ty/src/db.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,6 @@ pub trait HirDatabase: DefDatabase + std::fmt::Debug {
236236
fn trait_impls_in_deps(&self, krate: Crate) -> Arc<[Arc<TraitImpls>]>;
237237

238238
// Interned IDs for Chalk integration
239-
#[salsa::interned]
240-
fn intern_callable_def(&self, callable_def: CallableDefId) -> InternedCallableDefId;
241-
242239
#[salsa::interned]
243240
fn intern_type_or_const_param_id(
244241
&self,
@@ -347,7 +344,3 @@ impl_intern_key!(InternedClosureId, InternedClosure);
347344
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
348345
pub struct InternedCoroutine(pub DefWithBodyId, pub ExprId);
349346
impl_intern_key!(InternedCoroutineId, InternedCoroutine);
350-
351-
// This exists just for Chalk, because Chalk just has a single `FnDefId` where
352-
// we have different IDs for struct and enum variant constructors.
353-
impl_intern_key!(InternedCallableDefId, CallableDefId);

src/tools/rust-analyzer/crates/hir-ty/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub use lower::{
9898
ValueTyDefId, associated_type_shorthand_candidates, diagnostics::*,
9999
};
100100
pub use mapping::{
101-
from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, from_placeholder_idx,
101+
ToChalk, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, from_placeholder_idx,
102102
lt_from_placeholder_idx, lt_to_placeholder_idx, to_assoc_type_id, to_chalk_trait_id,
103103
to_foreign_def_id, to_placeholder_idx,
104104
};
@@ -542,7 +542,7 @@ impl CallableSig {
542542
}
543543

544544
pub fn from_def(db: &dyn HirDatabase, def: FnDefId, substs: &Substitution) -> CallableSig {
545-
let callable_def = db.lookup_intern_callable_def(def.into());
545+
let callable_def = ToChalk::from_chalk(db, def);
546546
let sig = db.callable_item_signature(callable_def);
547547
sig.substitute(Interner, substs)
548548
}

src/tools/rust-analyzer/crates/hir-ty/src/mapping.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
PlaceholderIndex, chalk_db, db::HirDatabase,
1717
};
1818

19-
pub(crate) trait ToChalk {
19+
pub trait ToChalk {
2020
type Chalk;
2121
fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk;
2222
fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self;
@@ -44,12 +44,12 @@ impl ToChalk for hir_def::ImplId {
4444
impl ToChalk for CallableDefId {
4545
type Chalk = FnDefId;
4646

47-
fn to_chalk(self, db: &dyn HirDatabase) -> FnDefId {
48-
db.intern_callable_def(self).into()
47+
fn to_chalk(self, _db: &dyn HirDatabase) -> FnDefId {
48+
chalk_ir::FnDefId(salsa::plumbing::AsId::as_id(&self))
4949
}
5050

5151
fn from_chalk(db: &dyn HirDatabase, fn_def_id: FnDefId) -> CallableDefId {
52-
db.lookup_intern_callable_def(fn_def_id.into())
52+
salsa::plumbing::FromIdWithDb::from_id(fn_def_id.0, db.zalsa())
5353
}
5454
}
5555

@@ -70,18 +70,6 @@ impl ToChalk for TypeAliasAsValue {
7070
}
7171
}
7272

73-
impl From<FnDefId> for crate::db::InternedCallableDefId {
74-
fn from(fn_def_id: FnDefId) -> Self {
75-
Self::from_id(fn_def_id.0)
76-
}
77-
}
78-
79-
impl From<crate::db::InternedCallableDefId> for FnDefId {
80-
fn from(callable_def_id: crate::db::InternedCallableDefId) -> Self {
81-
chalk_ir::FnDefId(callable_def_id.as_id())
82-
}
83-
}
84-
8573
impl From<OpaqueTyId> for crate::db::InternedOpaqueTyId {
8674
fn from(id: OpaqueTyId) -> Self {
8775
FromId::from_id(id.0)

src/tools/rust-analyzer/crates/hir-ty/src/mir/eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use triomphe::Arc;
3232

3333
use crate::{
3434
CallableDefId, ClosureId, ComplexMemoryMap, Const, ConstData, ConstScalar, FnDefId, Interner,
35-
MemoryMap, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt, TyKind,
35+
MemoryMap, Substitution, ToChalk, TraitEnvironment, Ty, TyBuilder, TyExt, TyKind,
3636
consteval::{ConstEvalError, intern_const_scalar, try_const_usize},
3737
db::{HirDatabase, InternedClosure},
3838
display::{ClosureStyle, DisplayTarget, HirDisplay},
@@ -2930,7 +2930,7 @@ pub fn render_const_using_debug_impl(
29302930
let a2 = evaluator.heap_allocate(evaluator.ptr_size() * 2, evaluator.ptr_size())?;
29312931
evaluator.write_memory(a2, &data.addr.to_bytes())?;
29322932
let debug_fmt_fn_ptr = evaluator.vtable_map.id(TyKind::FnDef(
2933-
db.intern_callable_def(debug_fmt_fn.into()).into(),
2933+
CallableDefId::FunctionId(debug_fmt_fn).to_chalk(db),
29342934
Substitution::from1(Interner, c.data(Interner).ty.clone()),
29352935
)
29362936
.intern(Interner));

src/tools/rust-analyzer/crates/hir-ty/src/mir/lower/as_place.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,8 @@ impl MirLowerCtx<'_> {
297297
let result_ref = TyKind::Ref(mutability, error_lifetime(), result_ty).intern(Interner);
298298
let mut result: Place = self.temp(result_ref, current, span)?.into();
299299
let index_fn_op = Operand::const_zst(
300-
TyKind::FnDef(
301-
self.db.intern_callable_def(CallableDefId::FunctionId(index_fn.0)).into(),
302-
index_fn.1,
303-
)
304-
.intern(Interner),
300+
TyKind::FnDef(CallableDefId::FunctionId(index_fn.0).to_chalk(self.db), index_fn.1)
301+
.intern(Interner),
305302
);
306303
let Some(current) = self.lower_call(
307304
index_fn_op,
@@ -357,7 +354,7 @@ impl MirLowerCtx<'_> {
357354
.ok_or(MirLowerError::LangItemNotFound(trait_lang_item))?;
358355
let deref_fn_op = Operand::const_zst(
359356
TyKind::FnDef(
360-
self.db.intern_callable_def(CallableDefId::FunctionId(deref_fn)).into(),
357+
CallableDefId::FunctionId(deref_fn).to_chalk(self.db),
361358
Substitution::from1(Interner, source_ty),
362359
)
363360
.intern(Interner),

src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use hir_expand::{
3737
};
3838
use hir_ty::{
3939
Adjustment, AliasTy, InferenceResult, Interner, LifetimeElisionKind, ProjectionTy,
40-
Substitution, TraitEnvironment, Ty, TyExt, TyKind, TyLoweringContext,
40+
Substitution, ToChalk, TraitEnvironment, Ty, TyExt, TyKind, TyLoweringContext,
4141
diagnostics::{
4242
InsideUnsafeBlock, record_literal_missing_fields, record_pattern_missing_fields,
4343
unsafe_operations,
@@ -1169,8 +1169,7 @@ impl<'db> SourceAnalyzer<'db> {
11691169
)
11701170
}
11711171
TyKind::FnDef(fn_id, subst) => {
1172-
let fn_id = hir_ty::db::InternedCallableDefId::from(*fn_id);
1173-
let fn_id = db.lookup_intern_callable_def(fn_id);
1172+
let fn_id = ToChalk::from_chalk(db, *fn_id);
11741173
let generic_def_id = match fn_id {
11751174
CallableDefId::StructId(id) => id.into(),
11761175
CallableDefId::FunctionId(id) => id.into(),

0 commit comments

Comments
 (0)