From 0caec7d250affd042e51d035fb6d86c0f7f25f94 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 18 Jun 2019 20:07:35 +0300 Subject: rename XSignature -> XData --- crates/ra_hir/src/code_model.rs | 46 +++++++++++++++---------------- crates/ra_hir/src/db.rs | 16 +++++------ crates/ra_hir/src/lib.rs | 4 +-- crates/ra_hir/src/ty/infer.rs | 25 ++++++++--------- crates/ra_hir/src/ty/lower.rs | 15 +++++----- crates/ra_hir/src/ty/method_resolution.rs | 8 +++--- 6 files changed, 55 insertions(+), 59 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 6602d1220..10f975b31 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -519,9 +519,8 @@ pub struct Function { pub(crate) id: FunctionId, } -/// The declared signature of a function. #[derive(Debug, Clone, PartialEq, Eq)] -pub struct FnSignature { +pub struct FnData { pub(crate) name: Name, pub(crate) params: Vec, pub(crate) ret_type: TypeRef, @@ -530,11 +529,11 @@ pub struct FnSignature { pub(crate) has_self_param: bool, } -impl FnSignature { - pub(crate) fn fn_signature_query( +impl FnData { + pub(crate) fn fn_data_query( db: &(impl DefDatabase + AstDatabase), func: Function, - ) -> Arc { + ) -> Arc { let src = func.source(db); let name = src.ast.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); let mut params = Vec::new(); @@ -569,7 +568,7 @@ impl FnSignature { TypeRef::unit() }; - let sig = FnSignature { name, params, ret_type, has_self_param }; + let sig = FnData { name, params, ret_type, has_self_param }; Arc::new(sig) } pub fn name(&self) -> &Name { @@ -597,7 +596,7 @@ impl Function { } pub fn name(self, db: &impl HirDatabase) -> Name { - self.signature(db).name.clone() + self.data(db).name.clone() } pub(crate) fn body_source_map(self, db: &impl HirDatabase) -> Arc { @@ -612,8 +611,8 @@ impl Function { db.type_for_def(self.into(), Namespace::Values) } - pub fn signature(self, db: &impl HirDatabase) -> Arc { - db.fn_signature(self) + pub fn data(self, db: &impl HirDatabase) -> Arc { + db.fn_data(self) } pub fn infer(self, db: &impl HirDatabase) -> Arc { @@ -670,8 +669,8 @@ impl Const { self.id.module(db) } - pub fn signature(self, db: &impl HirDatabase) -> Arc { - db.const_signature(self) + pub fn data(self, db: &impl HirDatabase) -> Arc { + db.const_data(self) } pub fn infer(self, db: &impl HirDatabase) -> Arc { @@ -696,14 +695,13 @@ impl Const { } } -/// The declared signature of a const. #[derive(Debug, Clone, PartialEq, Eq)] -pub struct ConstSignature { +pub struct ConstData { pub(crate) name: Name, pub(crate) type_ref: TypeRef, } -impl ConstSignature { +impl ConstData { pub fn name(&self) -> &Name { &self.name } @@ -712,27 +710,27 @@ impl ConstSignature { &self.type_ref } - pub(crate) fn const_signature_query( + pub(crate) fn const_data_query( db: &(impl DefDatabase + AstDatabase), konst: Const, - ) -> Arc { + ) -> Arc { let node = konst.source(db).ast; - const_signature_for(&*node) + const_data_for(&*node) } - pub(crate) fn static_signature_query( + pub(crate) fn static_data_query( db: &(impl DefDatabase + AstDatabase), konst: Static, - ) -> Arc { + ) -> Arc { let node = konst.source(db).ast; - const_signature_for(&*node) + const_data_for(&*node) } } -fn const_signature_for(node: &N) -> Arc { +fn const_data_for(node: &N) -> Arc { let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); - let sig = ConstSignature { name, type_ref }; + let sig = ConstData { name, type_ref }; Arc::new(sig) } @@ -746,8 +744,8 @@ impl Static { self.id.module(db) } - pub fn signature(self, db: &impl HirDatabase) -> Arc { - db.static_signature(self) + pub fn data(self, db: &impl HirDatabase) -> Arc { + db.static_data(self) } /// Builds a resolver for code inside this item. diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index c4dd54596..23c36014b 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -6,9 +6,9 @@ use ra_db::{SourceDatabase, salsa}; use crate::{ HirFileId, MacroDefId, AstIdMap, ErasedFileAstId, Crate, Module, MacroCallLoc, - Function, FnSignature, ExprScopes, TypeAlias, + Function, FnData, ExprScopes, TypeAlias, Struct, Enum, StructField, - Const, ConstSignature, Static, + Const, ConstData, Static, DefWithBody, Trait, ids, nameres::{Namespace, ImportSourceMap, RawItems, CrateDefMap}, @@ -109,17 +109,17 @@ pub trait DefDatabase: SourceDatabase { #[salsa::invoke(crate::generics::GenericParams::generic_params_query)] fn generic_params(&self, def: GenericDef) -> Arc; - #[salsa::invoke(crate::FnSignature::fn_signature_query)] - fn fn_signature(&self, func: Function) -> Arc; + #[salsa::invoke(crate::FnData::fn_data_query)] + fn fn_data(&self, func: Function) -> Arc; #[salsa::invoke(crate::type_alias::type_alias_data_query)] fn type_alias_data(&self, typ: TypeAlias) -> Arc; - #[salsa::invoke(crate::ConstSignature::const_signature_query)] - fn const_signature(&self, konst: Const) -> Arc; + #[salsa::invoke(crate::ConstData::const_data_query)] + fn const_data(&self, konst: Const) -> Arc; - #[salsa::invoke(crate::ConstSignature::static_signature_query)] - fn static_signature(&self, konst: Static) -> Arc; + #[salsa::invoke(crate::ConstData::static_data_query)] + fn static_data(&self, konst: Static) -> Arc; #[salsa::invoke(crate::lang_item::LangItems::lang_items_query)] fn lang_items(&self, krate: Crate) -> Arc; diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 2e99bdac8..f07a36926 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -75,9 +75,9 @@ pub use self::code_model::{ DefWithBody, Module, ModuleDef, ModuleSource, Struct, Union, Enum, EnumVariant, - Function, FnSignature, + Function, FnData, StructField, FieldSource, - Static, Const, ConstSignature, + Static, Const, ConstData, Trait, TypeAlias, MacroDef, Container, BuiltinType, src::{Source, HasSource}, diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 1ee40c70a..2c05ca734 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -27,7 +27,7 @@ use ra_prof::profile; use test_utils::tested_by; use crate::{ - Function, StructField, Path, Name, FnSignature, AdtDef, ConstSignature, HirDatabase, + Function, StructField, Path, Name, FnData, AdtDef, ConstData, HirDatabase, DefWithBody, ImplItem, type_ref::{TypeRef, Mutability}, expr::{ @@ -59,9 +59,9 @@ pub fn infer_query(db: &impl HirDatabase, def: DefWithBody) -> Arc ctx.collect_const_signature(&c.signature(db)), - DefWithBody::Function(ref f) => ctx.collect_fn_signature(&f.signature(db)), - DefWithBody::Static(ref s) => ctx.collect_const_signature(&s.signature(db)), + DefWithBody::Const(ref c) => ctx.collect_const(&c.data(db)), + DefWithBody::Function(ref f) => ctx.collect_fn(&f.data(db)), + DefWithBody::Static(ref s) => ctx.collect_const(&s.data(db)), } ctx.infer_body(); @@ -509,8 +509,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let item: crate::ModuleDef = ty.iterate_impl_items(self.db, krate, |item| { let matching_def: Option = match item { crate::ImplItem::Method(func) => { - let sig = func.signature(self.db); - if segment.name == *sig.name() { + if segment.name == func.name(self.db) { Some(func.into()) } else { None @@ -518,8 +517,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } crate::ImplItem::Const(konst) => { - let sig = konst.signature(self.db); - if segment.name == *sig.name() { + let data = konst.data(self.db); + if segment.name == *data.name() { Some(konst.into()) } else { None @@ -1283,18 +1282,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { ty } - fn collect_const_signature(&mut self, signature: &ConstSignature) { - self.return_ty = self.make_ty(signature.type_ref()); + fn collect_const(&mut self, data: &ConstData) { + self.return_ty = self.make_ty(data.type_ref()); } - fn collect_fn_signature(&mut self, signature: &FnSignature) { + fn collect_fn(&mut self, data: &FnData) { let body = Arc::clone(&self.body); // avoid borrow checker problem - for (type_ref, pat) in signature.params().iter().zip(body.params()) { + for (type_ref, pat) in data.params().iter().zip(body.params()) { let ty = self.make_ty(type_ref); self.infer_pat(*pat, &ty, BindingMode::default()); } - self.return_ty = self.make_ty(signature.ret_type()); + self.return_ty = self.make_ty(data.ret_type()); } fn infer_body(&mut self) { diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 300616a53..cb494baf4 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -353,11 +353,10 @@ pub(crate) fn generic_defaults(db: &impl HirDatabase, def: GenericDef) -> Substs } fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { - let signature = def.signature(db); + let data = def.data(db); let resolver = def.resolver(db); - let params = - signature.params().iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::>(); - let ret = Ty::from_hir(db, &resolver, signature.ret_type()); + let params = data.params().iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::>(); + let ret = Ty::from_hir(db, &resolver, data.ret_type()); FnSig::from_params_and_return(params, ret) } @@ -371,18 +370,18 @@ fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { /// Build the declared type of a const. fn type_for_const(db: &impl HirDatabase, def: Const) -> Ty { - let signature = def.signature(db); + let data = def.data(db); let resolver = def.resolver(db); - Ty::from_hir(db, &resolver, signature.type_ref()) + Ty::from_hir(db, &resolver, data.type_ref()) } /// Build the declared type of a static. fn type_for_static(db: &impl HirDatabase, def: Static) -> Ty { - let signature = def.signature(db); + let data = def.data(db); let resolver = def.resolver(db); - Ty::from_hir(db, &resolver, signature.type_ref()) + Ty::from_hir(db, &resolver, data.type_ref()) } /// Build the declared type of a static. diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index ad26d591c..46ec136bd 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -192,8 +192,8 @@ fn iterate_trait_method_candidates( let mut known_implemented = false; for item in data.items() { if let TraitItem::Function(m) = *item { - let sig = m.signature(db); - if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { + let data = m.data(db); + if name.map_or(true, |name| data.name() == name) && data.has_self_param() { if !known_implemented { let trait_ref = canonical_trait_ref(db, t, ty.clone()); if db.implements(krate, trait_ref).is_none() { @@ -227,8 +227,8 @@ fn iterate_inherent_methods( for impl_block in impls.lookup_impl_blocks(&ty.value) { for item in impl_block.items(db) { if let ImplItem::Method(f) = item { - let sig = f.signature(db); - if name.map_or(true, |name| sig.name() == name) && sig.has_self_param() { + let data = f.data(db); + if name.map_or(true, |name| data.name() == name) && data.has_self_param() { if let Some(result) = callback(&ty.value, f) { return Some(result); } -- cgit v1.2.3