diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-24 11:28:51 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-24 11:28:51 +0000 |
commit | 982a32aca317deb91ae03346cbc7880bd7d4429b (patch) | |
tree | f2e52047aa684cc4d8b253b3071cfa5a2d753ac9 /crates | |
parent | ea3124c12a52f28163a6375b6a5e3c79fc14312d (diff) | |
parent | 9c766db5ff9dad3ca13539c186f40f657380a831 (diff) |
Merge #2382
2382: Remove ids module r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_db/src/lib.rs | 14 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir/src/debug.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/diagnostics.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/from_source.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/ids.rs | 45 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits/chalk.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres.rs | 35 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 38 |
16 files changed, 106 insertions, 130 deletions
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index f9d012cb0..e8852531b 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -15,6 +15,20 @@ pub use crate::{ | |||
15 | pub use relative_path::{RelativePath, RelativePathBuf}; | 15 | pub use relative_path::{RelativePath, RelativePathBuf}; |
16 | pub use salsa; | 16 | pub use salsa; |
17 | 17 | ||
18 | #[macro_export] | ||
19 | macro_rules! impl_intern_key { | ||
20 | ($name:ident) => { | ||
21 | impl $crate::salsa::InternKey for $name { | ||
22 | fn from_intern_id(v: $crate::salsa::InternId) -> Self { | ||
23 | $name(v) | ||
24 | } | ||
25 | fn as_intern_id(&self) -> $crate::salsa::InternId { | ||
26 | self.0 | ||
27 | } | ||
28 | } | ||
29 | }; | ||
30 | } | ||
31 | |||
18 | pub trait CheckCanceled { | 32 | pub trait CheckCanceled { |
19 | /// Aborts current query if there are pending changes. | 33 | /// Aborts current query if there are pending changes. |
20 | /// | 34 | /// |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index fd7776fb7..36ea8d8bf 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -12,13 +12,14 @@ use hir_def::{ | |||
12 | per_ns::PerNs, | 12 | per_ns::PerNs, |
13 | resolver::{HasResolver, TypeNs}, | 13 | resolver::{HasResolver, TypeNs}, |
14 | type_ref::TypeRef, | 14 | type_ref::TypeRef, |
15 | ContainerId, HasModule, ImplId, LocalEnumVariantId, LocalImportId, LocalModuleId, | 15 | AstItemDef, ConstId, ContainerId, EnumId, FunctionId, HasModule, ImplId, LocalEnumVariantId, |
16 | LocalStructFieldId, Lookup, ModuleId, UnionId, | 16 | LocalImportId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, StructId, |
17 | TraitId, TypeAliasId, UnionId, | ||
17 | }; | 18 | }; |
18 | use hir_expand::{ | 19 | use hir_expand::{ |
19 | diagnostics::DiagnosticSink, | 20 | diagnostics::DiagnosticSink, |
20 | name::{self, AsName}, | 21 | name::{self, AsName}, |
21 | AstId, | 22 | AstId, MacroDefId, |
22 | }; | 23 | }; |
23 | use ra_db::{CrateId, Edition, FileId, FilePosition}; | 24 | use ra_db::{CrateId, Edition, FileId, FilePosition}; |
24 | use ra_syntax::{ast, AstNode, SyntaxNode}; | 25 | use ra_syntax::{ast, AstNode, SyntaxNode}; |
@@ -26,10 +27,6 @@ use ra_syntax::{ast, AstNode, SyntaxNode}; | |||
26 | use crate::{ | 27 | use crate::{ |
27 | db::{DefDatabase, HirDatabase}, | 28 | db::{DefDatabase, HirDatabase}, |
28 | expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, | 29 | expr::{BindingAnnotation, Body, BodySourceMap, ExprValidator, Pat, PatId}, |
29 | ids::{ | ||
30 | AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, | ||
31 | TypeAliasId, | ||
32 | }, | ||
33 | ty::{InferenceResult, Namespace, TraitRef}, | 30 | ty::{InferenceResult, Namespace, TraitRef}, |
34 | Either, HasSource, Name, Source, Ty, | 31 | Either, HasSource, Name, Source, Ty, |
35 | }; | 32 | }; |
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index b7bafe23d..59cda2e89 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs | |||
@@ -1,12 +1,11 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir_def::{HasChildSource, HasSource as _, Lookup, VariantId}; | 3 | use hir_def::{AstItemDef, HasChildSource, HasSource as _, Lookup, VariantId}; |
4 | use hir_expand::either::Either; | 4 | use hir_expand::either::Either; |
5 | use ra_syntax::ast::{self, AstNode}; | 5 | use ra_syntax::ast::{self, AstNode}; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | db::{DefDatabase, HirDatabase}, | 8 | db::{DefDatabase, HirDatabase}, |
9 | ids::AstItemDef, | ||
10 | Const, Enum, EnumVariant, FieldSource, Function, HasBody, Import, MacroDef, Module, | 9 | Const, Enum, EnumVariant, FieldSource, Function, HasBody, Import, MacroDef, Module, |
11 | ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, | 10 | ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, |
12 | }; | 11 | }; |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 3ae5df8d5..a9dab2d25 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -5,7 +5,6 @@ use std::sync::Arc; | |||
5 | use ra_db::salsa; | 5 | use ra_db::salsa; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | ids, | ||
9 | ty::{ | 8 | ty::{ |
10 | method_resolution::CrateImplBlocks, | 9 | method_resolution::CrateImplBlocks, |
11 | traits::{AssocTyValue, Impl}, | 10 | traits::{AssocTyValue, Impl}, |
@@ -71,11 +70,14 @@ pub trait HirDatabase: DefDatabase { | |||
71 | 70 | ||
72 | // Interned IDs for Chalk integration | 71 | // Interned IDs for Chalk integration |
73 | #[salsa::interned] | 72 | #[salsa::interned] |
74 | fn intern_type_ctor(&self, type_ctor: TypeCtor) -> ids::TypeCtorId; | 73 | fn intern_type_ctor(&self, type_ctor: TypeCtor) -> crate::ty::TypeCtorId; |
75 | #[salsa::interned] | 74 | #[salsa::interned] |
76 | fn intern_chalk_impl(&self, impl_: Impl) -> ids::GlobalImplId; | 75 | fn intern_chalk_impl(&self, impl_: Impl) -> crate::ty::traits::GlobalImplId; |
77 | #[salsa::interned] | 76 | #[salsa::interned] |
78 | fn intern_assoc_ty_value(&self, assoc_ty_value: AssocTyValue) -> ids::AssocTyValueId; | 77 | fn intern_assoc_ty_value( |
78 | &self, | ||
79 | assoc_ty_value: AssocTyValue, | ||
80 | ) -> crate::ty::traits::AssocTyValueId; | ||
79 | 81 | ||
80 | #[salsa::invoke(crate::ty::traits::chalk::associated_ty_data_query)] | 82 | #[salsa::invoke(crate::ty::traits::chalk::associated_ty_data_query)] |
81 | fn associated_ty_data( | 83 | fn associated_ty_data( |
diff --git a/crates/ra_hir/src/debug.rs b/crates/ra_hir/src/debug.rs index 8ec371f6e..7a2810f71 100644 --- a/crates/ra_hir/src/debug.rs +++ b/crates/ra_hir/src/debug.rs | |||
@@ -22,9 +22,10 @@ | |||
22 | 22 | ||
23 | use std::fmt; | 23 | use std::fmt; |
24 | 24 | ||
25 | use hir_expand::HirFileId; | ||
25 | use ra_db::{CrateId, FileId}; | 26 | use ra_db::{CrateId, FileId}; |
26 | 27 | ||
27 | use crate::{db::HirDatabase, Crate, HirFileId, Module, Name}; | 28 | use crate::{db::HirDatabase, Crate, Module, Name}; |
28 | 29 | ||
29 | impl Crate { | 30 | impl Crate { |
30 | pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ { | 31 | pub fn debug(self, db: &impl HirDebugDatabase) -> impl fmt::Debug + '_ { |
diff --git a/crates/ra_hir/src/diagnostics.rs b/crates/ra_hir/src/diagnostics.rs index 7d1b64858..dafacba70 100644 --- a/crates/ra_hir/src/diagnostics.rs +++ b/crates/ra_hir/src/diagnostics.rs | |||
@@ -2,9 +2,10 @@ | |||
2 | 2 | ||
3 | use std::any::Any; | 3 | use std::any::Any; |
4 | 4 | ||
5 | use hir_expand::HirFileId; | ||
5 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; | 6 | use ra_syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; |
6 | 7 | ||
7 | use crate::{db::AstDatabase, HirFileId, Name, Source}; | 8 | use crate::{db::AstDatabase, Name, Source}; |
8 | 9 | ||
9 | pub use hir_def::diagnostics::UnresolvedModule; | 10 | pub use hir_def::diagnostics::UnresolvedModule; |
10 | pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; | 11 | pub use hir_expand::diagnostics::{AstDiagnostic, Diagnostic, DiagnosticSink}; |
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index b86307c58..c3c3b05ed 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir_def::{ModuleId, StructId, StructOrUnionId, UnionId}; | 3 | use hir_def::{AstItemDef, LocationCtx, ModuleId, StructId, StructOrUnionId, UnionId}; |
4 | use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; | 4 | use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; |
5 | use ra_syntax::{ | 5 | use ra_syntax::{ |
6 | ast::{self, AstNode, NameOwner}, | 6 | ast::{self, AstNode, NameOwner}, |
@@ -9,7 +9,6 @@ use ra_syntax::{ | |||
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | db::{AstDatabase, DefDatabase, HirDatabase}, | 11 | db::{AstDatabase, DefDatabase, HirDatabase}, |
12 | ids::{AstItemDef, LocationCtx}, | ||
13 | AssocItem, Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, HasBody, HasSource, | 12 | AssocItem, Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, HasBody, HasSource, |
14 | ImplBlock, Local, MacroDef, Module, ModuleDef, ModuleSource, Source, Static, Struct, | 13 | ImplBlock, Local, MacroDef, Module, ModuleDef, ModuleSource, Source, Static, Struct, |
15 | StructField, Trait, TypeAlias, Union, VariantDef, | 14 | StructField, Trait, TypeAlias, Union, VariantDef, |
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs deleted file mode 100644 index 2b59365fb..000000000 --- a/crates/ra_hir/src/ids.rs +++ /dev/null | |||
@@ -1,45 +0,0 @@ | |||
1 | //! hir makes heavy use of ids: integer (u32) handlers to various things. You | ||
2 | //! can think of id as a pointer (but without a lifetime) or a file descriptor | ||
3 | //! (but for hir objects). | ||
4 | //! | ||
5 | //! This module defines a bunch of ids we are using. The most important ones are | ||
6 | //! probably `HirFileId` and `DefId`. | ||
7 | |||
8 | use ra_db::salsa; | ||
9 | |||
10 | pub use hir_def::{ | ||
11 | AstItemDef, ConstId, EnumId, FunctionId, ItemLoc, LocationCtx, StaticId, StructId, TraitId, | ||
12 | TypeAliasId, | ||
13 | }; | ||
14 | pub use hir_expand::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, MacroFileKind}; | ||
15 | |||
16 | macro_rules! impl_intern_key { | ||
17 | ($name:ident) => { | ||
18 | impl salsa::InternKey for $name { | ||
19 | fn from_intern_id(v: salsa::InternId) -> Self { | ||
20 | $name(v) | ||
21 | } | ||
22 | fn as_intern_id(&self) -> salsa::InternId { | ||
23 | self.0 | ||
24 | } | ||
25 | } | ||
26 | }; | ||
27 | } | ||
28 | |||
29 | /// This exists just for Chalk, because Chalk just has a single `StructId` where | ||
30 | /// we have different kinds of ADTs, primitive types and special type | ||
31 | /// constructors like tuples and function pointers. | ||
32 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
33 | pub struct TypeCtorId(salsa::InternId); | ||
34 | impl_intern_key!(TypeCtorId); | ||
35 | |||
36 | /// This exists just for Chalk, because our ImplIds are only unique per module. | ||
37 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
38 | pub struct GlobalImplId(salsa::InternId); | ||
39 | impl_intern_key!(GlobalImplId); | ||
40 | |||
41 | /// This exists just for Chalk, because it needs a unique ID for each associated | ||
42 | /// type value in an impl (even synthetic ones). | ||
43 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
44 | pub struct AssocTyValueId(salsa::InternId); | ||
45 | impl_intern_key!(AssocTyValueId); | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index e51d4d063..8c589c728 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -31,7 +31,6 @@ pub mod debug; | |||
31 | pub mod db; | 31 | pub mod db; |
32 | pub mod source_binder; | 32 | pub mod source_binder; |
33 | 33 | ||
34 | mod ids; | ||
35 | mod ty; | 34 | mod ty; |
36 | mod impl_block; | 35 | mod impl_block; |
37 | mod expr; | 36 | mod expr; |
@@ -58,7 +57,6 @@ pub use crate::{ | |||
58 | }, | 57 | }, |
59 | expr::ExprScopes, | 58 | expr::ExprScopes, |
60 | from_source::FromSource, | 59 | from_source::FromSource, |
61 | ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, | ||
62 | source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, | 60 | source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, |
63 | ty::{ | 61 | ty::{ |
64 | display::HirDisplay, | 62 | display::HirDisplay, |
@@ -73,4 +71,6 @@ pub use hir_def::{ | |||
73 | path::{Path, PathKind}, | 71 | path::{Path, PathKind}, |
74 | type_ref::Mutability, | 72 | type_ref::Mutability, |
75 | }; | 73 | }; |
76 | pub use hir_expand::{either::Either, name::Name, Source}; | 74 | pub use hir_expand::{ |
75 | either::Either, name::Name, HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Source, | ||
76 | }; | ||
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 797f90d50..0a836c913 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -11,9 +11,11 @@ use hir_def::{ | |||
11 | expr::{ExprId, PatId}, | 11 | expr::{ExprId, PatId}, |
12 | path::known, | 12 | path::known, |
13 | resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs}, | 13 | resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs}, |
14 | DefWithBodyId, | 14 | DefWithBodyId, LocationCtx, |
15 | }; | ||
16 | use hir_expand::{ | ||
17 | name::AsName, AstId, HirFileId, MacroCallId, MacroCallLoc, MacroFileKind, Source, | ||
15 | }; | 18 | }; |
16 | use hir_expand::{name::AsName, AstId, MacroCallId, MacroCallLoc, MacroFileKind, Source}; | ||
17 | use ra_syntax::{ | 19 | use ra_syntax::{ |
18 | ast::{self, AstNode}, | 20 | ast::{self, AstNode}, |
19 | match_ast, AstPtr, | 21 | match_ast, AstPtr, |
@@ -24,11 +26,10 @@ use ra_syntax::{ | |||
24 | use crate::{ | 26 | use crate::{ |
25 | db::HirDatabase, | 27 | db::HirDatabase, |
26 | expr::{BodySourceMap, ExprScopes, ScopeId}, | 28 | expr::{BodySourceMap, ExprScopes, ScopeId}, |
27 | ids::LocationCtx, | ||
28 | ty::method_resolution::{self, implements_trait}, | 29 | ty::method_resolution::{self, implements_trait}, |
29 | Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, | 30 | Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, |
30 | GenericParam, HasBody, HirFileId, Local, MacroDef, Module, Name, Path, ScopeDef, Static, | 31 | GenericParam, HasBody, Local, MacroDef, Module, Name, Path, ScopeDef, Static, Struct, Trait, |
31 | Struct, Trait, Ty, TypeAlias, | 32 | Ty, TypeAlias, |
32 | }; | 33 | }; |
33 | 34 | ||
34 | fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { | 35 | fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { |
@@ -544,7 +545,7 @@ fn adjust( | |||
544 | } | 545 | } |
545 | 546 | ||
546 | /// Given a `ast::MacroCall`, return what `MacroKindFile` it belongs to. | 547 | /// Given a `ast::MacroCall`, return what `MacroKindFile` it belongs to. |
547 | /// FIXME: Not completed | 548 | /// FIXME: Not completed |
548 | fn to_macro_file_kind(macro_call: &ast::MacroCall) -> MacroFileKind { | 549 | fn to_macro_file_kind(macro_call: &ast::MacroCall) -> MacroFileKind { |
549 | let syn = macro_call.syntax(); | 550 | let syn = macro_call.syntax(); |
550 | let parent = match syn.parent() { | 551 | let parent = match syn.parent() { |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 95b8df181..309bd2727 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -18,6 +18,7 @@ use std::sync::Arc; | |||
18 | use std::{fmt, iter, mem}; | 18 | use std::{fmt, iter, mem}; |
19 | 19 | ||
20 | use hir_def::{generics::GenericParams, AdtId}; | 20 | use hir_def::{generics::GenericParams, AdtId}; |
21 | use ra_db::{impl_intern_key, salsa}; | ||
21 | 22 | ||
22 | use crate::{ | 23 | use crate::{ |
23 | db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, FloatTy, | 24 | db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, FloatTy, |
@@ -114,6 +115,13 @@ pub enum TypeCtor { | |||
114 | Closure { def: DefWithBody, expr: ExprId }, | 115 | Closure { def: DefWithBody, expr: ExprId }, |
115 | } | 116 | } |
116 | 117 | ||
118 | /// This exists just for Chalk, because Chalk just has a single `StructId` where | ||
119 | /// we have different kinds of ADTs, primitive types and special type | ||
120 | /// constructors like tuples and function pointers. | ||
121 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
122 | pub struct TypeCtorId(salsa::InternId); | ||
123 | impl_intern_key!(TypeCtorId); | ||
124 | |||
117 | impl TypeCtor { | 125 | impl TypeCtor { |
118 | pub fn num_ty_params(self, db: &impl HirDatabase) -> usize { | 126 | pub fn num_ty_params(self, db: &impl HirDatabase) -> usize { |
119 | match self { | 127 | match self { |
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index 45f725438..268fa09e4 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs | |||
@@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex}; | |||
3 | 3 | ||
4 | use chalk_ir::{cast::Cast, family::ChalkIr}; | 4 | use chalk_ir::{cast::Cast, family::ChalkIr}; |
5 | use log::debug; | 5 | use log::debug; |
6 | use ra_db::salsa; | 6 | use ra_db::{impl_intern_key, salsa}; |
7 | use ra_prof::profile; | 7 | use ra_prof::profile; |
8 | use rustc_hash::FxHashSet; | 8 | use rustc_hash::FxHashSet; |
9 | 9 | ||
@@ -304,6 +304,10 @@ pub enum Impl { | |||
304 | /// Closure types implement the Fn traits synthetically. | 304 | /// Closure types implement the Fn traits synthetically. |
305 | ClosureFnTraitImpl(ClosureFnTraitImplData), | 305 | ClosureFnTraitImpl(ClosureFnTraitImplData), |
306 | } | 306 | } |
307 | /// This exists just for Chalk, because our ImplIds are only unique per module. | ||
308 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
309 | pub struct GlobalImplId(salsa::InternId); | ||
310 | impl_intern_key!(GlobalImplId); | ||
307 | 311 | ||
308 | /// An associated type value. Usually this comes from a `type` declaration | 312 | /// An associated type value. Usually this comes from a `type` declaration |
309 | /// inside an impl block, but for built-in impls we have to synthesize it. | 313 | /// inside an impl block, but for built-in impls we have to synthesize it. |
@@ -315,3 +319,8 @@ pub enum AssocTyValue { | |||
315 | /// The output type of the Fn trait implementation. | 319 | /// The output type of the Fn trait implementation. |
316 | ClosureFnTraitImplOutput(ClosureFnTraitImplData), | 320 | ClosureFnTraitImplOutput(ClosureFnTraitImplData), |
317 | } | 321 | } |
322 | /// This exists just for Chalk, because it needs a unique ID for each associated | ||
323 | /// type value in an impl (even synthetic ones). | ||
324 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
325 | pub struct AssocTyValueId(salsa::InternId); | ||
326 | impl_intern_key!(AssocTyValueId); | ||
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs index 53818a5e5..9efdc53c4 100644 --- a/crates/ra_hir/src/ty/traits/chalk.rs +++ b/crates/ra_hir/src/ty/traits/chalk.rs | |||
@@ -847,38 +847,38 @@ fn id_to_chalk<T: InternKey>(salsa_id: T) -> chalk_ir::RawId { | |||
847 | chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() } | 847 | chalk_ir::RawId { index: salsa_id.as_intern_id().as_u32() } |
848 | } | 848 | } |
849 | 849 | ||
850 | impl From<chalk_ir::StructId> for crate::ids::TypeCtorId { | 850 | impl From<chalk_ir::StructId> for crate::ty::TypeCtorId { |
851 | fn from(struct_id: chalk_ir::StructId) -> Self { | 851 | fn from(struct_id: chalk_ir::StructId) -> Self { |
852 | id_from_chalk(struct_id.0) | 852 | id_from_chalk(struct_id.0) |
853 | } | 853 | } |
854 | } | 854 | } |
855 | 855 | ||
856 | impl From<crate::ids::TypeCtorId> for chalk_ir::StructId { | 856 | impl From<crate::ty::TypeCtorId> for chalk_ir::StructId { |
857 | fn from(type_ctor_id: crate::ids::TypeCtorId) -> Self { | 857 | fn from(type_ctor_id: crate::ty::TypeCtorId) -> Self { |
858 | chalk_ir::StructId(id_to_chalk(type_ctor_id)) | 858 | chalk_ir::StructId(id_to_chalk(type_ctor_id)) |
859 | } | 859 | } |
860 | } | 860 | } |
861 | 861 | ||
862 | impl From<chalk_ir::ImplId> for crate::ids::GlobalImplId { | 862 | impl From<chalk_ir::ImplId> for crate::ty::traits::GlobalImplId { |
863 | fn from(impl_id: chalk_ir::ImplId) -> Self { | 863 | fn from(impl_id: chalk_ir::ImplId) -> Self { |
864 | id_from_chalk(impl_id.0) | 864 | id_from_chalk(impl_id.0) |
865 | } | 865 | } |
866 | } | 866 | } |
867 | 867 | ||
868 | impl From<crate::ids::GlobalImplId> for chalk_ir::ImplId { | 868 | impl From<crate::ty::traits::GlobalImplId> for chalk_ir::ImplId { |
869 | fn from(impl_id: crate::ids::GlobalImplId) -> Self { | 869 | fn from(impl_id: crate::ty::traits::GlobalImplId) -> Self { |
870 | chalk_ir::ImplId(id_to_chalk(impl_id)) | 870 | chalk_ir::ImplId(id_to_chalk(impl_id)) |
871 | } | 871 | } |
872 | } | 872 | } |
873 | 873 | ||
874 | impl From<chalk_rust_ir::AssociatedTyValueId> for crate::ids::AssocTyValueId { | 874 | impl From<chalk_rust_ir::AssociatedTyValueId> for crate::ty::traits::AssocTyValueId { |
875 | fn from(id: chalk_rust_ir::AssociatedTyValueId) -> Self { | 875 | fn from(id: chalk_rust_ir::AssociatedTyValueId) -> Self { |
876 | id_from_chalk(id.0) | 876 | id_from_chalk(id.0) |
877 | } | 877 | } |
878 | } | 878 | } |
879 | 879 | ||
880 | impl From<crate::ids::AssocTyValueId> for chalk_rust_ir::AssociatedTyValueId { | 880 | impl From<crate::ty::traits::AssocTyValueId> for chalk_rust_ir::AssociatedTyValueId { |
881 | fn from(assoc_ty_value_id: crate::ids::AssocTyValueId) -> Self { | 881 | fn from(assoc_ty_value_id: crate::ty::traits::AssocTyValueId) -> Self { |
882 | chalk_rust_ir::AssociatedTyValueId(id_to_chalk(assoc_ty_value_id)) | 882 | chalk_rust_ir::AssociatedTyValueId(id_to_chalk(assoc_ty_value_id)) |
883 | } | 883 | } |
884 | } | 884 | } |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 1d195d65d..b063530c2 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -35,7 +35,7 @@ use std::hash::{Hash, Hasher}; | |||
35 | 35 | ||
36 | use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, MacroDefId, Source}; | 36 | use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, MacroDefId, Source}; |
37 | use ra_arena::{impl_arena_id, map::ArenaMap, RawId}; | 37 | use ra_arena::{impl_arena_id, map::ArenaMap, RawId}; |
38 | use ra_db::{salsa, CrateId}; | 38 | use ra_db::{impl_intern_key, salsa, CrateId}; |
39 | use ra_syntax::{ast, AstNode}; | 39 | use ra_syntax::{ast, AstNode}; |
40 | 40 | ||
41 | use crate::{builtin_type::BuiltinType, db::InternDatabase}; | 41 | use crate::{builtin_type::BuiltinType, db::InternDatabase}; |
@@ -56,19 +56,6 @@ pub struct ModuleId { | |||
56 | pub struct LocalModuleId(RawId); | 56 | pub struct LocalModuleId(RawId); |
57 | impl_arena_id!(LocalModuleId); | 57 | impl_arena_id!(LocalModuleId); |
58 | 58 | ||
59 | macro_rules! impl_intern_key { | ||
60 | ($name:ident) => { | ||
61 | impl salsa::InternKey for $name { | ||
62 | fn from_intern_id(v: salsa::InternId) -> Self { | ||
63 | $name(v) | ||
64 | } | ||
65 | fn as_intern_id(&self) -> salsa::InternId { | ||
66 | self.0 | ||
67 | } | ||
68 | } | ||
69 | }; | ||
70 | } | ||
71 | |||
72 | #[derive(Debug)] | 59 | #[derive(Debug)] |
73 | pub struct ItemLoc<N: AstNode> { | 60 | pub struct ItemLoc<N: AstNode> { |
74 | pub(crate) module: ModuleId, | 61 | pub(crate) module: ModuleId, |
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 3b2e99647..f6cf59c5f 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs | |||
@@ -66,7 +66,7 @@ use ra_arena::Arena; | |||
66 | use ra_db::{CrateId, Edition, FileId}; | 66 | use ra_db::{CrateId, Edition, FileId}; |
67 | use ra_prof::profile; | 67 | use ra_prof::profile; |
68 | use ra_syntax::ast; | 68 | use ra_syntax::ast; |
69 | use rustc_hash::{FxHashMap, FxHashSet}; | 69 | use rustc_hash::FxHashMap; |
70 | 70 | ||
71 | use crate::{ | 71 | use crate::{ |
72 | builtin_type::BuiltinType, | 72 | builtin_type::BuiltinType, |
@@ -90,18 +90,6 @@ pub struct CrateDefMap { | |||
90 | root: LocalModuleId, | 90 | root: LocalModuleId, |
91 | modules: Arena<LocalModuleId, ModuleData>, | 91 | modules: Arena<LocalModuleId, ModuleData>, |
92 | 92 | ||
93 | /// Some macros are not well-behavior, which leads to infinite loop | ||
94 | /// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } } | ||
95 | /// We mark it down and skip it in collector | ||
96 | /// | ||
97 | /// FIXME: | ||
98 | /// Right now it only handle a poison macro in a single crate, | ||
99 | /// such that if other crate try to call that macro, | ||
100 | /// the whole process will do again until it became poisoned in that crate. | ||
101 | /// We should handle this macro set globally | ||
102 | /// However, do we want to put it as a global variable? | ||
103 | poison_macros: FxHashSet<MacroDefId>, | ||
104 | |||
105 | diagnostics: Vec<DefDiagnostic>, | 93 | diagnostics: Vec<DefDiagnostic>, |
106 | } | 94 | } |
107 | 95 | ||
@@ -234,7 +222,6 @@ impl CrateDefMap { | |||
234 | prelude: None, | 222 | prelude: None, |
235 | root, | 223 | root, |
236 | modules, | 224 | modules, |
237 | poison_macros: FxHashSet::default(), | ||
238 | diagnostics: Vec::new(), | 225 | diagnostics: Vec::new(), |
239 | } | 226 | } |
240 | }; | 227 | }; |
@@ -267,16 +254,6 @@ impl CrateDefMap { | |||
267 | self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink)) | 254 | self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink)) |
268 | } | 255 | } |
269 | 256 | ||
270 | pub fn resolve_path( | ||
271 | &self, | ||
272 | db: &impl DefDatabase, | ||
273 | original_module: LocalModuleId, | ||
274 | path: &Path, | ||
275 | ) -> (PerNs, Option<usize>) { | ||
276 | let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path); | ||
277 | (res.resolved_def, res.segment_index) | ||
278 | } | ||
279 | |||
280 | pub fn modules(&self) -> impl Iterator<Item = LocalModuleId> + '_ { | 257 | pub fn modules(&self) -> impl Iterator<Item = LocalModuleId> + '_ { |
281 | self.modules.iter().map(|(id, _data)| id) | 258 | self.modules.iter().map(|(id, _data)| id) |
282 | } | 259 | } |
@@ -287,6 +264,16 @@ impl CrateDefMap { | |||
287 | .filter(move |(_id, data)| data.definition == Some(file_id)) | 264 | .filter(move |(_id, data)| data.definition == Some(file_id)) |
288 | .map(|(id, _data)| id) | 265 | .map(|(id, _data)| id) |
289 | } | 266 | } |
267 | |||
268 | pub(crate) fn resolve_path( | ||
269 | &self, | ||
270 | db: &impl DefDatabase, | ||
271 | original_module: LocalModuleId, | ||
272 | path: &Path, | ||
273 | ) -> (PerNs, Option<usize>) { | ||
274 | let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path); | ||
275 | (res.resolved_def, res.segment_index) | ||
276 | } | ||
290 | } | 277 | } |
291 | 278 | ||
292 | impl ModuleData { | 279 | impl ModuleData { |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index b02364e86..1d004b6a6 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -8,7 +8,7 @@ use hir_expand::{ | |||
8 | use ra_cfg::CfgOptions; | 8 | use ra_cfg::CfgOptions; |
9 | use ra_db::{CrateId, FileId}; | 9 | use ra_db::{CrateId, FileId}; |
10 | use ra_syntax::{ast, SmolStr}; | 10 | use ra_syntax::{ast, SmolStr}; |
11 | use rustc_hash::FxHashMap; | 11 | use rustc_hash::{FxHashMap, FxHashSet}; |
12 | use test_utils::tested_by; | 12 | use test_utils::tested_by; |
13 | 13 | ||
14 | use crate::{ | 14 | use crate::{ |
@@ -57,6 +57,7 @@ pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> C | |||
57 | unexpanded_macros: Vec::new(), | 57 | unexpanded_macros: Vec::new(), |
58 | mod_dirs: FxHashMap::default(), | 58 | mod_dirs: FxHashMap::default(), |
59 | macro_stack_monitor: MacroStackMonitor::default(), | 59 | macro_stack_monitor: MacroStackMonitor::default(), |
60 | poison_macros: FxHashSet::default(), | ||
60 | cfg_options, | 61 | cfg_options, |
61 | }; | 62 | }; |
62 | collector.collect(); | 63 | collector.collect(); |
@@ -103,6 +104,17 @@ struct DefCollector<'a, DB> { | |||
103 | /// Some macro use `$tt:tt which mean we have to handle the macro perfectly | 104 | /// Some macro use `$tt:tt which mean we have to handle the macro perfectly |
104 | /// To prevent stack overflow, we add a deep counter here for prevent that. | 105 | /// To prevent stack overflow, we add a deep counter here for prevent that. |
105 | macro_stack_monitor: MacroStackMonitor, | 106 | macro_stack_monitor: MacroStackMonitor, |
107 | /// Some macros are not well-behavior, which leads to infinite loop | ||
108 | /// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } } | ||
109 | /// We mark it down and skip it in collector | ||
110 | /// | ||
111 | /// FIXME: | ||
112 | /// Right now it only handle a poison macro in a single crate, | ||
113 | /// such that if other crate try to call that macro, | ||
114 | /// the whole process will do again until it became poisoned in that crate. | ||
115 | /// We should handle this macro set globally | ||
116 | /// However, do we want to put it as a global variable? | ||
117 | poison_macros: FxHashSet<MacroDefId>, | ||
106 | 118 | ||
107 | cfg_options: &'a CfgOptions, | 119 | cfg_options: &'a CfgOptions, |
108 | } | 120 | } |
@@ -489,7 +501,7 @@ where | |||
489 | macro_call_id: MacroCallId, | 501 | macro_call_id: MacroCallId, |
490 | macro_def_id: MacroDefId, | 502 | macro_def_id: MacroDefId, |
491 | ) { | 503 | ) { |
492 | if self.def_map.poison_macros.contains(¯o_def_id) { | 504 | if self.poison_macros.contains(¯o_def_id) { |
493 | return; | 505 | return; |
494 | } | 506 | } |
495 | 507 | ||
@@ -509,7 +521,7 @@ where | |||
509 | .collect(raw_items.items()); | 521 | .collect(raw_items.items()); |
510 | } else { | 522 | } else { |
511 | log::error!("Too deep macro expansion: {:?}", macro_call_id); | 523 | log::error!("Too deep macro expansion: {:?}", macro_call_id); |
512 | self.def_map.poison_macros.insert(macro_def_id); | 524 | self.poison_macros.insert(macro_def_id); |
513 | } | 525 | } |
514 | 526 | ||
515 | self.macro_stack_monitor.decrease(macro_def_id); | 527 | self.macro_stack_monitor.decrease(macro_def_id); |
@@ -807,7 +819,7 @@ mod tests { | |||
807 | db: &impl DefDatabase, | 819 | db: &impl DefDatabase, |
808 | def_map: CrateDefMap, | 820 | def_map: CrateDefMap, |
809 | monitor: MacroStackMonitor, | 821 | monitor: MacroStackMonitor, |
810 | ) -> CrateDefMap { | 822 | ) -> (CrateDefMap, FxHashSet<MacroDefId>) { |
811 | let mut collector = DefCollector { | 823 | let mut collector = DefCollector { |
812 | db, | 824 | db, |
813 | def_map, | 825 | def_map, |
@@ -816,13 +828,18 @@ mod tests { | |||
816 | unexpanded_macros: Vec::new(), | 828 | unexpanded_macros: Vec::new(), |
817 | mod_dirs: FxHashMap::default(), | 829 | mod_dirs: FxHashMap::default(), |
818 | macro_stack_monitor: monitor, | 830 | macro_stack_monitor: monitor, |
831 | poison_macros: FxHashSet::default(), | ||
819 | cfg_options: &CfgOptions::default(), | 832 | cfg_options: &CfgOptions::default(), |
820 | }; | 833 | }; |
821 | collector.collect(); | 834 | collector.collect(); |
822 | collector.finish() | 835 | (collector.def_map, collector.poison_macros) |
823 | } | 836 | } |
824 | 837 | ||
825 | fn do_limited_resolve(code: &str, limit: u32, poison_limit: u32) -> CrateDefMap { | 838 | fn do_limited_resolve( |
839 | code: &str, | ||
840 | limit: u32, | ||
841 | poison_limit: u32, | ||
842 | ) -> (CrateDefMap, FxHashSet<MacroDefId>) { | ||
826 | let (db, _file_id) = TestDB::with_single_file(&code); | 843 | let (db, _file_id) = TestDB::with_single_file(&code); |
827 | let krate = db.test_crate(); | 844 | let krate = db.test_crate(); |
828 | 845 | ||
@@ -837,7 +854,6 @@ mod tests { | |||
837 | prelude: None, | 854 | prelude: None, |
838 | root, | 855 | root, |
839 | modules, | 856 | modules, |
840 | poison_macros: FxHashSet::default(), | ||
841 | diagnostics: Vec::new(), | 857 | diagnostics: Vec::new(), |
842 | } | 858 | } |
843 | }; | 859 | }; |
@@ -867,7 +883,7 @@ foo!(KABOOM); | |||
867 | 883 | ||
868 | #[test] | 884 | #[test] |
869 | fn test_macro_expand_poisoned() { | 885 | fn test_macro_expand_poisoned() { |
870 | let def = do_limited_resolve( | 886 | let (_, poison_macros) = do_limited_resolve( |
871 | r#" | 887 | r#" |
872 | macro_rules! foo { | 888 | macro_rules! foo { |
873 | ($ty:ty) => { foo!($ty); } | 889 | ($ty:ty) => { foo!($ty); } |
@@ -878,12 +894,12 @@ foo!(KABOOM); | |||
878 | 16, | 894 | 16, |
879 | ); | 895 | ); |
880 | 896 | ||
881 | assert_eq!(def.poison_macros.len(), 1); | 897 | assert_eq!(poison_macros.len(), 1); |
882 | } | 898 | } |
883 | 899 | ||
884 | #[test] | 900 | #[test] |
885 | fn test_macro_expand_normal() { | 901 | fn test_macro_expand_normal() { |
886 | let def = do_limited_resolve( | 902 | let (_, poison_macros) = do_limited_resolve( |
887 | r#" | 903 | r#" |
888 | macro_rules! foo { | 904 | macro_rules! foo { |
889 | ($ident:ident) => { struct $ident {} } | 905 | ($ident:ident) => { struct $ident {} } |
@@ -894,6 +910,6 @@ foo!(Bar); | |||
894 | 16, | 910 | 16, |
895 | ); | 911 | ); |
896 | 912 | ||
897 | assert_eq!(def.poison_macros.len(), 0); | 913 | assert_eq!(poison_macros.len(), 0); |
898 | } | 914 | } |
899 | } | 915 | } |