Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a43e486e
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,发现更多精彩内容 >>
提交
a43e486e
编写于
5月 02, 2020
作者:
D
Dylan MacKenzie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add MIR phase and query for drop elaboration
上级
f5370faa
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
48 addition
and
10 deletion
+48
-10
src/librustc_middle/mir/mod.rs
src/librustc_middle/mir/mod.rs
+2
-1
src/librustc_middle/query/mod.rs
src/librustc_middle/query/mod.rs
+6
-0
src/librustc_mir/transform/mod.rs
src/librustc_mir/transform/mod.rs
+40
-9
未找到文件。
src/librustc_middle/mir/mod.rs
浏览文件 @
a43e486e
...
...
@@ -76,7 +76,8 @@ pub enum MirPhase {
Build
=
0
,
Const
=
1
,
Validated
=
2
,
Optimized
=
3
,
DropElab
=
3
,
Optimized
=
4
,
}
impl
MirPhase
{
...
...
src/librustc_middle/query/mod.rs
浏览文件 @
a43e486e
...
...
@@ -190,6 +190,12 @@ fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
no_hash
}
query
mir_drops_elaborated_and_const_checked
(
key
:
LocalDefId
)
->
Steal
<
mir
::
Body
<
'tcx
>>
{
storage
(
ArenaCacheSelector
<
'tcx
>
)
no_hash
desc
{
|
tcx
|
"elaborating drops for `{}`"
,
tcx
.def_path_str
(
key
.to_def_id
())
}
}
query
mir_validated
(
key
:
LocalDefId
)
->
(
Steal
<
mir
::
Body
<
'tcx
>>
,
...
...
src/librustc_mir/transform/mod.rs
浏览文件 @
a43e486e
...
...
@@ -49,6 +49,7 @@ pub(crate) fn provide(providers: &mut Providers<'_>) {
mir_const
,
mir_const_qualif
,
mir_validated
,
mir_drops_elaborated_and_const_checked
,
optimized_mir
,
is_mir_available
,
promoted_mir
,
...
...
@@ -294,12 +295,31 @@ fn mir_validated(
(
tcx
.alloc_steal_mir
(
body
),
tcx
.alloc_steal_promoted
(
promoted
))
}
fn
run_optimization_passes
<
'tcx
>
(
fn
mir_drops_elaborated_and_const_checked
<
'tcx
>
(
tcx
:
TyCtxt
<
'tcx
>
,
def_id
:
LocalDefId
,
)
->
Steal
<
Body
<
'tcx
>>
{
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to
// execute before we can steal.
tcx
.ensure
()
.mir_borrowck
(
def_id
);
let
(
body
,
_
)
=
tcx
.mir_validated
(
def_id
);
let
mut
body
=
body
.steal
();
run_post_borrowck_cleanup_passes
(
tcx
,
&
mut
body
,
def_id
,
None
);
check_consts
::
post_drop_elaboration
::
check_live_drops
(
tcx
,
def_id
,
&
body
);
tcx
.alloc_steal_mir
(
body
)
}
/// After this series of passes, no lifetime analysis based on borrowing can be done.
fn
run_post_borrowck_cleanup_passes
<
'tcx
>
(
tcx
:
TyCtxt
<
'tcx
>
,
body
:
&
mut
Body
<
'tcx
>
,
def_id
:
LocalDefId
,
promoted
:
Option
<
Promoted
>
,
)
{
debug!
(
"post_borrowck_cleanup({:?})"
,
def_id
);
let
post_borrowck_cleanup
:
&
[
&
dyn
MirPass
<
'tcx
>
]
=
&
[
// Remove all things only needed by analysis
&
no_landing_pads
::
NoLandingPads
::
new
(
tcx
),
...
...
@@ -318,9 +338,24 @@ fn run_optimization_passes<'tcx>(
// but before optimizations begin.
&
add_retag
::
AddRetag
,
&
simplify
::
SimplifyCfg
::
new
(
"elaborate-drops"
),
// No lifetime analysis based on borrowing can be done from here on out.
];
run_passes
(
tcx
,
body
,
InstanceDef
::
Item
(
def_id
.to_def_id
()),
promoted
,
MirPhase
::
DropElab
,
&
[
post_borrowck_cleanup
],
);
}
fn
run_optimization_passes
<
'tcx
>
(
tcx
:
TyCtxt
<
'tcx
>
,
body
:
&
mut
Body
<
'tcx
>
,
def_id
:
LocalDefId
,
promoted
:
Option
<
Promoted
>
,
)
{
let
optimizations
:
&
[
&
dyn
MirPass
<
'tcx
>
]
=
&
[
&
unreachable_prop
::
UnreachablePropagation
,
&
uninhabited_enum_branching
::
UninhabitedEnumBranching
,
...
...
@@ -368,6 +403,7 @@ fn run_optimization_passes<'tcx>(
let
mir_opt_level
=
tcx
.sess.opts.debugging_opts.mir_opt_level
;
#[rustfmt::skip]
run_passes
(
tcx
,
body
,
...
...
@@ -375,7 +411,6 @@ fn run_optimization_passes<'tcx>(
promoted
,
MirPhase
::
Optimized
,
&
[
post_borrowck_cleanup
,
if
mir_opt_level
>
0
{
optimizations
}
else
{
no_optimizations
},
pre_codegen_cleanup
,
],
...
...
@@ -393,12 +428,7 @@ fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> {
let
def_id
=
def_id
.expect_local
();
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to
// execute before we can steal.
tcx
.ensure
()
.mir_borrowck
(
def_id
);
let
(
body
,
_
)
=
tcx
.mir_validated
(
def_id
);
let
mut
body
=
body
.steal
();
let
mut
body
=
tcx
.mir_drops_elaborated_and_const_checked
(
def_id
)
.steal
();
run_optimization_passes
(
tcx
,
&
mut
body
,
def_id
,
None
);
debug_assert!
(
!
body
.has_free_regions
(),
"Free regions in optimized MIR"
);
...
...
@@ -418,6 +448,7 @@ fn promoted_mir(tcx: TyCtxt<'_>, def_id: DefId) -> IndexVec<Promoted, Body<'_>>
let
mut
promoted
=
promoted
.steal
();
for
(
p
,
mut
body
)
in
promoted
.iter_enumerated_mut
()
{
run_post_borrowck_cleanup_passes
(
tcx
,
&
mut
body
,
def_id
,
Some
(
p
));
run_optimization_passes
(
tcx
,
&
mut
body
,
def_id
,
Some
(
p
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录