diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/name.rs | 30 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 19 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests/incremental.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 16 |
6 files changed, 48 insertions, 24 deletions
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml index a86dfa6b2..78808e72f 100644 --- a/crates/ra_hir/Cargo.toml +++ b/crates/ra_hir/Cargo.toml | |||
@@ -13,6 +13,7 @@ parking_lot = "0.8.0" | |||
13 | ena = "0.11" | 13 | ena = "0.11" |
14 | join_to_string = "0.1.3" | 14 | join_to_string = "0.1.3" |
15 | either = "1.5.2" | 15 | either = "1.5.2" |
16 | once_cell = "0.2" | ||
16 | 17 | ||
17 | ra_syntax = { path = "../ra_syntax" } | 18 | ra_syntax = { path = "../ra_syntax" } |
18 | ra_arena = { path = "../ra_arena" } | 19 | ra_arena = { path = "../ra_arena" } |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3053f5488..e3c765674 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -106,7 +106,7 @@ impl BuiltinType { | |||
106 | (KnownName::U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })), | 106 | (KnownName::U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })), |
107 | 107 | ||
108 | (KnownName::F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })), | 108 | (KnownName::F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })), |
109 | (KnownName::F64, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })), | 109 | (KnownName::F64, BuiltinType::Float(FloatTy { bitness: FloatBitness::X64 })), |
110 | ]; | 110 | ]; |
111 | } | 111 | } |
112 | 112 | ||
diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir/src/name.rs index e3a82cf03..e9003e00b 100644 --- a/crates/ra_hir/src/name.rs +++ b/crates/ra_hir/src/name.rs | |||
@@ -123,7 +123,7 @@ impl AsName for ra_db::Dependency { | |||
123 | // const ISIZE: Name = Name::new("isize") | 123 | // const ISIZE: Name = Name::new("isize") |
124 | // ``` | 124 | // ``` |
125 | // but const-fn is not that powerful yet. | 125 | // but const-fn is not that powerful yet. |
126 | #[derive(Debug, PartialEq, Eq)] | 126 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
127 | pub(crate) enum KnownName { | 127 | pub(crate) enum KnownName { |
128 | Isize, | 128 | Isize, |
129 | I8, | 129 | I8, |
@@ -151,3 +151,31 @@ pub(crate) enum KnownName { | |||
151 | 151 | ||
152 | MacroRules, | 152 | MacroRules, |
153 | } | 153 | } |
154 | |||
155 | impl AsName for KnownName { | ||
156 | fn as_name(&self) -> Name { | ||
157 | let s = match self { | ||
158 | KnownName::Isize => "isize", | ||
159 | KnownName::I8 => "i8", | ||
160 | KnownName::I16 => "i16", | ||
161 | KnownName::I32 => "i32", | ||
162 | KnownName::I64 => "i64", | ||
163 | KnownName::I128 => "i128", | ||
164 | KnownName::Usize => "usize", | ||
165 | KnownName::U8 => "u8", | ||
166 | KnownName::U16 => "u16", | ||
167 | KnownName::U32 => "u32", | ||
168 | KnownName::U64 => "u64", | ||
169 | KnownName::U128 => "u128", | ||
170 | KnownName::F32 => "f32", | ||
171 | KnownName::F64 => "f64", | ||
172 | KnownName::Bool => "bool", | ||
173 | KnownName::Char => "char", | ||
174 | KnownName::Str => "str", | ||
175 | KnownName::SelfType => "Self", | ||
176 | KnownName::SelfParam => "self", | ||
177 | KnownName::MacroRules => "macro_rules", | ||
178 | }; | ||
179 | Name::new(s.into()) | ||
180 | } | ||
181 | } | ||
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 51a7b8b95..aa26345b2 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -62,9 +62,10 @@ use ra_db::{FileId, Edition}; | |||
62 | use test_utils::tested_by; | 62 | use test_utils::tested_by; |
63 | use ra_syntax::ast; | 63 | use ra_syntax::ast; |
64 | use ra_prof::profile; | 64 | use ra_prof::profile; |
65 | use once_cell::sync::Lazy; | ||
65 | 66 | ||
66 | use crate::{ | 67 | use crate::{ |
67 | ModuleDef, Name, Crate, Module, MacroDef, KnownName, BuiltinType, | 68 | ModuleDef, Name, Crate, Module, MacroDef, AsName, BuiltinType, |
68 | DefDatabase, Path, PathKind, HirFileId, Trait, | 69 | DefDatabase, Path, PathKind, HirFileId, Trait, |
69 | ids::MacroDefId, | 70 | ids::MacroDefId, |
70 | diagnostics::DiagnosticSink, | 71 | diagnostics::DiagnosticSink, |
@@ -140,12 +141,22 @@ pub struct ModuleScope { | |||
140 | macros: FxHashMap<Name, MacroDef>, | 141 | macros: FxHashMap<Name, MacroDef>, |
141 | } | 142 | } |
142 | 143 | ||
144 | static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| { | ||
145 | BuiltinType::ALL | ||
146 | .iter() | ||
147 | .map(|&(known_name, ty)| { | ||
148 | (known_name.as_name(), Resolution { def: PerNs::types(ty.into()), import: None }) | ||
149 | }) | ||
150 | .collect() | ||
151 | }); | ||
152 | |||
143 | impl ModuleScope { | 153 | impl ModuleScope { |
144 | pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)> + 'a { | 154 | pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a Name, &'a Resolution)> + 'a { |
145 | self.items.iter() | 155 | //FIXME: shadowing |
156 | self.items.iter().chain(BUILTIN_SCOPE.iter()) | ||
146 | } | 157 | } |
147 | pub fn get(&self, name: &Name) -> Option<&Resolution> { | 158 | pub fn get(&self, name: &Name) -> Option<&Resolution> { |
148 | self.items.get(name) | 159 | self.items.get(name).or_else(|| BUILTIN_SCOPE.get(name)) |
149 | } | 160 | } |
150 | pub fn traits<'a>(&'a self) -> impl Iterator<Item = Trait> + 'a { | 161 | pub fn traits<'a>(&'a self) -> impl Iterator<Item = Trait> + 'a { |
151 | self.items.values().filter_map(|r| match r.def.take_types() { | 162 | self.items.values().filter_map(|r| match r.def.take_types() { |
@@ -154,7 +165,7 @@ impl ModuleScope { | |||
154 | }) | 165 | }) |
155 | } | 166 | } |
156 | fn get_item_or_macro(&self, name: &Name) -> Option<ItemOrMacro> { | 167 | fn get_item_or_macro(&self, name: &Name) -> Option<ItemOrMacro> { |
157 | match (self.items.get(name), self.macros.get(name)) { | 168 | match (self.get(name), self.macros.get(name)) { |
158 | (Some(item), _) if !item.def.is_none() => Some(Either::Left(item.def)), | 169 | (Some(item), _) if !item.def.is_none() => Some(Either::Left(item.def)), |
159 | (_, Some(macro_)) => Some(Either::Right(*macro_)), | 170 | (_, Some(macro_)) => Some(Either::Right(*macro_)), |
160 | _ => None, | 171 | _ => None, |
diff --git a/crates/ra_hir/src/nameres/tests/incremental.rs b/crates/ra_hir/src/nameres/tests/incremental.rs index 001f76ac3..bc721f6e0 100644 --- a/crates/ra_hir/src/nameres/tests/incremental.rs +++ b/crates/ra_hir/src/nameres/tests/incremental.rs | |||
@@ -116,7 +116,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() { | |||
116 | let events = db.log_executed(|| { | 116 | let events = db.log_executed(|| { |
117 | let module = crate::source_binder::module_from_file_id(&db, pos.file_id).unwrap(); | 117 | let module = crate::source_binder::module_from_file_id(&db, pos.file_id).unwrap(); |
118 | let decls = module.declarations(&db); | 118 | let decls = module.declarations(&db); |
119 | assert_eq!(decls.len(), 1); | 119 | assert_eq!(decls.len(), 18); |
120 | }); | 120 | }); |
121 | assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | 121 | assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) |
122 | } | 122 | } |
@@ -126,7 +126,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() { | |||
126 | let events = db.log_executed(|| { | 126 | let events = db.log_executed(|| { |
127 | let module = crate::source_binder::module_from_file_id(&db, pos.file_id).unwrap(); | 127 | let module = crate::source_binder::module_from_file_id(&db, pos.file_id).unwrap(); |
128 | let decls = module.declarations(&db); | 128 | let decls = module.declarations(&db); |
129 | assert_eq!(decls.len(), 1); | 129 | assert_eq!(decls.len(), 18); |
130 | }); | 130 | }); |
131 | assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | 131 | assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) |
132 | } | 132 | } |
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index c4cef2d7c..d2ba01826 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -65,22 +65,6 @@ impl Ty { | |||
65 | } | 65 | } |
66 | 66 | ||
67 | pub(crate) fn from_hir_path(db: &impl HirDatabase, resolver: &Resolver, path: &Path) -> Self { | 67 | pub(crate) fn from_hir_path(db: &impl HirDatabase, resolver: &Resolver, path: &Path) -> Self { |
68 | if let Some(name) = path.as_ident() { | ||
69 | // TODO: remove this | ||
70 | if let Some(int_ty) = primitive::IntTy::from_type_name(name) { | ||
71 | return Ty::simple(TypeCtor::Int(primitive::UncertainIntTy::Known(int_ty))); | ||
72 | } else if let Some(float_ty) = primitive::FloatTy::from_type_name(name) { | ||
73 | return Ty::simple(TypeCtor::Float(primitive::UncertainFloatTy::Known(float_ty))); | ||
74 | } else if let Some(known) = name.as_known_name() { | ||
75 | match known { | ||
76 | KnownName::Bool => return Ty::simple(TypeCtor::Bool), | ||
77 | KnownName::Char => return Ty::simple(TypeCtor::Char), | ||
78 | KnownName::Str => return Ty::simple(TypeCtor::Str), | ||
79 | _ => {} | ||
80 | } | ||
81 | } | ||
82 | } | ||
83 | |||
84 | // Resolve the path (in type namespace) | 68 | // Resolve the path (in type namespace) |
85 | let resolution = resolver.resolve_path(db, path).take_types(); | 69 | let resolution = resolver.resolve_path(db, path).take_types(); |
86 | 70 | ||