mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
Remove last traces of nameres from hir
This commit is contained in:
parent
73fcf9a2d6
commit
f0eb9cc6e6
8 changed files with 59 additions and 67 deletions
|
@ -28,11 +28,10 @@ use crate::{
|
||||||
TypeAliasId,
|
TypeAliasId,
|
||||||
},
|
},
|
||||||
impl_block::ImplBlock,
|
impl_block::ImplBlock,
|
||||||
nameres::{ImportId, Namespace},
|
|
||||||
resolve::{Resolver, Scope, TypeNs},
|
resolve::{Resolver, Scope, TypeNs},
|
||||||
traits::TraitData,
|
traits::TraitData,
|
||||||
ty::{InferenceResult, TraitRef},
|
ty::{InferenceResult, TraitRef},
|
||||||
Either, HasSource, Name, ScopeDef, Ty,
|
Either, HasSource, Name, ScopeDef, Ty, {ImportId, Namespace},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// hir::Crate describes a single crate. It's the main interface with which
|
/// hir::Crate describes a single crate. It's the main interface with which
|
||||||
|
|
|
@ -11,14 +11,13 @@ use crate::{
|
||||||
ids,
|
ids,
|
||||||
impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks},
|
impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks},
|
||||||
lang_item::{LangItemTarget, LangItems},
|
lang_item::{LangItemTarget, LangItems},
|
||||||
nameres::Namespace,
|
|
||||||
traits::TraitData,
|
traits::TraitData,
|
||||||
ty::{
|
ty::{
|
||||||
method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate,
|
method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate,
|
||||||
InferenceResult, Substs, Ty, TypableDef, TypeCtor,
|
InferenceResult, Substs, Ty, TypableDef, TypeCtor,
|
||||||
},
|
},
|
||||||
type_alias::TypeAliasData,
|
type_alias::TypeAliasData,
|
||||||
Const, ConstData, Crate, DefWithBody, ExprScopes, FnData, Function, Module, Static,
|
Const, ConstData, Crate, DefWithBody, ExprScopes, FnData, Function, Module, Namespace, Static,
|
||||||
StructField, Trait, TypeAlias,
|
StructField, Trait, TypeAlias,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ pub mod mock;
|
||||||
pub mod source_binder;
|
pub mod source_binder;
|
||||||
|
|
||||||
mod ids;
|
mod ids;
|
||||||
mod nameres;
|
|
||||||
mod adt;
|
mod adt;
|
||||||
mod traits;
|
mod traits;
|
||||||
mod type_alias;
|
mod type_alias;
|
||||||
|
@ -73,7 +72,6 @@ pub use crate::{
|
||||||
generics::{GenericDef, GenericParam, GenericParams, HasGenericParams},
|
generics::{GenericDef, GenericParam, GenericParams, HasGenericParams},
|
||||||
ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile},
|
ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile},
|
||||||
impl_block::ImplBlock,
|
impl_block::ImplBlock,
|
||||||
nameres::{ImportId, Namespace, PerNs},
|
|
||||||
resolve::ScopeDef,
|
resolve::ScopeDef,
|
||||||
source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
|
source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
|
||||||
ty::{
|
ty::{
|
||||||
|
@ -83,6 +81,10 @@ pub use crate::{
|
||||||
|
|
||||||
pub use hir_def::{
|
pub use hir_def::{
|
||||||
builtin_type::BuiltinType,
|
builtin_type::BuiltinType,
|
||||||
|
nameres::{
|
||||||
|
per_ns::{Namespace, PerNs},
|
||||||
|
raw::ImportId,
|
||||||
|
},
|
||||||
path::{Path, PathKind},
|
path::{Path, PathKind},
|
||||||
type_ref::Mutability,
|
type_ref::Mutability,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
//! This module implements import-resolution/macro expansion algorithm.
|
|
||||||
//!
|
|
||||||
//! The result of this module is `CrateDefMap`: a data structure which contains:
|
|
||||||
//!
|
|
||||||
//! * a tree of modules for the crate
|
|
||||||
//! * for each module, a set of items visible in the module (directly declared
|
|
||||||
//! or imported)
|
|
||||||
//!
|
|
||||||
//! Note that `CrateDefMap` contains fully macro expanded code.
|
|
||||||
//!
|
|
||||||
//! Computing `CrateDefMap` can be partitioned into several logically
|
|
||||||
//! independent "phases". The phases are mutually recursive though, there's no
|
|
||||||
//! strict ordering.
|
|
||||||
//!
|
|
||||||
//! ## Collecting RawItems
|
|
||||||
//!
|
|
||||||
//! This happens in the `raw` module, which parses a single source file into a
|
|
||||||
//! set of top-level items. Nested imports are desugared to flat imports in
|
|
||||||
//! this phase. Macro calls are represented as a triple of (Path, Option<Name>,
|
|
||||||
//! TokenTree).
|
|
||||||
//!
|
|
||||||
//! ## Collecting Modules
|
|
||||||
//!
|
|
||||||
//! This happens in the `collector` module. In this phase, we recursively walk
|
|
||||||
//! tree of modules, collect raw items from submodules, populate module scopes
|
|
||||||
//! with defined items (so, we assign item ids in this phase) and record the set
|
|
||||||
//! of unresolved imports and macros.
|
|
||||||
//!
|
|
||||||
//! While we walk tree of modules, we also record macro_rules definitions and
|
|
||||||
//! expand calls to macro_rules defined macros.
|
|
||||||
//!
|
|
||||||
//! ## Resolving Imports
|
|
||||||
//!
|
|
||||||
//! We maintain a list of currently unresolved imports. On every iteration, we
|
|
||||||
//! try to resolve some imports from this list. If the import is resolved, we
|
|
||||||
//! record it, by adding an item to current module scope and, if necessary, by
|
|
||||||
//! recursively populating glob imports.
|
|
||||||
//!
|
|
||||||
//! ## Resolving Macros
|
|
||||||
//!
|
|
||||||
//! macro_rules from the same crate use a global mutable namespace. We expand
|
|
||||||
//! them immediately, when we collect modules.
|
|
||||||
//!
|
|
||||||
//! Macros from other crates (including proc-macros) can be used with
|
|
||||||
//! `foo::bar!` syntax. We handle them similarly to imports. There's a list of
|
|
||||||
//! unexpanded macros. On every iteration, we try to resolve each macro call
|
|
||||||
//! path and, upon success, we run macro expansion and "collect module" phase
|
|
||||||
//! on the result
|
|
||||||
|
|
||||||
pub use hir_def::nameres::{
|
|
||||||
per_ns::{Namespace, PerNs},
|
|
||||||
raw::ImportId,
|
|
||||||
};
|
|
|
@ -19,8 +19,8 @@ use crate::{
|
||||||
},
|
},
|
||||||
generics::GenericParams,
|
generics::GenericParams,
|
||||||
impl_block::ImplBlock,
|
impl_block::ImplBlock,
|
||||||
nameres::PerNs,
|
Adt, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, PerNs, Static, Struct, Trait,
|
||||||
Adt, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, Trait, TypeAlias,
|
TypeAlias,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
|
|
|
@ -11,12 +11,11 @@ use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
|
expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
|
||||||
generics::{GenericParams, HasGenericParams},
|
generics::{GenericParams, HasGenericParams},
|
||||||
nameres::Namespace,
|
|
||||||
ty::{
|
ty::{
|
||||||
autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation,
|
autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation,
|
||||||
ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
|
ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
|
||||||
},
|
},
|
||||||
Adt, Name,
|
Adt, Name, Namespace,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||||
|
|
|
@ -23,15 +23,14 @@ use crate::{
|
||||||
db::HirDatabase,
|
db::HirDatabase,
|
||||||
generics::HasGenericParams,
|
generics::HasGenericParams,
|
||||||
generics::{GenericDef, WherePredicate},
|
generics::{GenericDef, WherePredicate},
|
||||||
nameres::Namespace,
|
|
||||||
resolve::{Resolver, TypeNs},
|
resolve::{Resolver, TypeNs},
|
||||||
ty::{
|
ty::{
|
||||||
primitive::{FloatTy, IntTy},
|
primitive::{FloatTy, IntTy},
|
||||||
Adt,
|
Adt,
|
||||||
},
|
},
|
||||||
util::make_mut_slice,
|
util::make_mut_slice,
|
||||||
Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait,
|
Const, Enum, EnumVariant, Function, ModuleDef, Namespace, Path, Static, Struct, StructField,
|
||||||
TypeAlias, Union,
|
Trait, TypeAlias, Union,
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Ty {
|
impl Ty {
|
||||||
|
|
|
@ -1,4 +1,51 @@
|
||||||
//! FIXME: write short doc here
|
//! This module implements import-resolution/macro expansion algorithm.
|
||||||
|
//!
|
||||||
|
//! The result of this module is `CrateDefMap`: a data structure which contains:
|
||||||
|
//!
|
||||||
|
//! * a tree of modules for the crate
|
||||||
|
//! * for each module, a set of items visible in the module (directly declared
|
||||||
|
//! or imported)
|
||||||
|
//!
|
||||||
|
//! Note that `CrateDefMap` contains fully macro expanded code.
|
||||||
|
//!
|
||||||
|
//! Computing `CrateDefMap` can be partitioned into several logically
|
||||||
|
//! independent "phases". The phases are mutually recursive though, there's no
|
||||||
|
//! strict ordering.
|
||||||
|
//!
|
||||||
|
//! ## Collecting RawItems
|
||||||
|
//!
|
||||||
|
//! This happens in the `raw` module, which parses a single source file into a
|
||||||
|
//! set of top-level items. Nested imports are desugared to flat imports in
|
||||||
|
//! this phase. Macro calls are represented as a triple of (Path, Option<Name>,
|
||||||
|
//! TokenTree).
|
||||||
|
//!
|
||||||
|
//! ## Collecting Modules
|
||||||
|
//!
|
||||||
|
//! This happens in the `collector` module. In this phase, we recursively walk
|
||||||
|
//! tree of modules, collect raw items from submodules, populate module scopes
|
||||||
|
//! with defined items (so, we assign item ids in this phase) and record the set
|
||||||
|
//! of unresolved imports and macros.
|
||||||
|
//!
|
||||||
|
//! While we walk tree of modules, we also record macro_rules definitions and
|
||||||
|
//! expand calls to macro_rules defined macros.
|
||||||
|
//!
|
||||||
|
//! ## Resolving Imports
|
||||||
|
//!
|
||||||
|
//! We maintain a list of currently unresolved imports. On every iteration, we
|
||||||
|
//! try to resolve some imports from this list. If the import is resolved, we
|
||||||
|
//! record it, by adding an item to current module scope and, if necessary, by
|
||||||
|
//! recursively populating glob imports.
|
||||||
|
//!
|
||||||
|
//! ## Resolving Macros
|
||||||
|
//!
|
||||||
|
//! macro_rules from the same crate use a global mutable namespace. We expand
|
||||||
|
//! them immediately, when we collect modules.
|
||||||
|
//!
|
||||||
|
//! Macros from other crates (including proc-macros) can be used with
|
||||||
|
//! `foo::bar!` syntax. We handle them similarly to imports. There's a list of
|
||||||
|
//! unexpanded macros. On every iteration, we try to resolve each macro call
|
||||||
|
//! path and, upon success, we run macro expansion and "collect module" phase
|
||||||
|
//! on the result
|
||||||
|
|
||||||
// FIXME: review privacy of submodules
|
// FIXME: review privacy of submodules
|
||||||
pub mod raw;
|
pub mod raw;
|
||||||
|
|
Loading…
Reference in a new issue