Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1d578002
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,发现更多精彩内容 >>
提交
1d578002
编写于
7月 04, 2011
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: Migrate tag variants to interior vectors
上级
2e1aa04f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
37 deletion
+35
-37
src/comp/metadata/decoder.rs
src/comp/metadata/decoder.rs
+5
-5
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+14
-14
src/comp/middle/ty.rs
src/comp/middle/ty.rs
+12
-14
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+4
-4
未找到文件。
src/comp/metadata/decoder.rs
浏览文件 @
1d578002
...
...
@@ -194,27 +194,27 @@ fn get_symbol(session::session sess, ast::def_id def) -> str {
ret
item_symbol
(
lookup_item
(
def
._1
,
data
));
}
fn
get_tag_variants
(
ty
::
ctxt
tcx
,
ast
::
def_id
def
)
->
vec
[
ty
::
variant_info
]
{
fn
get_tag_variants
(
ty
::
ctxt
tcx
,
ast
::
def_id
def
)
->
ty
::
variant_info
[
]
{
auto
external_crate_id
=
def
._0
;
auto
data
=
tcx
.sess
.get_external_crate
(
external_crate_id
)
.data
;
auto
items
=
ebml
::
get_doc
(
ebml
::
new_doc
(
data
),
tag_items
);
auto
item
=
find_item
(
def
._1
,
items
);
let
vec
[
ty
::
variant_info
]
infos
=
[];
let
ty
::
variant_info
[]
infos
=
~
[];
auto
variant_ids
=
tag_variant_ids
(
item
,
external_crate_id
);
for
(
ast
::
def_id
did
in
variant_ids
)
{
auto
item
=
find_item
(
did
._1
,
items
);
auto
ctor_ty
=
item_type
(
item
,
external_crate_id
,
tcx
);
let
vec
[
ty
::
t
]
arg_tys
=
[];
let
ty
::
t
[]
arg_tys
=
~
[];
alt
(
ty
::
struct
(
tcx
,
ctor_ty
))
{
case
(
ty
::
ty_fn
(
_
,
?
args
,
_
,
_
,
_
))
{
for
(
ty
::
arg
a
in
args
)
{
arg_tys
+=
[
a
.ty
];
}
for
(
ty
::
arg
a
in
args
)
{
arg_tys
+=
~
[
a
.ty
];
}
}
case
(
_
)
{
// Nullary tag variant.
}
}
infos
+=
[
rec
(
args
=
arg_tys
,
ctor_ty
=
ctor_ty
,
id
=
did
)];
infos
+=
~
[
rec
(
args
=
arg_tys
,
ctor_ty
=
ctor_ty
,
id
=
did
)];
}
ret
infos
;
}
...
...
src/comp/middle/trans.rs
浏览文件 @
1d578002
...
...
@@ -903,7 +903,7 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
fn
type_of_tag
(
&@
crate_ctxt
cx
,
&
span
sp
,
&
ast
::
def_id
did
,
&
ty
::
t
t
)
->
TypeRef
{
auto
degen
=
vec
::
len
(
ty
::
tag_variants
(
cx
.tcx
,
did
))
==
1u
;
auto
degen
=
std
::
i
vec
::
len
(
ty
::
tag_variants
(
cx
.tcx
,
did
))
==
1u
;
if
(
ty
::
type_has_dynamic_size
(
cx
.tcx
,
t
))
{
if
(
degen
)
{
ret
T_i8
();
}
else
{
ret
T_opaque_tag
(
cx
.tn
);
}
...
...
@@ -1351,7 +1351,7 @@ fn align_elements(&@block_ctxt cx, &vec[ty::t] elts) -> result {
for
(
ty
::
variant_info
variant
in
variants
)
{
// Perform type substitution on the raw argument types.
let
vec
[
ty
::
t
]
raw_tys
=
variant
.args
;
let
ty
::
t
[
]
raw_tys
=
variant
.args
;
let
vec
[
ty
::
t
]
tys
=
[];
for
(
ty
::
t
raw_ty
in
raw_tys
)
{
auto
t
=
...
...
@@ -1366,7 +1366,7 @@ fn align_elements(&@block_ctxt cx, &vec[ty::t] elts) -> result {
bcx
.build
.Store
(
umax
(
bcx
,
this_size
,
old_max_size
),
max_size
);
}
auto
max_size_val
=
bcx
.build
.Load
(
max_size
);
auto
total_size
=
if
(
vec
::
len
(
variants
)
!=
1u
)
{
auto
total_size
=
if
(
std
::
i
vec
::
len
(
variants
)
!=
1u
)
{
bcx
.build
.Add
(
max_size_val
,
llsize_of
(
T_int
()))
}
else
{
max_size_val
};
ret
rslt
(
bcx
,
total_size
);
...
...
@@ -2655,7 +2655,7 @@ fn adapter(&@block_ctxt bcx, ValueRef av, ValueRef bv, ty::t unit_ty,
fn
iter_variant
(
@
block_ctxt
cx
,
ValueRef
a_tup
,
ValueRef
b_tup
,
&
ty
::
variant_info
variant
,
&
ty
::
t
[]
tps
,
&
ast
::
def_id
tid
,
&
val_pair_and_ty_fn
f
)
->
result
{
if
(
vec
::
len
[
ty
::
t
](
variant
.args
)
==
0u
)
{
if
(
std
::
i
vec
::
len
[
ty
::
t
](
variant
.args
)
==
0u
)
{
ret
rslt
(
cx
,
C_nil
());
}
auto
fn_ty
=
variant
.ctor_ty
;
...
...
@@ -2664,12 +2664,10 @@ fn iter_variant(@block_ctxt cx, ValueRef a_tup, ValueRef b_tup,
case
(
ty
::
ty_fn
(
_
,
?
args
,
_
,
_
,
_
))
{
auto
j
=
0
;
for
(
ty
::
arg
a
in
args
)
{
auto
rslt
=
GEP_tag
(
cx
,
a_tup
,
tid
,
variant
.id
,
tps
,
j
);
auto
rslt
=
GEP_tag
(
cx
,
a_tup
,
tid
,
variant
.id
,
tps
,
j
);
auto
llfldp_a
=
rslt
.val
;
cx
=
rslt
.bcx
;
rslt
=
GEP_tag
(
cx
,
b_tup
,
tid
,
variant
.id
,
tps
,
j
);
rslt
=
GEP_tag
(
cx
,
b_tup
,
tid
,
variant
.id
,
tps
,
j
);
auto
llfldp_b
=
rslt
.val
;
cx
=
rslt
.bcx
;
auto
ty_subst
=
...
...
@@ -2730,7 +2728,7 @@ fn iter_variant(@block_ctxt cx, ValueRef a_tup, ValueRef b_tup,
}
case
(
ty
::
ty_tag
(
?
tid
,
?
tps
))
{
auto
variants
=
ty
::
tag_variants
(
cx
.fcx.lcx.ccx.tcx
,
tid
);
auto
n_variants
=
vec
::
len
(
variants
);
auto
n_variants
=
std
::
i
vec
::
len
(
variants
);
// Cast the tags to types we can GEP into.
if
(
n_variants
==
1u
)
{
...
...
@@ -4159,8 +4157,8 @@ fn autoderef_lval(&@block_ctxt cx, ValueRef v, &ty::t t, bool is_lval)
}
case
(
ty
::
ty_tag
(
?
did
,
?
tps
))
{
auto
variants
=
ty
::
tag_variants
(
ccx
.tcx
,
did
);
if
(
vec
::
len
(
variants
)
!=
1u
||
vec
::
len
(
variants
.
(
0
)
.args
)
!=
1u
)
{
if
(
std
::
i
vec
::
len
(
variants
)
!=
1u
||
std
::
i
vec
::
len
(
variants
.
(
0
)
.args
)
!=
1u
)
{
break
;
}
if
(
is_lval
)
{
v1
=
cx
.build
.Load
(
v1
);
}
...
...
@@ -4700,7 +4698,7 @@ fn trans_pat_match(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
auto
matched_cx
=
new_sub_block_ctxt
(
cx
,
"matched_cx"
);
auto
llblobptr
=
llval
;
if
(
vec
::
len
(
variants
)
==
1u
)
{
if
(
std
::
i
vec
::
len
(
variants
)
==
1u
)
{
cx
.build
.Br
(
matched_cx
.llbb
);
}
else
{
auto
lltagptr
=
...
...
@@ -4789,7 +4787,8 @@ fn trans_pat_binding(&@block_ctxt cx, &@ast::pat pat, ValueRef llval,
"trans_pat_binding: internal error, unbound var"
);
}
}
auto
llblobptr
=
llval
;
if
(
vec
::
len
(
ty
::
tag_variants
(
cx
.fcx.lcx.ccx.tcx
,
vdef
._0
))
!=
1u
)
{
if
(
std
::
ivec
::
len
(
ty
::
tag_variants
(
cx
.fcx.lcx.ccx.tcx
,
vdef
._0
))
!=
1u
)
{
auto
lltagptr
=
cx
.build
.PointerCast
(
llval
,
T_opaque_tag_ptr
(
cx
.fcx.lcx.ccx.tn
));
llblobptr
=
cx
.build
.GEP
(
lltagptr
,
[
C_int
(
0
),
C_int
(
1
)]);
...
...
@@ -4987,7 +4986,8 @@ fn trans_path(&@block_ctxt cx, &ast::path p, ast::node_id id) -> lval_result {
auto
bcx
=
alloc_result
.bcx
;
auto
lltagptr
=
bcx
.build
.PointerCast
(
lltagblob
,
T_ptr
(
lltagty
));
if
(
vec
::
len
(
ty
::
tag_variants
(
ccx
.tcx
,
tid
))
!=
1u
)
{
if
(
std
::
ivec
::
len
(
ty
::
tag_variants
(
ccx
.tcx
,
tid
))
!=
1u
)
{
auto
lldiscrim_gv
=
lookup_discriminant
(
bcx
.fcx.lcx
,
tid
,
vid
);
auto
lldiscrim
=
bcx
.build
.Load
(
lldiscrim_gv
);
...
...
src/comp/middle/ty.rs
浏览文件 @
1d578002
...
...
@@ -1288,8 +1288,8 @@ fn type_autoderef(&ctxt cx, &ty::t t) -> ty::t {
}
case
(
ty
::
ty_tag
(
?
did
,
?
tps
))
{
auto
variants
=
tag_variants
(
cx
,
did
);
if
(
vec
::
len
(
variants
)
!=
1u
||
vec
::
len
(
variants
.
(
0
)
.args
)
!=
1u
)
{
if
(
i
vec
::
len
(
variants
)
!=
1u
||
i
vec
::
len
(
variants
.
(
0
)
.args
)
!=
1u
)
{
break
;
}
t1
=
substitute_type_params
(
cx
,
tps
,
variants
.
(
0
)
.args
.
(
0
));
...
...
@@ -2812,12 +2812,10 @@ fn def_has_ty_params(&ast::def def) -> bool {
// Tag information
type
variant_info
=
rec
(
vec
[
ty
::
t
]
args
,
ty
::
t
ctor_ty
,
ast
::
def_id
id
);
type
variant_info
=
rec
(
ty
::
t
[
]
args
,
ty
::
t
ctor_ty
,
ast
::
def_id
id
);
fn
tag_variants
(
&
ctxt
cx
,
&
ast
::
def_id
id
)
->
vec
[
variant_info
]
{
if
(
ast
::
local_crate
!=
id
._0
)
{
ret
decoder
::
get_tag_variants
(
cx
,
id
);
}
fn
tag_variants
(
&
ctxt
cx
,
&
ast
::
def_id
id
)
->
variant_info
[]
{
if
(
ast
::
local_crate
!=
id
._0
)
{
ret
decoder
::
get_tag_variants
(
cx
,
id
);
}
auto
item
=
alt
(
cx
.items
.find
(
id
._1
))
{
case
(
some
(
?
i
))
{
i
}
case
(
none
)
{
...
...
@@ -2828,22 +2826,22 @@ fn tag_variants(&ctxt cx, &ast::def_id id) -> vec[variant_info] {
case
(
ast_map
::
node_item
(
?
item
))
{
alt
(
item
.node
)
{
case
(
ast
::
item_tag
(
?
variants
,
_
))
{
let
v
ec
[
variant_info
]
result
=
[];
let
v
ariant_info
[]
result
=
~
[];
for
(
ast
::
variant
variant
in
variants
)
{
auto
ctor_ty
=
node_id_to_monotype
(
cx
,
variant
.node.id
);
let
vec
[
t
]
arg_tys
=
[];
let
t
[]
arg_tys
=
~
[];
if
(
vec
::
len
[
ast
::
variant_arg
](
variant
.node.args
)
>
0u
)
{
for
(
arg
a
in
ty_fn_args
(
cx
,
ctor_ty
))
{
arg_tys
+=
[
a
.ty
];
arg_tys
+=
~
[
a
.ty
];
}
}
auto
did
=
variant
.node.id
;
result
+=
[
rec
(
args
=
arg_tys
,
ctor_ty
=
ctor_ty
,
id
=
ast
::
local_def
(
did
))];
~
[
rec
(
args
=
arg_tys
,
ctor_ty
=
ctor_ty
,
id
=
ast
::
local_def
(
did
))];
}
ret
result
;
}
...
...
@@ -2858,7 +2856,7 @@ fn tag_variant_with_id(&ctxt cx, &ast::def_id tag_id, &ast::def_id variant_id)
->
variant_info
{
auto
variants
=
tag_variants
(
cx
,
tag_id
);
auto
i
=
0u
;
while
(
i
<
vec
::
len
[
variant_info
](
variants
))
{
while
(
i
<
i
vec
::
len
[
variant_info
](
variants
))
{
auto
variant
=
variants
.
(
i
);
if
(
def_eq
(
variant
.id
,
variant_id
))
{
ret
variant
;
}
i
+=
1u
;
...
...
src/comp/middle/typeck.rs
浏览文件 @
1d578002
...
...
@@ -876,8 +876,8 @@ fn do_autoderef(&@fn_ctxt fcx, &span sp, &ty::t t) -> ty::t {
}
case
(
ty
::
ty_tag
(
?
did
,
?
tps
))
{
auto
variants
=
ty
::
tag_variants
(
fcx
.ccx.tcx
,
did
);
if
(
vec
::
len
(
variants
)
!=
1u
||
vec
::
len
(
variants
.
(
0
)
.args
)
!=
1u
)
{
if
(
i
vec
::
len
(
variants
)
!=
1u
||
i
vec
::
len
(
variants
.
(
0
)
.args
)
!=
1u
)
{
ret
t1
;
}
t1
=
ty
::
substitute_type_params
(
fcx
.ccx.tcx
,
tps
,
...
...
@@ -1651,8 +1651,8 @@ fn check_binop_type_compat(&@fn_ctxt fcx, span span,
case
(
ty
::
ty_res
(
_
,
?
inner
,
_
))
{
oper_t
=
inner
;
}
case
(
ty
::
ty_tag
(
?
id
,
?
tps
))
{
auto
variants
=
ty
::
tag_variants
(
fcx
.ccx.tcx
,
id
);
if
(
vec
::
len
(
variants
)
!=
1u
||
vec
::
len
(
variants
.
(
0
)
.args
)
!=
1u
)
{
if
(
i
vec
::
len
(
variants
)
!=
1u
||
i
vec
::
len
(
variants
.
(
0
)
.args
)
!=
1u
)
{
fcx
.ccx.tcx.sess
.span_fatal
(
expr
.span
,
"can only dereference tags "
+
"with a single variant which has a "
+
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录