From b017bae8370e166034ac569c357b662358d45f19 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 8 Dec 2019 12:26:53 +0100 Subject: remove `infer` method from CodeModel --- crates/ra_hir/src/code_model.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9cbea024a..0100ac91c 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -31,7 +31,7 @@ use ra_syntax::ast; use crate::{ db::{DefDatabase, HirDatabase}, ty::display::HirFormatter, - ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk}, + ty::{self, InEnvironment, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk}, CallableDef, HirDisplay, InFile, Name, }; @@ -519,10 +519,6 @@ impl Function { db.body(self.id.into()) } - pub fn infer(self, db: &impl HirDatabase) -> Arc { - db.infer(self.id.into()) - } - /// The containing impl block, if this is a method. pub fn impl_block(self, db: &impl DefDatabase) -> Option { match self.container(db) { @@ -548,7 +544,7 @@ impl Function { } pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { - let infer = self.infer(db); + let infer = db.infer(self.id.into()); infer.add_diagnostics(db, self.id, sink); let mut validator = ExprValidator::new(self.id, infer, sink); validator.validate_body(db); @@ -573,10 +569,6 @@ impl Const { db.const_data(self.id).name.clone() } - pub fn infer(self, db: &impl HirDatabase) -> Arc { - db.infer(self.id.into()) - } - /// The containing impl block, if this is a type alias. pub fn impl_block(self, db: &impl DefDatabase) -> Option { match self.container(db) { @@ -615,10 +607,6 @@ impl Static { pub fn krate(self, db: &impl DefDatabase) -> Option { Some(self.module(db).krate()) } - - pub fn infer(self, db: &impl HirDatabase) -> Arc { - db.infer(self.id.into()) - } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -- cgit v1.2.3 From b77d7c24aa929e53a2bc2a0ffa319de9bf1ab1fa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 8 Dec 2019 12:27:21 +0100 Subject: Remove bodies from code_model --- crates/ra_hir/src/code_model.rs | 9 --------- 1 file changed, 9 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 0100ac91c..906716dfc 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -7,7 +7,6 @@ use std::sync::Arc; use either::Either; use hir_def::{ adt::VariantData, - body::{Body, BodySourceMap}, builtin_type::BuiltinType, docs::Documentation, expr::{BindingAnnotation, Pat, PatId}, @@ -511,14 +510,6 @@ impl Function { db.function_data(self.id).params.clone() } - pub fn body_source_map(self, db: &impl HirDatabase) -> Arc { - db.body_with_source_map(self.id.into()).1 - } - - pub fn body(self, db: &impl HirDatabase) -> Arc { - db.body(self.id.into()) - } - /// The containing impl block, if this is a method. pub fn impl_block(self, db: &impl DefDatabase) -> Option { match self.container(db) { -- cgit v1.2.3 From b37c6a746b6c7cf85dc1ec6e40ac41455b8f2ec0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 8 Dec 2019 12:44:14 +0100 Subject: Remove ty from code_model --- crates/ra_hir/src/code_model.rs | 36 ++++++++++++++++-------------------- crates/ra_hir/src/from_id.rs | 14 +++++++------- crates/ra_hir/src/lib.rs | 7 +------ crates/ra_hir/src/source_binder.rs | 24 ++++++++++++------------ crates/ra_hir/src/ty.rs | 4 ---- 5 files changed, 36 insertions(+), 49 deletions(-) delete mode 100644 crates/ra_hir/src/ty.rs (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 906716dfc..3d956afa7 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -23,14 +23,15 @@ use hir_expand::{ name::{self, AsName}, MacroDefId, }; -use hir_ty::expr::ExprValidator; +use hir_ty::{ + autoderef, display::HirFormatter, expr::ExprValidator, ApplicationTy, Canonical, InEnvironment, + TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk, +}; use ra_db::{CrateId, Edition, FileId}; use ra_syntax::ast; use crate::{ db::{DefDatabase, HirDatabase}, - ty::display::HirFormatter, - ty::{self, InEnvironment, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk}, CallableDef, HirDisplay, InFile, Name, }; @@ -87,10 +88,6 @@ impl Crate { pub fn all(db: &impl DefDatabase) -> Vec { db.crate_graph().iter().map(|id| Crate { id }).collect() } - - pub fn crate_id(self) -> CrateId { - self.id - } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -937,7 +934,7 @@ impl Type { pub fn fields(&self, db: &impl HirDatabase) -> Vec<(StructField, Type)> { if let Ty::Apply(a_ty) = &self.ty.value { match a_ty.ctor { - ty::TypeCtor::Adt(AdtId::StructId(s)) => { + TypeCtor::Adt(AdtId::StructId(s)) => { let var_def = s.into(); return db .field_types(var_def) @@ -959,7 +956,7 @@ impl Type { let mut res = Vec::new(); if let Ty::Apply(a_ty) = &self.ty.value { match a_ty.ctor { - ty::TypeCtor::Tuple { .. } => { + TypeCtor::Tuple { .. } => { for ty in a_ty.parameters.iter() { let ty = ty.clone().subst(&a_ty.parameters); res.push(self.derived(ty)); @@ -995,10 +992,10 @@ impl Type { pub fn autoderef<'a>(&'a self, db: &'a impl HirDatabase) -> impl Iterator + 'a { // There should be no inference vars in types passed here // FIXME check that? - let canonical = crate::ty::Canonical { value: self.ty.value.clone(), num_vars: 0 }; + let canonical = Canonical { value: self.ty.value.clone(), num_vars: 0 }; let environment = self.ty.environment.clone(); let ty = InEnvironment { value: canonical, environment: environment.clone() }; - ty::autoderef(db, Some(self.krate), ty) + autoderef(db, Some(self.krate), ty) .map(|canonical| canonical.value) .map(move |ty| self.derived(ty)) } @@ -1038,15 +1035,14 @@ impl Type { // FIXME: provide required accessors such that it becomes implementable from outside. pub fn is_equal_for_find_impls(&self, other: &Type) -> bool { match (&self.ty.value, &other.ty.value) { - (Ty::Apply(a_original_ty), Ty::Apply(ty::ApplicationTy { ctor, parameters })) => { - match ctor { - TypeCtor::Ref(..) => match parameters.as_single() { - Ty::Apply(a_ty) => a_original_ty.ctor == a_ty.ctor, - _ => false, - }, - _ => a_original_ty.ctor == *ctor, - } - } + (Ty::Apply(a_original_ty), Ty::Apply(ApplicationTy { ctor, parameters })) => match ctor + { + TypeCtor::Ref(..) => match parameters.as_single() { + Ty::Apply(a_ty) => a_original_ty.ctor == a_ty.ctor, + _ => false, + }, + _ => a_original_ty.ctor == *ctor, + }, _ => false, } } diff --git a/crates/ra_hir/src/from_id.rs b/crates/ra_hir/src/from_id.rs index 0398d0ee6..75a1a7772 100644 --- a/crates/ra_hir/src/from_id.rs +++ b/crates/ra_hir/src/from_id.rs @@ -9,16 +9,10 @@ use hir_def::{ }; use crate::{ - Adt, AssocItem, AttrDef, Crate, DefWithBody, EnumVariant, GenericDef, ModuleDef, StructField, + Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, GenericDef, ModuleDef, StructField, VariantDef, }; -impl From for Crate { - fn from(id: ra_db::CrateId) -> Self { - Crate { id } - } -} - macro_rules! from_id { ($(($id:path, $ty:path)),*) => {$( impl From<$id> for $ty { @@ -26,10 +20,16 @@ macro_rules! from_id { $ty { id } } } + impl From<$ty> for $id { + fn from(ty: $ty) -> $id { + ty.id + } + } )*} } from_id![ + (ra_db::CrateId, crate::Crate), (hir_def::ModuleId, crate::Module), (hir_def::StructId, crate::Struct), (hir_def::UnionId, crate::Union), diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 9eb34b5dc..bb22882b1 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -31,7 +31,6 @@ pub mod debug; pub mod db; pub mod source_binder; -mod ty; pub mod diagnostics; mod from_id; @@ -48,11 +47,6 @@ pub use crate::{ }, from_source::FromSource, source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, - ty::{ - display::HirDisplay, - primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness, Uncertain}, - ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk, - }, }; pub use hir_def::{ @@ -66,3 +60,4 @@ pub use hir_def::{ pub use hir_expand::{ name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, }; +pub use hir_ty::{display::HirDisplay, CallableDef}; diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index c5a920688..9efd0477c 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -22,6 +22,10 @@ use hir_def::{ use hir_expand::{ hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind, }; +use hir_ty::{ + method_resolution::{self, implements_trait}, + Canonical, InEnvironment, InferenceResult, TraitEnvironment, Ty, +}; use ra_syntax::{ ast::{self, AstNode}, match_ast, AstPtr, @@ -30,13 +34,9 @@ use ra_syntax::{ }; use crate::{ - db::HirDatabase, - ty::{ - method_resolution::{self, implements_trait}, - InEnvironment, TraitEnvironment, Ty, - }, - Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, ImplBlock, Local, - MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, + db::HirDatabase, Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, + ImplBlock, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, + TypeParam, }; fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option { @@ -100,7 +100,7 @@ pub struct SourceAnalyzer { resolver: Resolver, body_owner: Option, body_source_map: Option>, - infer: Option>, + infer: Option>, scopes: Option>, } @@ -376,7 +376,7 @@ impl SourceAnalyzer { // There should be no inference vars in types passed here // FIXME check that? // FIXME replace Unknown by bound vars here - let canonical = crate::ty::Canonical { value: ty.ty.value.clone(), num_vars: 0 }; + let canonical = Canonical { value: ty.ty.value.clone(), num_vars: 0 }; method_resolution::iterate_method_candidates( &canonical, db, @@ -400,7 +400,7 @@ impl SourceAnalyzer { // There should be no inference vars in types passed here // FIXME check that? // FIXME replace Unknown by bound vars here - let canonical = crate::ty::Canonical { value: ty.ty.value.clone(), num_vars: 0 }; + let canonical = Canonical { value: ty.ty.value.clone(), num_vars: 0 }; method_resolution::iterate_method_candidates( &canonical, db, @@ -418,7 +418,7 @@ impl SourceAnalyzer { // ) -> impl Iterator + 'a { // // There should be no inference vars in types passed here // // FIXME check that? - // let canonical = crate::ty::Canonical { value: ty, num_vars: 0 }; + // let canonical = Canonical { value: ty, num_vars: 0 }; // let krate = self.resolver.krate(); // let environment = TraitEnvironment::lower(db, &self.resolver); // let ty = crate::ty::InEnvironment { value: canonical, environment }; @@ -440,7 +440,7 @@ impl SourceAnalyzer { _ => return false, }; - let canonical_ty = crate::ty::Canonical { value: ty, num_vars: 0 }; + let canonical_ty = Canonical { value: ty, num_vars: 0 }; implements_trait(&canonical_ty, db, &self.resolver, krate.into(), std_future_trait) } diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs deleted file mode 100644 index 4ed69c00d..000000000 --- a/crates/ra_hir/src/ty.rs +++ /dev/null @@ -1,4 +0,0 @@ -//! The type system. We currently use this to infer types for completion, hover -//! information and various assists. - -pub use hir_ty::*; -- cgit v1.2.3 From e2cc55207619f987fd5cc274628b8e49e15ec856 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 8 Dec 2019 12:51:25 +0100 Subject: Remove dead code --- crates/ra_hir/src/code_model.rs | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3d956afa7..7ac1bf461 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -507,30 +507,6 @@ impl Function { db.function_data(self.id).params.clone() } - /// The containing impl block, if this is a method. - pub fn impl_block(self, db: &impl DefDatabase) -> Option { - match self.container(db) { - Some(Container::ImplBlock(it)) => Some(it), - _ => None, - } - } - - /// The containing trait, if this is a trait method definition. - pub fn parent_trait(self, db: &impl DefDatabase) -> Option { - match self.container(db) { - Some(Container::Trait(it)) => Some(it), - _ => None, - } - } - - pub fn container(self, db: &impl DefDatabase) -> Option { - match self.id.lookup(db).container { - ContainerId::TraitId(it) => Some(Container::Trait(it.into())), - ContainerId::ImplId(it) => Some(Container::ImplBlock(it.into())), - ContainerId::ModuleId(_) => None, - } - } - pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { let infer = db.infer(self.id.into()); infer.add_diagnostics(db, self.id, sink); @@ -709,15 +685,6 @@ impl AssocItem { AssocItem::TypeAlias(t) => t.module(db), } } - - pub fn container(self, db: &impl DefDatabase) -> Container { - match self { - AssocItem::Function(f) => f.container(db), - AssocItem::Const(c) => c.container(db), - AssocItem::TypeAlias(t) => t.container(db), - } - .expect("AssocItem without container") - } } #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] -- cgit v1.2.3