diff options
author | Aleksey Kladov <[email protected]> | 2019-10-31 07:51:54 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-10-31 07:51:54 +0000 |
commit | b20d37cb49536e19f6af57b00258f86eb8f19325 (patch) | |
tree | 8459ba446606dd0920a87de23276a8c5f80fd58a /crates/ra_hir/src | |
parent | 6f4d5f7339395d854e4ba2af227de851246e528f (diff) |
move builtin types to hir_def
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 48 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/primitive.rs | 22 |
6 files changed, 24 insertions, 78 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index a6ce23dd1..e0c6d6340 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -6,13 +6,11 @@ pub(crate) mod docs; | |||
6 | use std::sync::Arc; | 6 | use std::sync::Arc; |
7 | 7 | ||
8 | use hir_def::{ | 8 | use hir_def::{ |
9 | builtin_type::BuiltinType, | ||
9 | type_ref::{Mutability, TypeRef}, | 10 | type_ref::{Mutability, TypeRef}, |
10 | CrateModuleId, ModuleId, | 11 | CrateModuleId, ModuleId, |
11 | }; | 12 | }; |
12 | use hir_expand::name::{ | 13 | use hir_expand::name::{self, AsName}; |
13 | self, AsName, BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16, | ||
14 | U32, U64, U8, USIZE, | ||
15 | }; | ||
16 | use ra_db::{CrateId, Edition}; | 14 | use ra_db::{CrateId, Edition}; |
17 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; | 15 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; |
18 | 16 | ||
@@ -30,10 +28,7 @@ use crate::{ | |||
30 | nameres::{ImportId, ModuleScope, Namespace}, | 28 | nameres::{ImportId, ModuleScope, Namespace}, |
31 | resolve::{Resolver, Scope, TypeNs}, | 29 | resolve::{Resolver, Scope, TypeNs}, |
32 | traits::TraitData, | 30 | traits::TraitData, |
33 | ty::{ | 31 | ty::{InferenceResult, TraitRef}, |
34 | primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, | ||
35 | InferenceResult, TraitRef, | ||
36 | }, | ||
37 | Either, HasSource, Name, Ty, | 32 | Either, HasSource, Name, Ty, |
38 | }; | 33 | }; |
39 | 34 | ||
@@ -87,41 +82,6 @@ pub struct Module { | |||
87 | pub(crate) id: ModuleId, | 82 | pub(crate) id: ModuleId, |
88 | } | 83 | } |
89 | 84 | ||
90 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
91 | pub enum BuiltinType { | ||
92 | Char, | ||
93 | Bool, | ||
94 | Str, | ||
95 | Int(IntTy), | ||
96 | Float(FloatTy), | ||
97 | } | ||
98 | |||
99 | impl BuiltinType { | ||
100 | #[rustfmt::skip] | ||
101 | pub(crate) const ALL: &'static [(Name, BuiltinType)] = &[ | ||
102 | (CHAR, BuiltinType::Char), | ||
103 | (BOOL, BuiltinType::Bool), | ||
104 | (STR, BuiltinType::Str), | ||
105 | |||
106 | (ISIZE, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::Xsize })), | ||
107 | (I8, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X8 })), | ||
108 | (I16, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X16 })), | ||
109 | (I32, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X32 })), | ||
110 | (I64, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X64 })), | ||
111 | (I128, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X128 })), | ||
112 | |||
113 | (USIZE, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })), | ||
114 | (U8, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })), | ||
115 | (U16, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })), | ||
116 | (U32, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })), | ||
117 | (U64, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })), | ||
118 | (U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })), | ||
119 | |||
120 | (F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })), | ||
121 | (F64, BuiltinType::Float(FloatTy { bitness: FloatBitness::X64 })), | ||
122 | ]; | ||
123 | } | ||
124 | |||
125 | /// The defs which can be visible in the module. | 85 | /// The defs which can be visible in the module. |
126 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 86 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
127 | pub enum ModuleDef { | 87 | pub enum ModuleDef { |
@@ -625,7 +585,7 @@ impl FnData { | |||
625 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { | 585 | let self_type = if let Some(type_ref) = self_param.ascribed_type() { |
626 | TypeRef::from_ast(type_ref) | 586 | TypeRef::from_ast(type_ref) |
627 | } else { | 587 | } else { |
628 | let self_type = TypeRef::Path(SELF_TYPE.into()); | 588 | let self_type = TypeRef::Path(name::SELF_TYPE.into()); |
629 | match self_param.kind() { | 589 | match self_param.kind() { |
630 | ast::SelfParamKind::Owned => self_type, | 590 | ast::SelfParamKind::Owned => self_type, |
631 | ast::SelfParamKind::Ref => { | 591 | ast::SelfParamKind::Ref => { |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 603b0c3dc..40f5562b4 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -63,9 +63,9 @@ pub use crate::{ | |||
63 | code_model::{ | 63 | code_model::{ |
64 | docs::{DocDef, Docs, Documentation}, | 64 | docs::{DocDef, Docs, Documentation}, |
65 | src::{HasBodySource, HasSource, Source}, | 65 | src::{HasBodySource, HasSource, Source}, |
66 | Adt, AssocItem, BuiltinType, Const, ConstData, Container, Crate, CrateDependency, | 66 | Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, |
67 | DefWithBody, Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, | 67 | EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, |
68 | ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, | 68 | ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, |
69 | }, | 69 | }, |
70 | expr::ExprScopes, | 70 | expr::ExprScopes, |
71 | from_source::FromSource, | 71 | from_source::FromSource, |
@@ -81,6 +81,7 @@ pub use crate::{ | |||
81 | }; | 81 | }; |
82 | 82 | ||
83 | pub use hir_def::{ | 83 | pub use hir_def::{ |
84 | builtin_type::BuiltinType, | ||
84 | path::{Path, PathKind}, | 85 | path::{Path, PathKind}, |
85 | type_ref::Mutability, | 86 | type_ref::Mutability, |
86 | }; | 87 | }; |
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 7c4d07de0..7ba031827 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -54,7 +54,7 @@ mod tests; | |||
54 | 54 | ||
55 | use std::sync::Arc; | 55 | use std::sync::Arc; |
56 | 56 | ||
57 | use hir_def::CrateModuleId; | 57 | use hir_def::{builtin_type::BuiltinType, CrateModuleId}; |
58 | use once_cell::sync::Lazy; | 58 | use once_cell::sync::Lazy; |
59 | use ra_arena::Arena; | 59 | use ra_arena::Arena; |
60 | use ra_db::{Edition, FileId}; | 60 | use ra_db::{Edition, FileId}; |
@@ -68,8 +68,7 @@ use crate::{ | |||
68 | diagnostics::DiagnosticSink, | 68 | diagnostics::DiagnosticSink, |
69 | ids::MacroDefId, | 69 | ids::MacroDefId, |
70 | nameres::diagnostics::DefDiagnostic, | 70 | nameres::diagnostics::DefDiagnostic, |
71 | Adt, AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, | 71 | Adt, AstId, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait, |
72 | Trait, | ||
73 | }; | 72 | }; |
74 | 73 | ||
75 | pub use self::per_ns::{Namespace, PerNs}; | 74 | pub use self::per_ns::{Namespace, PerNs}; |
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index f77c9df9f..75b24d386 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use hir_def::{ | 4 | use hir_def::{ |
5 | builtin_type::BuiltinType, | ||
5 | path::{Path, PathKind}, | 6 | path::{Path, PathKind}, |
6 | CrateModuleId, | 7 | CrateModuleId, |
7 | }; | 8 | }; |
@@ -18,8 +19,7 @@ use crate::{ | |||
18 | generics::GenericParams, | 19 | generics::GenericParams, |
19 | impl_block::ImplBlock, | 20 | impl_block::ImplBlock, |
20 | nameres::{CrateDefMap, PerNs}, | 21 | nameres::{CrateDefMap, PerNs}, |
21 | Adt, BuiltinType, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, | 22 | Adt, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, Trait, TypeAlias, |
22 | Trait, TypeAlias, | ||
23 | }; | 23 | }; |
24 | 24 | ||
25 | #[derive(Debug, Clone, Default)] | 25 | #[derive(Debug, Clone, Default)] |
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 0f49a0e54..dd7cd979f 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -9,6 +9,7 @@ use std::iter; | |||
9 | use std::sync::Arc; | 9 | use std::sync::Arc; |
10 | 10 | ||
11 | use hir_def::{ | 11 | use hir_def::{ |
12 | builtin_type::BuiltinType, | ||
12 | path::{GenericArg, PathSegment}, | 13 | path::{GenericArg, PathSegment}, |
13 | type_ref::{TypeBound, TypeRef}, | 14 | type_ref::{TypeBound, TypeRef}, |
14 | }; | 15 | }; |
@@ -24,10 +25,13 @@ use crate::{ | |||
24 | generics::{GenericDef, WherePredicate}, | 25 | generics::{GenericDef, WherePredicate}, |
25 | nameres::Namespace, | 26 | nameres::Namespace, |
26 | resolve::{Resolver, TypeNs}, | 27 | resolve::{Resolver, TypeNs}, |
27 | ty::Adt, | 28 | ty::{ |
29 | primitive::{FloatTy, IntTy}, | ||
30 | Adt, | ||
31 | }, | ||
28 | util::make_mut_slice, | 32 | util::make_mut_slice, |
29 | BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, | 33 | Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait, |
30 | Trait, TypeAlias, Union, | 34 | TypeAlias, Union, |
31 | }; | 35 | }; |
32 | 36 | ||
33 | impl Ty { | 37 | impl Ty { |
@@ -643,8 +647,10 @@ fn type_for_builtin(def: BuiltinType) -> Ty { | |||
643 | BuiltinType::Char => TypeCtor::Char, | 647 | BuiltinType::Char => TypeCtor::Char, |
644 | BuiltinType::Bool => TypeCtor::Bool, | 648 | BuiltinType::Bool => TypeCtor::Bool, |
645 | BuiltinType::Str => TypeCtor::Str, | 649 | BuiltinType::Str => TypeCtor::Str, |
646 | BuiltinType::Int(ty) => TypeCtor::Int(ty.into()), | 650 | BuiltinType::Int { signedness, bitness } => { |
647 | BuiltinType::Float(ty) => TypeCtor::Float(ty.into()), | 651 | TypeCtor::Int(IntTy { signedness, bitness }.into()) |
652 | } | ||
653 | BuiltinType::Float { bitness } => TypeCtor::Float(FloatTy { bitness }.into()), | ||
648 | }) | 654 | }) |
649 | } | 655 | } |
650 | 656 | ||
diff --git a/crates/ra_hir/src/ty/primitive.rs b/crates/ra_hir/src/ty/primitive.rs index 8966f9d1d..1749752f1 100644 --- a/crates/ra_hir/src/ty/primitive.rs +++ b/crates/ra_hir/src/ty/primitive.rs | |||
@@ -2,27 +2,7 @@ | |||
2 | 2 | ||
3 | use std::fmt; | 3 | use std::fmt; |
4 | 4 | ||
5 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] | 5 | pub use hir_def::builtin_type::{FloatBitness, IntBitness, Signedness}; |
6 | pub enum Signedness { | ||
7 | Signed, | ||
8 | Unsigned, | ||
9 | } | ||
10 | |||
11 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] | ||
12 | pub enum IntBitness { | ||
13 | Xsize, | ||
14 | X8, | ||
15 | X16, | ||
16 | X32, | ||
17 | X64, | ||
18 | X128, | ||
19 | } | ||
20 | |||
21 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] | ||
22 | pub enum FloatBitness { | ||
23 | X32, | ||
24 | X64, | ||
25 | } | ||
26 | 6 | ||
27 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] | 7 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] |
28 | pub enum UncertainIntTy { | 8 | pub enum UncertainIntTy { |