diff options
author | Aleksey Kladov <[email protected]> | 2019-11-20 13:03:59 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-20 13:22:58 +0000 |
commit | cebeedc66fc40097eae20bf1767a285d00269966 (patch) | |
tree | e54c306ac0512e3610430574dc8bea39e4b50218 /crates/ra_hir_def/src/impls.rs | |
parent | 06fa3d8389c833b01f482bf35b0f850e627612b9 (diff) |
Next gen IDs for functions
The current system with AstIds has two primaraly drawbacks:
* It is possible to manufacture IDs out of thin air.
For example, it's possible to create IDs for items which are not
considered in CrateDefMap due to cfg. Or it is possible to mixup
structs and unions, because they share ID space.
* Getting the ID of a parent requires a secondary index.
Instead, the plan is to pursue the more traditional approach, where
each items stores the id of the parent declaration. This makes
`FromSource` more awkward, but also more correct: now, to get from an
AST to HIR, we first do this recursively for the parent item, and the
just search the children of the parent for the matching def
Diffstat (limited to 'crates/ra_hir_def/src/impls.rs')
-rw-r--r-- | crates/ra_hir_def/src/impls.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/crates/ra_hir_def/src/impls.rs b/crates/ra_hir_def/src/impls.rs index 4323dfcb6..9be38c5e1 100644 --- a/crates/ra_hir_def/src/impls.rs +++ b/crates/ra_hir_def/src/impls.rs | |||
@@ -5,11 +5,12 @@ | |||
5 | 5 | ||
6 | use std::sync::Arc; | 6 | use std::sync::Arc; |
7 | 7 | ||
8 | use hir_expand::AstId; | ||
8 | use ra_syntax::ast; | 9 | use ra_syntax::ast; |
9 | 10 | ||
10 | use crate::{ | 11 | use crate::{ |
11 | db::DefDatabase2, type_ref::TypeRef, AssocItemId, AstItemDef, ConstId, FunctionId, ImplId, | 12 | db::DefDatabase2, type_ref::TypeRef, AssocItemId, AstItemDef, ConstId, FunctionContainerId, |
12 | LocationCtx, TypeAliasId, | 13 | FunctionLoc, ImplId, Intern, LocationCtx, TypeAliasId, |
13 | }; | 14 | }; |
14 | 15 | ||
15 | #[derive(Debug, Clone, PartialEq, Eq)] | 16 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -35,7 +36,12 @@ impl ImplData { | |||
35 | .impl_items() | 36 | .impl_items() |
36 | .map(|item_node| match item_node { | 37 | .map(|item_node| match item_node { |
37 | ast::ImplItem::FnDef(it) => { | 38 | ast::ImplItem::FnDef(it) => { |
38 | FunctionId::from_ast_id(ctx, items.ast_id(&it)).into() | 39 | let func_id = FunctionLoc { |
40 | container: FunctionContainerId::ImplId(id), | ||
41 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), | ||
42 | } | ||
43 | .intern(db); | ||
44 | func_id.into() | ||
39 | } | 45 | } |
40 | ast::ImplItem::ConstDef(it) => { | 46 | ast::ImplItem::ConstDef(it) => { |
41 | ConstId::from_ast_id(ctx, items.ast_id(&it)).into() | 47 | ConstId::from_ast_id(ctx, items.ast_id(&it)).into() |