Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
af607162
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,发现更多精彩内容 >>
提交
af607162
编写于
6月 14, 2012
作者:
M
Michael Sullivan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Get an initial implementation of boxed vectors working.
上级
9e9e2804
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
71 addition
and
40 deletion
+71
-40
src/rustc/middle/trans/base.rs
src/rustc/middle/trans/base.rs
+7
-7
src/rustc/middle/trans/shape.rs
src/rustc/middle/trans/shape.rs
+1
-2
src/rustc/middle/trans/tvec.rs
src/rustc/middle/trans/tvec.rs
+56
-28
src/rustc/middle/trans/type_of.rs
src/rustc/middle/trans/type_of.rs
+3
-1
src/rustc/middle/ty.rs
src/rustc/middle/ty.rs
+4
-2
未找到文件。
src/rustc/middle/trans/base.rs
浏览文件 @
af607162
...
...
@@ -706,12 +706,6 @@ fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) {
let
bcx
=
drop_ty
(
bcx
,
body
,
body_mt
.ty
);
trans_free
(
bcx
,
v
)
}
ty
::
ty_estr
(
ty
::
vstore_box
)
{
let
v
=
PointerCast
(
bcx
,
v
,
type_of
(
ccx
,
t
));
trans_free
(
bcx
,
v
)
}
ty
::
ty_opaque_box
{
let
v
=
PointerCast
(
bcx
,
v
,
type_of
(
ccx
,
t
));
let
td
=
Load
(
bcx
,
GEPi
(
bcx
,
v
,
[
0u
,
abi
::
box_field_tydesc
]));
...
...
@@ -725,8 +719,11 @@ fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) {
uniq
::
make_free_glue
(
bcx
,
v
,
t
)
}
ty
::
ty_evec
(
_
,
ty
::
vstore_uniq
)
|
ty
::
ty_estr
(
ty
::
vstore_uniq
)
|
ty
::
ty_evec
(
_
,
ty
::
vstore_box
)
|
ty
::
ty_estr
(
ty
::
vstore_box
)
|
ty
::
ty_vec
(
_
)
|
ty
::
ty_str
{
tvec
::
make_free_glue
(
bcx
,
PointerCast
(
bcx
,
v
,
type_of
(
ccx
,
t
)),
t
)
make_free_glue
(
bcx
,
v
,
tvec
::
expand_boxed_vec_ty
(
bcx
.tcx
(),
t
));
ret
;
}
ty
::
ty_evec
(
_
,
_
)
{
bcx
.sess
()
.unimpl
(
"trans::base::make_free_glue on other evec"
);
...
...
@@ -794,6 +791,9 @@ fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
ty
::
ty_evec
(
_
,
ty
::
vstore_uniq
)
|
ty
::
ty_estr
(
ty
::
vstore_uniq
)
{
free_ty
(
bcx
,
Load
(
bcx
,
v0
),
t
)
}
ty
::
ty_unboxed_vec
(
_
)
{
tvec
::
make_drop_glue_unboxed
(
bcx
,
v0
,
t
)
}
ty
::
ty_res
(
did
,
inner
,
substs
)
{
trans_res_drop
(
bcx
,
v0
,
did
,
inner
,
substs
.tps
)
}
...
...
src/rustc/middle/trans/shape.rs
浏览文件 @
af607162
...
...
@@ -277,8 +277,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
}
ty
::
ty_evec
(
mt
,
ty
::
vstore_uniq
)
|
ty
::
ty_vec
(
mt
)
{
shape_of
(
ccx
,
ty
::
mk_imm_uniq
(
ccx
.tcx
,
ty
::
mk_unboxed_vec
(
ccx
.tcx
,
mt
)))
shape_of
(
ccx
,
tvec
::
expand_boxed_vec_ty
(
ccx
.tcx
,
t
))
}
ty
::
ty_estr
(
ty
::
vstore_fixed
(
n
))
{
...
...
src/rustc/middle/trans/tvec.rs
浏览文件 @
af607162
...
...
@@ -5,13 +5,35 @@
import
base
::{
call_memmove
,
INIT
,
copy_val
,
load_if_immediate
,
get_tydesc
,
sub_block
,
do_spill_noroot
,
dest
,
bcx_icx
,
non_gc_box_cast
};
dest
,
bcx_icx
,
non_gc_box_cast
,
heap
,
heap_exchange
,
heap_shared
};
import
syntax
::
codemap
::
span
;
import
shape
::
llsize_of
;
import
build
::
*
;
import
common
::
*
;
import
util
::
ppaux
::
ty_to_str
;
// Boxed vector types are in some sense currently a "shorthand" for a box
// containing an unboxed vector. This expands a boxed vector type into such an
// expanded type. It doesn't respect mutability, but that doesn't matter at
// this point.
fn
expand_boxed_vec_ty
(
tcx
:
ty
::
ctxt
,
t
:
ty
::
t
)
->
ty
::
t
{
let
unit_ty
=
ty
::
sequence_element_type
(
tcx
,
t
);
let
unboxed_vec_ty
=
ty
::
mk_mut_unboxed_vec
(
tcx
,
unit_ty
);
alt
ty
::
get
(
t
)
.struct
{
ty
::
ty_vec
(
_
)
|
ty
::
ty_str
|
ty
::
ty_estr
(
ty
::
vstore_uniq
)
|
ty
::
ty_evec
(
_
,
ty
::
vstore_uniq
)
{
ty
::
mk_imm_uniq
(
tcx
,
unboxed_vec_ty
)
}
ty
::
ty_estr
(
ty
::
vstore_box
)
|
ty
::
ty_evec
(
_
,
ty
::
vstore_box
)
{
ty
::
mk_imm_box
(
tcx
,
unboxed_vec_ty
)
}
_
{
tcx
.sess
.bug
(
"non boxed-vec type
\
in tvec::expand_boxed_vec_ty"
);
}
}
}
fn
get_fill
(
bcx
:
block
,
vptr
:
ValueRef
)
->
ValueRef
{
let
_
icx
=
bcx
.insn_ctxt
(
"tvec::get_fill"
);
Load
(
bcx
,
GEPi
(
bcx
,
vptr
,
[
0u
,
abi
::
vec_elt_fill
]))
...
...
@@ -40,21 +62,25 @@ fn pointer_add(bcx: block, ptr: ValueRef, bytes: ValueRef) -> ValueRef {
ret
PointerCast
(
bcx
,
InBoundsGEP
(
bcx
,
bptr
,
[
bytes
]),
old_ty
);
}
fn
alloc_
uniq_
raw
(
bcx
:
block
,
unit_ty
:
ty
::
t
,
fill
:
ValueRef
,
alloc
:
ValueRef
)
->
result
{
let
_
icx
=
bcx
.insn_ctxt
(
"tvec::alloc_uniq
_raw
"
);
fn
alloc_raw
(
bcx
:
block
,
unit_ty
:
ty
::
t
,
fill
:
ValueRef
,
alloc
:
ValueRef
,
heap
:
heap
)
->
result
{
let
_
icx
=
bcx
.insn_ctxt
(
"tvec::alloc_uniq"
);
let
ccx
=
bcx
.ccx
();
let
vecbodyty
=
ty
::
mk_mut_unboxed_vec
(
bcx
.tcx
(),
unit_ty
);
let
vecsize
=
Add
(
bcx
,
alloc
,
llsize_of
(
ccx
,
ccx
.opaque_vec_type
));
let
{
box
,
body
}
=
base
::
malloc_
unique_dyn
(
bcx
,
vecbodyty
,
vecsize
);
let
{
box
,
body
}
=
base
::
malloc_
general_dyn
(
bcx
,
vecbodyty
,
heap
,
vecsize
);
Store
(
bcx
,
fill
,
GEPi
(
bcx
,
body
,
[
0u
,
abi
::
vec_elt_fill
]));
Store
(
bcx
,
alloc
,
GEPi
(
bcx
,
body
,
[
0u
,
abi
::
vec_elt_alloc
]));
ret
{
bcx
:
bcx
,
val
:
box
};
}
fn
alloc_uniq_raw
(
bcx
:
block
,
unit_ty
:
ty
::
t
,
fill
:
ValueRef
,
alloc
:
ValueRef
)
->
result
{
alloc_raw
(
bcx
,
unit_ty
,
fill
,
alloc
,
heap_exchange
)
}
fn
alloc_
uniq
(
bcx
:
block
,
unit_ty
:
ty
::
t
,
elts
:
uint
)
->
result
{
fn
alloc_
vec
(
bcx
:
block
,
unit_ty
:
ty
::
t
,
elts
:
uint
,
heap
:
heap
)
->
result
{
let
_
icx
=
bcx
.insn_ctxt
(
"tvec::alloc_uniq"
);
let
ccx
=
bcx
.ccx
();
let
llunitty
=
type_of
::
type_of
(
ccx
,
unit_ty
);
...
...
@@ -63,7 +89,7 @@ fn alloc_uniq(bcx: block, unit_ty: ty::t, elts: uint) -> result {
let
fill
=
Mul
(
bcx
,
C_uint
(
ccx
,
elts
),
unit_sz
);
let
alloc
=
if
elts
<
4u
{
Mul
(
bcx
,
C_int
(
ccx
,
4
),
unit_sz
)
}
else
{
fill
};
let
{
bcx
:
bcx
,
val
:
vptr
}
=
alloc_
uniq_raw
(
bcx
,
unit_ty
,
fill
,
alloc
);
let
{
bcx
:
bcx
,
val
:
vptr
}
=
alloc_
raw
(
bcx
,
unit_ty
,
fill
,
alloc
,
heap
);
ret
{
bcx
:
bcx
,
val
:
vptr
};
}
...
...
@@ -79,20 +105,18 @@ fn duplicate_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> result {
call_memmove
(
bcx
,
new_data_ptr
,
data_ptr
,
fill
);
let
bcx
=
if
ty
::
type_needs_drop
(
bcx
.tcx
(),
unit_ty
)
{
iter_vec
(
bcx
,
newptr
,
vec_ty
,
base
::
take_ty
)
iter_vec
_raw
(
bcx
,
new_data_ptr
,
vec_ty
,
fill
,
base
::
take_ty
)
}
else
{
bcx
};
ret
rslt
(
bcx
,
newptr
);
}
fn
make_free_glue
(
bcx
:
block
,
vptr
:
ValueRef
,
vec_ty
:
ty
::
t
)
->
fn
make_drop_glue_unboxed
(
bcx
:
block
,
vptr
:
ValueRef
,
vec_ty
:
ty
::
t
)
->
block
{
let
_
icx
=
bcx
.insn_ctxt
(
"tvec::make_
free_glue
"
);
let
_
icx
=
bcx
.insn_ctxt
(
"tvec::make_
drop_glue_unboxed
"
);
let
tcx
=
bcx
.tcx
(),
unit_ty
=
ty
::
sequence_element_type
(
tcx
,
vec_ty
);
base
::
with_cond
(
bcx
,
IsNotNull
(
bcx
,
vptr
))
{|
bcx
|
let
bcx
=
if
ty
::
type_needs_drop
(
tcx
,
unit_ty
)
{
iter_vec
(
bcx
,
vptr
,
vec_ty
,
base
::
drop_ty
)
}
else
{
bcx
};
base
::
trans_unique_free
(
bcx
,
vptr
)
}
if
ty
::
type_needs_drop
(
tcx
,
unit_ty
)
{
iter_vec_unboxed
(
bcx
,
vptr
,
vec_ty
,
base
::
drop_ty
)
}
else
{
bcx
}
}
fn
trans_evec
(
bcx
:
block
,
args
:
[
@
ast
::
expr
],
...
...
@@ -141,13 +165,18 @@ fn trans_evec(bcx: block, args: [@ast::expr],
{
bcx
:
bcx
,
val
:
p
,
dataptr
:
vp
}
}
ast
::
vstore_uniq
{
let
{
bcx
,
val
}
=
alloc_uniq
(
bcx
,
unit_ty
,
args
.len
());
let
{
bcx
,
val
}
=
alloc_vec
(
bcx
,
unit_ty
,
args
.len
(),
heap_exchange
);
add_clean_free
(
bcx
,
val
,
true
);
let
dataptr
=
get_dataptr
(
bcx
,
get_bodyptr
(
bcx
,
val
));
{
bcx
:
bcx
,
val
:
val
,
dataptr
:
dataptr
}
}
ast
::
vstore_box
{
bcx
.ccx
()
.sess
.unimpl
(
"unhandled tvec::trans_evec"
);
let
{
bcx
,
val
}
=
alloc_vec
(
bcx
,
unit_ty
,
args
.len
(),
heap_shared
);
add_clean_free
(
bcx
,
val
,
true
);
let
dataptr
=
get_dataptr
(
bcx
,
get_bodyptr
(
bcx
,
val
));
{
bcx
:
bcx
,
val
:
val
,
dataptr
:
dataptr
}
}
};
...
...
@@ -223,13 +252,11 @@ fn get_base_and_len(cx: block, v: ValueRef, e_ty: ty::t)
let
len
=
Load
(
cx
,
GEPi
(
cx
,
v
,
[
0u
,
abi
::
slice_elt_len
]));
(
base
,
len
)
}
ty
::
vstore_uniq
{
ty
::
vstore_uniq
|
ty
::
vstore_box
{
#
debug
[
"get_base_and_len: %s"
,
val_str
(
ccx
.tn
,
v
)];
let
body
=
tvec
::
get_bodyptr
(
cx
,
v
);
(
tvec
::
get_dataptr
(
cx
,
body
),
tvec
::
get_fill
(
cx
,
body
))
}
ty
::
vstore_box
{
cx
.ccx
()
.sess
.unimpl
(
"unhandled tvec::get_base_and_len"
);
}
}
}
...
...
@@ -388,7 +415,7 @@ fn trans_add(bcx: block, vec_ty: ty::t, lhs: ValueRef,
fn
iter_vec_raw
(
bcx
:
block
,
data_ptr
:
ValueRef
,
vec_ty
:
ty
::
t
,
fill
:
ValueRef
,
f
:
iter_vec_block
)
->
block
{
let
_
icx
=
bcx
.insn_ctxt
(
"tvec::iter_vec_
uniq
"
);
let
_
icx
=
bcx
.insn_ctxt
(
"tvec::iter_vec_
raw
"
);
let
unit_ty
=
ty
::
sequence_element_type
(
bcx
.tcx
(),
vec_ty
);
...
...
@@ -422,11 +449,12 @@ fn iter_vec_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t,
iter_vec_raw
(
bcx
,
data_ptr
,
vec_ty
,
fill
,
f
)
}
fn
iter_vec
(
bcx
:
block
,
vptr
:
ValueRef
,
vec_ty
:
ty
::
t
,
f
:
iter_vec_block
)
->
block
{
let
_
icx
=
bcx
.insn_ctxt
(
"tvec::iter_vec"
);
let
fill
=
get_fill
(
bcx
,
get_bodyptr
(
bcx
,
vptr
));
ret
iter_vec_uniq
(
bcx
,
vptr
,
vec_ty
,
fill
,
f
);
fn
iter_vec_unboxed
(
bcx
:
block
,
body_ptr
:
ValueRef
,
vec_ty
:
ty
::
t
,
f
:
iter_vec_block
)
->
block
{
let
_
icx
=
bcx
.insn_ctxt
(
"tvec::iter_vec_unboxed"
);
let
fill
=
get_fill
(
bcx
,
body_ptr
);
let
dataptr
=
get_dataptr
(
bcx
,
body_ptr
);
ret
iter_vec_raw
(
bcx
,
dataptr
,
vec_ty
,
fill
,
f
);
}
//
...
...
src/rustc/middle/trans/type_of.rs
浏览文件 @
af607162
...
...
@@ -91,7 +91,9 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
}
ty
::
ty_enum
(
did
,
_
)
{
type_of_enum
(
cx
,
did
,
t
)
}
ty
::
ty_estr
(
ty
::
vstore_box
)
{
T_box_ptr
(
T_box
(
cx
,
T_i8
()))
}
ty
::
ty_evec
(
mt
,
ty
::
vstore_box
)
|
ty
::
ty_evec
(
mt
,
ty
::
vstore_box
)
{
T_box_ptr
(
T_box
(
cx
,
T_vec
(
cx
,
type_of
(
cx
,
mt
.ty
))))
}
ty
::
ty_box
(
mt
)
{
T_box_ptr
(
T_box
(
cx
,
type_of
(
cx
,
mt
.ty
)))
}
ty
::
ty_opaque_box
{
T_box_ptr
(
T_box
(
cx
,
T_i8
()))
}
ty
::
ty_uniq
(
mt
)
{
T_unique_ptr
(
T_unique
(
cx
,
type_of
(
cx
,
mt
.ty
)))
}
...
...
src/rustc/middle/ty.rs
浏览文件 @
af607162
...
...
@@ -1112,7 +1112,7 @@ fn type_is_str(ty: t) -> bool {
fn
sequence_element_type
(
cx
:
ctxt
,
ty
:
t
)
->
t
{
alt
get
(
ty
)
.struct
{
ty_str
|
ty_estr
(
_
)
{
ret
mk_mach_uint
(
cx
,
ast
::
ty_u8
);
}
ty_vec
(
mt
)
|
ty_evec
(
mt
,
_
)
{
ret
mt
.ty
;
}
ty_vec
(
mt
)
|
ty_evec
(
mt
,
_
)
|
ty_unboxed_vec
(
mt
)
{
ret
mt
.ty
;
}
_
{
cx
.sess
.bug
(
"sequence_element_type called on non-sequence value"
);
}
}
}
...
...
@@ -1134,7 +1134,8 @@ fn get_element_type(ty: t, i: uint) -> t {
pure
fn
type_is_boxed
(
ty
:
t
)
->
bool
{
alt
get
(
ty
)
.struct
{
ty_box
(
_
)
|
ty_opaque_box
{
true
}
ty_box
(
_
)
|
ty_opaque_box
|
ty_evec
(
_
,
vstore_box
)
|
ty_estr
(
vstore_box
)
{
true
}
_
{
false
}
}
}
...
...
@@ -1212,6 +1213,7 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
ty_estr
(
vstore_fixed
(
_
))
|
ty_estr
(
vstore_slice
(
_
))
|
ty_evec
(
_
,
vstore_slice
(
_
))
{
false
}
ty_evec
(
mt
,
vstore_fixed
(
_
))
{
type_needs_drop
(
cx
,
mt
.ty
)
}
ty_unboxed_vec
(
mt
)
{
type_needs_drop
(
cx
,
mt
.ty
)
}
ty_rec
(
flds
)
{
for
flds
.each
{|
f
|
if
type_needs_drop
(
cx
,
f
.mt.ty
)
{
accum
=
true
;
}
}
accum
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录