aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs3
-rw-r--r--crates/ra_hir/src/db.rs3
-rw-r--r--crates/ra_hir/src/lib.rs6
-rw-r--r--crates/ra_hir/src/nameres.rs53
-rw-r--r--crates/ra_hir/src/resolve.rs4
-rw-r--r--crates/ra_hir/src/ty/infer/expr.rs3
-rw-r--r--crates/ra_hir/src/ty/lower.rs5
7 files changed, 11 insertions, 66 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index f03b59217..181c5d47a 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -28,11 +28,10 @@ use crate::{
28 TypeAliasId, 28 TypeAliasId,
29 }, 29 },
30 impl_block::ImplBlock, 30 impl_block::ImplBlock,
31 nameres::{ImportId, Namespace},
32 resolve::{Resolver, Scope, TypeNs}, 31 resolve::{Resolver, Scope, TypeNs},
33 traits::TraitData, 32 traits::TraitData,
34 ty::{InferenceResult, TraitRef}, 33 ty::{InferenceResult, TraitRef},
35 Either, HasSource, Name, ScopeDef, Ty, 34 Either, HasSource, Name, ScopeDef, Ty, {ImportId, Namespace},
36}; 35};
37 36
38/// hir::Crate describes a single crate. It's the main interface with which 37/// hir::Crate describes a single crate. It's the main interface with which
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index f45804c7c..eb66325f7 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -11,14 +11,13 @@ use crate::{
11 ids, 11 ids,
12 impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks}, 12 impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks},
13 lang_item::{LangItemTarget, LangItems}, 13 lang_item::{LangItemTarget, LangItems},
14 nameres::Namespace,
15 traits::TraitData, 14 traits::TraitData,
16 ty::{ 15 ty::{
17 method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate, 16 method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate,
18 InferenceResult, Substs, Ty, TypableDef, TypeCtor, 17 InferenceResult, Substs, Ty, TypableDef, TypeCtor,
19 }, 18 },
20 type_alias::TypeAliasData, 19 type_alias::TypeAliasData,
21 Const, ConstData, Crate, DefWithBody, ExprScopes, FnData, Function, Module, Static, 20 Const, ConstData, Crate, DefWithBody, ExprScopes, FnData, Function, Module, Namespace, Static,
22 StructField, Trait, TypeAlias, 21 StructField, Trait, TypeAlias,
23}; 22};
24 23
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 52bad2228..3ba99d92d 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -34,7 +34,6 @@ pub mod mock;
34pub mod source_binder; 34pub mod source_binder;
35 35
36mod ids; 36mod ids;
37mod nameres;
38mod adt; 37mod adt;
39mod traits; 38mod traits;
40mod type_alias; 39mod type_alias;
@@ -73,7 +72,6 @@ pub use crate::{
73 generics::{GenericDef, GenericParam, GenericParams, HasGenericParams}, 72 generics::{GenericDef, GenericParam, GenericParams, HasGenericParams},
74 ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, 73 ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile},
75 impl_block::ImplBlock, 74 impl_block::ImplBlock,
76 nameres::{ImportId, Namespace, PerNs},
77 resolve::ScopeDef, 75 resolve::ScopeDef,
78 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, 76 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
79 ty::{ 77 ty::{
@@ -83,6 +81,10 @@ pub use crate::{
83 81
84pub use hir_def::{ 82pub use hir_def::{
85 builtin_type::BuiltinType, 83 builtin_type::BuiltinType,
84 nameres::{
85 per_ns::{Namespace, PerNs},
86 raw::ImportId,
87 },
86 path::{Path, PathKind}, 88 path::{Path, PathKind},
87 type_ref::Mutability, 89 type_ref::Mutability,
88}; 90};
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
deleted file mode 100644
index 875addc84..000000000
--- a/crates/ra_hir/src/nameres.rs
+++ /dev/null
@@ -1,53 +0,0 @@
1//! This module implements import-resolution/macro expansion algorithm.
2//!
3//! The result of this module is `CrateDefMap`: a data structure which contains:
4//!
5//! * a tree of modules for the crate
6//! * for each module, a set of items visible in the module (directly declared
7//! or imported)
8//!
9//! Note that `CrateDefMap` contains fully macro expanded code.
10//!
11//! Computing `CrateDefMap` can be partitioned into several logically
12//! independent "phases". The phases are mutually recursive though, there's no
13//! strict ordering.
14//!
15//! ## Collecting RawItems
16//!
17//! This happens in the `raw` module, which parses a single source file into a
18//! set of top-level items. Nested imports are desugared to flat imports in
19//! this phase. Macro calls are represented as a triple of (Path, Option<Name>,
20//! TokenTree).
21//!
22//! ## Collecting Modules
23//!
24//! This happens in the `collector` module. In this phase, we recursively walk
25//! tree of modules, collect raw items from submodules, populate module scopes
26//! with defined items (so, we assign item ids in this phase) and record the set
27//! of unresolved imports and macros.
28//!
29//! While we walk tree of modules, we also record macro_rules definitions and
30//! expand calls to macro_rules defined macros.
31//!
32//! ## Resolving Imports
33//!
34//! We maintain a list of currently unresolved imports. On every iteration, we
35//! try to resolve some imports from this list. If the import is resolved, we
36//! record it, by adding an item to current module scope and, if necessary, by
37//! recursively populating glob imports.
38//!
39//! ## Resolving Macros
40//!
41//! macro_rules from the same crate use a global mutable namespace. We expand
42//! them immediately, when we collect modules.
43//!
44//! Macros from other crates (including proc-macros) can be used with
45//! `foo::bar!` syntax. We handle them similarly to imports. There's a list of
46//! unexpanded macros. On every iteration, we try to resolve each macro call
47//! path and, upon success, we run macro expansion and "collect module" phase
48//! on the result
49
50pub use hir_def::nameres::{
51 per_ns::{Namespace, PerNs},
52 raw::ImportId,
53};
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 3e3f8c252..b932b0c8c 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -19,8 +19,8 @@ use crate::{
19 }, 19 },
20 generics::GenericParams, 20 generics::GenericParams,
21 impl_block::ImplBlock, 21 impl_block::ImplBlock,
22 nameres::PerNs, 22 Adt, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, PerNs, Static, Struct, Trait,
23 Adt, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, Trait, TypeAlias, 23 TypeAlias,
24}; 24};
25 25
26#[derive(Debug, Clone, Default)] 26#[derive(Debug, Clone, Default)]
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs
index fed52df39..a09ef5c5d 100644
--- a/crates/ra_hir/src/ty/infer/expr.rs
+++ b/crates/ra_hir/src/ty/infer/expr.rs
@@ -11,12 +11,11 @@ use crate::{
11 db::HirDatabase, 11 db::HirDatabase,
12 expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, 12 expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
13 generics::{GenericParams, HasGenericParams}, 13 generics::{GenericParams, HasGenericParams},
14 nameres::Namespace,
15 ty::{ 14 ty::{
16 autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation, 15 autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation,
17 ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, 16 ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
18 }, 17 },
19 Adt, Name, 18 Adt, Name, Namespace,
20}; 19};
21 20
22impl<'a, D: HirDatabase> InferenceContext<'a, D> { 21impl<'a, D: HirDatabase> InferenceContext<'a, D> {
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 8e2834307..e29ab8492 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -23,15 +23,14 @@ use crate::{
23 db::HirDatabase, 23 db::HirDatabase,
24 generics::HasGenericParams, 24 generics::HasGenericParams,
25 generics::{GenericDef, WherePredicate}, 25 generics::{GenericDef, WherePredicate},
26 nameres::Namespace,
27 resolve::{Resolver, TypeNs}, 26 resolve::{Resolver, TypeNs},
28 ty::{ 27 ty::{
29 primitive::{FloatTy, IntTy}, 28 primitive::{FloatTy, IntTy},
30 Adt, 29 Adt,
31 }, 30 },
32 util::make_mut_slice, 31 util::make_mut_slice,
33 Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait, 32 Const, Enum, EnumVariant, Function, ModuleDef, Namespace, Path, Static, Struct, StructField,
34 TypeAlias, Union, 33 Trait, TypeAlias, Union,
35}; 34};
36 35
37impl Ty { 36impl Ty {