Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2cf96496
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,发现更多精彩内容 >>
提交
2cf96496
编写于
9月 16, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Immutable `ExpansionData`.
上级
f3c7333f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
23 deletion
+37
-23
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+3
-3
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+9
-2
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+25
-18
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
2cf96496
...
...
@@ -203,7 +203,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
let
ext
=
macro_rules
::
compile
(
&
self
.session.parse_sess
,
&
def
);
let
shadowing
=
self
.resolve_macro_name
(
Mark
::
root
(),
name
,
false
)
.is_some
();
self
.expansion_data
[
&
Mark
::
root
()]
.module.macros
.borrow_mut
()
self
.expansion_data
[
&
Mark
::
root
()]
.module
.
get
()
.
macros
.borrow_mut
()
.insert
(
name
,
macros
::
NameBinding
{
ext
:
Rc
::
new
(
ext
),
expansion
:
expansion
,
...
...
@@ -525,8 +525,8 @@ pub struct BuildReducedGraphVisitor<'a, 'b: 'a> {
impl
<
'a
,
'b
>
BuildReducedGraphVisitor
<
'a
,
'b
>
{
fn
visit_invoc
(
&
mut
self
,
id
:
ast
::
NodeId
)
{
self
.resolver.expansion_data
.get_mut
(
&
Mark
::
from_placeholder_id
(
id
))
.unwrap
()
.module
=
self
.resolver.current_module
;
let
mark
=
Mark
::
from_placeholder_id
(
id
);
self
.resolver.expansion_data
[
&
mark
]
.module
.set
(
self
.resolver.current_module
)
;
}
}
...
...
src/librustc_resolve/lib.rs
浏览文件 @
2cf96496
...
...
@@ -77,6 +77,7 @@
use
std
::
rc
::
Rc
;
use
resolve_imports
::{
ImportDirective
,
NameResolution
};
use
macros
::
ExpansionData
;
// NB: This module needs to be declared first so diagnostics are
// registered before they are used.
...
...
@@ -1088,7 +1089,7 @@ pub struct Resolver<'a> {
macro_names
:
FnvHashSet
<
Name
>
,
// Maps the `Mark` of an expansion to its containing module or block.
expansion_data
:
FnvHashMap
<
Mark
,
macros
::
ExpansionData
<
'a
>>
,
expansion_data
:
FnvHashMap
<
Mark
,
&
'a
ExpansionData
<
'a
>>
,
}
pub
struct
ResolverArenas
<
'a
>
{
...
...
@@ -1097,6 +1098,7 @@ pub struct ResolverArenas<'a> {
name_bindings
:
arena
::
TypedArena
<
NameBinding
<
'a
>>
,
import_directives
:
arena
::
TypedArena
<
ImportDirective
<
'a
>>
,
name_resolutions
:
arena
::
TypedArena
<
RefCell
<
NameResolution
<
'a
>>>
,
expansion_data
:
arena
::
TypedArena
<
ExpansionData
<
'a
>>
,
}
impl
<
'a
>
ResolverArenas
<
'a
>
{
...
...
@@ -1120,6 +1122,9 @@ fn alloc_import_directive(&'a self, import_directive: ImportDirective<'a>)
fn
alloc_name_resolution
(
&
'a
self
)
->
&
'a
RefCell
<
NameResolution
<
'a
>>
{
self
.name_resolutions
.alloc
(
Default
::
default
())
}
fn
alloc_expansion_data
(
&
'a
self
,
expansion_data
:
ExpansionData
<
'a
>
)
->
&
'a
ExpansionData
<
'a
>
{
self
.expansion_data
.alloc
(
expansion_data
)
}
}
impl
<
'a
>
ty
::
NodeIdTree
for
Resolver
<
'a
>
{
...
...
@@ -1206,7 +1211,8 @@ pub fn new(session: &'a Session,
DefCollector
::
new
(
&
mut
definitions
)
.collect_root
();
let
mut
expansion_data
=
FnvHashMap
();
expansion_data
.insert
(
Mark
::
root
(),
macros
::
ExpansionData
::
root
(
graph_root
));
expansion_data
.insert
(
Mark
::
root
(),
arenas
.alloc_expansion_data
(
ExpansionData
::
root
(
graph_root
)));
Resolver
{
session
:
session
,
...
...
@@ -1277,6 +1283,7 @@ pub fn arenas() -> ResolverArenas<'a> {
name_bindings
:
arena
::
TypedArena
::
new
(),
import_directives
:
arena
::
TypedArena
::
new
(),
name_resolutions
:
arena
::
TypedArena
::
new
(),
expansion_data
:
arena
::
TypedArena
::
new
(),
}
}
...
...
src/librustc_resolve/macros.rs
浏览文件 @
2cf96496
...
...
@@ -12,6 +12,7 @@
use
build_reduced_graph
::
BuildReducedGraphVisitor
;
use
rustc
::
hir
::
def_id
::{
CRATE_DEF_INDEX
,
DefIndex
};
use
rustc
::
hir
::
map
::{
self
,
DefCollector
};
use
std
::
cell
::
Cell
;
use
std
::
rc
::
Rc
;
use
syntax
::
ast
;
use
syntax
::
errors
::
DiagnosticBuilder
;
...
...
@@ -35,7 +36,7 @@ pub struct NameBinding {
#[derive(Clone)]
pub
struct
ExpansionData
<
'a
>
{
backtrace
:
SyntaxContext
,
pub
module
:
Module
<
'a
>
,
pub
module
:
Cell
<
Module
<
'a
>
>
,
def_index
:
DefIndex
,
// True if this expansion is in a `const_integer` position, for example `[u32; m!()]`.
// c.f. `DefCollector::visit_ast_const_integer`.
...
...
@@ -46,7 +47,7 @@ impl<'a> ExpansionData<'a> {
pub
fn
root
(
graph_root
:
Module
<
'a
>
)
->
Self
{
ExpansionData
{
backtrace
:
SyntaxContext
::
empty
(),
module
:
graph_root
,
module
:
Cell
::
new
(
graph_root
)
,
def_index
:
CRATE_DEF_INDEX
,
const_integer
:
false
,
}
...
...
@@ -61,18 +62,18 @@ fn next_node_id(&mut self) -> ast::NodeId {
fn
get_module_scope
(
&
mut
self
,
id
:
ast
::
NodeId
)
->
Mark
{
let
mark
=
Mark
::
fresh
();
let
module
=
self
.module_map
[
&
id
];
self
.expansion_data
.insert
(
mark
,
ExpansionData
{
self
.expansion_data
.insert
(
mark
,
self
.arenas
.alloc_expansion_data
(
ExpansionData
{
backtrace
:
SyntaxContext
::
empty
(),
module
:
module
,
module
:
Cell
::
new
(
module
)
,
def_index
:
module
.def_id
()
.unwrap
()
.index
,
const_integer
:
false
,
});
})
)
;
mark
}
fn
visit_expansion
(
&
mut
self
,
mark
:
Mark
,
expansion
:
&
Expansion
)
{
self
.collect_def_ids
(
mark
,
expansion
);
self
.current_module
=
self
.expansion_data
[
&
mark
]
.module
;
self
.current_module
=
self
.expansion_data
[
&
mark
]
.module
.get
()
;
expansion
.visit_with
(
&
mut
BuildReducedGraphVisitor
{
resolver
:
self
,
expansion
:
mark
});
}
...
...
@@ -81,13 +82,14 @@ fn add_macro(&mut self, scope: Mark, mut def: ast::MacroDef) {
self
.session
.span_err
(
def
.span
,
"user-defined macros may not be named `macro_rules`"
);
}
if
def
.use_locally
{
let
ExpansionData
{
mut
module
,
backtrace
,
..
}
=
self
.expansion_data
[
&
scope
];
let
expansion_data
=
self
.expansion_data
[
&
scope
];
let
mut
module
=
expansion_data
.module
.get
();
while
module
.macros_escape
{
module
=
module
.parent
.unwrap
();
}
let
binding
=
NameBinding
{
ext
:
Rc
::
new
(
macro_rules
::
compile
(
&
self
.session.parse_sess
,
&
def
)),
expansion
:
backtrace
.data
()
.prev_ctxt
.data
()
.outer_mark
,
expansion
:
expansion_data
.
backtrace
.data
()
.prev_ctxt
.data
()
.outer_mark
,
shadowing
:
self
.resolve_macro_name
(
scope
,
def
.ident.name
,
false
)
.is_some
(),
span
:
def
.span
,
};
...
...
@@ -119,7 +121,7 @@ fn add_expansions_at_stmt(&mut self, id: ast::NodeId, macros: Vec<Mark>) {
fn
find_attr_invoc
(
&
mut
self
,
attrs
:
&
mut
Vec
<
ast
::
Attribute
>
)
->
Option
<
ast
::
Attribute
>
{
for
i
in
0
..
attrs
.len
()
{
let
name
=
intern
(
&
attrs
[
i
]
.name
());
match
self
.expansion_data
[
&
Mark
::
root
()]
.module.macros
.borrow
()
.get
(
&
name
)
{
match
self
.expansion_data
[
&
Mark
::
root
()]
.module
.
get
()
.
macros
.borrow
()
.get
(
&
name
)
{
Some
(
binding
)
=>
match
*
binding
.ext
{
MultiModifier
(
..
)
|
MultiDecorator
(
..
)
|
SyntaxExtension
::
AttrProcMacro
(
..
)
=>
{
return
Some
(
attrs
.remove
(
i
))
...
...
@@ -164,10 +166,11 @@ fn resolve_derive_mode(&mut self, ident: ast::Ident) -> Option<Rc<MultiItemModif
impl
<
'a
>
Resolver
<
'a
>
{
pub
fn
resolve_macro_name
(
&
mut
self
,
scope
:
Mark
,
name
:
ast
::
Name
,
record_used
:
bool
)
->
Option
<
Rc
<
SyntaxExtension
>>
{
let
ExpansionData
{
mut
module
,
backtrace
,
..
}
=
self
.expansion_data
[
&
scope
];
let
expansion_data
=
self
.expansion_data
[
&
scope
];
let
mut
module
=
expansion_data
.module
.get
();
loop
{
if
let
Some
(
binding
)
=
module
.macros
.borrow
()
.get
(
&
name
)
{
let
mut
backtrace
=
backtrace
.data
();
let
mut
backtrace
=
expansion_data
.
backtrace
.data
();
while
binding
.expansion
!=
backtrace
.outer_mark
{
if
backtrace
.outer_mark
!=
Mark
::
root
()
{
backtrace
=
backtrace
.prev_ctxt
.data
();
...
...
@@ -205,14 +208,18 @@ fn suggest_macro_name(&mut self, name: &str, err: &mut DiagnosticBuilder<'a>) {
}
fn
collect_def_ids
(
&
mut
self
,
mark
:
Mark
,
expansion
:
&
Expansion
)
{
let
expansion_data
=
&
mut
self
.expansion_data
;
let
ExpansionData
{
backtrace
,
def_index
,
const_integer
,
module
}
=
expansion_data
[
&
mark
];
let
Resolver
{
ref
mut
expansion_data
,
arenas
,
graph_root
,
..
}
=
*
self
;
let
ExpansionData
{
def_index
,
const_integer
,
backtrace
,
..
}
=
expansion_data
[
&
mark
]
.clone
();
let
visit_macro_invoc
=
&
mut
|
invoc
:
map
::
MacroInvocationData
|
{
expansion_data
.entry
(
invoc
.mark
)
.or_insert
(
ExpansionData
{
backtrace
:
backtrace
.apply_mark
(
invoc
.mark
),
def_index
:
invoc
.def_index
,
const_integer
:
invoc
.const_integer
,
module
:
module
,
expansion_data
.entry
(
invoc
.mark
)
.or_insert_with
(||
{
arenas
.alloc_expansion_data
(
ExpansionData
{
backtrace
:
backtrace
.apply_mark
(
invoc
.mark
),
def_index
:
invoc
.def_index
,
const_integer
:
invoc
.const_integer
,
module
:
Cell
::
new
(
graph_root
),
})
});
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录