Skip to content

Remove InternedCallableDefId #19997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/hir-ty/src/chalk_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
}
}
Expand Down
7 changes: 0 additions & 7 deletions crates/hir-ty/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
4 changes: 2 additions & 2 deletions crates/hir-ty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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)
}
Expand Down
20 changes: 4 additions & 16 deletions crates/hir-ty/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
}
}

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/mir/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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));
Expand Down
9 changes: 3 additions & 6 deletions crates/hir-ty/src/mir/lower/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 2 additions & 3 deletions crates/hir/src/source_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down