Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
85aaf392
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,发现更多精彩内容 >>
提交
85aaf392
编写于
2月 26, 2013
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reimplement type_needs_drop on top of TypeContents
上级
6439e286
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
81 deletion
+17
-81
src/librustc/middle/ty.rs
src/librustc/middle/ty.rs
+17
-81
未找到文件。
src/librustc/middle/ty.rs
浏览文件 @
85aaf392
...
...
@@ -259,7 +259,6 @@ struct ctxt_ {
rcache
:
creader_cache
,
ccache
:
constness_cache
,
short_names_cache
:
HashMap
<
t
,
@~
str
>
,
needs_drop_cache
:
HashMap
<
t
,
bool
>
,
needs_unwind_cleanup_cache
:
HashMap
<
t
,
bool
>
,
tc_cache
:
@
mut
LinearMap
<
uint
,
TypeContents
>
,
ast_ty_to_ty_cache
:
HashMap
<
node_id
,
ast_ty_to_ty_cache_entry
>
,
...
...
@@ -822,7 +821,6 @@ pub fn mk_ctxt(s: session::Session,
rcache
:
mk_rcache
(),
ccache
:
HashMap
(),
short_names_cache
:
new_ty_hash
(),
needs_drop_cache
:
new_ty_hash
(),
needs_unwind_cleanup_cache
:
new_ty_hash
(),
tc_cache
:
@
mut
LinearMap
::
new
(),
ast_ty_to_ty_cache
:
HashMap
(),
...
...
@@ -1600,79 +1598,7 @@ pub fn type_is_immediate(ty: t) -> bool {
}
pub
fn
type_needs_drop
(
cx
:
ctxt
,
ty
:
t
)
->
bool
{
match
cx
.needs_drop_cache
.find
(
&
ty
)
{
Some
(
result
)
=>
return
result
,
None
=>
{
/* fall through */
}
}
let
mut
accum
=
false
;
let
result
=
match
/*bad*/
copy
get
(
ty
)
.sty
{
// scalar types
ty_nil
|
ty_bot
|
ty_bool
|
ty_int
(
_
)
|
ty_float
(
_
)
|
ty_uint
(
_
)
|
ty_type
|
ty_ptr
(
_
)
|
ty_rptr
(
_
,
_
)
|
ty_estr
(
vstore_fixed
(
_
))
|
ty_estr
(
vstore_slice
(
_
))
|
ty_evec
(
_
,
vstore_slice
(
_
))
|
ty_self
=>
false
,
ty_box
(
_
)
|
ty_uniq
(
_
)
|
ty_opaque_box
|
ty_opaque_closure_ptr
(
*
)
|
ty_estr
(
vstore_uniq
)
|
ty_estr
(
vstore_box
)
|
ty_evec
(
_
,
vstore_uniq
)
|
ty_evec
(
_
,
vstore_box
)
=>
true
,
ty_trait
(
_
,
_
,
vstore_box
)
|
ty_trait
(
_
,
_
,
vstore_uniq
)
=>
true
,
ty_trait
(
_
,
_
,
vstore_fixed
(
_
))
|
ty_trait
(
_
,
_
,
vstore_slice
(
_
))
=>
false
,
ty_param
(
*
)
|
ty_infer
(
*
)
|
ty_err
=>
true
,
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
}
ty_struct
(
did
,
ref
substs
)
=>
{
// Any struct with a dtor needs a drop
ty_dtor
(
cx
,
did
)
.is_present
()
||
{
for
vec
::
each
(
ty
::
struct_fields
(
cx
,
did
,
substs
))
|
f
|
{
if
type_needs_drop
(
cx
,
f
.mt.ty
)
{
accum
=
true
;
}
}
accum
}
}
ty_tup
(
elts
)
=>
{
for
elts
.each
|
m
|
{
if
type_needs_drop
(
cx
,
*
m
)
{
accum
=
true
;
}
}
accum
}
ty_enum
(
did
,
ref
substs
)
=>
{
let
variants
=
enum_variants
(
cx
,
did
);
for
vec
::
each
(
*
variants
)
|
variant
|
{
for
variant
.args.each
|
aty
|
{
// Perform any type parameter substitutions.
let
arg_ty
=
subst
(
cx
,
substs
,
*
aty
);
if
type_needs_drop
(
cx
,
arg_ty
)
{
accum
=
true
;
}
}
if
accum
{
break
;
}
}
accum
}
ty_bare_fn
(
*
)
=>
false
,
ty_closure
(
ref
fty
)
=>
{
match
fty
.sigil
{
ast
::
BorrowedSigil
=>
false
,
ast
::
ManagedSigil
|
ast
::
OwnedSigil
=>
true
,
}
}
};
cx
.needs_drop_cache
.insert
(
ty
,
result
);
return
result
;
type_contents
(
cx
,
ty
)
.needs_drop
(
cx
)
}
// Some things don't need cleanups during unwinding because the
...
...
@@ -1819,7 +1745,7 @@ fn moves_by_default(&self, cx: ctxt) -> bool {
static
fn
nonimplicitly_copyable
(
cx
:
ctxt
)
->
TypeContents
{
let
base
=
TypeContents
::
noncopyable
(
cx
)
+
TC_OWNED_POINTER
;
if
cx
.vecs_implicitly_copyable
{
base
}
else
{
base
+
TC_OWNED_
SLICE
}
if
cx
.vecs_implicitly_copyable
{
base
}
else
{
base
+
TC_OWNED_
VEC
}
}
fn
is_safe_for_default_mode
(
&
self
,
cx
:
ctxt
)
->
bool
{
...
...
@@ -1828,7 +1754,17 @@ fn is_safe_for_default_mode(&self, cx: ctxt) -> bool {
static
fn
nondefault_mode
(
cx
:
ctxt
)
->
TypeContents
{
let
tc
=
TypeContents
::
nonimplicitly_copyable
(
cx
);
tc
+
TC_BIG
+
TC_OWNED_SLICE
// disregard cx.vecs_implicitly_copyable
tc
+
TC_BIG
+
TC_OWNED_VEC
// disregard cx.vecs_implicitly_copyable
}
fn
needs_drop
(
&
self
,
cx
:
ctxt
)
->
bool
{
let
tc
=
TC_MANAGED
+
TC_DTOR
+
TypeContents
::
owned
(
cx
);
self
.intersects
(
tc
)
}
static
fn
owned
(
&
self
,
_
cx
:
ctxt
)
->
TypeContents
{
//! Any kind of owned contents.
TC_OWNED_CLOSURE
+
TC_OWNED_POINTER
+
TC_OWNED_VEC
}
}
...
...
@@ -1859,8 +1795,8 @@ impl ToStr for TypeContents {
/// Contains an owned pointer (~T) but not slice of some kind
const
TC_OWNED_POINTER
:
TypeContents
=
TypeContents
{
bits
:
0b000000000010
};
/// Contains an owned
slice
const
TC_OWNED_
SLICE
:
TypeContents
=
TypeContents
{
bits
:
0b000000000100
};
/// Contains an owned
vector ~[] or owned string ~str
const
TC_OWNED_
VEC
:
TypeContents
=
TypeContents
{
bits
:
0b000000000100
};
/// Contains a ~fn() or a ~Trait, which is non-copyable.
const
TC_OWNED_CLOSURE
:
TypeContents
=
TypeContents
{
bits
:
0b000000001000
};
...
...
@@ -1963,7 +1899,7 @@ fn tc_ty(cx: ctxt,
}
ty_estr
(
vstore_uniq
)
=>
{
TC_OWNED_
SLICE
TC_OWNED_
VEC
}
ty_closure
(
ref
c
)
=>
{
...
...
@@ -1996,7 +1932,7 @@ fn tc_ty(cx: ctxt,
}
ty_evec
(
mt
,
vstore_uniq
)
=>
{
TC_OWNED_
SLICE
+
tc_mt
(
cx
,
mt
,
cache
)
TC_OWNED_
VEC
+
tc_mt
(
cx
,
mt
,
cache
)
}
ty_evec
(
mt
,
vstore_box
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录