Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7a336f1e
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,发现更多精彩内容 >>
提交
7a336f1e
编写于
1月 08, 2012
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify last use to take into account cap clause, add new test
上级
106385cb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
68 addition
and
10 deletion
+68
-10
src/comp/middle/last_use.rs
src/comp/middle/last_use.rs
+25
-8
src/comp/middle/trans_closure.rs
src/comp/middle/trans_closure.rs
+19
-1
src/test/run-pass/cap-clause-move.rs
src/test/run-pass/cap-clause-move.rs
+0
-1
src/test/run-pass/task-spawn-move-and-copy.rs
src/test/run-pass/task-spawn-move-and-copy.rs
+24
-0
未找到文件。
src/comp/middle/last_use.rs
浏览文件 @
7a336f1e
...
...
@@ -136,6 +136,16 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
v
.visit_expr
(
dest
,
cx
,
v
);
clear_if_path
(
cx
,
dest
,
v
,
true
);
}
expr_fn
(
_
,
_
,
_
,
cap_clause
)
{
// n.b.: safe to ignore copies, as if they are unused
// then they are ignored, otherwise they will show up
// as freevars in the body.
vec
::
iter
(
cap_clause
.moves
)
{|
ci
|
clear_def_if_path
(
cx
,
cx
.def_map
.get
(
ci
.id
),
true
);
}
visit
::
visit_expr
(
ex
,
cx
,
v
);
}
expr_call
(
f
,
args
,
_
)
{
v
.visit_expr
(
f
,
cx
,
v
);
let
i
=
0u
,
fns
=
[];
...
...
@@ -263,18 +273,25 @@ fn clear_in_current(cx: ctx, my_def: node_id, to: bool) {
}
}
fn
clear_def_if_path
(
cx
:
ctx
,
d
:
def
,
to
:
bool
)
->
option
<
node_id
>
{
alt
d
{
def_local
(
def_id
,
let_copy
.
)
|
def_arg
(
def_id
,
by_copy
.
)
|
def_arg
(
def_id
,
by_move
.
)
{
clear_in_current
(
cx
,
def_id
.node
,
to
);
some
(
def_id
.node
)
}
_
{
none
}
}
}
fn
clear_if_path
(
cx
:
ctx
,
ex
:
@
expr
,
v
:
visit
::
vt
<
ctx
>
,
to
:
bool
)
->
option
::
t
<
node_id
>
{
alt
ex
.node
{
expr_path
(
_
)
{
alt
cx
.def_map
.get
(
ex
.id
)
{
def_local
(
def_id
,
let_copy
.
)
|
def_arg
(
def_id
,
by_copy
.
)
|
def_arg
(
def_id
,
by_move
.
)
{
clear_in_current
(
cx
,
def_id
.node
,
to
);
ret
option
::
some
(
def_id
.node
);
}
_
{}
}
ret
clear_def_if_path
(
cx
,
cx
.def_map
.get
(
ex
.id
),
to
);
}
_
{
v
.visit_expr
(
ex
,
cx
,
v
);
}
}
...
...
src/comp/middle/trans_closure.rs
浏览文件 @
7a336f1e
...
...
@@ -9,6 +9,7 @@
import
option
::{
some
,
none
};
import
back
::
abi
;
import
syntax
::
codemap
::
span
;
import
syntax
::
print
::
pprust
::
expr_to_str
;
import
back
::
link
::{
mangle_internal_name_by_path
,
mangle_internal_name_by_path_and_seq
};
...
...
@@ -121,6 +122,18 @@
env_ref
(
ValueRef
,
ty
::
t
,
lval_kind
);
}
fn
ev_to_str
(
ccx
:
@
crate_ctxt
,
ev
:
environment_value
)
->
str
{
alt
ev
{
env_expr
(
ex
)
{
expr_to_str
(
ex
)
}
env_copy
(
v
,
t
,
lk
)
{
#
fmt
(
"copy(%s,%s)"
,
val_str
(
ccx
.tn
,
v
),
ty_to_str
(
ccx
.tcx
,
t
))
}
env_move
(
v
,
t
,
lk
)
{
#
fmt
(
"move(%s,%s)"
,
val_str
(
ccx
.tn
,
v
),
ty_to_str
(
ccx
.tcx
,
t
))
}
env_ref
(
v
,
t
,
lk
)
{
#
fmt
(
"ref(%s,%s)"
,
val_str
(
ccx
.tn
,
v
),
ty_to_str
(
ccx
.tcx
,
t
))
}
}
}
fn
mk_tydesc_ty
(
tcx
:
ty
::
ctxt
,
ck
:
ty
::
closure_kind
)
->
ty
::
t
{
ret
alt
ck
{
ty
::
closure_block
.
|
ty
::
closure_shared
.
{
ty
::
mk_type
(
tcx
)
}
...
...
@@ -284,7 +297,7 @@ fn maybe_clone_tydesc(bcx: @block_ctxt,
};
}
//
let ccx = bcx_ccx(bcx);
let
ccx
=
bcx_ccx
(
bcx
);
let
tcx
=
bcx_tcx
(
bcx
);
// compute the shape of the closure
...
...
@@ -351,6 +364,11 @@ fn maybe_clone_tydesc(bcx: @block_ctxt,
let
{
bcx
:
bcx
,
val
:
bindings_slot
}
=
GEP_tup_like_1
(
bcx
,
cboxptr_ty
,
llbox
,
[
0
,
abi
::
cbox_elt_bindings
]);
vec
::
iteri
(
bound_values
)
{
|
i
,
bv
|
if
(
!
ccx
.sess
.get_opts
()
.no_asm_comments
)
{
add_comment
(
bcx
,
#
fmt
(
"Copy %s into closure"
,
ev_to_str
(
ccx
,
bv
)));
}
let
bound_data
=
GEPi
(
bcx
,
bindings_slot
,
[
0
,
i
as
int
]);
alt
bv
{
env_expr
(
e
)
{
...
...
src/test/run-pass/cap-clause-move.rs
浏览文件 @
7a336f1e
// error-pattern: warning: Captured variable 'y' not used in closure
fn
main
()
{
let
x
=
~
1
;
let
y
=
ptr
::
addr_of
(
*
x
)
as
uint
;
...
...
src/test/run-pass/task-spawn-move-and-copy.rs
0 → 100644
浏览文件 @
7a336f1e
fn
main
()
{
let
p
=
comm
::
port
::
<
uint
>
();
let
ch
=
comm
::
chan
(
p
);
let
x
=
~
1
;
let
x_in_parent
=
ptr
::
addr_of
(
*
x
)
as
uint
;
let
y
=
~
2
;
let
y_in_parent
=
ptr
::
addr_of
(
*
y
)
as
uint
;
task
::
spawn
(
sendfn
[
copy
ch
,
y
;
move
x
]()
{
let
x_in_child
=
ptr
::
addr_of
(
*
x
)
as
uint
;
comm
::
send
(
ch
,
x_in_child
);
let
y_in_child
=
ptr
::
addr_of
(
*
y
)
as
uint
;
comm
::
send
(
ch
,
y_in_child
);
});
let
x_in_child
=
comm
::
recv
(
p
);
assert
x_in_parent
==
x_in_child
;
let
y_in_child
=
comm
::
recv
(
p
);
assert
y_in_parent
!=
y_in_child
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录