From b598ab8be46b50d5f407c3858c7b2c788328edc7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 13:13:17 +0200 Subject: Rename CallableDefId -> InternedCallabelDefid --- crates/ra_hir_ty/src/db.rs | 8 +++++++- crates/ra_hir_ty/src/lib.rs | 8 +------- crates/ra_hir_ty/src/traits/chalk.rs | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'crates/ra_hir_ty') diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index 608bab1b1..cad3856c9 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs @@ -77,7 +77,7 @@ pub trait HirDatabase: DefDatabase + Upcast { // Interned IDs for Chalk integration #[salsa::interned] - fn intern_callable_def(&self, callable_def: CallableDef) -> crate::CallableDefId; + fn intern_callable_def(&self, callable_def: CallableDef) -> InternedCallableDefId; #[salsa::interned] fn intern_type_param_id(&self, param_id: TypeParamId) -> GlobalTypeParamId; #[salsa::interned] @@ -151,3 +151,9 @@ impl_intern_key!(InternedOpaqueTyId); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct ClosureId(salsa::InternId); impl_intern_key!(ClosureId); + +/// This exists just for Chalk, because Chalk just has a single `FnDefId` where +/// we have different IDs for struct and enum variant constructors. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] +pub struct InternedCallableDefId(salsa::InternId); +impl_intern_key!(InternedCallableDefId); diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 9f034eca5..72b089604 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -33,7 +33,7 @@ use hir_def::{ TypeParamId, }; use itertools::Itertools; -use ra_db::{impl_intern_key, salsa, CrateId}; +use ra_db::{salsa, CrateId}; use crate::{ db::HirDatabase, @@ -140,12 +140,6 @@ pub enum TypeCtor { Closure { def: DefWithBodyId, expr: ExprId }, } -/// This exists just for Chalk, because Chalk just has a single `FnDefId` where -/// we have different IDs for struct and enum variant constructors. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] -pub struct CallableDefId(salsa::InternId); -impl_intern_key!(CallableDefId); - impl TypeCtor { pub fn num_ty_params(self, db: &dyn HirDatabase) -> usize { match self { diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 1ef5baa05..e0a6cfe88 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -552,14 +552,14 @@ pub(crate) fn fn_def_datum_query( Arc::new(datum) } -impl From for crate::CallableDefId { +impl From for crate::db::InternedCallableDefId { fn from(fn_def_id: FnDefId) -> Self { InternKey::from_intern_id(fn_def_id.0) } } -impl From for FnDefId { - fn from(callable_def_id: crate::CallableDefId) -> Self { +impl From for FnDefId { + fn from(callable_def_id: crate::db::InternedCallableDefId) -> Self { chalk_ir::FnDefId(callable_def_id.as_intern_id()) } } -- cgit v1.2.3 From b5ce84b17023d27f4e96ec7911aca712db0e000b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 16 Jul 2020 13:15:00 +0200 Subject: Align CallableDefId naming with other ids --- crates/ra_hir_ty/src/db.rs | 6 ++--- crates/ra_hir_ty/src/diagnostics/unsafe_check.rs | 4 ++-- crates/ra_hir_ty/src/display.rs | 10 ++++---- crates/ra_hir_ty/src/infer/expr.rs | 6 ++--- crates/ra_hir_ty/src/lib.rs | 6 ++--- crates/ra_hir_ty/src/lower.rs | 30 ++++++++++++------------ crates/ra_hir_ty/src/traits/chalk.rs | 4 ++-- crates/ra_hir_ty/src/traits/chalk/mapping.rs | 6 ++--- crates/ra_hir_ty/src/traits/chalk/tls.rs | 24 +++++++++---------- 9 files changed, 49 insertions(+), 47 deletions(-) (limited to 'crates/ra_hir_ty') diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index cad3856c9..c773adc67 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs @@ -13,7 +13,7 @@ use ra_prof::profile; use crate::{ method_resolution::{InherentImpls, TraitImpls}, traits::chalk, - Binders, CallableDef, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig, + Binders, CallableDefId, GenericPredicate, InferenceResult, OpaqueTyId, PolyFnSig, ReturnTypeImplTraits, TraitRef, Ty, TyDefId, ValueTyDefId, }; use hir_expand::name::Name; @@ -45,7 +45,7 @@ pub trait HirDatabase: DefDatabase + Upcast { fn field_types(&self, var: VariantId) -> Arc>>; #[salsa::invoke(crate::callable_item_sig)] - fn callable_item_signature(&self, def: CallableDef) -> PolyFnSig; + fn callable_item_signature(&self, def: CallableDefId) -> PolyFnSig; #[salsa::invoke(crate::lower::return_type_impl_traits)] fn return_type_impl_traits( @@ -77,7 +77,7 @@ pub trait HirDatabase: DefDatabase + Upcast { // Interned IDs for Chalk integration #[salsa::interned] - fn intern_callable_def(&self, callable_def: CallableDef) -> InternedCallableDefId; + fn intern_callable_def(&self, callable_def: CallableDefId) -> InternedCallableDefId; #[salsa::interned] fn intern_type_param_id(&self, param_id: TypeParamId) -> GlobalTypeParamId; #[salsa::interned] diff --git a/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs b/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs index 9e4ed9a8b..5cc76bdce 100644 --- a/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/ra_hir_ty/src/diagnostics/unsafe_check.rs @@ -11,7 +11,7 @@ use hir_def::{ use hir_expand::diagnostics::DiagnosticSink; use crate::{ - db::HirDatabase, diagnostics::MissingUnsafe, lower::CallableDef, ApplicationTy, + db::HirDatabase, diagnostics::MissingUnsafe, lower::CallableDefId, ApplicationTy, InferenceResult, Ty, TypeCtor, }; @@ -88,7 +88,7 @@ fn walk_unsafe( Expr::Call { callee, .. } => { let ty = &infer[*callee]; if let &Ty::Apply(ApplicationTy { - ctor: TypeCtor::FnDef(CallableDef::FunctionId(func)), + ctor: TypeCtor::FnDef(CallableDefId::FunctionId(func)), .. }) = ty { diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs index c860c254c..758d5f5ac 100644 --- a/crates/ra_hir_ty/src/display.rs +++ b/crates/ra_hir_ty/src/display.rs @@ -3,7 +3,7 @@ use std::fmt; use crate::{ - db::HirDatabase, utils::generics, ApplicationTy, CallableDef, FnSig, GenericPredicate, + db::HirDatabase, utils::generics, ApplicationTy, CallableDefId, FnSig, GenericPredicate, Obligation, OpaqueTyId, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, }; use hir_def::{ @@ -263,9 +263,11 @@ impl HirDisplay for ApplicationTy { TypeCtor::FnDef(def) => { let sig = f.db.callable_item_signature(def).subst(&self.parameters); match def { - CallableDef::FunctionId(ff) => write!(f, "fn {}", f.db.function_data(ff).name)?, - CallableDef::StructId(s) => write!(f, "{}", f.db.struct_data(s).name)?, - CallableDef::EnumVariantId(e) => { + CallableDefId::FunctionId(ff) => { + write!(f, "fn {}", f.db.function_data(ff).name)? + } + CallableDefId::StructId(s) => write!(f, "{}", f.db.struct_data(s).name)?, + CallableDefId::EnumVariantId(e) => { write!(f, "{}", f.db.enum_data(e.parent).variants[e.local_id].name)? } }; diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index ab586b018..731b062c2 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -17,7 +17,7 @@ use crate::{ autoderef, method_resolution, op, traits::{FnTrait, InEnvironment}, utils::{generics, variant_data, Generics}, - ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Rawness, Substs, + ApplicationTy, Binders, CallableDefId, InferTy, IntTy, Mutability, Obligation, Rawness, Substs, TraitRef, Ty, TypeCtor, }; @@ -854,7 +854,7 @@ impl<'a> InferenceContext<'a> { } // add obligation for trait implementation, if this is a trait method match def { - CallableDef::FunctionId(f) => { + CallableDefId::FunctionId(f) => { if let AssocContainerId::TraitId(trait_) = f.lookup(self.db.upcast()).container { @@ -865,7 +865,7 @@ impl<'a> InferenceContext<'a> { self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); } } - CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {} + CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => {} } } } diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 72b089604..0ef5ca78f 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -44,7 +44,7 @@ use crate::{ pub use autoderef::autoderef; pub use infer::{InferTy, InferenceResult}; -pub use lower::CallableDef; +pub use lower::CallableDefId; pub use lower::{ associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId, TyLoweringContext, ValueTyDefId, @@ -102,7 +102,7 @@ pub enum TypeCtor { /// fn foo() -> i32 { 1 } /// let bar = foo; // bar: fn() -> i32 {foo} /// ``` - FnDef(CallableDef), + FnDef(CallableDefId), /// A pointer to a function. Written as `fn() -> i32`. /// @@ -767,7 +767,7 @@ impl Ty { } } - pub fn as_callable(&self) -> Option<(CallableDef, &Substs)> { + pub fn as_callable(&self) -> Option<(CallableDefId, &Substs)> { match self { Ty::Apply(ApplicationTy { ctor: TypeCtor::FnDef(callable_def), parameters }) => { Some((*callable_def, parameters)) diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index 6f4398e84..f274579ea 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs @@ -768,11 +768,11 @@ fn count_impl_traits(type_ref: &TypeRef) -> usize { } /// Build the signature of a callable item (function, struct or enum variant). -pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDef) -> PolyFnSig { +pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDefId) -> PolyFnSig { match def { - CallableDef::FunctionId(f) => fn_sig_for_fn(db, f), - CallableDef::StructId(s) => fn_sig_for_struct_constructor(db, s), - CallableDef::EnumVariantId(e) => fn_sig_for_enum_variant_constructor(db, e), + CallableDefId::FunctionId(f) => fn_sig_for_fn(db, f), + CallableDefId::StructId(s) => fn_sig_for_struct_constructor(db, s), + CallableDefId::EnumVariantId(e) => fn_sig_for_enum_variant_constructor(db, e), } } @@ -1107,31 +1107,31 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders { } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum CallableDef { +pub enum CallableDefId { FunctionId(FunctionId), StructId(StructId), EnumVariantId(EnumVariantId), } -impl_from!(FunctionId, StructId, EnumVariantId for CallableDef); +impl_from!(FunctionId, StructId, EnumVariantId for CallableDefId); -impl CallableDef { +impl CallableDefId { pub fn krate(self, db: &dyn HirDatabase) -> CrateId { let db = db.upcast(); match self { - CallableDef::FunctionId(f) => f.lookup(db).module(db), - CallableDef::StructId(s) => s.lookup(db).container.module(db), - CallableDef::EnumVariantId(e) => e.parent.lookup(db).container.module(db), + CallableDefId::FunctionId(f) => f.lookup(db).module(db), + CallableDefId::StructId(s) => s.lookup(db).container.module(db), + CallableDefId::EnumVariantId(e) => e.parent.lookup(db).container.module(db), } .krate } } -impl From for GenericDefId { - fn from(def: CallableDef) -> GenericDefId { +impl From for GenericDefId { + fn from(def: CallableDefId) -> GenericDefId { match def { - CallableDef::FunctionId(f) => f.into(), - CallableDef::StructId(s) => s.into(), - CallableDef::EnumVariantId(e) => e.into(), + CallableDefId::FunctionId(f) => f.into(), + CallableDefId::StructId(s) => s.into(), + CallableDefId::EnumVariantId(e) => e.into(), } } } diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index e0a6cfe88..78d0bc43b 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -18,7 +18,7 @@ use crate::{ display::HirDisplay, method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, utils::generics, - CallableDef, DebruijnIndex, FnSig, GenericPredicate, Substs, Ty, TypeCtor, + CallableDefId, DebruijnIndex, FnSig, GenericPredicate, Substs, Ty, TypeCtor, }; use mapping::{ convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, @@ -525,7 +525,7 @@ pub(crate) fn fn_def_datum_query( _krate: CrateId, fn_def_id: FnDefId, ) -> Arc { - let callable_def: CallableDef = from_chalk(db, fn_def_id); + let callable_def: CallableDefId = from_chalk(db, fn_def_id); let generic_params = generics(db.upcast(), callable_def.into()); let sig = db.callable_item_signature(callable_def); let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs index a852ce2ac..09d8347ca 100644 --- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs +++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs @@ -16,7 +16,7 @@ use crate::{ db::HirDatabase, primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, traits::{Canonical, Obligation}, - ApplicationTy, CallableDef, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId, + ApplicationTy, CallableDefId, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeCtor, }; @@ -454,14 +454,14 @@ impl ToChalk for hir_def::ImplId { } } -impl ToChalk for CallableDef { +impl ToChalk for CallableDefId { type Chalk = FnDefId; fn to_chalk(self, db: &dyn HirDatabase) -> FnDefId { db.intern_callable_def(self).into() } - fn from_chalk(db: &dyn HirDatabase, fn_def_id: FnDefId) -> CallableDef { + fn from_chalk(db: &dyn HirDatabase, fn_def_id: FnDefId) -> CallableDefId { db.lookup_intern_callable_def(fn_def_id.into()) } } diff --git a/crates/ra_hir_ty/src/traits/chalk/tls.rs b/crates/ra_hir_ty/src/traits/chalk/tls.rs index 1e226baea..db915625c 100644 --- a/crates/ra_hir_ty/src/traits/chalk/tls.rs +++ b/crates/ra_hir_ty/src/traits/chalk/tls.rs @@ -5,7 +5,7 @@ use chalk_ir::{AliasTy, GenericArg, Goal, Goals, Lifetime, ProgramClauseImplicat use itertools::Itertools; use super::{from_chalk, Interner}; -use crate::{db::HirDatabase, CallableDef, TypeCtor}; +use crate::{db::HirDatabase, CallableDefId, TypeCtor}; use hir_def::{AdtId, AssocContainerId, DefWithBodyId, Lookup, TypeAliasId}; pub use unsafe_tls::{set_current_program, with_current_program}; @@ -38,16 +38,16 @@ impl DebugContext<'_> { } TypeCtor::FnDef(def) => { let name = match def { - CallableDef::FunctionId(ff) => self.0.function_data(ff).name.clone(), - CallableDef::StructId(s) => self.0.struct_data(s).name.clone(), - CallableDef::EnumVariantId(e) => { + CallableDefId::FunctionId(ff) => self.0.function_data(ff).name.clone(), + CallableDefId::StructId(s) => self.0.struct_data(s).name.clone(), + CallableDefId::EnumVariantId(e) => { let enum_data = self.0.enum_data(e.parent); enum_data.variants[e.local_id].name.clone() } }; match def { - CallableDef::FunctionId(_) => write!(f, "{{fn {}}}", name)?, - CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => { + CallableDefId::FunctionId(_) => write!(f, "{{fn {}}}", name)?, + CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => { write!(f, "{{ctor {}}}", name)? } } @@ -255,18 +255,18 @@ impl DebugContext<'_> { fn_def_id: chalk_ir::FnDefId, fmt: &mut fmt::Formatter<'_>, ) -> Result<(), fmt::Error> { - let def: CallableDef = from_chalk(self.0, fn_def_id); + let def: CallableDefId = from_chalk(self.0, fn_def_id); let name = match def { - CallableDef::FunctionId(ff) => self.0.function_data(ff).name.clone(), - CallableDef::StructId(s) => self.0.struct_data(s).name.clone(), - CallableDef::EnumVariantId(e) => { + CallableDefId::FunctionId(ff) => self.0.function_data(ff).name.clone(), + CallableDefId::StructId(s) => self.0.struct_data(s).name.clone(), + CallableDefId::EnumVariantId(e) => { let enum_data = self.0.enum_data(e.parent); enum_data.variants[e.local_id].name.clone() } }; match def { - CallableDef::FunctionId(_) => write!(fmt, "{{fn {}}}", name), - CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => { + CallableDefId::FunctionId(_) => write!(fmt, "{{fn {}}}", name), + CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => { write!(fmt, "{{ctor {}}}", name) } } -- cgit v1.2.3