Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
924e8aaa
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,发现更多精彩内容 >>
提交
924e8aaa
编写于
9月 28, 2020
作者:
T
Tomasz Miąsko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Liveness analysis for everybody
Perform liveness analysis for every body instead of limiting it to fns.
上级
381b445f
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
174 addition
and
42 deletion
+174
-42
compiler/rustc_passes/src/liveness.rs
compiler/rustc_passes/src/liveness.rs
+28
-34
src/test/ui/consts/const-block-non-item-statement-3.rs
src/test/ui/consts/const-block-non-item-statement-3.rs
+1
-1
src/test/ui/consts/const-block-non-item-statement-rpass.rs
src/test/ui/consts/const-block-non-item-statement-rpass.rs
+1
-1
src/test/ui/consts/control-flow/drop-pass.rs
src/test/ui/consts/control-flow/drop-pass.rs
+1
-0
src/test/ui/liveness/liveness-consts.rs
src/test/ui/liveness/liveness-consts.rs
+63
-0
src/test/ui/liveness/liveness-consts.stderr
src/test/ui/liveness/liveness-consts.stderr
+68
-0
src/test/ui/liveness/liveness-derive.rs
src/test/ui/liveness/liveness-derive.rs
+1
-1
src/test/ui/liveness/liveness-derive.stderr
src/test/ui/liveness/liveness-derive.stderr
+11
-5
未找到文件。
compiler/rustc_passes/src/liveness.rs
浏览文件 @
924e8aaa
...
...
@@ -90,12 +90,12 @@
use
rustc_hir
as
hir
;
use
rustc_hir
::
def
::
*
;
use
rustc_hir
::
def_id
::
LocalDefId
;
use
rustc_hir
::
intravisit
::{
self
,
FnKind
,
NestedVisitorMap
,
Visitor
};
use
rustc_hir
::{
Expr
,
HirId
,
HirIdMap
,
HirIdSet
,
Node
};
use
rustc_hir
::
intravisit
::{
self
,
NestedVisitorMap
,
Visitor
};
use
rustc_hir
::{
Expr
,
HirId
,
HirIdMap
,
HirIdSet
};
use
rustc_index
::
vec
::
IndexVec
;
use
rustc_middle
::
hir
::
map
::
Map
;
use
rustc_middle
::
ty
::
query
::
Providers
;
use
rustc_middle
::
ty
::{
self
,
TyCtxt
};
use
rustc_middle
::
ty
::{
self
,
DefIdTree
,
TyCtxt
};
use
rustc_session
::
lint
;
use
rustc_span
::
symbol
::{
kw
,
sym
,
Symbol
};
use
rustc_span
::
Span
;
...
...
@@ -318,49 +318,38 @@ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
NestedVisitorMap
::
OnlyBodies
(
self
.tcx
.hir
())
}
fn
visit_fn
(
&
mut
self
,
fk
:
FnKind
<
'tcx
>
,
decl
:
&
'tcx
hir
::
FnDecl
<
'tcx
>
,
body_id
:
hir
::
BodyId
,
sp
:
Span
,
id
:
HirId
,
)
{
debug!
(
"visit_fn {:?}"
,
id
);
fn
visit_body
(
&
mut
self
,
body
:
&
'tcx
hir
::
Body
<
'tcx
>
)
{
debug!
(
"visit_body {:?}"
,
body
.id
());
// swap in a new set of IR maps for this function body:
let
def_id
=
self
.tcx
.hir
()
.local_def_id
(
id
);
let
mut
fn_maps
=
IrMaps
::
new
(
self
.tcx
);
// swap in a new set of IR maps for this body
let
mut
maps
=
IrMaps
::
new
(
self
.tcx
);
let
hir_id
=
maps
.tcx
.hir
()
.body_owner
(
body
.id
());
let
def_id
=
maps
.tcx
.hir
()
.local_def_id
(
hir_id
);
// Don't run unused pass for #[derive()]
if
let
FnKind
::
Method
(
..
)
=
fk
{
let
parent
=
self
.tcx
.hir
()
.get_parent_item
(
id
);
if
let
Some
(
Node
::
Item
(
i
))
=
self
.tcx
.hir
()
.find
(
parent
)
{
if
i
.attrs
.iter
()
.any
(|
a
|
self
.tcx.sess
.check_name
(
a
,
sym
::
automatically_derived
))
{
if
let
Some
(
parent
)
=
self
.tcx
.parent
(
def_id
.to_def_id
())
{
if
let
DefKind
::
Impl
=
self
.tcx
.def_kind
(
parent
.expect_local
())
{
if
self
.tcx
.has_attr
(
parent
,
sym
::
automatically_derived
)
{
return
;
}
}
}
debug!
(
"creating fn_maps: {:p}"
,
&
fn_maps
);
let
body
=
self
.tcx
.hir
()
.body
(
body_id
);
if
let
Some
(
upvars
)
=
self
.tcx
.upvars_mentioned
(
def_id
)
{
if
let
Some
(
upvars
)
=
maps
.tcx
.upvars_mentioned
(
def_id
)
{
for
(
&
var_hir_id
,
_u
pvar
)
in
upvars
{
let
var_name
=
self
.tcx
.hir
()
.name
(
var_hir_id
);
fn_
maps
.add_variable
(
Upvar
(
var_hir_id
,
var_name
));
let
var_name
=
maps
.tcx
.hir
()
.name
(
var_hir_id
);
maps
.add_variable
(
Upvar
(
var_hir_id
,
var_name
));
}
}
// gather up the various local variables, significant expressions,
// and so forth:
intravisit
::
walk_
fn
(
&
mut
fn_maps
,
fk
,
decl
,
body_id
,
sp
,
id
);
intravisit
::
walk_
body
(
&
mut
maps
,
body
);
// compute liveness
let
mut
lsets
=
Liveness
::
new
(
&
mut
fn_
maps
,
def_id
);
let
entry_ln
=
lsets
.compute
(
&
body
,
sp
,
id
);
lsets
.log_liveness
(
entry_ln
,
id
);
let
mut
lsets
=
Liveness
::
new
(
&
mut
maps
,
def_id
);
let
entry_ln
=
lsets
.compute
(
&
body
,
hir_
id
);
lsets
.log_liveness
(
entry_ln
,
body
.id
()
.hir_
id
);
// check for various error conditions
lsets
.visit_body
(
body
);
...
...
@@ -845,8 +834,8 @@ fn acc(&mut self, ln: LiveNode, var: Variable, acc: u32) {
self
.rwu_table
.assign_unpacked
(
idx
,
rwu
);
}
fn
compute
(
&
mut
self
,
body
:
&
hir
::
Body
<
'_
>
,
span
:
Span
,
id
:
hir
::
HirId
)
->
LiveNode
{
debug!
(
"compute:
using id for body, {:?}"
,
body
.value
);
fn
compute
(
&
mut
self
,
body
:
&
hir
::
Body
<
'_
>
,
hir_id
:
HirId
)
->
LiveNode
{
debug!
(
"compute:
for body {:?}"
,
body
.id
()
.hir_id
);
// # Liveness of captured variables
//
...
...
@@ -890,7 +879,7 @@ fn compute(&mut self, body: &hir::Body<'_>, span: Span, id: hir::HirId) -> LiveN
return
succ
;
}
let
ty
=
self
.typeck_results
.node_type
(
id
);
let
ty
=
self
.typeck_results
.node_type
(
hir_
id
);
match
ty
.kind
()
{
ty
::
Closure
(
_
def_id
,
substs
)
=>
match
substs
.as_closure
()
.kind
()
{
ty
::
ClosureKind
::
Fn
=>
{}
...
...
@@ -899,7 +888,12 @@ fn compute(&mut self, body: &hir::Body<'_>, span: Span, id: hir::HirId) -> LiveN
},
ty
::
Generator
(
..
)
=>
return
succ
,
_
=>
{
span_bug!
(
span
,
"{} has upvars so it should have a closure type: {:?}"
,
id
,
ty
);
span_bug!
(
body
.value.span
,
"{} has upvars so it should have a closure type: {:?}"
,
hir_id
,
ty
);
}
};
...
...
src/test/ui/consts/const-block-non-item-statement-3.rs
浏览文件 @
924e8aaa
// run-pass
#![allow(dead_code)]
#![allow(dead_code
,
unused
)]
type
Array
=
[
u32
;
{
let
x
=
2
;
5
}];
...
...
src/test/ui/consts/const-block-non-item-statement-rpass.rs
浏览文件 @
924e8aaa
// run-pass
#![allow(dead_code)]
#![allow(dead_code
,
unused
)]
#[repr(u8)]
enum
Foo
{
...
...
src/test/ui/consts/control-flow/drop-pass.rs
浏览文件 @
924e8aaa
// run-pass
// revisions: stock precise
#![allow(unused)]
#![cfg_attr(precise,
feature(const_precise_live_drops))]
// `x` is always moved into the final value and is not dropped inside the initializer.
...
...
src/test/ui/liveness/liveness-consts.rs
0 → 100644
浏览文件 @
924e8aaa
// check-pass
#![warn(unused)]
#![allow(unreachable_code)]
pub
static
A
:
i32
=
{
let
mut
i
=
0
;
let
mut
a
=
0
;
//~ WARN variable `a` is assigned to, but never used
while
i
<
10
{
i
+=
1
;
a
+=
1
;
}
i
};
pub
const
B
:
u32
=
{
let
mut
b
=
1
;
b
+=
1
;
//~ WARN value assigned to `b` is never read
b
=
42
;
b
};
pub
enum
E
{
V1
=
{
let
e
=
1
;
//~ WARN unused variable: `e`
1
},
V2
=
{
let
_
f
=
10
;
2
}
}
pub
fn
f
(
x
:
[
u8
;
{
let
s
=
17
;
100
}])
->
[
u8
;
{
let
z
=
18
;
100
}]
{
//~^ WARN unused variable: `s`
//~| WARN unused variable: `z`
x
}
pub
trait
T
{
const
T
:
usize
=
{
let
mut
t
=
10
;
t
=
t
+
t
;
//~ WARN value assigned to `t` is never read
20
};
}
impl
T
for
String
{
const
T
:
usize
=
{
let
w
=
10
;
//~ WARN unused variable: `w`
loop
{
break
;
let
_
=
w
;
}
44
};
}
fn
main
()
{
let
_
=
[();
{
let
z
=
42
;
//~ WARN unused variable: `z`
35
}];
}
src/test/ui/liveness/liveness-consts.stderr
0 → 100644
浏览文件 @
924e8aaa
warning: variable `a` is assigned to, but never used
--> $DIR/liveness-consts.rs:7:9
|
LL | let mut a = 0;
| ^^^^^
|
note: the lint level is defined here
--> $DIR/liveness-consts.rs:2:9
|
LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
= note: consider using `_a` instead
warning: value assigned to `b` is never read
--> $DIR/liveness-consts.rs:17:5
|
LL | b += 1;
| ^
|
note: the lint level is defined here
--> $DIR/liveness-consts.rs:2:9
|
LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]`
= help: maybe it is overwritten before being read?
warning: unused variable: `e`
--> $DIR/liveness-consts.rs:24:13
|
LL | let e = 1;
| ^ help: if this is intentional, prefix it with an underscore: `_e`
warning: unused variable: `s`
--> $DIR/liveness-consts.rs:33:24
|
LL | pub fn f(x: [u8; { let s = 17; 100 }]) -> [u8; { let z = 18; 100 }] {
| ^ help: if this is intentional, prefix it with an underscore: `_s`
warning: unused variable: `z`
--> $DIR/liveness-consts.rs:33:55
|
LL | pub fn f(x: [u8; { let s = 17; 100 }]) -> [u8; { let z = 18; 100 }] {
| ^ help: if this is intentional, prefix it with an underscore: `_z`
warning: unused variable: `z`
--> $DIR/liveness-consts.rs:60:13
|
LL | let z = 42;
| ^ help: if this is intentional, prefix it with an underscore: `_z`
warning: value assigned to `t` is never read
--> $DIR/liveness-consts.rs:42:9
|
LL | t = t + t;
| ^
|
= help: maybe it is overwritten before being read?
warning: unused variable: `w`
--> $DIR/liveness-consts.rs:49:13
|
LL | let w = 10;
| ^ help: if this is intentional, prefix it with an underscore: `_w`
warning: 8 warnings emitted
src/test/ui/liveness/liveness-derive.rs
浏览文件 @
924e8aaa
...
...
@@ -12,7 +12,7 @@ pub trait T: Sized {
impl
T
for
u32
{
const
N
:
usize
=
{
let
a
=
0
;
//
FIXME should warn about unused variable
let
a
=
0
;
//
~ WARN unused variable: `a`
4
};
...
...
src/test/ui/liveness/liveness-derive.stderr
浏览文件 @
924e8aaa
warning: unused variable: `
b
`
--> $DIR/liveness-derive.rs:
20
:13
warning: unused variable: `
a
`
--> $DIR/liveness-derive.rs:
15
:13
|
LL | let
b = 16
;
| ^ help: if this is intentional, prefix it with an underscore: `_
b
`
LL | let
a = 0
;
| ^ help: if this is intentional, prefix it with an underscore: `_
a
`
|
note: the lint level is defined here
--> $DIR/liveness-derive.rs:6:9
...
...
@@ -11,5 +11,11 @@ LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`
warning: 1 warning emitted
warning: unused variable: `b`
--> $DIR/liveness-derive.rs:20:13
|
LL | let b = 16;
| ^ help: if this is intentional, prefix it with an underscore: `_b`
warning: 2 warnings emitted
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录