Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
9c514a1c
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,发现更多精彩内容 >>
提交
9c514a1c
编写于
10月 19, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor away `CrateLoader::load_macros`.
上级
49686007
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
23 addition
and
33 deletion
+23
-33
src/librustc/middle/cstore.rs
src/librustc/middle/cstore.rs
+2
-2
src/librustc_metadata/creader.rs
src/librustc_metadata/creader.rs
+14
-14
src/librustc_metadata/cstore.rs
src/librustc_metadata/cstore.rs
+2
-13
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+5
-4
未找到文件。
src/librustc/middle/cstore.rs
浏览文件 @
9c514a1c
...
...
@@ -423,7 +423,7 @@ pub enum LoadedMacros {
}
pub
trait
CrateLoader
{
fn
load_macros
(
&
mut
self
,
extern_crate
:
&
ast
::
Item
)
->
LoadedMacros
;
fn
process_item
(
&
mut
self
,
item
:
&
ast
::
Item
,
defs
:
&
Definitions
)
;
fn
process_item
(
&
mut
self
,
item
:
&
ast
::
Item
,
defs
:
&
Definitions
,
load_macros
:
bool
)
->
Option
<
LoadedMacros
>
;
fn
postprocess
(
&
mut
self
,
krate
:
&
ast
::
Crate
);
}
src/librustc_metadata/creader.rs
浏览文件 @
9c514a1c
...
...
@@ -23,7 +23,7 @@
use
rustc
::
middle
;
use
rustc
::
middle
::
cstore
::{
CrateStore
,
validate_crate_name
,
ExternCrate
};
use
rustc
::
util
::
nodemap
::{
FnvHashMap
,
FnvHashSet
};
use
rustc
::
hir
::
map
as
hir_map
;
use
rustc
::
hir
::
map
::
Definitions
;
use
std
::
cell
::{
RefCell
,
Cell
};
use
std
::
ops
::
Deref
;
...
...
@@ -631,8 +631,6 @@ fn load_derive_macros(&mut self, item: &ast::Item, index: DefIndex, svh: Svh, pa
use
rustc_back
::
dynamic_lib
::
DynamicLibrary
;
use
syntax_ext
::
deriving
::
custom
::
CustomDerive
;
self
.cstore
.add_used_for_derive_macros
(
item
);
// Make sure the path contains a / or the linker will search for it.
let
path
=
env
::
current_dir
()
.unwrap
()
.join
(
path
);
let
lib
=
match
DynamicLibrary
::
open
(
Some
(
&
path
))
{
...
...
@@ -1020,13 +1018,19 @@ fn postprocess(&mut self, krate: &ast::Crate) {
self
.register_statically_included_foreign_items
();
}
fn
process_item
(
&
mut
self
,
item
:
&
ast
::
Item
,
definitions
:
&
hir_map
::
Definitions
)
{
fn
process_item
(
&
mut
self
,
item
:
&
ast
::
Item
,
definitions
:
&
Definitions
,
load_macros
:
bool
)
->
Option
<
LoadedMacros
>
{
match
item
.node
{
ast
::
ItemKind
::
ExternCrate
(
_
)
=>
{}
ast
::
ItemKind
::
ForeignMod
(
ref
fm
)
=>
return
self
.process_foreign_mod
(
item
,
fm
),
_
=>
return
,
ast
::
ItemKind
::
ForeignMod
(
ref
fm
)
=>
{
self
.process_foreign_mod
(
item
,
fm
);
return
None
;
}
_
=>
return
None
,
}
let
loaded_macros
=
if
load_macros
{
Some
(
self
.read_macros
(
item
))
}
else
{
None
};
// If this `extern crate` item has `#[macro_use]` then we can safely skip it.
// These annotations were processed during macro expansion and are already loaded
// (if necessary) into our crate store.
...
...
@@ -1034,15 +1038,13 @@ fn process_item(&mut self, item: &ast::Item, definitions: &hir_map::Definitions)
// Note that it's important we *don't* fall through below as some `#[macro_use]`
// crates are explicitly not linked (e.g. macro crates) so we want to ensure
// we avoid `resolve_crate` with those.
if
attr
::
contains_name
(
&
item
.attrs
,
"macro_use"
)
{
if
self
.cstore
.was_used_for_derive_macros
(
item
)
{
return
}
if
let
Some
(
LoadedMacros
::
CustomDerives
(
..
))
=
loaded_macros
{
return
loaded_macros
;
}
if
let
Some
(
info
)
=
self
.extract_crate_info
(
item
)
{
if
!
info
.should_link
{
return
;
return
loaded_macros
;
}
let
(
cnum
,
..
)
=
self
.resolve_crate
(
...
...
@@ -1058,9 +1060,7 @@ fn process_item(&mut self, item: &ast::Item, definitions: &hir_map::Definitions)
self
.cstore
.add_extern_mod_stmt_cnum
(
info
.id
,
cnum
);
}
}
fn
load_macros
(
&
mut
self
,
extern_crate
:
&
ast
::
Item
)
->
LoadedMacros
{
self
.read_macros
(
extern_crate
)
loaded_macros
}
}
src/librustc_metadata/cstore.rs
浏览文件 @
9c514a1c
...
...
@@ -21,14 +21,13 @@
use
rustc
::
middle
::
cstore
::
ExternCrate
;
use
rustc_back
::
PanicStrategy
;
use
rustc_data_structures
::
indexed_vec
::
IndexVec
;
use
rustc
::
util
::
nodemap
::{
FnvHashMap
,
NodeMap
,
NodeSet
,
DefIdMap
,
FnvHashSet
};
use
rustc
::
util
::
nodemap
::{
FnvHashMap
,
NodeMap
,
NodeSet
,
DefIdMap
};
use
std
::
cell
::{
RefCell
,
Cell
};
use
std
::
rc
::
Rc
;
use
std
::
path
::
PathBuf
;
use
flate
::
Bytes
;
use
syntax
::
ast
::{
self
,
Ident
};
use
syntax
::
attr
;
use
syntax
::{
ast
,
attr
};
use
syntax_pos
;
pub
use
rustc
::
middle
::
cstore
::{
NativeLibraryKind
,
LinkagePreference
};
...
...
@@ -105,7 +104,6 @@ pub struct CStore {
pub
inlined_item_cache
:
RefCell
<
DefIdMap
<
Option
<
CachedInlinedItem
>>>
,
pub
defid_for_inlined_node
:
RefCell
<
NodeMap
<
DefId
>>
,
pub
visible_parent_map
:
RefCell
<
DefIdMap
<
DefId
>>
,
pub
used_for_derive_macro
:
RefCell
<
FnvHashSet
<
Ident
>>
,
}
impl
CStore
{
...
...
@@ -121,7 +119,6 @@ pub fn new(dep_graph: &DepGraph) -> CStore {
visible_parent_map
:
RefCell
::
new
(
FnvHashMap
()),
inlined_item_cache
:
RefCell
::
new
(
FnvHashMap
()),
defid_for_inlined_node
:
RefCell
::
new
(
FnvHashMap
()),
used_for_derive_macro
:
RefCell
::
new
(
FnvHashSet
()),
}
}
...
...
@@ -277,14 +274,6 @@ pub fn do_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>
{
self
.extern_mod_crate_map
.borrow
()
.get
(
&
emod_id
)
.cloned
()
}
pub
fn
was_used_for_derive_macros
(
&
self
,
i
:
&
ast
::
Item
)
->
bool
{
self
.used_for_derive_macro
.borrow
()
.contains
(
&
i
.ident
)
}
pub
fn
add_used_for_derive_macros
(
&
self
,
i
:
&
ast
::
Item
)
{
self
.used_for_derive_macro
.borrow_mut
()
.insert
(
i
.ident
);
}
}
impl
CrateMetadata
{
...
...
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
9c514a1c
...
...
@@ -215,12 +215,11 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
}
let
loaded_macros
=
if
legacy_imports
!=
LegacyMacroImports
::
default
()
{
Some
(
self
.crate_loader
.load_macros
(
item
)
)
self
.crate_loader
.process_item
(
item
,
&
self
.definitions
,
true
)
}
else
{
None
self
.crate_loader
.process_item
(
item
,
&
self
.definitions
,
false
)
};
self
.crate_loader
.process_item
(
item
,
&
self
.definitions
);
// n.b. we don't need to look at the path option here, because cstore already did
let
crate_id
=
self
.session.cstore
.extern_mod_stmt_cnum
(
item
.id
);
let
module
=
if
let
Some
(
crate_id
)
=
crate_id
{
...
...
@@ -270,7 +269,9 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
self
.current_module
=
module
;
}
ItemKind
::
ForeignMod
(
..
)
=>
self
.crate_loader
.process_item
(
item
,
&
self
.definitions
),
ItemKind
::
ForeignMod
(
..
)
=>
{
self
.crate_loader
.process_item
(
item
,
&
self
.definitions
,
false
);
}
// These items live in the value namespace.
ItemKind
::
Static
(
_
,
m
,
_
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录