Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
df8f2c6e
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
df8f2c6e
编写于
1月 13, 2018
作者:
K
kennytm
提交者:
GitHub
1月 13, 2018
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #47306 - alexreg:dataflow-analysis, r=eddyb
Don't track local_needs_drop separately in qualify_consts. None
上级
f4ff4c01
e2c1a939
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
23 deletion
+41
-23
src/librustc_mir/transform/qualify_consts.rs
src/librustc_mir/transform/qualify_consts.rs
+31
-23
src/test/compile-fail/static-drop-scope.rs
src/test/compile-fail/static-drop-scope.rs
+10
-0
未找到文件。
src/librustc_mir/transform/qualify_consts.rs
浏览文件 @
df8f2c6e
...
...
@@ -122,7 +122,6 @@ struct Qualifier<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
return_qualif
:
Option
<
Qualif
>
,
qualif
:
Qualif
,
const_fn_arg_vars
:
BitVector
,
local_needs_drop
:
IndexVec
<
Local
,
Option
<
Span
>>
,
temp_promotion_state
:
IndexVec
<
Local
,
TempState
>
,
promotion_candidates
:
Vec
<
Candidate
>
}
...
...
@@ -136,6 +135,16 @@ fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let
mut
rpo
=
traversal
::
reverse_postorder
(
mir
);
let
temps
=
promote_consts
::
collect_temps
(
mir
,
&
mut
rpo
);
rpo
.reset
();
let
param_env
=
tcx
.param_env
(
def_id
);
let
mut
temp_qualif
=
IndexVec
::
from_elem
(
None
,
&
mir
.local_decls
);
for
arg
in
mir
.args_iter
()
{
let
mut
qualif
=
Qualif
::
NEEDS_DROP
;
qualif
.restrict
(
mir
.local_decls
[
arg
]
.ty
,
tcx
,
param_env
);
temp_qualif
[
arg
]
=
Some
(
qualif
);
}
Qualifier
{
mode
,
span
:
mir
.span
,
...
...
@@ -143,12 +152,11 @@ fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>,
mir
,
rpo
,
tcx
,
param_env
:
tcx
.param_env
(
def_id
)
,
temp_qualif
:
IndexVec
::
from_elem
(
None
,
&
mir
.local_decls
)
,
param_env
,
temp_qualif
,
return_qualif
:
None
,
qualif
:
Qualif
::
empty
(),
const_fn_arg_vars
:
BitVector
::
new
(
mir
.local_decls
.len
()),
local_needs_drop
:
IndexVec
::
from_elem
(
None
,
&
mir
.local_decls
),
temp_promotion_state
:
temps
,
promotion_candidates
:
vec!
[]
}
...
...
@@ -255,15 +263,6 @@ fn assign(&mut self, dest: &Place<'tcx>, location: Location) {
return
;
}
// When initializing a local, record whether the *value* being
// stored in it needs dropping, which it may not, even if its
// type does, e.g. `None::<String>`.
if
let
Place
::
Local
(
local
)
=
*
dest
{
if
qualif
.intersects
(
Qualif
::
NEEDS_DROP
)
{
self
.local_needs_drop
[
local
]
=
Some
(
self
.span
);
}
}
match
*
dest
{
Place
::
Local
(
index
)
if
self
.mir
.local_kind
(
index
)
==
LocalKind
::
Temp
=>
{
debug!
(
"store to temp {:?}"
,
index
);
...
...
@@ -424,17 +423,20 @@ fn visit_local(&mut self,
&
local
:
&
Local
,
_
:
PlaceContext
<
'tcx
>
,
_
:
Location
)
{
match
self
.mir
.local_kind
(
local
)
{
let
kind
=
self
.mir
.local_kind
(
local
);
match
kind
{
LocalKind
::
ReturnPointer
=>
{
self
.not_const
();
}
LocalKind
::
Arg
=>
{
self
.add
(
Qualif
::
FN_ARGUMENT
);
}
LocalKind
::
Var
=>
{
self
.add
(
Qualif
::
NOT_CONST
);
}
LocalKind
::
Arg
|
LocalKind
::
Temp
=>
{
if
let
LocalKind
::
Arg
=
kind
{
self
.add
(
Qualif
::
FN_ARGUMENT
);
}
if
!
self
.temp_promotion_state
[
local
]
.is_promotable
()
{
self
.add
(
Qualif
::
NOT_PROMOTABLE
);
}
...
...
@@ -529,16 +531,18 @@ fn visit_place(&mut self,
fn
visit_operand
(
&
mut
self
,
operand
:
&
Operand
<
'tcx
>
,
location
:
Location
)
{
match
*
operand
{
Operand
::
Copy
(
ref
place
)
|
Operand
::
Move
(
ref
place
)
=>
{
Operand
::
Copy
(
_
)
|
Operand
::
Move
(
_
)
=>
{
self
.nest
(|
this
|
{
this
.super_operand
(
operand
,
location
);
this
.try_consume
();
});
// Mark the consumed locals to indicate later drops are noops.
if
let
Place
::
Local
(
local
)
=
*
place
{
self
.local_needs_drop
[
local
]
=
None
;
if
let
Operand
::
Move
(
Place
::
Local
(
local
))
=
*
operand
{
self
.temp_qualif
[
local
]
=
self
.temp_qualif
[
local
]
.map
(|
q
|
q
-
Qualif
::
NEEDS_DROP
);
}
}
Operand
::
Constant
(
ref
constant
)
=>
{
...
...
@@ -847,9 +851,13 @@ struct and enum constructors",
// HACK(eddyb) Emulate a bit of dataflow analysis,
// conservatively, that drop elaboration will do.
let
needs_drop
=
if
let
Place
::
Local
(
local
)
=
*
place
{
self
.local_needs_drop
[
local
]
if
self
.temp_qualif
[
local
]
.map_or
(
true
,
|
q
|
q
.intersects
(
Qualif
::
NEEDS_DROP
))
{
Some
(
self
.mir.local_decls
[
local
]
.source_info.span
)
}
else
{
None
}
}
else
{
None
Some
(
self
.span
)
};
if
let
Some
(
span
)
=
needs_drop
{
...
...
src/test/compile-fail/static-drop-scope.rs
浏览文件 @
df8f2c6e
...
...
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(const_fn)]
struct
WithDtor
;
impl
Drop
for
WithDtor
{
...
...
@@ -28,4 +30,12 @@ fn drop(&mut self) {}
const
EARLY_DROP_C
:
i32
=
(
WithDtor
,
0
)
.1
;
//~^ ERROR destructors cannot be evaluated at compile-time
const
fn
const_drop
<
T
>
(
_
:
T
)
{}
//~^ ERROR destructors cannot be evaluated at compile-time
const
fn
const_drop2
<
T
>
(
x
:
T
)
{
(
x
,
())
.1
//~^ ERROR destructors cannot be evaluated at compile-time
}
fn
main
()
{}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录