Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f051c60d
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,发现更多精彩内容 >>
提交
f051c60d
编写于
12月 17, 2016
作者:
M
Mark Simulacrum
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduce extensions to FunctionContext in cleanup.
上级
1804131b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
27 deletion
+29
-27
src/librustc_trans/callee.rs
src/librustc_trans/callee.rs
+2
-2
src/librustc_trans/cleanup.rs
src/librustc_trans/cleanup.rs
+23
-22
src/librustc_trans/glue.rs
src/librustc_trans/glue.rs
+4
-3
未找到文件。
src/librustc_trans/callee.rs
浏览文件 @
f051c60d
...
...
@@ -398,7 +398,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
let
llfn
=
callee
.reify
(
bcx
.ccx
());
let
llret
;
if
let
Some
(
landing_pad
)
=
self_scope
.
as_ref
()
.and_then
(|
c
|
c
.landing_pad
)
{
if
let
Some
(
landing_pad
)
=
self_scope
.
landing_pad
{
let
normal_bcx
=
bcx
.fcx
()
.build_new_block
(
"normal-return"
);
llret
=
bcx
.invoke
(
llfn
,
&
llargs
[
..
],
normal_bcx
.llbb
(),
landing_pad
,
None
);
bcx
=
normal_bcx
;
...
...
@@ -416,7 +416,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
if
fn_ret
.0
.is_never
()
{
bcx
.unreachable
();
}
fcx
.trans_scope
(
&
bcx
,
self_scope
);
self_scope
.trans
(
&
bcx
);
fcx
.finish
(
&
bcx
);
ccx
.instances
()
.borrow_mut
()
.insert
(
method_instance
,
lloncefn
);
...
...
src/librustc_trans/cleanup.rs
浏览文件 @
f051c60d
...
...
@@ -29,7 +29,7 @@
pub
struct
CleanupScope
<
'tcx
>
{
// Cleanup to run upon scope exit.
cleanup
:
DropValue
<
'tcx
>
,
cleanup
:
Option
<
DropValue
<
'tcx
>
>
,
// Computed on creation if compiling with landing pads (!sess.no_landing_pads)
pub
landing_pad
:
Option
<
BasicBlockRef
>
,
...
...
@@ -92,21 +92,11 @@ fn eq(&self, label: &UnwindKind) -> bool {
}
}
}
impl
<
'blk
,
'tcx
>
FunctionContext
<
'blk
,
'tcx
>
{
pub
fn
trans_scope
(
&
self
,
bcx
:
&
BlockAndBuilder
<
'blk
,
'tcx
>
,
custom_scope
:
Option
<
CleanupScope
<
'tcx
>>
)
{
if
let
Some
(
scope
)
=
custom_scope
{
scope
.cleanup
.trans
(
None
,
&
bcx
);
}
}
/// Schedules a (deep) drop of `val`, which is a pointer to an instance of
/// `ty`
pub
fn
schedule_drop_mem
(
&
self
,
val
:
ValueRef
,
ty
:
Ty
<
'tcx
>
)
->
Option
<
CleanupScope
<
'tcx
>
>
{
if
!
self
.type_needs_drop
(
ty
)
{
return
None
;
}
impl
<
'blk
,
'tcx
>
FunctionContext
<
'blk
,
'tcx
>
{
///
Schedules a (deep) drop of `val`, which is a pointer to an instance of
`ty`
pub
fn
schedule_drop_mem
(
&
self
,
val
:
ValueRef
,
ty
:
Ty
<
'tcx
>
)
->
CleanupScope
<
'tcx
>
{
if
!
self
.type_needs_drop
(
ty
)
{
return
CleanupScope
::
noop
()
;
}
let
drop
=
DropValue
{
val
:
val
,
ty
:
ty
,
...
...
@@ -115,7 +105,7 @@ pub fn schedule_drop_mem(&self, val: ValueRef, ty: Ty<'tcx>) -> Option<CleanupSc
debug!
(
"schedule_drop_mem(val={:?}, ty={:?}) skip_dtor={}"
,
Value
(
val
),
ty
,
drop
.skip_dtor
);
Some
(
CleanupScope
::
new
(
self
,
drop
)
)
CleanupScope
::
new
(
self
,
drop
)
}
/// Issue #23611: Schedules a (deep) drop of the contents of
...
...
@@ -123,11 +113,10 @@ pub fn schedule_drop_mem(&self, val: ValueRef, ty: Ty<'tcx>) -> Option<CleanupSc
/// `ty`. The scheduled code handles extracting the discriminant
/// and dropping the contents associated with that variant
/// *without* executing any associated drop implementation.
pub
fn
schedule_drop_adt_contents
(
&
self
,
val
:
ValueRef
,
ty
:
Ty
<
'tcx
>
)
->
Option
<
CleanupScope
<
'tcx
>>
{
pub
fn
schedule_drop_adt_contents
(
&
self
,
val
:
ValueRef
,
ty
:
Ty
<
'tcx
>
)
->
CleanupScope
<
'tcx
>
{
// `if` below could be "!contents_needs_drop"; skipping drop
// is just an optimization, so sound to be conservative.
if
!
self
.type_needs_drop
(
ty
)
{
return
None
;
}
if
!
self
.type_needs_drop
(
ty
)
{
return
CleanupScope
::
noop
()
;
}
let
drop
=
DropValue
{
val
:
val
,
...
...
@@ -138,15 +127,14 @@ pub fn schedule_drop_adt_contents(&self, val: ValueRef, ty: Ty<'tcx>)
debug!
(
"schedule_drop_adt_contents(val={:?}, ty={:?}) skip_dtor={}"
,
Value
(
val
),
ty
,
drop
.skip_dtor
);
Some
(
CleanupScope
::
new
(
self
,
drop
)
)
CleanupScope
::
new
(
self
,
drop
)
}
}
impl
<
'tcx
>
CleanupScope
<
'tcx
>
{
fn
new
<
'a
>
(
fcx
:
&
FunctionContext
<
'a
,
'tcx
>
,
drop_val
:
DropValue
<
'tcx
>
)
->
CleanupScope
<
'tcx
>
{
CleanupScope
{
cleanup
:
drop_val
,
cleanup
:
Some
(
drop_val
)
,
landing_pad
:
if
!
fcx
.ccx
.sess
()
.no_landing_pads
()
{
Some
(
CleanupScope
::
get_landing_pad
(
fcx
,
&
drop_val
))
}
else
{
...
...
@@ -155,6 +143,19 @@ fn new<'a>(fcx: &FunctionContext<'a, 'tcx>, drop_val: DropValue<'tcx>) -> Cleanu
}
}
pub
fn
noop
()
->
CleanupScope
<
'tcx
>
{
CleanupScope
{
cleanup
:
None
,
landing_pad
:
None
,
}
}
pub
fn
trans
<
'a
>
(
self
,
bcx
:
&
'a
BlockAndBuilder
<
'a
,
'tcx
>
)
{
if
let
Some
(
cleanup
)
=
self
.cleanup
{
cleanup
.trans
(
None
,
&
bcx
);
}
}
/// Creates a landing pad for the top scope. The landing pad will perform all cleanups necessary
/// for an unwind and then `resume` to continue error propagation:
///
...
...
src/librustc_trans/glue.rs
浏览文件 @
f051c60d
...
...
@@ -32,6 +32,7 @@
use
type_
::
Type
;
use
value
::
Value
;
use
Disr
;
use
cleanup
::
CleanupScope
;
use
syntax_pos
::
DUMMY_SP
;
...
...
@@ -224,7 +225,7 @@ fn trans_custom_dtor<'blk, 'tcx>(mut bcx: BlockAndBuilder<'blk, 'tcx>,
let
contents_scope
=
if
!
shallow_drop
{
bcx
.fcx
()
.schedule_drop_adt_contents
(
v0
,
t
)
}
else
{
None
CleanupScope
::
noop
()
};
let
(
sized_args
,
unsized_args
);
...
...
@@ -252,7 +253,7 @@ fn trans_custom_dtor<'blk, 'tcx>(mut bcx: BlockAndBuilder<'blk, 'tcx>,
let
callee
=
Callee
::
def
(
bcx
.ccx
(),
dtor_did
,
vtbl
.substs
);
let
fn_ty
=
callee
.direct_fn_type
(
bcx
.ccx
(),
&
[]);
let
llret
;
if
let
Some
(
landing_pad
)
=
contents_scope
.
as_ref
()
.and_then
(|
c
|
c
.landing_pad
)
{
if
let
Some
(
landing_pad
)
=
contents_scope
.
landing_pad
{
let
normal_bcx
=
bcx
.fcx
()
.build_new_block
(
"normal-return"
);
llret
=
bcx
.invoke
(
callee
.reify
(
bcx
.ccx
()),
args
,
normal_bcx
.llbb
(),
landing_pad
,
None
);
bcx
=
normal_bcx
;
...
...
@@ -260,7 +261,7 @@ fn trans_custom_dtor<'blk, 'tcx>(mut bcx: BlockAndBuilder<'blk, 'tcx>,
llret
=
bcx
.call
(
callee
.reify
(
bcx
.ccx
()),
args
,
None
);
}
fn_ty
.apply_attrs_callsite
(
llret
);
bcx
.fcx
()
.trans_scope
(
&
bcx
,
contents_scope
);
contents_scope
.trans
(
&
bcx
);
bcx
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录