Skip to content

Commit 468982e

Browse files
bors[bot]matklad
andauthored
Merge #5405
5405: Align CallableDefId naming with other ids r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 8a88023 + b5ce84b commit 468982e

File tree

14 files changed

+69
-67
lines changed

14 files changed

+69
-67
lines changed

crates/ra_hir/src/code_model.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use stdx::impl_from;
4040
use crate::{
4141
db::{DefDatabase, HirDatabase},
4242
has_source::HasSource,
43-
CallableDef, HirDisplay, InFile, Name,
43+
CallableDefId, HirDisplay, InFile, Name,
4444
};
4545

4646
/// hir::Crate describes a single crate. It's the main interface with which
@@ -1226,7 +1226,7 @@ impl Type {
12261226
}
12271227

12281228
// FIXME: this method is broken, as it doesn't take closures into account.
1229-
pub fn as_callable(&self) -> Option<CallableDef> {
1229+
pub fn as_callable(&self) -> Option<CallableDefId> {
12301230
Some(self.ty.value.as_callable()?.0)
12311231
}
12321232

crates/ra_hir/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ pub use hir_expand::{
5555
hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId,
5656
MacroFile, Origin,
5757
};
58-
pub use hir_ty::{display::HirDisplay, CallableDef};
58+
pub use hir_ty::{display::HirDisplay, CallableDefId};

crates/ra_hir_ty/src/db.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use ra_prof::profile;
1313
use crate::{
1414
method_resolution::{InherentImpls, TraitImpls},
1515
traits::chalk,
16-
Binders, CallableDef, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig,
16+
Binders, CallableDefId, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig,
1717
ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId,
1818
};
1919
use hir_expand::name::Name;
@@ -45,7 +45,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
4545
fn field_types(&self, var: VariantId) -> Arc<ArenaMap<LocalFieldId, Binders<Ty>>>;
4646

4747
#[salsa::invoke(crate::callable_item_sig)]
48-
fn callable_item_signature(&self, def: CallableDef) -> PolyFnSig;
48+
fn callable_item_signature(&self, def: CallableDefId) -> PolyFnSig;
4949

5050
#[salsa::invoke(crate::lower::return_type_impl_traits)]
5151
fn return_type_impl_traits(
@@ -77,7 +77,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
7777

7878
// Interned IDs for Chalk integration
7979
#[salsa::interned]
80-
fn intern_callable_def(&self, callable_def: CallableDef) -> crate::CallableDefId;
80+
fn intern_callable_def(&self, callable_def: CallableDefId) -> InternedCallableDefId;
8181
#[salsa::interned]
8282
fn intern_type_param_id(&self, param_id: TypeParamId) -> GlobalTypeParamId;
8383
#[salsa::interned]
@@ -151,3 +151,9 @@ impl_intern_key!(InternedOpaqueTyId);
151151
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
152152
pub struct ClosureId(salsa::InternId);
153153
impl_intern_key!(ClosureId);
154+
155+
/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
156+
/// we have different IDs for struct and enum variant constructors.
157+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
158+
pub struct InternedCallableDefId(salsa::InternId);
159+
impl_intern_key!(InternedCallableDefId);

crates/ra_hir_ty/src/diagnostics/unsafe_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use hir_def::{
1111
use hir_expand::diagnostics::DiagnosticSink;
1212

1313
use crate::{
14-
db::HirDatabase, diagnostics::MissingUnsafe, lower::CallableDef, ApplicationTy,
14+
db::HirDatabase, diagnostics::MissingUnsafe, lower::CallableDefId, ApplicationTy,
1515
InferenceResult, Ty, TypeCtor,
1616
};
1717

@@ -88,7 +88,7 @@ fn walk_unsafe(
8888
Expr::Call { callee, .. } => {
8989
let ty = &infer[*callee];
9090
if let &Ty::Apply(ApplicationTy {
91-
ctor: TypeCtor::FnDef(CallableDef::FunctionId(func)),
91+
ctor: TypeCtor::FnDef(CallableDefId::FunctionId(func)),
9292
..
9393
}) = ty
9494
{

crates/ra_hir_ty/src/display.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::fmt;
44

55
use crate::{
6-
db::HirDatabase, utils::generics, ApplicationTy, CallableDef, FnSig, GenericPredicate,
6+
db::HirDatabase, utils::generics, ApplicationTy, CallableDefId, FnSig, GenericPredicate,
77
Obligation, OpaqueTyId, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
88
};
99
use hir_def::{
@@ -263,9 +263,11 @@ impl HirDisplay for ApplicationTy {
263263
TypeCtor::FnDef(def) => {
264264
let sig = f.db.callable_item_signature(def).subst(&self.parameters);
265265
match def {
266-
CallableDef::FunctionId(ff) => write!(f, "fn {}", f.db.function_data(ff).name)?,
267-
CallableDef::StructId(s) => write!(f, "{}", f.db.struct_data(s).name)?,
268-
CallableDef::EnumVariantId(e) => {
266+
CallableDefId::FunctionId(ff) => {
267+
write!(f, "fn {}", f.db.function_data(ff).name)?
268+
}
269+
CallableDefId::StructId(s) => write!(f, "{}", f.db.struct_data(s).name)?,
270+
CallableDefId::EnumVariantId(e) => {
269271
write!(f, "{}", f.db.enum_data(e.parent).variants[e.local_id].name)?
270272
}
271273
};

crates/ra_hir_ty/src/infer/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
autoderef, method_resolution, op,
1818
traits::{FnTrait, InEnvironment},
1919
utils::{generics, variant_data, Generics},
20-
ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Rawness, Substs,
20+
ApplicationTy, Binders, CallableDefId, InferTy, IntTy, Mutability, Obligation, Rawness, Substs,
2121
TraitRef, Ty, TypeCtor,
2222
};
2323

@@ -854,7 +854,7 @@ impl<'a> InferenceContext<'a> {
854854
}
855855
// add obligation for trait implementation, if this is a trait method
856856
match def {
857-
CallableDef::FunctionId(f) => {
857+
CallableDefId::FunctionId(f) => {
858858
if let AssocContainerId::TraitId(trait_) =
859859
f.lookup(self.db.upcast()).container
860860
{
@@ -865,7 +865,7 @@ impl<'a> InferenceContext<'a> {
865865
self.obligations.push(Obligation::Trait(TraitRef { trait_, substs }));
866866
}
867867
}
868-
CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {}
868+
CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => {}
869869
}
870870
}
871871
}

crates/ra_hir_ty/src/lib.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use hir_def::{
3333
TypeParamId,
3434
};
3535
use itertools::Itertools;
36-
use ra_db::{impl_intern_key, salsa, CrateId};
36+
use ra_db::{salsa, CrateId};
3737

3838
use crate::{
3939
db::HirDatabase,
@@ -44,7 +44,7 @@ use crate::{
4444

4545
pub use autoderef::autoderef;
4646
pub use infer::{InferTy, InferenceResult};
47-
pub use lower::CallableDef;
47+
pub use lower::CallableDefId;
4848
pub use lower::{
4949
associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId,
5050
TyLoweringContext, ValueTyDefId,
@@ -102,7 +102,7 @@ pub enum TypeCtor {
102102
/// fn foo() -> i32 { 1 }
103103
/// let bar = foo; // bar: fn() -> i32 {foo}
104104
/// ```
105-
FnDef(CallableDef),
105+
FnDef(CallableDefId),
106106

107107
/// A pointer to a function. Written as `fn() -> i32`.
108108
///
@@ -140,12 +140,6 @@ pub enum TypeCtor {
140140
Closure { def: DefWithBodyId, expr: ExprId },
141141
}
142142

143-
/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
144-
/// we have different IDs for struct and enum variant constructors.
145-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
146-
pub struct CallableDefId(salsa::InternId);
147-
impl_intern_key!(CallableDefId);
148-
149143
impl TypeCtor {
150144
pub fn num_ty_params(self, db: &dyn HirDatabase) -> usize {
151145
match self {
@@ -773,7 +767,7 @@ impl Ty {
773767
}
774768
}
775769

776-
pub fn as_callable(&self) -> Option<(CallableDef, &Substs)> {
770+
pub fn as_callable(&self) -> Option<(CallableDefId, &Substs)> {
777771
match self {
778772
Ty::Apply(ApplicationTy { ctor: TypeCtor::FnDef(callable_def), parameters }) => {
779773
Some((*callable_def, parameters))

crates/ra_hir_ty/src/lower.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -768,11 +768,11 @@ fn count_impl_traits(type_ref: &TypeRef) -> usize {
768768
}
769769

770770
/// Build the signature of a callable item (function, struct or enum variant).
771-
pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDef) -> PolyFnSig {
771+
pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDefId) -> PolyFnSig {
772772
match def {
773-
CallableDef::FunctionId(f) => fn_sig_for_fn(db, f),
774-
CallableDef::StructId(s) => fn_sig_for_struct_constructor(db, s),
775-
CallableDef::EnumVariantId(e) => fn_sig_for_enum_variant_constructor(db, e),
773+
CallableDefId::FunctionId(f) => fn_sig_for_fn(db, f),
774+
CallableDefId::StructId(s) => fn_sig_for_struct_constructor(db, s),
775+
CallableDefId::EnumVariantId(e) => fn_sig_for_enum_variant_constructor(db, e),
776776
}
777777
}
778778

@@ -1107,31 +1107,31 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
11071107
}
11081108

11091109
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1110-
pub enum CallableDef {
1110+
pub enum CallableDefId {
11111111
FunctionId(FunctionId),
11121112
StructId(StructId),
11131113
EnumVariantId(EnumVariantId),
11141114
}
1115-
impl_from!(FunctionId, StructId, EnumVariantId for CallableDef);
1115+
impl_from!(FunctionId, StructId, EnumVariantId for CallableDefId);
11161116

1117-
impl CallableDef {
1117+
impl CallableDefId {
11181118
pub fn krate(self, db: &dyn HirDatabase) -> CrateId {
11191119
let db = db.upcast();
11201120
match self {
1121-
CallableDef::FunctionId(f) => f.lookup(db).module(db),
1122-
CallableDef::StructId(s) => s.lookup(db).container.module(db),
1123-
CallableDef::EnumVariantId(e) => e.parent.lookup(db).container.module(db),
1121+
CallableDefId::FunctionId(f) => f.lookup(db).module(db),
1122+
CallableDefId::StructId(s) => s.lookup(db).container.module(db),
1123+
CallableDefId::EnumVariantId(e) => e.parent.lookup(db).container.module(db),
11241124
}
11251125
.krate
11261126
}
11271127
}
11281128

1129-
impl From<CallableDef> for GenericDefId {
1130-
fn from(def: CallableDef) -> GenericDefId {
1129+
impl From<CallableDefId> for GenericDefId {
1130+
fn from(def: CallableDefId) -> GenericDefId {
11311131
match def {
1132-
CallableDef::FunctionId(f) => f.into(),
1133-
CallableDef::StructId(s) => s.into(),
1134-
CallableDef::EnumVariantId(e) => e.into(),
1132+
CallableDefId::FunctionId(f) => f.into(),
1133+
CallableDefId::StructId(s) => s.into(),
1134+
CallableDefId::EnumVariantId(e) => e.into(),
11351135
}
11361136
}
11371137
}

crates/ra_hir_ty/src/traits/chalk.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
display::HirDisplay,
1919
method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS},
2020
utils::generics,
21-
CallableDef, DebruijnIndex, FnSig, GenericPredicate, Substs, Ty, TypeCtor,
21+
CallableDefId, DebruijnIndex, FnSig, GenericPredicate, Substs, Ty, TypeCtor,
2222
};
2323
use mapping::{
2424
convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue,
@@ -525,7 +525,7 @@ pub(crate) fn fn_def_datum_query(
525525
_krate: CrateId,
526526
fn_def_id: FnDefId,
527527
) -> Arc<FnDefDatum> {
528-
let callable_def: CallableDef = from_chalk(db, fn_def_id);
528+
let callable_def: CallableDefId = from_chalk(db, fn_def_id);
529529
let generic_params = generics(db.upcast(), callable_def.into());
530530
let sig = db.callable_item_signature(callable_def);
531531
let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST);
@@ -552,14 +552,14 @@ pub(crate) fn fn_def_datum_query(
552552
Arc::new(datum)
553553
}
554554

555-
impl From<FnDefId> for crate::CallableDefId {
555+
impl From<FnDefId> for crate::db::InternedCallableDefId {
556556
fn from(fn_def_id: FnDefId) -> Self {
557557
InternKey::from_intern_id(fn_def_id.0)
558558
}
559559
}
560560

561-
impl From<crate::CallableDefId> for FnDefId {
562-
fn from(callable_def_id: crate::CallableDefId) -> Self {
561+
impl From<crate::db::InternedCallableDefId> for FnDefId {
562+
fn from(callable_def_id: crate::db::InternedCallableDefId) -> Self {
563563
chalk_ir::FnDefId(callable_def_id.as_intern_id())
564564
}
565565
}

crates/ra_hir_ty/src/traits/chalk/mapping.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
db::HirDatabase,
1717
primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness},
1818
traits::{Canonical, Obligation},
19-
ApplicationTy, CallableDef, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId,
19+
ApplicationTy, CallableDefId, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId,
2020
ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeCtor,
2121
};
2222

@@ -454,14 +454,14 @@ impl ToChalk for hir_def::ImplId {
454454
}
455455
}
456456

457-
impl ToChalk for CallableDef {
457+
impl ToChalk for CallableDefId {
458458
type Chalk = FnDefId;
459459

460460
fn to_chalk(self, db: &dyn HirDatabase) -> FnDefId {
461461
db.intern_callable_def(self).into()
462462
}
463463

464-
fn from_chalk(db: &dyn HirDatabase, fn_def_id: FnDefId) -> CallableDef {
464+
fn from_chalk(db: &dyn HirDatabase, fn_def_id: FnDefId) -> CallableDefId {
465465
db.lookup_intern_callable_def(fn_def_id.into())
466466
}
467467
}

crates/ra_hir_ty/src/traits/chalk/tls.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplicat
55
use itertools::Itertools;
66

77
use super::{from_chalk, Interner};
8-
use crate::{db::HirDatabase, CallableDef, TypeCtor};
8+
use crate::{db::HirDatabase, CallableDefId, TypeCtor};
99
use hir_def::{AdtId, AssocContainerId, DefWithBodyId, Lookup, TypeAliasId};
1010

1111
pub use unsafe_tls::{set_current_program, with_current_program};
@@ -38,16 +38,16 @@ impl DebugContext<'_> {
3838
}
3939
TypeCtor::FnDef(def) => {
4040
let name = match def {
41-
CallableDef::FunctionId(ff) => self.0.function_data(ff).name.clone(),
42-
CallableDef::StructId(s) => self.0.struct_data(s).name.clone(),
43-
CallableDef::EnumVariantId(e) => {
41+
CallableDefId::FunctionId(ff) => self.0.function_data(ff).name.clone(),
42+
CallableDefId::StructId(s) => self.0.struct_data(s).name.clone(),
43+
CallableDefId::EnumVariantId(e) => {
4444
let enum_data = self.0.enum_data(e.parent);
4545
enum_data.variants[e.local_id].name.clone()
4646
}
4747
};
4848
match def {
49-
CallableDef::FunctionId(_) => write!(f, "{{fn {}}}", name)?,
50-
CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {
49+
CallableDefId::FunctionId(_) => write!(f, "{{fn {}}}", name)?,
50+
CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => {
5151
write!(f, "{{ctor {}}}", name)?
5252
}
5353
}
@@ -255,18 +255,18 @@ impl DebugContext<'_> {
255255
fn_def_id: chalk_ir::FnDefId<Interner>,
256256
fmt: &mut fmt::Formatter<'_>,
257257
) -> Result<(), fmt::Error> {
258-
let def: CallableDef = from_chalk(self.0, fn_def_id);
258+
let def: CallableDefId = from_chalk(self.0, fn_def_id);
259259
let name = match def {
260-
CallableDef::FunctionId(ff) => self.0.function_data(ff).name.clone(),
261-
CallableDef::StructId(s) => self.0.struct_data(s).name.clone(),
262-
CallableDef::EnumVariantId(e) => {
260+
CallableDefId::FunctionId(ff) => self.0.function_data(ff).name.clone(),
261+
CallableDefId::StructId(s) => self.0.struct_data(s).name.clone(),
262+
CallableDefId::EnumVariantId(e) => {
263263
let enum_data = self.0.enum_data(e.parent);
264264
enum_data.variants[e.local_id].name.clone()
265265
}
266266
};
267267
match def {
268-
CallableDef::FunctionId(_) => write!(fmt, "{{fn {}}}", name),
269-
CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {
268+
CallableDefId::FunctionId(_) => write!(fmt, "{{fn {}}}", name),
269+
CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => {
270270
write!(fmt, "{{ctor {}}}", name)
271271
}
272272
}

crates/ra_ide/src/call_hierarchy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub(crate) fn outgoing_calls(db: &RootDatabase, position: FilePosition) -> Optio
9797
//FIXME: Type::as_callable is broken
9898
let callable_def = sema.type_of_expr(&expr.expr()?)?.as_callable()?;
9999
match callable_def {
100-
hir::CallableDef::FunctionId(it) => {
100+
hir::CallableDefId::FunctionId(it) => {
101101
let fn_def: hir::Function = it.into();
102102
let nav = fn_def.to_nav(db);
103103
Some(nav)

crates/ra_ide/src/call_info.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ fn call_info_for_token(sema: &Semantics<RootDatabase>, token: SyntaxToken) -> Op
5353
//FIXME: Type::as_callable is broken
5454
let callable_def = sema.type_of_expr(&call.expr()?)?.as_callable()?;
5555
match callable_def {
56-
hir::CallableDef::FunctionId(it) => {
56+
hir::CallableDefId::FunctionId(it) => {
5757
let fn_def = it.into();
5858
FunctionSignature::from_hir(sema.db, fn_def)
5959
}
60-
hir::CallableDef::StructId(it) => {
60+
hir::CallableDefId::StructId(it) => {
6161
FunctionSignature::from_struct(sema.db, it.into())?
6262
}
63-
hir::CallableDef::EnumVariantId(it) => {
63+
hir::CallableDefId::EnumVariantId(it) => {
6464
FunctionSignature::from_enum_variant(sema.db, it.into())?
6565
}
6666
}

crates/ra_ide/src/inlay_hints.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,13 @@ fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<
324324
// FIXME: Type::as_callable is broken for closures
325325
let callable_def = sema.type_of_expr(&expr.expr()?)?.as_callable()?;
326326
match callable_def {
327-
hir::CallableDef::FunctionId(it) => {
327+
hir::CallableDefId::FunctionId(it) => {
328328
Some(FunctionSignature::from_hir(sema.db, it.into()))
329329
}
330-
hir::CallableDef::StructId(it) => {
330+
hir::CallableDefId::StructId(it) => {
331331
FunctionSignature::from_struct(sema.db, it.into())
332332
}
333-
hir::CallableDef::EnumVariantId(it) => {
333+
hir::CallableDefId::EnumVariantId(it) => {
334334
FunctionSignature::from_enum_variant(sema.db, it.into())
335335
}
336336
}

0 commit comments

Comments
 (0)