Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7e277d96
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,发现更多精彩内容 >>
提交
7e277d96
编写于
2月 27, 2019
作者:
L
ljedrz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
middle & privacy: partially HirIdify
上级
d987b46b
变更
2
展开全部
隐藏空白更改
内联
并排
Showing
2 changed file
with
120 addition
and
106 deletion
+120
-106
src/librustc/middle/reachable.rs
src/librustc/middle/reachable.rs
+35
-29
src/librustc_privacy/lib.rs
src/librustc_privacy/lib.rs
+85
-77
未找到文件。
src/librustc/middle/reachable.rs
浏览文件 @
7e277d96
...
...
@@ -14,10 +14,9 @@
use
crate
::
ty
::
query
::
Providers
;
use
crate
::
middle
::
privacy
;
use
crate
::
session
::
config
;
use
crate
::
util
::
nodemap
::{
Node
Set
,
FxHashSet
};
use
crate
::
util
::
nodemap
::{
HirId
Set
,
FxHashSet
};
use
rustc_target
::
spec
::
abi
::
Abi
;
use
syntax
::
ast
;
use
crate
::
hir
;
use
crate
::
hir
::
def_id
::
LOCAL_CRATE
;
use
crate
::
hir
::
intravisit
::{
Visitor
,
NestedVisitorMap
};
...
...
@@ -70,10 +69,10 @@ struct ReachableContext<'a, 'tcx: 'a> {
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
tables
:
&
'a
ty
::
TypeckTables
<
'tcx
>
,
// The set of items which must be exported in the linkage sense.
reachable_symbols
:
Node
Set
,
reachable_symbols
:
HirId
Set
,
// A worklist of item IDs. Each item ID in this worklist will be inlined
// and will be scanned for further references.
worklist
:
Vec
<
ast
::
Node
Id
>
,
worklist
:
Vec
<
hir
::
Hir
Id
>
,
// Whether any output of this compilation is a library
any_library
:
bool
,
}
...
...
@@ -104,27 +103,28 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
match
def
{
Some
(
Def
::
Local
(
node_id
))
|
Some
(
Def
::
Upvar
(
node_id
,
..
))
=>
{
self
.reachable_symbols
.insert
(
node_id
);
let
hir_id
=
self
.tcx
.hir
()
.node_to_hir_id
(
node_id
);
self
.reachable_symbols
.insert
(
hir_id
);
}
Some
(
def
)
=>
{
if
let
Some
((
node
_id
,
def_id
))
=
def
.opt_def_id
()
.and_then
(|
def_id
|
{
self
.tcx
.hir
()
.as_local_
node_id
(
def_id
)
.map
(|
node_id
|
(
node
_id
,
def_id
))
if
let
Some
((
hir
_id
,
def_id
))
=
def
.opt_def_id
()
.and_then
(|
def_id
|
{
self
.tcx
.hir
()
.as_local_
hir_id
(
def_id
)
.map
(|
hir_id
|
(
hir
_id
,
def_id
))
})
{
if
self
.def_id_represents_local_inlined_item
(
def_id
)
{
self
.worklist
.push
(
node
_id
);
self
.worklist
.push
(
hir
_id
);
}
else
{
match
def
{
// If this path leads to a constant, then we need to
// recurse into the constant to continue finding
// items that are reachable.
Def
::
Const
(
..
)
|
Def
::
AssociatedConst
(
..
)
=>
{
self
.worklist
.push
(
node
_id
);
self
.worklist
.push
(
hir
_id
);
}
// If this wasn't a static, then the destination is
// surely reachable.
_
=>
{
self
.reachable_symbols
.insert
(
node
_id
);
self
.reachable_symbols
.insert
(
hir
_id
);
}
}
}
...
...
@@ -204,14 +204,14 @@ fn propagate(&mut self) {
continue
}
if
let
Some
(
ref
item
)
=
self
.tcx
.hir
()
.find
(
search_item
)
{
if
let
Some
(
ref
item
)
=
self
.tcx
.hir
()
.find
_by_hir_id
(
search_item
)
{
self
.propagate_node
(
item
,
search_item
);
}
}
}
fn
propagate_node
(
&
mut
self
,
node
:
&
Node
<
'tcx
>
,
search_item
:
ast
::
Node
Id
)
{
search_item
:
hir
::
Hir
Id
)
{
if
!
self
.any_library
{
// If we are building an executable, only explicitly extern
// types need to be exported.
...
...
@@ -221,7 +221,7 @@ fn propagate_node(&mut self, node: &Node<'tcx>,
}
else
{
false
};
let
def_id
=
self
.tcx
.hir
()
.local_def_id
(
item
.
id
);
let
def_id
=
self
.tcx
.hir
()
.local_def_id
_from_hir_id
(
item
.hir_
id
);
let
codegen_attrs
=
self
.tcx
.codegen_fn_attrs
(
def_id
);
let
is_extern
=
codegen_attrs
.contains_extern_indicator
();
let
std_internal
=
codegen_attrs
.flags
.contains
(
...
...
@@ -242,7 +242,7 @@ fn propagate_node(&mut self, node: &Node<'tcx>,
Node
::
Item
(
item
)
=>
{
match
item
.node
{
hir
::
ItemKind
::
Fn
(
..
,
body
)
=>
{
let
def_id
=
self
.tcx
.hir
()
.local_def_id
(
item
.
id
);
let
def_id
=
self
.tcx
.hir
()
.local_def_id
_from_hir_id
(
item
.hir_
id
);
if
item_might_be_inlined
(
self
.tcx
,
&
item
,
self
.tcx
.codegen_fn_attrs
(
def_id
))
{
...
...
@@ -295,7 +295,7 @@ fn propagate_node(&mut self, node: &Node<'tcx>,
self
.visit_nested_body
(
body
);
}
hir
::
ImplItemKind
::
Method
(
_
,
body
)
=>
{
let
did
=
self
.tcx
.hir
()
.get_parent_did
(
search_item
);
let
did
=
self
.tcx
.hir
()
.get_parent_did
_by_hir_id
(
search_item
);
if
method_might_be_inlined
(
self
.tcx
,
impl_item
,
did
)
{
self
.visit_nested_body
(
body
)
}
...
...
@@ -317,7 +317,7 @@ fn propagate_node(&mut self, node: &Node<'tcx>,
_
=>
{
bug!
(
"found unexpected node kind in worklist: {} ({:?})"
,
self
.tcx
.hir
()
.
node
_to_string
(
search_item
),
self
.tcx
.hir
()
.
hir
_to_string
(
search_item
),
node
,
);
}
...
...
@@ -336,7 +336,7 @@ fn propagate_node(&mut self, node: &Node<'tcx>,
struct
CollectPrivateImplItemsVisitor
<
'a
,
'tcx
:
'a
>
{
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
access_levels
:
&
'a
privacy
::
AccessLevels
,
worklist
:
&
'a
mut
Vec
<
ast
::
Node
Id
>
,
worklist
:
&
'a
mut
Vec
<
hir
::
Hir
Id
>
,
}
impl
<
'a
,
'tcx
:
'a
>
ItemLikeVisitor
<
'tcx
>
for
CollectPrivateImplItemsVisitor
<
'a
,
'tcx
>
{
...
...
@@ -348,13 +348,18 @@ fn visit_item(&mut self, item: &hir::Item) {
let
codegen_attrs
=
self
.tcx
.codegen_fn_attrs
(
def_id
);
if
codegen_attrs
.contains_extern_indicator
()
||
codegen_attrs
.flags
.contains
(
CodegenFnAttrFlags
::
RUSTC_STD_INTERNAL_SYMBOL
)
{
self
.worklist
.push
(
item
.id
);
self
.worklist
.push
(
item
.
hir_
id
);
}
// We need only trait impls here, not inherent impls, and only non-exported ones
if
let
hir
::
ItemKind
::
Impl
(
..
,
Some
(
ref
trait_ref
),
_
,
ref
impl_item_refs
)
=
item
.node
{
if
!
self
.access_levels
.is_reachable
(
item
.id
)
{
self
.worklist
.extend
(
impl_item_refs
.iter
()
.map
(|
r
|
r
.id.node_id
));
let
node_id
=
self
.tcx
.hir
()
.hir_to_node_id
(
item
.hir_id
);
if
!
self
.access_levels
.is_reachable
(
node_id
)
{
// FIXME(@ljedrz): rework back to a nice extend when item Ids contain HirId
for
impl_item_ref
in
impl_item_refs
{
let
hir_id
=
self
.tcx
.hir
()
.node_to_hir_id
(
impl_item_ref
.id.node_id
);
self
.worklist
.push
(
hir_id
);
}
let
trait_def_id
=
match
trait_ref
.path.def
{
Def
::
Trait
(
def_id
)
=>
def_id
,
...
...
@@ -368,11 +373,11 @@ fn visit_item(&mut self, item: &hir::Item) {
let
provided_trait_methods
=
self
.tcx
.provided_trait_methods
(
trait_def_id
);
self
.worklist
.reserve
(
provided_trait_methods
.len
());
for
default_method
in
provided_trait_methods
{
let
node
_id
=
self
.tcx
.hir
()
.as_local_node
_id
(
default_method
.def_id
)
.unwrap
();
self
.worklist
.push
(
node
_id
);
let
hir
_id
=
self
.tcx
.hir
()
.as_local_hir
_id
(
default_method
.def_id
)
.unwrap
();
self
.worklist
.push
(
hir
_id
);
}
}
}
...
...
@@ -388,7 +393,7 @@ fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
// We introduce a new-type here, so we can have a specialized HashStable
// implementation for it.
#[derive(Clone)]
pub
struct
ReachableSet
(
pub
Lrc
<
Node
Set
>
);
pub
struct
ReachableSet
(
pub
Lrc
<
HirId
Set
>
);
fn
reachable_set
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
crate_num
:
CrateNum
)
->
ReachableSet
{
debug_assert!
(
crate_num
==
LOCAL_CRATE
);
...
...
@@ -412,11 +417,12 @@ fn reachable_set<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) ->
// If other crates link to us, they're going to expect to be able to
// use the lang items, so we need to be sure to mark them as
// exported.
reachable_context
.worklist
.extend
(
access_levels
.map
.iter
()
.map
(|(
id
,
_
)|
*
id
));
reachable_context
.worklist
.extend
(
access_levels
.map
.iter
()
.map
(|(
id
,
_
)|
tcx
.hir
()
.node_to_hir_id
(
*
id
)));
for
item
in
tcx
.lang_items
()
.items
()
.iter
()
{
if
let
Some
(
did
)
=
*
item
{
if
let
Some
(
node_id
)
=
tcx
.hir
()
.as_local_node
_id
(
did
)
{
reachable_context
.worklist
.push
(
node
_id
);
if
let
Some
(
hir_id
)
=
tcx
.hir
()
.as_local_hir
_id
(
did
)
{
reachable_context
.worklist
.push
(
hir
_id
);
}
}
}
...
...
src/librustc_privacy/lib.rs
浏览文件 @
7e277d96
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录