Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
fb4710ce
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,发现更多精彩内容 >>
提交
fb4710ce
编写于
2月 15, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a field in Module for the ResolverArenas
上级
6b94bc34
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
27 deletion
+39
-27
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+4
-5
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+28
-13
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+7
-9
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
fb4710ce
...
...
@@ -98,14 +98,14 @@ fn build_reduced_graph(self, krate: &hir::Crate) {
fn
try_define
<
T
>
(
&
self
,
parent
:
Module
<
'b
>
,
name
:
Name
,
ns
:
Namespace
,
def
:
T
)
where
T
:
ToNameBinding
<
'b
>
{
let
_
=
parent
.try_define_child
(
name
,
ns
,
self
.new_name_binding
(
def
.to_name_binding
()
));
let
_
=
parent
.try_define_child
(
name
,
ns
,
def
.to_name_binding
(
));
}
/// Defines `name` in namespace `ns` of module `parent` to be `def` if it is not yet defined;
/// otherwise, reports an error.
fn
define
<
T
:
ToNameBinding
<
'b
>>
(
&
self
,
parent
:
Module
<
'b
>
,
name
:
Name
,
ns
:
Namespace
,
def
:
T
)
{
let
binding
=
self
.new_name_binding
(
def
.to_name_binding
()
);
let
old_binding
=
match
parent
.try_define_child
(
name
,
ns
,
binding
)
{
let
binding
=
def
.to_name_binding
(
);
let
old_binding
=
match
parent
.try_define_child
(
name
,
ns
,
binding
.clone
()
)
{
Ok
(())
=>
return
,
Err
(
old_binding
)
=>
old_binding
,
};
...
...
@@ -709,8 +709,7 @@ fn build_import_directive(&mut self,
let
directive
=
ImportDirective
::
new
(
module_path
,
subclass
,
span
,
id
,
is_public
,
shadowable
);
let
directive
=
self
.resolver.arenas
.alloc_import_directive
(
directive
);
module_
.unresolved_imports
.borrow_mut
()
.push
(
directive
);
module_
.add_import_directive
(
directive
);
self
.unresolved_imports
+=
1
;
}
}
...
...
src/librustc_resolve/lib.rs
浏览文件 @
fb4710ce
...
...
@@ -845,13 +845,18 @@ pub struct ModuleS<'a> {
// access the children must be preceded with a
// `populate_module_if_necessary` call.
populated
:
Cell
<
bool
>
,
arenas
:
&
'a
ResolverArenas
<
'a
>
,
}
pub
type
Module
<
'a
>
=
&
'a
ModuleS
<
'a
>
;
impl
<
'a
>
ModuleS
<
'a
>
{
fn
new
(
parent_link
:
ParentLink
<
'a
>
,
def
:
Option
<
Def
>
,
external
:
bool
,
is_public
:
bool
)
->
Self
{
fn
new
(
parent_link
:
ParentLink
<
'a
>
,
def
:
Option
<
Def
>
,
external
:
bool
,
is_public
:
bool
,
arenas
:
&
'a
ResolverArenas
<
'a
>
)
->
Self
{
ModuleS
{
parent_link
:
parent_link
,
def
:
def
,
...
...
@@ -865,6 +870,7 @@ fn new(parent_link: ParentLink<'a>, def: Option<Def>, external: bool, is_public:
pub_count
:
Cell
::
new
(
0
),
pub_glob_count
:
Cell
::
new
(
0
),
populated
:
Cell
::
new
(
!
external
),
arenas
:
arenas
}
}
...
...
@@ -881,8 +887,9 @@ fn resolve_name(&self, name: Name, ns: Namespace, allow_private_imports: bool)
}
// Define the name or return the existing binding if there is a collision.
fn
try_define_child
(
&
self
,
name
:
Name
,
ns
:
Namespace
,
binding
:
&
'a
NameBinding
<
'a
>
)
fn
try_define_child
(
&
self
,
name
:
Name
,
ns
:
Namespace
,
binding
:
NameBinding
<
'a
>
)
->
Result
<
(),
&
'a
NameBinding
<
'a
>>
{
let
binding
=
self
.arenas
.alloc_name_binding
(
binding
);
let
mut
children
=
self
.resolutions
.borrow_mut
();
let
resolution
=
children
.entry
((
name
,
ns
))
.or_insert_with
(
Default
::
default
);
...
...
@@ -898,6 +905,11 @@ fn try_define_child(&self, name: Name, ns: Namespace, binding: &'a NameBinding<'
resolution
.try_define
(
binding
)
}
fn
add_import_directive
(
&
self
,
import_directive
:
ImportDirective
)
{
let
import_directive
=
self
.arenas
.alloc_import_directive
(
import_directive
);
self
.unresolved_imports
.borrow_mut
()
.push
(
import_directive
);
}
fn
increment_outstanding_references_for
(
&
self
,
name
:
Name
,
ns
:
Namespace
)
{
let
mut
children
=
self
.resolutions
.borrow_mut
();
children
.entry
((
name
,
ns
))
.or_insert_with
(
Default
::
default
)
.outstanding_references
+=
1
;
...
...
@@ -995,14 +1007,14 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
// Records a possibly-private value, type, or module definition.
#[derive(Debug)]
#[derive(
Clone,
Debug)]
pub
struct
NameBinding
<
'a
>
{
modifiers
:
DefModifiers
,
kind
:
NameBindingKind
<
'a
>
,
span
:
Option
<
Span
>
,
}
#[derive(Debug)]
#[derive(
Clone,
Debug)]
enum
NameBindingKind
<
'a
>
{
Def
(
Def
),
Module
(
Module
<
'a
>
),
...
...
@@ -1171,6 +1183,12 @@ pub struct ResolverArenas<'a> {
}
impl
<
'a
>
ResolverArenas
<
'a
>
{
fn
alloc_module
(
&
'a
self
,
module
:
ModuleS
<
'a
>
)
->
Module
<
'a
>
{
self
.modules
.alloc
(
module
)
}
fn
alloc_name_binding
(
&
'a
self
,
name_binding
:
NameBinding
<
'a
>
)
->
&
'a
NameBinding
<
'a
>
{
self
.name_bindings
.alloc
(
name_binding
)
}
fn
alloc_import_directive
(
&
'a
self
,
import_directive
:
ImportDirective
)
->
&
'a
ImportDirective
{
self
.import_directives
.alloc
(
import_directive
)
}
...
...
@@ -1189,8 +1207,9 @@ fn new(session: &'a Session,
arenas
:
&
'a
ResolverArenas
<
'a
>
)
->
Resolver
<
'a
,
'tcx
>
{
let
root_def_id
=
ast_map
.local_def_id
(
CRATE_NODE_ID
);
let
graph_root
=
ModuleS
::
new
(
NoParentLink
,
Some
(
Def
::
Mod
(
root_def_id
)),
false
,
true
);
let
graph_root
=
arenas
.modules
.alloc
(
graph_root
);
let
graph_root
=
ModuleS
::
new
(
NoParentLink
,
Some
(
Def
::
Mod
(
root_def_id
)),
false
,
true
,
arenas
);
let
graph_root
=
arenas
.alloc_module
(
graph_root
);
Resolver
{
session
:
session
,
...
...
@@ -1250,11 +1269,7 @@ fn new_module(&self,
def
:
Option
<
Def
>
,
external
:
bool
,
is_public
:
bool
)
->
Module
<
'a
>
{
self
.arenas.modules
.alloc
(
ModuleS
::
new
(
parent_link
,
def
,
external
,
is_public
))
}
fn
new_name_binding
(
&
self
,
name_binding
:
NameBinding
<
'a
>
)
->
&
'a
NameBinding
<
'a
>
{
self
.arenas.name_bindings
.alloc
(
name_binding
)
self
.arenas
.alloc_module
(
ModuleS
::
new
(
parent_link
,
def
,
external
,
is_public
,
self
.arenas
))
}
fn
new_extern_crate_module
(
&
self
,
...
...
@@ -1263,7 +1278,7 @@ fn new_extern_crate_module(&self,
is_public
:
bool
,
local_node_id
:
NodeId
)
->
Module
<
'a
>
{
let
mut
module
=
ModuleS
::
new
(
parent_link
,
Some
(
def
),
false
,
is_public
);
let
mut
module
=
ModuleS
::
new
(
parent_link
,
Some
(
def
),
false
,
is_public
,
self
.arenas
);
module
.extern_crate_id
=
Some
(
local_node_id
);
self
.arenas.modules
.alloc
(
module
)
}
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
fb4710ce
...
...
@@ -236,15 +236,14 @@ fn import_resolving_error(&self, e: ImportResolvingError<'b>) {
// If it's a single failed import then create a "fake" import
// resolution for it so that later resolve stages won't complain.
if
let
SingleImport
{
target
,
..
}
=
e
.import_directive.subclass
{
let
dummy_binding
=
self
.resolver
.
new
_name_binding
(
NameBinding
{
let
dummy_binding
=
self
.resolver.
arenas
.alloc
_name_binding
(
NameBinding
{
modifiers
:
DefModifiers
::
PRELUDE
,
kind
:
NameBindingKind
::
Def
(
Def
::
Err
),
span
:
None
,
});
let
dummy_binding
=
self
.resolver
.new_name_binding
(
e
.import_directive
.import
(
dummy_binding
,
None
));
let
dummy_binding
=
e
.import_directive
.import
(
dummy_binding
,
None
);
let
_
=
e
.source_module
.try_define_child
(
target
,
ValueNS
,
dummy_binding
);
let
_
=
e
.source_module
.try_define_child
(
target
,
ValueNS
,
dummy_binding
.clone
()
);
let
_
=
e
.source_module
.try_define_child
(
target
,
TypeNS
,
dummy_binding
);
}
...
...
@@ -534,9 +533,8 @@ fn define(&mut self,
name
:
Name
,
ns
:
Namespace
,
binding
:
NameBinding
<
'b
>
)
{
let
binding
=
self
.resolver
.new_name_binding
(
binding
);
if
let
Err
(
old_binding
)
=
parent
.try_define_child
(
name
,
ns
,
binding
)
{
self
.report_conflict
(
name
,
ns
,
binding
,
old_binding
);
if
let
Err
(
old_binding
)
=
parent
.try_define_child
(
name
,
ns
,
binding
.clone
())
{
self
.report_conflict
(
name
,
ns
,
&
binding
,
old_binding
);
}
else
if
binding
.is_public
()
{
// Add to the export map
if
let
(
Some
(
parent_def_id
),
Some
(
def
))
=
(
parent
.def_id
(),
binding
.def
())
{
let
parent_node_id
=
self
.resolver.ast_map
.as_local_node_id
(
parent_def_id
)
.unwrap
();
...
...
@@ -549,8 +547,8 @@ fn define(&mut self,
fn
report_conflict
(
&
mut
self
,
name
:
Name
,
ns
:
Namespace
,
binding
:
&
'b
NameBinding
<
'b
>
,
old_binding
:
&
'b
NameBinding
<
'b
>
)
{
binding
:
&
NameBinding
,
old_binding
:
&
NameBinding
)
{
// Error on the second of two conflicting imports
if
old_binding
.is_import
()
&&
binding
.is_import
()
&&
old_binding
.span
.unwrap
()
.lo
>
binding
.span
.unwrap
()
.lo
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录