diff options
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/db.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/generics.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/impls.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 48 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir_def/src/traits.rs | 10 |
6 files changed, 74 insertions, 19 deletions
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index e4ffdebe9..d6d32fb8c 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -14,13 +14,13 @@ use crate::{ | |||
14 | CrateDefMap, | 14 | CrateDefMap, |
15 | }, | 15 | }, |
16 | traits::{TraitData, TraitItemsIndex}, | 16 | traits::{TraitData, TraitItemsIndex}, |
17 | DefWithBodyId, EnumId, FunctionLoc, ImplId, ItemLoc, ModuleId, StructOrUnionId, TraitId, | 17 | DefWithBodyId, EnumId, ImplId, ItemLoc, ModuleId, StructOrUnionId, TraitId, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | #[salsa::query_group(InternDatabaseStorage)] | 20 | #[salsa::query_group(InternDatabaseStorage)] |
21 | pub trait InternDatabase: SourceDatabase { | 21 | pub trait InternDatabase: SourceDatabase { |
22 | #[salsa::interned] | 22 | #[salsa::interned] |
23 | fn intern_function(&self, loc: FunctionLoc) -> crate::FunctionId; | 23 | fn intern_function(&self, loc: crate::FunctionLoc) -> crate::FunctionId; |
24 | #[salsa::interned] | 24 | #[salsa::interned] |
25 | fn intern_struct_or_union(&self, loc: ItemLoc<ast::StructDef>) -> crate::StructOrUnionId; | 25 | fn intern_struct_or_union(&self, loc: ItemLoc<ast::StructDef>) -> crate::StructOrUnionId; |
26 | #[salsa::interned] | 26 | #[salsa::interned] |
@@ -32,7 +32,7 @@ pub trait InternDatabase: SourceDatabase { | |||
32 | #[salsa::interned] | 32 | #[salsa::interned] |
33 | fn intern_trait(&self, loc: ItemLoc<ast::TraitDef>) -> crate::TraitId; | 33 | fn intern_trait(&self, loc: ItemLoc<ast::TraitDef>) -> crate::TraitId; |
34 | #[salsa::interned] | 34 | #[salsa::interned] |
35 | fn intern_type_alias(&self, loc: ItemLoc<ast::TypeAliasDef>) -> crate::TypeAliasId; | 35 | fn intern_type_alias(&self, loc: crate::TypeAliasLoc) -> crate::TypeAliasId; |
36 | #[salsa::interned] | 36 | #[salsa::interned] |
37 | fn intern_impl(&self, loc: ItemLoc<ast::ImplBlock>) -> crate::ImplId; | 37 | fn intern_impl(&self, loc: ItemLoc<ast::ImplBlock>) -> crate::ImplId; |
38 | } | 38 | } |
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index 11dd2a948..17a5d5f43 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs | |||
@@ -72,7 +72,7 @@ impl GenericParams { | |||
72 | let self_param = TypeRef::Path(name::SELF_TYPE.into()); | 72 | let self_param = TypeRef::Path(name::SELF_TYPE.into()); |
73 | generics.fill_bounds(&it.source(db).value, self_param); | 73 | generics.fill_bounds(&it.source(db).value, self_param); |
74 | } | 74 | } |
75 | GenericDefId::TypeAliasId(it) => generics.fill(&it.source(db).value, start), | 75 | GenericDefId::TypeAliasId(it) => generics.fill(&it.lookup(db).source(db).value, start), |
76 | // Note that we don't add `Self` here: in `impl`s, `Self` is not a | 76 | // Note that we don't add `Self` here: in `impl`s, `Self` is not a |
77 | // type-parameter, but rather is a type-alias for impl's target | 77 | // type-parameter, but rather is a type-alias for impl's target |
78 | // type, so this is handled by the resolver. | 78 | // type, so this is handled by the resolver. |
diff --git a/crates/ra_hir_def/src/impls.rs b/crates/ra_hir_def/src/impls.rs index 9be38c5e1..703e4d503 100644 --- a/crates/ra_hir_def/src/impls.rs +++ b/crates/ra_hir_def/src/impls.rs | |||
@@ -10,7 +10,7 @@ use ra_syntax::ast; | |||
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | db::DefDatabase2, type_ref::TypeRef, AssocItemId, AstItemDef, ConstId, FunctionContainerId, | 12 | db::DefDatabase2, type_ref::TypeRef, AssocItemId, AstItemDef, ConstId, FunctionContainerId, |
13 | FunctionLoc, ImplId, Intern, LocationCtx, TypeAliasId, | 13 | FunctionLoc, ImplId, Intern, LocationCtx, TypeAliasContainerId, TypeAliasLoc, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | #[derive(Debug, Clone, PartialEq, Eq)] | 16 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -36,18 +36,23 @@ impl ImplData { | |||
36 | .impl_items() | 36 | .impl_items() |
37 | .map(|item_node| match item_node { | 37 | .map(|item_node| match item_node { |
38 | ast::ImplItem::FnDef(it) => { | 38 | ast::ImplItem::FnDef(it) => { |
39 | let func_id = FunctionLoc { | 39 | let def = FunctionLoc { |
40 | container: FunctionContainerId::ImplId(id), | 40 | container: FunctionContainerId::ImplId(id), |
41 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), | 41 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), |
42 | } | 42 | } |
43 | .intern(db); | 43 | .intern(db); |
44 | func_id.into() | 44 | def.into() |
45 | } | 45 | } |
46 | ast::ImplItem::ConstDef(it) => { | 46 | ast::ImplItem::ConstDef(it) => { |
47 | ConstId::from_ast_id(ctx, items.ast_id(&it)).into() | 47 | ConstId::from_ast_id(ctx, items.ast_id(&it)).into() |
48 | } | 48 | } |
49 | ast::ImplItem::TypeAliasDef(it) => { | 49 | ast::ImplItem::TypeAliasDef(it) => { |
50 | TypeAliasId::from_ast_id(ctx, items.ast_id(&it)).into() | 50 | let def = TypeAliasLoc { |
51 | container: TypeAliasContainerId::ImplId(id), | ||
52 | ast_id: AstId::new(src.file_id, items.ast_id(&it)), | ||
53 | } | ||
54 | .intern(db); | ||
55 | def.into() | ||
51 | } | 56 | } |
52 | }) | 57 | }) |
53 | .collect() | 58 | .collect() |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index b9a13776f..6052370b4 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -332,16 +332,35 @@ impl AstItemDef<ast::TraitDef> for TraitId { | |||
332 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 332 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
333 | pub struct TypeAliasId(salsa::InternId); | 333 | pub struct TypeAliasId(salsa::InternId); |
334 | impl_intern_key!(TypeAliasId); | 334 | impl_intern_key!(TypeAliasId); |
335 | impl AstItemDef<ast::TypeAliasDef> for TypeAliasId { | 335 | |
336 | fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::TypeAliasDef>) -> Self { | 336 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
337 | db.intern_type_alias(loc) | 337 | pub struct TypeAliasLoc { |
338 | pub container: TypeAliasContainerId, | ||
339 | pub ast_id: AstId<ast::TypeAliasDef>, | ||
340 | } | ||
341 | |||
342 | impl Intern for TypeAliasLoc { | ||
343 | type ID = TypeAliasId; | ||
344 | fn intern(self, db: &impl db::DefDatabase2) -> TypeAliasId { | ||
345 | db.intern_type_alias(self) | ||
338 | } | 346 | } |
339 | fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::TypeAliasDef> { | 347 | } |
340 | db.lookup_intern_type_alias(self) | 348 | |
349 | impl Lookup for TypeAliasId { | ||
350 | type Data = TypeAliasLoc; | ||
351 | fn lookup(&self, db: &impl db::DefDatabase2) -> TypeAliasLoc { | ||
352 | db.lookup_intern_type_alias(*self) | ||
341 | } | 353 | } |
342 | } | 354 | } |
343 | 355 | ||
344 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 356 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
357 | pub enum TypeAliasContainerId { | ||
358 | ModuleId(ModuleId), | ||
359 | ImplId(ImplId), | ||
360 | TraitId(TraitId), | ||
361 | } | ||
362 | |||
363 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
345 | pub struct ImplId(salsa::InternId); | 364 | pub struct ImplId(salsa::InternId); |
346 | impl_intern_key!(ImplId); | 365 | impl_intern_key!(ImplId); |
347 | impl AstItemDef<ast::ImplBlock> for ImplId { | 366 | impl AstItemDef<ast::ImplBlock> for ImplId { |
@@ -476,6 +495,16 @@ impl HasModule for FunctionLoc { | |||
476 | } | 495 | } |
477 | } | 496 | } |
478 | 497 | ||
498 | impl HasModule for TypeAliasLoc { | ||
499 | fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { | ||
500 | match self.container { | ||
501 | TypeAliasContainerId::ModuleId(it) => it, | ||
502 | TypeAliasContainerId::ImplId(it) => it.module(db), | ||
503 | TypeAliasContainerId::TraitId(it) => it.module(db), | ||
504 | } | ||
505 | } | ||
506 | } | ||
507 | |||
479 | pub trait HasSource { | 508 | pub trait HasSource { |
480 | type Value; | 509 | type Value; |
481 | fn source(&self, db: &impl db::DefDatabase2) -> Source<Self::Value>; | 510 | fn source(&self, db: &impl db::DefDatabase2) -> Source<Self::Value>; |
@@ -489,3 +518,12 @@ impl HasSource for FunctionLoc { | |||
489 | Source::new(self.ast_id.file_id(), node) | 518 | Source::new(self.ast_id.file_id(), node) |
490 | } | 519 | } |
491 | } | 520 | } |
521 | |||
522 | impl HasSource for TypeAliasLoc { | ||
523 | type Value = ast::TypeAliasDef; | ||
524 | |||
525 | fn source(&self, db: &impl db::DefDatabase2) -> Source<ast::TypeAliasDef> { | ||
526 | let node = self.ast_id.to_node(db); | ||
527 | Source::new(self.ast_id.file_id(), node) | ||
528 | } | ||
529 | } | ||
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index d2ed94a87..060185b61 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -21,7 +21,7 @@ use crate::{ | |||
21 | path::{Path, PathKind}, | 21 | path::{Path, PathKind}, |
22 | AdtId, AstId, AstItemDef, ConstId, CrateModuleId, EnumId, EnumVariantId, FunctionContainerId, | 22 | AdtId, AstId, AstItemDef, ConstId, CrateModuleId, EnumId, EnumVariantId, FunctionContainerId, |
23 | FunctionLoc, ImplId, Intern, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, | 23 | FunctionLoc, ImplId, Intern, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, |
24 | StructOrUnionId, TraitId, TypeAliasId, UnionId, | 24 | StructOrUnionId, TraitId, TypeAliasContainerId, TypeAliasLoc, UnionId, |
25 | }; | 25 | }; |
26 | 26 | ||
27 | pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> CrateDefMap { | 27 | pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> CrateDefMap { |
@@ -673,13 +673,13 @@ where | |||
673 | let name = def.name.clone(); | 673 | let name = def.name.clone(); |
674 | let def: PerNs = match def.kind { | 674 | let def: PerNs = match def.kind { |
675 | raw::DefKind::Function(ast_id) => { | 675 | raw::DefKind::Function(ast_id) => { |
676 | let f = FunctionLoc { | 676 | let def = FunctionLoc { |
677 | container: FunctionContainerId::ModuleId(module), | 677 | container: FunctionContainerId::ModuleId(module), |
678 | ast_id: AstId::new(self.file_id, ast_id), | 678 | ast_id: AstId::new(self.file_id, ast_id), |
679 | } | 679 | } |
680 | .intern(self.def_collector.db); | 680 | .intern(self.def_collector.db); |
681 | 681 | ||
682 | PerNs::values(f.into()) | 682 | PerNs::values(def.into()) |
683 | } | 683 | } |
684 | raw::DefKind::Struct(ast_id) => { | 684 | raw::DefKind::Struct(ast_id) => { |
685 | let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); | 685 | let id = StructOrUnionId::from_ast_id(ctx, ast_id).into(); |
@@ -698,7 +698,13 @@ where | |||
698 | } | 698 | } |
699 | raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()), | 699 | raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()), |
700 | raw::DefKind::TypeAlias(ast_id) => { | 700 | raw::DefKind::TypeAlias(ast_id) => { |
701 | PerNs::types(TypeAliasId::from_ast_id(ctx, ast_id).into()) | 701 | let def = TypeAliasLoc { |
702 | container: TypeAliasContainerId::ModuleId(module), | ||
703 | ast_id: AstId::new(self.file_id, ast_id), | ||
704 | } | ||
705 | .intern(self.def_collector.db); | ||
706 | |||
707 | PerNs::types(def.into()) | ||
702 | } | 708 | } |
703 | }; | 709 | }; |
704 | let resolution = Resolution { def, import: None }; | 710 | let resolution = Resolution { def, import: None }; |
diff --git a/crates/ra_hir_def/src/traits.rs b/crates/ra_hir_def/src/traits.rs index 6e36bc0d0..228524a57 100644 --- a/crates/ra_hir_def/src/traits.rs +++ b/crates/ra_hir_def/src/traits.rs | |||
@@ -12,7 +12,7 @@ use rustc_hash::FxHashMap; | |||
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | db::DefDatabase2, AssocItemId, AstItemDef, ConstId, FunctionContainerId, FunctionLoc, Intern, | 14 | db::DefDatabase2, AssocItemId, AstItemDef, ConstId, FunctionContainerId, FunctionLoc, Intern, |
15 | LocationCtx, ModuleDefId, ModuleId, TraitId, TypeAliasId, | 15 | LocationCtx, ModuleDefId, ModuleId, TraitId, TypeAliasContainerId, TypeAliasLoc, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | #[derive(Debug, Clone, PartialEq, Eq)] | 18 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -41,7 +41,12 @@ impl TraitData { | |||
41 | .intern(db) | 41 | .intern(db) |
42 | .into(), | 42 | .into(), |
43 | ast::ImplItem::ConstDef(it) => ConstId::from_ast(ctx, &it).into(), | 43 | ast::ImplItem::ConstDef(it) => ConstId::from_ast(ctx, &it).into(), |
44 | ast::ImplItem::TypeAliasDef(it) => TypeAliasId::from_ast(ctx, &it).into(), | 44 | ast::ImplItem::TypeAliasDef(it) => TypeAliasLoc { |
45 | container: TypeAliasContainerId::TraitId(tr), | ||
46 | ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), | ||
47 | } | ||
48 | .intern(db) | ||
49 | .into(), | ||
45 | }) | 50 | }) |
46 | .collect() | 51 | .collect() |
47 | } else { | 52 | } else { |
@@ -65,6 +70,7 @@ impl TraitItemsIndex { | |||
65 | for item in db.trait_data(tr).items.iter() { | 70 | for item in db.trait_data(tr).items.iter() { |
66 | match item { | 71 | match item { |
67 | AssocItemId::FunctionId(_) => (), | 72 | AssocItemId::FunctionId(_) => (), |
73 | AssocItemId::TypeAliasId(_) => (), | ||
68 | _ => { | 74 | _ => { |
69 | let prev = index.traits_by_def.insert(*item, tr); | 75 | let prev = index.traits_by_def.insert(*item, tr); |
70 | assert!(prev.is_none()); | 76 | assert!(prev.is_none()); |