aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-31 07:55:15 +0000
committerGitHub <[email protected]>2019-10-31 07:55:15 +0000
commit7973c91281837bbb5c5a0bf3b1c71a5b52654b20 (patch)
tree8459ba446606dd0920a87de23276a8c5f80fd58a /crates
parent51092ee72aa87787a65645ccdf82d3cb5a015915 (diff)
parentb20d37cb49536e19f6af57b00258f86eb8f19325 (diff)
Merge #2140
2140: move builtin types to hir_def r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model.rs48
-rw-r--r--crates/ra_hir/src/lib.rs7
-rw-r--r--crates/ra_hir/src/nameres.rs5
-rw-r--r--crates/ra_hir/src/resolve.rs4
-rw-r--r--crates/ra_hir/src/ty/lower.rs16
-rw-r--r--crates/ra_hir/src/ty/primitive.rs22
-rw-r--r--crates/ra_hir_def/src/builtin_type.rs63
-rw-r--r--crates/ra_hir_def/src/lib.rs1
8 files changed, 88 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;
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use hir_def::{ 8use hir_def::{
9 builtin_type::BuiltinType,
9 type_ref::{Mutability, TypeRef}, 10 type_ref::{Mutability, TypeRef},
10 CrateModuleId, ModuleId, 11 CrateModuleId, ModuleId,
11}; 12};
12use hir_expand::name::{ 13use 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};
16use ra_db::{CrateId, Edition}; 14use ra_db::{CrateId, Edition};
17use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; 15use 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)]
91pub enum BuiltinType {
92 Char,
93 Bool,
94 Str,
95 Int(IntTy),
96 Float(FloatTy),
97}
98
99impl 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)]
127pub enum ModuleDef { 87pub 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
83pub use hir_def::{ 83pub 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
55use std::sync::Arc; 55use std::sync::Arc;
56 56
57use hir_def::CrateModuleId; 57use hir_def::{builtin_type::BuiltinType, CrateModuleId};
58use once_cell::sync::Lazy; 58use once_cell::sync::Lazy;
59use ra_arena::Arena; 59use ra_arena::Arena;
60use ra_db::{Edition, FileId}; 60use 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
75pub use self::per_ns::{Namespace, PerNs}; 74pub 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 @@
2use std::sync::Arc; 2use std::sync::Arc;
3 3
4use hir_def::{ 4use 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;
9use std::sync::Arc; 9use std::sync::Arc;
10 10
11use hir_def::{ 11use 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
33impl Ty { 37impl 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
3use std::fmt; 3use std::fmt;
4 4
5#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] 5pub use hir_def::builtin_type::{FloatBitness, IntBitness, Signedness};
6pub enum Signedness {
7 Signed,
8 Unsigned,
9}
10
11#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
12pub enum IntBitness {
13 Xsize,
14 X8,
15 X16,
16 X32,
17 X64,
18 X128,
19}
20
21#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
22pub 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)]
28pub enum UncertainIntTy { 8pub enum UncertainIntTy {
diff --git a/crates/ra_hir_def/src/builtin_type.rs b/crates/ra_hir_def/src/builtin_type.rs
new file mode 100644
index 000000000..12929caa9
--- /dev/null
+++ b/crates/ra_hir_def/src/builtin_type.rs
@@ -0,0 +1,63 @@
1//! This module defines built-in types.
2//!
3//! A peculiarity of built-in types is that they are always available and are
4//! not associated with any particular crate.
5
6use hir_expand::name::{self, Name};
7
8#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
9pub enum Signedness {
10 Signed,
11 Unsigned,
12}
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
15pub enum IntBitness {
16 Xsize,
17 X8,
18 X16,
19 X32,
20 X64,
21 X128,
22}
23
24#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
25pub enum FloatBitness {
26 X32,
27 X64,
28}
29
30#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31pub enum BuiltinType {
32 Char,
33 Bool,
34 Str,
35 Int { signedness: Signedness, bitness: IntBitness },
36 Float { bitness: FloatBitness },
37}
38
39impl BuiltinType {
40 #[rustfmt::skip]
41 pub const ALL: &'static [(Name, BuiltinType)] = &[
42 (name::CHAR, BuiltinType::Char),
43 (name::BOOL, BuiltinType::Bool),
44 (name::STR, BuiltinType::Str ),
45
46 (name::ISIZE, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::Xsize }),
47 (name::I8, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X8 }),
48 (name::I16, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X16 }),
49 (name::I32, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X32 }),
50 (name::I64, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X64 }),
51 (name::I128, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X128 }),
52
53 (name::USIZE, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize }),
54 (name::U8, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X8 }),
55 (name::U16, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X16 }),
56 (name::U32, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X32 }),
57 (name::U64, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X64 }),
58 (name::U128, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X128 }),
59
60 (name::F32, BuiltinType::Float { bitness: FloatBitness::X32 }),
61 (name::F64, BuiltinType::Float { bitness: FloatBitness::X64 }),
62 ];
63}
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 7a6c7b301..8cbff673c 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -11,6 +11,7 @@ pub mod db;
11pub mod attr; 11pub mod attr;
12pub mod path; 12pub mod path;
13pub mod type_ref; 13pub mod type_ref;
14pub mod builtin_type;
14 15
15// FIXME: this should be private 16// FIXME: this should be private
16pub mod nameres; 17pub mod nameres;