diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-08 11:52:43 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-08 11:52:43 +0000 |
commit | 596e6db46c9c79b2b2be20a4b5461dca35d44b0f (patch) | |
tree | e2ed14ae5aaf7756b1b8f19eaf1318102bd9a26b /crates/ra_hir/src | |
parent | 7a6b6ed0a5311cabee9d68a89100aed46523243b (diff) | |
parent | e2cc55207619f987fd5cc274628b8e49e15ec856 (diff) |
Merge #2499
2499: Remove ty from code_model r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 92 | ||||
-rw-r--r-- | crates/ra_hir/src/from_id.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 24 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 4 |
5 files changed, 37 insertions, 104 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 9cbea024a..7ac1bf461 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; | |||
7 | use either::Either; | 7 | use either::Either; |
8 | use hir_def::{ | 8 | use hir_def::{ |
9 | adt::VariantData, | 9 | adt::VariantData, |
10 | body::{Body, BodySourceMap}, | ||
11 | builtin_type::BuiltinType, | 10 | builtin_type::BuiltinType, |
12 | docs::Documentation, | 11 | docs::Documentation, |
13 | expr::{BindingAnnotation, Pat, PatId}, | 12 | expr::{BindingAnnotation, Pat, PatId}, |
@@ -24,14 +23,15 @@ use hir_expand::{ | |||
24 | name::{self, AsName}, | 23 | name::{self, AsName}, |
25 | MacroDefId, | 24 | MacroDefId, |
26 | }; | 25 | }; |
27 | use hir_ty::expr::ExprValidator; | 26 | use hir_ty::{ |
27 | autoderef, display::HirFormatter, expr::ExprValidator, ApplicationTy, Canonical, InEnvironment, | ||
28 | TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk, | ||
29 | }; | ||
28 | use ra_db::{CrateId, Edition, FileId}; | 30 | use ra_db::{CrateId, Edition, FileId}; |
29 | use ra_syntax::ast; | 31 | use ra_syntax::ast; |
30 | 32 | ||
31 | use crate::{ | 33 | use crate::{ |
32 | db::{DefDatabase, HirDatabase}, | 34 | db::{DefDatabase, HirDatabase}, |
33 | ty::display::HirFormatter, | ||
34 | ty::{self, InEnvironment, InferenceResult, TraitEnvironment, Ty, TyDefId, TypeCtor, TypeWalk}, | ||
35 | CallableDef, HirDisplay, InFile, Name, | 35 | CallableDef, HirDisplay, InFile, Name, |
36 | }; | 36 | }; |
37 | 37 | ||
@@ -88,10 +88,6 @@ impl Crate { | |||
88 | pub fn all(db: &impl DefDatabase) -> Vec<Crate> { | 88 | pub fn all(db: &impl DefDatabase) -> Vec<Crate> { |
89 | db.crate_graph().iter().map(|id| Crate { id }).collect() | 89 | db.crate_graph().iter().map(|id| Crate { id }).collect() |
90 | } | 90 | } |
91 | |||
92 | pub fn crate_id(self) -> CrateId { | ||
93 | self.id | ||
94 | } | ||
95 | } | 91 | } |
96 | 92 | ||
97 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 93 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -511,44 +507,8 @@ impl Function { | |||
511 | db.function_data(self.id).params.clone() | 507 | db.function_data(self.id).params.clone() |
512 | } | 508 | } |
513 | 509 | ||
514 | pub fn body_source_map(self, db: &impl HirDatabase) -> Arc<BodySourceMap> { | ||
515 | db.body_with_source_map(self.id.into()).1 | ||
516 | } | ||
517 | |||
518 | pub fn body(self, db: &impl HirDatabase) -> Arc<Body> { | ||
519 | db.body(self.id.into()) | ||
520 | } | ||
521 | |||
522 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | ||
523 | db.infer(self.id.into()) | ||
524 | } | ||
525 | |||
526 | /// The containing impl block, if this is a method. | ||
527 | pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> { | ||
528 | match self.container(db) { | ||
529 | Some(Container::ImplBlock(it)) => Some(it), | ||
530 | _ => None, | ||
531 | } | ||
532 | } | ||
533 | |||
534 | /// The containing trait, if this is a trait method definition. | ||
535 | pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> { | ||
536 | match self.container(db) { | ||
537 | Some(Container::Trait(it)) => Some(it), | ||
538 | _ => None, | ||
539 | } | ||
540 | } | ||
541 | |||
542 | pub fn container(self, db: &impl DefDatabase) -> Option<Container> { | ||
543 | match self.id.lookup(db).container { | ||
544 | ContainerId::TraitId(it) => Some(Container::Trait(it.into())), | ||
545 | ContainerId::ImplId(it) => Some(Container::ImplBlock(it.into())), | ||
546 | ContainerId::ModuleId(_) => None, | ||
547 | } | ||
548 | } | ||
549 | |||
550 | pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { | 510 | pub fn diagnostics(self, db: &impl HirDatabase, sink: &mut DiagnosticSink) { |
551 | let infer = self.infer(db); | 511 | let infer = db.infer(self.id.into()); |
552 | infer.add_diagnostics(db, self.id, sink); | 512 | infer.add_diagnostics(db, self.id, sink); |
553 | let mut validator = ExprValidator::new(self.id, infer, sink); | 513 | let mut validator = ExprValidator::new(self.id, infer, sink); |
554 | validator.validate_body(db); | 514 | validator.validate_body(db); |
@@ -573,10 +533,6 @@ impl Const { | |||
573 | db.const_data(self.id).name.clone() | 533 | db.const_data(self.id).name.clone() |
574 | } | 534 | } |
575 | 535 | ||
576 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | ||
577 | db.infer(self.id.into()) | ||
578 | } | ||
579 | |||
580 | /// The containing impl block, if this is a type alias. | 536 | /// The containing impl block, if this is a type alias. |
581 | pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> { | 537 | pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> { |
582 | match self.container(db) { | 538 | match self.container(db) { |
@@ -615,10 +571,6 @@ impl Static { | |||
615 | pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { | 571 | pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { |
616 | Some(self.module(db).krate()) | 572 | Some(self.module(db).krate()) |
617 | } | 573 | } |
618 | |||
619 | pub fn infer(self, db: &impl HirDatabase) -> Arc<InferenceResult> { | ||
620 | db.infer(self.id.into()) | ||
621 | } | ||
622 | } | 574 | } |
623 | 575 | ||
624 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 576 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -733,15 +685,6 @@ impl AssocItem { | |||
733 | AssocItem::TypeAlias(t) => t.module(db), | 685 | AssocItem::TypeAlias(t) => t.module(db), |
734 | } | 686 | } |
735 | } | 687 | } |
736 | |||
737 | pub fn container(self, db: &impl DefDatabase) -> Container { | ||
738 | match self { | ||
739 | AssocItem::Function(f) => f.container(db), | ||
740 | AssocItem::Const(c) => c.container(db), | ||
741 | AssocItem::TypeAlias(t) => t.container(db), | ||
742 | } | ||
743 | .expect("AssocItem without container") | ||
744 | } | ||
745 | } | 688 | } |
746 | 689 | ||
747 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] | 690 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] |
@@ -958,7 +901,7 @@ impl Type { | |||
958 | pub fn fields(&self, db: &impl HirDatabase) -> Vec<(StructField, Type)> { | 901 | pub fn fields(&self, db: &impl HirDatabase) -> Vec<(StructField, Type)> { |
959 | if let Ty::Apply(a_ty) = &self.ty.value { | 902 | if let Ty::Apply(a_ty) = &self.ty.value { |
960 | match a_ty.ctor { | 903 | match a_ty.ctor { |
961 | ty::TypeCtor::Adt(AdtId::StructId(s)) => { | 904 | TypeCtor::Adt(AdtId::StructId(s)) => { |
962 | let var_def = s.into(); | 905 | let var_def = s.into(); |
963 | return db | 906 | return db |
964 | .field_types(var_def) | 907 | .field_types(var_def) |
@@ -980,7 +923,7 @@ impl Type { | |||
980 | let mut res = Vec::new(); | 923 | let mut res = Vec::new(); |
981 | if let Ty::Apply(a_ty) = &self.ty.value { | 924 | if let Ty::Apply(a_ty) = &self.ty.value { |
982 | match a_ty.ctor { | 925 | match a_ty.ctor { |
983 | ty::TypeCtor::Tuple { .. } => { | 926 | TypeCtor::Tuple { .. } => { |
984 | for ty in a_ty.parameters.iter() { | 927 | for ty in a_ty.parameters.iter() { |
985 | let ty = ty.clone().subst(&a_ty.parameters); | 928 | let ty = ty.clone().subst(&a_ty.parameters); |
986 | res.push(self.derived(ty)); | 929 | res.push(self.derived(ty)); |
@@ -1016,10 +959,10 @@ impl Type { | |||
1016 | pub fn autoderef<'a>(&'a self, db: &'a impl HirDatabase) -> impl Iterator<Item = Type> + 'a { | 959 | pub fn autoderef<'a>(&'a self, db: &'a impl HirDatabase) -> impl Iterator<Item = Type> + 'a { |
1017 | // There should be no inference vars in types passed here | 960 | // There should be no inference vars in types passed here |
1018 | // FIXME check that? | 961 | // FIXME check that? |
1019 | let canonical = crate::ty::Canonical { value: self.ty.value.clone(), num_vars: 0 }; | 962 | let canonical = Canonical { value: self.ty.value.clone(), num_vars: 0 }; |
1020 | let environment = self.ty.environment.clone(); | 963 | let environment = self.ty.environment.clone(); |
1021 | let ty = InEnvironment { value: canonical, environment: environment.clone() }; | 964 | let ty = InEnvironment { value: canonical, environment: environment.clone() }; |
1022 | ty::autoderef(db, Some(self.krate), ty) | 965 | autoderef(db, Some(self.krate), ty) |
1023 | .map(|canonical| canonical.value) | 966 | .map(|canonical| canonical.value) |
1024 | .map(move |ty| self.derived(ty)) | 967 | .map(move |ty| self.derived(ty)) |
1025 | } | 968 | } |
@@ -1059,15 +1002,14 @@ impl Type { | |||
1059 | // FIXME: provide required accessors such that it becomes implementable from outside. | 1002 | // FIXME: provide required accessors such that it becomes implementable from outside. |
1060 | pub fn is_equal_for_find_impls(&self, other: &Type) -> bool { | 1003 | pub fn is_equal_for_find_impls(&self, other: &Type) -> bool { |
1061 | match (&self.ty.value, &other.ty.value) { | 1004 | match (&self.ty.value, &other.ty.value) { |
1062 | (Ty::Apply(a_original_ty), Ty::Apply(ty::ApplicationTy { ctor, parameters })) => { | 1005 | (Ty::Apply(a_original_ty), Ty::Apply(ApplicationTy { ctor, parameters })) => match ctor |
1063 | match ctor { | 1006 | { |
1064 | TypeCtor::Ref(..) => match parameters.as_single() { | 1007 | TypeCtor::Ref(..) => match parameters.as_single() { |
1065 | Ty::Apply(a_ty) => a_original_ty.ctor == a_ty.ctor, | 1008 | Ty::Apply(a_ty) => a_original_ty.ctor == a_ty.ctor, |
1066 | _ => false, | 1009 | _ => false, |
1067 | }, | 1010 | }, |
1068 | _ => a_original_ty.ctor == *ctor, | 1011 | _ => a_original_ty.ctor == *ctor, |
1069 | } | 1012 | }, |
1070 | } | ||
1071 | _ => false, | 1013 | _ => false, |
1072 | } | 1014 | } |
1073 | } | 1015 | } |
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::{ | |||
9 | }; | 9 | }; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | Adt, AssocItem, AttrDef, Crate, DefWithBody, EnumVariant, GenericDef, ModuleDef, StructField, | 12 | Adt, AssocItem, AttrDef, DefWithBody, EnumVariant, GenericDef, ModuleDef, StructField, |
13 | VariantDef, | 13 | VariantDef, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | impl From<ra_db::CrateId> for Crate { | ||
17 | fn from(id: ra_db::CrateId) -> Self { | ||
18 | Crate { id } | ||
19 | } | ||
20 | } | ||
21 | |||
22 | macro_rules! from_id { | 16 | macro_rules! from_id { |
23 | ($(($id:path, $ty:path)),*) => {$( | 17 | ($(($id:path, $ty:path)),*) => {$( |
24 | impl From<$id> for $ty { | 18 | impl From<$id> for $ty { |
@@ -26,10 +20,16 @@ macro_rules! from_id { | |||
26 | $ty { id } | 20 | $ty { id } |
27 | } | 21 | } |
28 | } | 22 | } |
23 | impl From<$ty> for $id { | ||
24 | fn from(ty: $ty) -> $id { | ||
25 | ty.id | ||
26 | } | ||
27 | } | ||
29 | )*} | 28 | )*} |
30 | } | 29 | } |
31 | 30 | ||
32 | from_id![ | 31 | from_id![ |
32 | (ra_db::CrateId, crate::Crate), | ||
33 | (hir_def::ModuleId, crate::Module), | 33 | (hir_def::ModuleId, crate::Module), |
34 | (hir_def::StructId, crate::Struct), | 34 | (hir_def::StructId, crate::Struct), |
35 | (hir_def::UnionId, crate::Union), | 35 | (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; | |||
31 | pub mod db; | 31 | pub mod db; |
32 | pub mod source_binder; | 32 | pub mod source_binder; |
33 | 33 | ||
34 | mod ty; | ||
35 | pub mod diagnostics; | 34 | pub mod diagnostics; |
36 | 35 | ||
37 | mod from_id; | 36 | mod from_id; |
@@ -48,11 +47,6 @@ pub use crate::{ | |||
48 | }, | 47 | }, |
49 | from_source::FromSource, | 48 | from_source::FromSource, |
50 | source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, | 49 | source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, |
51 | ty::{ | ||
52 | display::HirDisplay, | ||
53 | primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness, Uncertain}, | ||
54 | ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk, | ||
55 | }, | ||
56 | }; | 50 | }; |
57 | 51 | ||
58 | pub use hir_def::{ | 52 | pub use hir_def::{ |
@@ -66,3 +60,4 @@ pub use hir_def::{ | |||
66 | pub use hir_expand::{ | 60 | pub use hir_expand::{ |
67 | name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, | 61 | name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, |
68 | }; | 62 | }; |
63 | 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::{ | |||
22 | use hir_expand::{ | 22 | use hir_expand::{ |
23 | hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind, | 23 | hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind, |
24 | }; | 24 | }; |
25 | use hir_ty::{ | ||
26 | method_resolution::{self, implements_trait}, | ||
27 | Canonical, InEnvironment, InferenceResult, TraitEnvironment, Ty, | ||
28 | }; | ||
25 | use ra_syntax::{ | 29 | use ra_syntax::{ |
26 | ast::{self, AstNode}, | 30 | ast::{self, AstNode}, |
27 | match_ast, AstPtr, | 31 | match_ast, AstPtr, |
@@ -30,13 +34,9 @@ use ra_syntax::{ | |||
30 | }; | 34 | }; |
31 | 35 | ||
32 | use crate::{ | 36 | use crate::{ |
33 | db::HirDatabase, | 37 | db::HirDatabase, Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, |
34 | ty::{ | 38 | ImplBlock, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, |
35 | method_resolution::{self, implements_trait}, | 39 | TypeParam, |
36 | InEnvironment, TraitEnvironment, Ty, | ||
37 | }, | ||
38 | Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, ImplBlock, Local, | ||
39 | MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, | ||
40 | }; | 40 | }; |
41 | 41 | ||
42 | fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> { | 42 | fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> { |
@@ -100,7 +100,7 @@ pub struct SourceAnalyzer { | |||
100 | resolver: Resolver, | 100 | resolver: Resolver, |
101 | body_owner: Option<DefWithBody>, | 101 | body_owner: Option<DefWithBody>, |
102 | body_source_map: Option<Arc<BodySourceMap>>, | 102 | body_source_map: Option<Arc<BodySourceMap>>, |
103 | infer: Option<Arc<crate::ty::InferenceResult>>, | 103 | infer: Option<Arc<InferenceResult>>, |
104 | scopes: Option<Arc<ExprScopes>>, | 104 | scopes: Option<Arc<ExprScopes>>, |
105 | } | 105 | } |
106 | 106 | ||
@@ -376,7 +376,7 @@ impl SourceAnalyzer { | |||
376 | // There should be no inference vars in types passed here | 376 | // There should be no inference vars in types passed here |
377 | // FIXME check that? | 377 | // FIXME check that? |
378 | // FIXME replace Unknown by bound vars here | 378 | // FIXME replace Unknown by bound vars here |
379 | let canonical = crate::ty::Canonical { value: ty.ty.value.clone(), num_vars: 0 }; | 379 | let canonical = Canonical { value: ty.ty.value.clone(), num_vars: 0 }; |
380 | method_resolution::iterate_method_candidates( | 380 | method_resolution::iterate_method_candidates( |
381 | &canonical, | 381 | &canonical, |
382 | db, | 382 | db, |
@@ -400,7 +400,7 @@ impl SourceAnalyzer { | |||
400 | // There should be no inference vars in types passed here | 400 | // There should be no inference vars in types passed here |
401 | // FIXME check that? | 401 | // FIXME check that? |
402 | // FIXME replace Unknown by bound vars here | 402 | // FIXME replace Unknown by bound vars here |
403 | let canonical = crate::ty::Canonical { value: ty.ty.value.clone(), num_vars: 0 }; | 403 | let canonical = Canonical { value: ty.ty.value.clone(), num_vars: 0 }; |
404 | method_resolution::iterate_method_candidates( | 404 | method_resolution::iterate_method_candidates( |
405 | &canonical, | 405 | &canonical, |
406 | db, | 406 | db, |
@@ -418,7 +418,7 @@ impl SourceAnalyzer { | |||
418 | // ) -> impl Iterator<Item = Ty> + 'a { | 418 | // ) -> impl Iterator<Item = Ty> + 'a { |
419 | // // There should be no inference vars in types passed here | 419 | // // There should be no inference vars in types passed here |
420 | // // FIXME check that? | 420 | // // FIXME check that? |
421 | // let canonical = crate::ty::Canonical { value: ty, num_vars: 0 }; | 421 | // let canonical = Canonical { value: ty, num_vars: 0 }; |
422 | // let krate = self.resolver.krate(); | 422 | // let krate = self.resolver.krate(); |
423 | // let environment = TraitEnvironment::lower(db, &self.resolver); | 423 | // let environment = TraitEnvironment::lower(db, &self.resolver); |
424 | // let ty = crate::ty::InEnvironment { value: canonical, environment }; | 424 | // let ty = crate::ty::InEnvironment { value: canonical, environment }; |
@@ -440,7 +440,7 @@ impl SourceAnalyzer { | |||
440 | _ => return false, | 440 | _ => return false, |
441 | }; | 441 | }; |
442 | 442 | ||
443 | let canonical_ty = crate::ty::Canonical { value: ty, num_vars: 0 }; | 443 | let canonical_ty = Canonical { value: ty, num_vars: 0 }; |
444 | implements_trait(&canonical_ty, db, &self.resolver, krate.into(), std_future_trait) | 444 | implements_trait(&canonical_ty, db, &self.resolver, krate.into(), std_future_trait) |
445 | } | 445 | } |
446 | 446 | ||
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 @@ | |||
1 | //! The type system. We currently use this to infer types for completion, hover | ||
2 | //! information and various assists. | ||
3 | |||
4 | pub use hir_ty::*; | ||