Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
68d6edda
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
68d6edda
编写于
2月 18, 2018
作者:
M
Michal 'vorner' Vaner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Some comments and documentation for name resolution crate
上级
c9b86a91
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
42 addition
and
3 deletion
+42
-3
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+42
-3
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
68d6edda
...
...
@@ -162,6 +162,10 @@ enum ResolutionError<'a> {
ForwardDeclaredTyParam
,
}
/// Combines an error with provided span and emits it
///
/// This takes the error provided, combines it with the span and any additional spans inside the
/// error and emits it.
fn
resolve_error
<
'sess
,
'a
>
(
resolver
:
&
'sess
Resolver
,
span
:
Span
,
resolution_error
:
ResolutionError
<
'a
>
)
{
...
...
@@ -364,7 +368,7 @@ struct BindingInfo {
binding_mode
:
BindingMode
,
}
// Map from the name in a pattern to its binding mode.
//
/
Map from the name in a pattern to its binding mode.
type
BindingMap
=
FxHashMap
<
Ident
,
BindingInfo
>
;
#[derive(Copy,
Clone,
PartialEq,
Eq,
Debug)]
...
...
@@ -559,6 +563,9 @@ fn error_code(self, has_unexpected_resolution: bool) -> &'static str {
}
}
/// Different kinds of symbols don't influence each other.
///
/// Therefore, they have a separate universe (namespace).
#[derive(Copy,
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Debug)]
pub
enum
Namespace
{
TypeNS
,
...
...
@@ -566,6 +573,7 @@ pub enum Namespace {
MacroNS
,
}
/// Just a helper ‒ separate structure for each namespace.
#[derive(Clone,
Default,
Debug)]
pub
struct
PerNS
<
T
>
{
value_ns
:
T
,
...
...
@@ -662,6 +670,7 @@ fn visit_mod(
}
}
/// This thing walks the whole crate in DFS manner, visiting each item, resolving names as it goes.
impl
<
'a
,
'tcx
>
Visitor
<
'tcx
>
for
Resolver
<
'a
>
{
fn
visit_item
(
&
mut
self
,
item
:
&
'tcx
Item
)
{
self
.resolve_item
(
item
);
...
...
@@ -788,7 +797,9 @@ fn visit_fn(&mut self,
fn
visit_generics
(
&
mut
self
,
generics
:
&
'tcx
Generics
)
{
// For type parameter defaults, we have to ban access
// to following type parameters, as the Substs can only
// provide previous type parameters as they're built.
// provide previous type parameters as they're built. We
// put all the parameters on the ban list and then remove
// them one by one as they are processed and become available.
let
mut
default_ban_rib
=
Rib
::
new
(
ForwardTyParamBanRibKind
);
default_ban_rib
.bindings
.extend
(
generics
.params
.iter
()
.filter_map
(|
p
|
if
let
GenericParam
::
Type
(
ref
tp
)
=
*
p
{
Some
(
tp
)
}
else
{
None
})
...
...
@@ -864,6 +875,16 @@ enum RibKind<'a> {
}
/// One local scope.
///
/// A rib represents a scope names can live in. Note that these appear in many places, not just
/// around braces. At any place where the list of accessible names (of the given namespace)
/// changes, a new rib is put onto a stack. This may be, for example, a `let` statement (because it
/// introduces variables), a macro, etc.
///
/// Different [rib kinds](enum.RibKind) are transparent for different names.
///
/// The resolution keeps a separate stack of ribs as it traverses the AST for each namespace. When
/// resolving, the name is looked up from inside out.
#[derive(Debug)]
struct
Rib
<
'a
>
{
bindings
:
FxHashMap
<
Ident
,
Def
>
,
...
...
@@ -879,6 +900,11 @@ fn new(kind: RibKind<'a>) -> Rib<'a> {
}
}
/// An intermediate resolution result.
///
/// This refers to the thing referred by a name. The difference between `Def` and `Item` is that
/// items are visible in their whole block, while defs only from the place they are defined
/// forward.
enum
LexicalScopeBinding
<
'a
>
{
Item
(
&
'a
NameBinding
<
'a
>
),
Def
(
Def
),
...
...
@@ -909,7 +935,11 @@ enum PathResult<'a> {
}
enum
ModuleKind
{
/// Inline `mod something { ... }`.
Block
(
NodeId
),
/// Module from another file.
///
/// Also called a normal module in the following code.
Def
(
Def
,
Name
),
}
...
...
@@ -1194,6 +1224,9 @@ fn descr(&self) -> &'static str {
}
/// Interns the names of the primitive types.
///
/// All other types are defined somewhere and possibly imported, but the primitive ones need
/// special handling, since they have no place of origin.
struct
PrimitiveTypeTable
{
primitive_types
:
FxHashMap
<
Name
,
PrimTy
>
,
}
...
...
@@ -1228,6 +1261,8 @@ fn intern(&mut self, string: &str, primitive_type: PrimTy) {
}
/// The main resolver class.
///
/// This is the visitor that walks the whole crate.
pub
struct
Resolver
<
'a
>
{
session
:
&
'a
Session
,
cstore
:
&
'a
CrateStore
,
...
...
@@ -1359,6 +1394,7 @@ pub struct Resolver<'a> {
injected_crate
:
Option
<
Module
<
'a
>>
,
}
/// Nothing really interesting here, it just provides memory for the rest of the crate.
pub
struct
ResolverArenas
<
'a
>
{
modules
:
arena
::
TypedArena
<
ModuleData
<
'a
>>
,
local_modules
:
RefCell
<
Vec
<
Module
<
'a
>>>
,
...
...
@@ -1404,10 +1440,12 @@ fn parent(self, id: DefId) -> Option<DefId> {
match
id
.krate
{
LOCAL_CRATE
=>
self
.definitions
.def_key
(
id
.index
)
.parent
,
_
=>
self
.cstore
.def_key
(
id
)
.parent
,
}
.map
(|
index
|
DefId
{
index
:
index
,
..
id
})
}
.map
(|
index
|
DefId
{
index
,
..
id
})
}
}
/// This is the interface through which the rest of the compiler asks about name resolution after
/// the whole AST has been indexed.
impl
<
'a
>
hir
::
lowering
::
Resolver
for
Resolver
<
'a
>
{
fn
resolve_hir_path
(
&
mut
self
,
path
:
&
mut
hir
::
Path
,
is_value
:
bool
)
{
self
.resolve_hir_path_cb
(
path
,
is_value
,
...
...
@@ -1630,6 +1668,7 @@ pub fn arenas() -> ResolverArenas<'a> {
}
}
/// Runs the function on each namespace.
fn
per_ns
<
T
,
F
:
FnMut
(
&
mut
Self
,
Namespace
)
->
T
>
(
&
mut
self
,
mut
f
:
F
)
->
PerNS
<
T
>
{
PerNS
{
type_ns
:
f
(
self
,
TypeNS
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录