diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 248 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/method_resolution.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk.rs | 2 |
5 files changed, 61 insertions, 198 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 35e1f752b..ecf883272 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -754,7 +754,7 @@ impl ImplBlock { | |||
754 | let environment = TraitEnvironment::lower(db, &resolver); | 754 | let environment = TraitEnvironment::lower(db, &resolver); |
755 | let ty = Ty::from_hir(db, &resolver, &impl_data.target_type); | 755 | let ty = Ty::from_hir(db, &resolver, &impl_data.target_type); |
756 | Type { | 756 | Type { |
757 | krate: self.id.lookup(db).container.krate, | 757 | krate: self.id.lookup(db).container.module(db).krate, |
758 | ty: InEnvironment { value: ty, environment }, | 758 | ty: InEnvironment { value: ty, environment }, |
759 | } | 759 | } |
760 | } | 760 | } |
@@ -768,7 +768,7 @@ impl ImplBlock { | |||
768 | } | 768 | } |
769 | 769 | ||
770 | pub fn module(&self, db: &impl DefDatabase) -> Module { | 770 | pub fn module(&self, db: &impl DefDatabase) -> Module { |
771 | self.id.lookup(db).container.into() | 771 | self.id.lookup(db).container.module(db).into() |
772 | } | 772 | } |
773 | 773 | ||
774 | pub fn krate(&self, db: &impl DefDatabase) -> Crate { | 774 | pub fn krate(&self, db: &impl DefDatabase) -> Crate { |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 140eccf26..d11b573e5 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -45,7 +45,7 @@ use std::hash::Hash; | |||
45 | use hir_expand::{ast_id_map::FileAstId, AstId, HirFileId, InFile, MacroDefId}; | 45 | use hir_expand::{ast_id_map::FileAstId, AstId, HirFileId, InFile, MacroDefId}; |
46 | use ra_arena::{impl_arena_id, RawId}; | 46 | use ra_arena::{impl_arena_id, RawId}; |
47 | use ra_db::{impl_intern_key, salsa, CrateId}; | 47 | use ra_db::{impl_intern_key, salsa, CrateId}; |
48 | use ra_syntax::ast; | 48 | use ra_syntax::{ast, AstNode}; |
49 | 49 | ||
50 | use crate::builtin_type::BuiltinType; | 50 | use crate::builtin_type::BuiltinType; |
51 | 51 | ||
@@ -65,101 +65,57 @@ pub struct ModuleId { | |||
65 | pub struct LocalModuleId(RawId); | 65 | pub struct LocalModuleId(RawId); |
66 | impl_arena_id!(LocalModuleId); | 66 | impl_arena_id!(LocalModuleId); |
67 | 67 | ||
68 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
69 | pub struct FunctionId(salsa::InternId); | ||
70 | impl_intern_key!(FunctionId); | ||
71 | |||
72 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 68 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
73 | pub struct FunctionLoc { | 69 | pub struct ItemLoc<N: AstNode> { |
74 | pub container: AssocContainerId, | 70 | pub container: ContainerId, |
75 | pub ast_id: AstId<ast::FnDef>, | 71 | pub ast_id: AstId<N>, |
76 | } | 72 | } |
77 | 73 | ||
78 | impl Intern for FunctionLoc { | 74 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
79 | type ID = FunctionId; | 75 | pub struct AssocItemLoc<N: AstNode> { |
80 | fn intern(self, db: &impl db::DefDatabase) -> FunctionId { | 76 | pub container: AssocContainerId, |
81 | db.intern_function(self) | 77 | pub ast_id: AstId<N>, |
82 | } | ||
83 | } | 78 | } |
84 | 79 | ||
85 | impl Lookup for FunctionId { | 80 | macro_rules! impl_intern { |
86 | type Data = FunctionLoc; | 81 | ($id:ident, $loc:ident, $intern:ident, $lookup:ident) => { |
87 | fn lookup(&self, db: &impl db::DefDatabase) -> FunctionLoc { | 82 | impl_intern_key!($id); |
88 | db.lookup_intern_function(*self) | ||
89 | } | ||
90 | } | ||
91 | 83 | ||
92 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 84 | impl Intern for $loc { |
93 | pub struct StructId(salsa::InternId); | 85 | type ID = $id; |
94 | impl_intern_key!(StructId); | 86 | fn intern(self, db: &impl db::DefDatabase) -> $id { |
87 | db.$intern(self) | ||
88 | } | ||
89 | } | ||
95 | 90 | ||
96 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 91 | impl Lookup for $id { |
97 | pub struct StructLoc { | 92 | type Data = $loc; |
98 | pub container: ContainerId, | 93 | fn lookup(&self, db: &impl db::DefDatabase) -> $loc { |
99 | pub ast_id: AstId<ast::StructDef>, | 94 | db.$lookup(*self) |
95 | } | ||
96 | } | ||
97 | }; | ||
100 | } | 98 | } |
101 | 99 | ||
102 | impl Intern for StructLoc { | 100 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
103 | type ID = StructId; | 101 | pub struct FunctionId(salsa::InternId); |
104 | fn intern(self, db: &impl db::DefDatabase) -> StructId { | 102 | type FunctionLoc = AssocItemLoc<ast::FnDef>; |
105 | db.intern_struct(self) | 103 | impl_intern!(FunctionId, FunctionLoc, intern_function, lookup_intern_function); |
106 | } | ||
107 | } | ||
108 | 104 | ||
109 | impl Lookup for StructId { | 105 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
110 | type Data = StructLoc; | 106 | pub struct StructId(salsa::InternId); |
111 | fn lookup(&self, db: &impl db::DefDatabase) -> StructLoc { | 107 | type StructLoc = ItemLoc<ast::StructDef>; |
112 | db.lookup_intern_struct(*self) | 108 | impl_intern!(StructId, StructLoc, intern_struct, lookup_intern_struct); |
113 | } | ||
114 | } | ||
115 | 109 | ||
116 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 110 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
117 | pub struct UnionId(salsa::InternId); | 111 | pub struct UnionId(salsa::InternId); |
118 | impl_intern_key!(UnionId); | 112 | pub type UnionLoc = ItemLoc<ast::UnionDef>; |
119 | 113 | impl_intern!(UnionId, UnionLoc, intern_union, lookup_intern_union); | |
120 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
121 | pub struct UnionLoc { | ||
122 | pub container: ContainerId, | ||
123 | pub ast_id: AstId<ast::UnionDef>, | ||
124 | } | ||
125 | |||
126 | impl Intern for UnionLoc { | ||
127 | type ID = UnionId; | ||
128 | fn intern(self, db: &impl db::DefDatabase) -> UnionId { | ||
129 | db.intern_union(self) | ||
130 | } | ||
131 | } | ||
132 | |||
133 | impl Lookup for UnionId { | ||
134 | type Data = UnionLoc; | ||
135 | fn lookup(&self, db: &impl db::DefDatabase) -> UnionLoc { | ||
136 | db.lookup_intern_union(*self) | ||
137 | } | ||
138 | } | ||
139 | 114 | ||
140 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 115 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
141 | pub struct EnumId(salsa::InternId); | 116 | pub struct EnumId(salsa::InternId); |
142 | impl_intern_key!(EnumId); | 117 | pub type EnumLoc = ItemLoc<ast::EnumDef>; |
143 | 118 | impl_intern!(EnumId, EnumLoc, intern_enum, lookup_intern_enum); | |
144 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
145 | pub struct EnumLoc { | ||
146 | pub container: ContainerId, | ||
147 | pub ast_id: AstId<ast::EnumDef>, | ||
148 | } | ||
149 | |||
150 | impl Intern for EnumLoc { | ||
151 | type ID = EnumId; | ||
152 | fn intern(self, db: &impl db::DefDatabase) -> EnumId { | ||
153 | db.intern_enum(self) | ||
154 | } | ||
155 | } | ||
156 | |||
157 | impl Lookup for EnumId { | ||
158 | type Data = EnumLoc; | ||
159 | fn lookup(&self, db: &impl db::DefDatabase) -> EnumLoc { | ||
160 | db.lookup_intern_enum(*self) | ||
161 | } | ||
162 | } | ||
163 | 119 | ||
164 | // FIXME: rename to `VariantId`, only enums can ave variants | 120 | // FIXME: rename to `VariantId`, only enums can ave variants |
165 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 121 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -184,122 +140,38 @@ impl_arena_id!(LocalStructFieldId); | |||
184 | 140 | ||
185 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 141 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
186 | pub struct ConstId(salsa::InternId); | 142 | pub struct ConstId(salsa::InternId); |
187 | impl_intern_key!(ConstId); | 143 | type ConstLoc = AssocItemLoc<ast::ConstDef>; |
188 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 144 | impl_intern!(ConstId, ConstLoc, intern_const, lookup_intern_const); |
189 | pub struct ConstLoc { | ||
190 | pub container: AssocContainerId, | ||
191 | pub ast_id: AstId<ast::ConstDef>, | ||
192 | } | ||
193 | |||
194 | impl Intern for ConstLoc { | ||
195 | type ID = ConstId; | ||
196 | fn intern(self, db: &impl db::DefDatabase) -> ConstId { | ||
197 | db.intern_const(self) | ||
198 | } | ||
199 | } | ||
200 | |||
201 | impl Lookup for ConstId { | ||
202 | type Data = ConstLoc; | ||
203 | fn lookup(&self, db: &impl db::DefDatabase) -> ConstLoc { | ||
204 | db.lookup_intern_const(*self) | ||
205 | } | ||
206 | } | ||
207 | 145 | ||
208 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 146 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
209 | pub struct StaticId(salsa::InternId); | 147 | pub struct StaticId(salsa::InternId); |
210 | impl_intern_key!(StaticId); | 148 | pub type StaticLoc = ItemLoc<ast::StaticDef>; |
211 | 149 | impl_intern!(StaticId, StaticLoc, intern_static, lookup_intern_static); | |
212 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
213 | pub struct StaticLoc { | ||
214 | pub container: ContainerId, | ||
215 | pub ast_id: AstId<ast::StaticDef>, | ||
216 | } | ||
217 | |||
218 | impl Intern for StaticLoc { | ||
219 | type ID = StaticId; | ||
220 | fn intern(self, db: &impl db::DefDatabase) -> StaticId { | ||
221 | db.intern_static(self) | ||
222 | } | ||
223 | } | ||
224 | |||
225 | impl Lookup for StaticId { | ||
226 | type Data = StaticLoc; | ||
227 | fn lookup(&self, db: &impl db::DefDatabase) -> StaticLoc { | ||
228 | db.lookup_intern_static(*self) | ||
229 | } | ||
230 | } | ||
231 | 150 | ||
232 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 151 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
233 | pub struct TraitId(salsa::InternId); | 152 | pub struct TraitId(salsa::InternId); |
234 | impl_intern_key!(TraitId); | 153 | pub type TraitLoc = ItemLoc<ast::TraitDef>; |
235 | 154 | impl_intern!(TraitId, TraitLoc, intern_trait, lookup_intern_trait); | |
236 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
237 | pub struct TraitLoc { | ||
238 | pub container: ContainerId, | ||
239 | pub ast_id: AstId<ast::TraitDef>, | ||
240 | } | ||
241 | |||
242 | impl Intern for TraitLoc { | ||
243 | type ID = TraitId; | ||
244 | fn intern(self, db: &impl db::DefDatabase) -> TraitId { | ||
245 | db.intern_trait(self) | ||
246 | } | ||
247 | } | ||
248 | |||
249 | impl Lookup for TraitId { | ||
250 | type Data = TraitLoc; | ||
251 | fn lookup(&self, db: &impl db::DefDatabase) -> TraitLoc { | ||
252 | db.lookup_intern_trait(*self) | ||
253 | } | ||
254 | } | ||
255 | 155 | ||
256 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 156 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
257 | pub struct TypeAliasId(salsa::InternId); | 157 | pub struct TypeAliasId(salsa::InternId); |
258 | impl_intern_key!(TypeAliasId); | 158 | type TypeAliasLoc = AssocItemLoc<ast::TypeAliasDef>; |
259 | 159 | impl_intern!(TypeAliasId, TypeAliasLoc, intern_type_alias, lookup_intern_type_alias); | |
260 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
261 | pub struct TypeAliasLoc { | ||
262 | pub container: AssocContainerId, | ||
263 | pub ast_id: AstId<ast::TypeAliasDef>, | ||
264 | } | ||
265 | |||
266 | impl Intern for TypeAliasLoc { | ||
267 | type ID = TypeAliasId; | ||
268 | fn intern(self, db: &impl db::DefDatabase) -> TypeAliasId { | ||
269 | db.intern_type_alias(self) | ||
270 | } | ||
271 | } | ||
272 | |||
273 | impl Lookup for TypeAliasId { | ||
274 | type Data = TypeAliasLoc; | ||
275 | fn lookup(&self, db: &impl db::DefDatabase) -> TypeAliasLoc { | ||
276 | db.lookup_intern_type_alias(*self) | ||
277 | } | ||
278 | } | ||
279 | 160 | ||
280 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 161 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
281 | pub struct ImplId(salsa::InternId); | 162 | pub struct ImplId(salsa::InternId); |
282 | impl_intern_key!(ImplId); | 163 | type ImplLoc = ItemLoc<ast::ImplBlock>; |
283 | 164 | impl_intern!(ImplId, ImplLoc, intern_impl, lookup_intern_impl); | |
284 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
285 | pub struct ImplLoc { | ||
286 | pub container: ModuleId, | ||
287 | pub ast_id: AstId<ast::ImplBlock>, | ||
288 | } | ||
289 | 165 | ||
290 | impl Intern for ImplLoc { | 166 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
291 | type ID = ImplId; | 167 | pub struct TypeParamId { |
292 | fn intern(self, db: &impl db::DefDatabase) -> ImplId { | 168 | pub parent: GenericDefId, |
293 | db.intern_impl(self) | 169 | pub local_id: LocalTypeParamId, |
294 | } | ||
295 | } | 170 | } |
296 | 171 | ||
297 | impl Lookup for ImplId { | 172 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
298 | type Data = ImplLoc; | 173 | pub struct LocalTypeParamId(RawId); |
299 | fn lookup(&self, db: &impl db::DefDatabase) -> ImplLoc { | 174 | impl_arena_id!(LocalTypeParamId); |
300 | db.lookup_intern_impl(*self) | ||
301 | } | ||
302 | } | ||
303 | 175 | ||
304 | macro_rules! impl_froms { | 176 | macro_rules! impl_froms { |
305 | ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { | 177 | ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { |
@@ -321,16 +193,6 @@ macro_rules! impl_froms { | |||
321 | } | 193 | } |
322 | 194 | ||
323 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 195 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
324 | pub struct TypeParamId { | ||
325 | pub parent: GenericDefId, | ||
326 | pub local_id: LocalTypeParamId, | ||
327 | } | ||
328 | |||
329 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
330 | pub struct LocalTypeParamId(RawId); | ||
331 | impl_arena_id!(LocalTypeParamId); | ||
332 | |||
333 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
334 | pub enum ContainerId { | 196 | pub enum ContainerId { |
335 | ModuleId(ModuleId), | 197 | ModuleId(ModuleId), |
336 | DefWithBodyId(DefWithBodyId), | 198 | DefWithBodyId(DefWithBodyId), |
@@ -498,7 +360,7 @@ impl HasModule for AssocContainerId { | |||
498 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { | 360 | fn module(&self, db: &impl db::DefDatabase) -> ModuleId { |
499 | match *self { | 361 | match *self { |
500 | AssocContainerId::ContainerId(it) => it.module(db), | 362 | AssocContainerId::ContainerId(it) => it.module(db), |
501 | AssocContainerId::ImplId(it) => it.lookup(db).container, | 363 | AssocContainerId::ImplId(it) => it.lookup(db).container.module(db), |
502 | AssocContainerId::TraitId(it) => it.lookup(db).container.module(db), | 364 | AssocContainerId::TraitId(it) => it.lookup(db).container.module(db), |
503 | } | 365 | } |
504 | } | 366 | } |
@@ -550,7 +412,7 @@ impl HasModule for GenericDefId { | |||
550 | GenericDefId::AdtId(it) => it.module(db), | 412 | GenericDefId::AdtId(it) => it.module(db), |
551 | GenericDefId::TraitId(it) => it.lookup(db).container.module(db), | 413 | GenericDefId::TraitId(it) => it.lookup(db).container.module(db), |
552 | GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), | 414 | GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), |
553 | GenericDefId::ImplId(it) => it.lookup(db).container, | 415 | GenericDefId::ImplId(it) => it.lookup(db).container.module(db), |
554 | GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), | 416 | GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container.module(db), |
555 | GenericDefId::ConstId(it) => it.lookup(db).module(db), | 417 | GenericDefId::ConstId(it) => it.lookup(db).module(db), |
556 | } | 418 | } |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index a1ea130e0..e68bf4868 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -661,9 +661,10 @@ where | |||
661 | krate: self.def_collector.def_map.krate, | 661 | krate: self.def_collector.def_map.krate, |
662 | local_id: self.module_id, | 662 | local_id: self.module_id, |
663 | }; | 663 | }; |
664 | let container = ContainerId::ModuleId(module); | ||
664 | let ast_id = self.raw_items[imp].ast_id; | 665 | let ast_id = self.raw_items[imp].ast_id; |
665 | let impl_id = | 666 | let impl_id = |
666 | ImplLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } | 667 | ImplLoc { container, ast_id: AstId::new(self.file_id, ast_id) } |
667 | .intern(self.def_collector.db); | 668 | .intern(self.def_collector.db); |
668 | self.def_collector.def_map.modules[self.module_id].impls.push(impl_id) | 669 | self.def_collector.def_map.modules[self.module_id].impls.push(impl_id) |
669 | } | 670 | } |
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 1b2f4014c..92fb4c081 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -134,7 +134,7 @@ impl Ty { | |||
134 | LangItemTarget::ImplBlockId(it) => Some(it), | 134 | LangItemTarget::ImplBlockId(it) => Some(it), |
135 | _ => None, | 135 | _ => None, |
136 | }) | 136 | }) |
137 | .map(|it| it.lookup(db).container.krate) | 137 | .map(|it| it.lookup(db).container.module(db).krate) |
138 | .collect(); | 138 | .collect(); |
139 | Some(res) | 139 | Some(res) |
140 | } | 140 | } |
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index dd4fa9664..5eb032d86 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs | |||
@@ -673,7 +673,7 @@ fn impl_block_datum( | |||
673 | let bound_vars = Substs::bound_vars(&generic_params); | 673 | let bound_vars = Substs::bound_vars(&generic_params); |
674 | let trait_ref = trait_ref.subst(&bound_vars); | 674 | let trait_ref = trait_ref.subst(&bound_vars); |
675 | let trait_ = trait_ref.trait_; | 675 | let trait_ = trait_ref.trait_; |
676 | let impl_type = if impl_id.lookup(db).container.krate == krate { | 676 | let impl_type = if impl_id.lookup(db).container.module(db).krate == krate { |
677 | chalk_rust_ir::ImplType::Local | 677 | chalk_rust_ir::ImplType::Local |
678 | } else { | 678 | } else { |
679 | chalk_rust_ir::ImplType::External | 679 | chalk_rust_ir::ImplType::External |