Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ced10626
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,发现更多精彩内容 >>
提交
ced10626
编写于
1月 26, 2015
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Address
@EddyB
nit by simplifying `ClosureEnv`.
上级
a962bdb3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
38 deletion
+29
-38
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/base.rs
+14
-9
src/librustc_trans/trans/closure.rs
src/librustc_trans/trans/closure.rs
+15
-29
未找到文件。
src/librustc_trans/trans/base.rs
浏览文件 @
ced10626
...
...
@@ -1775,7 +1775,7 @@ pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
_
attributes
:
&
[
ast
::
Attribute
],
output_type
:
ty
::
FnOutput
<
'tcx
>
,
abi
:
Abi
,
closure_env
:
closure
::
ClosureEnv
<
'b
,
'tcx
>
)
{
closure_env
:
closure
::
ClosureEnv
<
'b
>
)
{
ccx
.stats
()
.n_closures
.set
(
ccx
.stats
()
.n_closures
.get
()
+
1
);
let
_
icx
=
push_ctxt
(
"trans_closure"
);
...
...
@@ -1784,12 +1784,17 @@ pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
debug!
(
"trans_closure(..., param_substs={})"
,
param_substs
.repr
(
ccx
.tcx
()));
let
has_env
=
match
closure_env
{
closure
::
ClosureEnv
::
Closure
(
_
)
=>
true
,
closure
::
ClosureEnv
::
NotClosure
=>
false
,
};
let
(
arena
,
fcx
):
(
TypedArena
<
_
>
,
FunctionContext
);
arena
=
TypedArena
::
new
();
fcx
=
new_fn_ctxt
(
ccx
,
llfndecl
,
fn_ast_id
,
closure_env
.kind
!=
closure
::
ClosureKind
::
NotClosure
,
has_env
,
output_type
,
param_substs
,
Some
(
body
.span
),
...
...
@@ -1808,13 +1813,13 @@ pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
decl
.inputs
.iter
()
.map
(|
arg
|
node_id_type
(
bcx
,
arg
.id
))
.collect
::
<
Vec
<
_
>>
();
let
monomorphized_arg_types
=
match
closure_env
.kind
{
closure
::
Closure
Kind
::
NotClosure
=>
{
let
monomorphized_arg_types
=
match
closure_env
{
closure
::
Closure
Env
::
NotClosure
=>
{
monomorphized_arg_types
}
// Tuple up closure argument types for the "rust-call" ABI.
closure
::
Closure
Kind
::
Closure
=>
{
closure
::
Closure
Env
::
Closure
(
_
)
=>
{
vec!
[
ty
::
mk_tup
(
ccx
.tcx
(),
monomorphized_arg_types
)]
}
};
...
...
@@ -1835,14 +1840,14 @@ pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
&
monomorphized_arg_types
[])
};
bcx
=
match
closure_env
.kind
{
closure
::
Closure
Kind
::
NotClosure
=>
{
bcx
=
match
closure_env
{
closure
::
Closure
Env
::
NotClosure
=>
{
copy_args_to_allocas
(
bcx
,
arg_scope
,
&
decl
.inputs
[],
arg_datums
)
}
closure
::
Closure
Kind
::
Closure
=>
{
closure
::
Closure
Env
::
Closure
(
_
)
=>
{
copy_closure_args_to_allocas
(
bcx
,
arg_scope
,
...
...
@@ -1932,7 +1937,7 @@ pub fn trans_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
attrs
,
output_type
,
abi
,
closure
::
ClosureEnv
::
new
(
&
[],
closure
::
ClosureKind
::
NotClosure
)
);
closure
::
ClosureEnv
::
NotClosure
);
}
pub
fn
trans_enum_variant
<
'a
,
'tcx
>
(
ccx
:
&
CrateContext
<
'a
,
'tcx
>
,
...
...
src/librustc_trans/trans/closure.rs
浏览文件 @
ced10626
...
...
@@ -97,37 +97,23 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
bcx
}
#[derive(PartialEq)]
pub
enum
ClosureKind
<
'tcx
>
{
pub
enum
ClosureEnv
<
'a
>
{
NotClosure
,
Closure
,
Closure
(
&
'a
[
ty
::
Freevar
])
,
}
pub
struct
ClosureEnv
<
'a
,
'tcx
>
{
freevars
:
&
'a
[
ty
::
Freevar
],
pub
kind
:
ClosureKind
<
'tcx
>
}
impl
<
'a
,
'tcx
>
ClosureEnv
<
'a
,
'tcx
>
{
pub
fn
new
(
freevars
:
&
'a
[
ty
::
Freevar
],
kind
:
ClosureKind
<
'tcx
>
)
->
ClosureEnv
<
'a
,
'tcx
>
{
ClosureEnv
{
freevars
:
freevars
,
kind
:
kind
}
}
pub
fn
load
<
'blk
>
(
self
,
bcx
:
Block
<
'blk
,
'tcx
>
,
arg_scope
:
ScopeId
)
->
Block
<
'blk
,
'tcx
>
{
// Don't bother to create the block if there's nothing to load
if
self
.freevars
.is_empty
()
{
return
bcx
;
}
match
self
.kind
{
ClosureKind
::
NotClosure
=>
bcx
,
ClosureKind
::
Closure
=>
{
load_closure_environment
(
bcx
,
arg_scope
,
self
.freevars
)
impl
<
'a
>
ClosureEnv
<
'a
>
{
pub
fn
load
<
'blk
,
'tcx
>
(
self
,
bcx
:
Block
<
'blk
,
'tcx
>
,
arg_scope
:
ScopeId
)
->
Block
<
'blk
,
'tcx
>
{
match
self
{
ClosureEnv
::
NotClosure
=>
bcx
,
ClosureEnv
::
Closure
(
freevars
)
=>
{
if
freevars
.is_empty
()
{
bcx
}
else
{
load_closure_environment
(
bcx
,
arg_scope
,
freevars
)
}
}
}
}
...
...
@@ -224,7 +210,7 @@ pub fn trans_closure_expr<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
&
[],
sig
.output
,
function_type
.abi
,
ClosureEnv
::
new
(
&
freevars
[],
ClosureKind
::
Closure
));
ClosureEnv
::
Closure
(
&
freevars
[]
));
// Don't hoist this to the top of the function. It's perfectly legitimate
// to have a zero-size closure (in which case dest will be `Ignore`) and
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录