Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3ee630bb
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,发现更多精彩内容 >>
提交
3ee630bb
编写于
12月 22, 2011
作者:
M
Marijn Haverbeke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add ty::new_ty_hash, clean up comparing of ty::t's
上级
e2e077c8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
30 addition
and
49 deletion
+30
-49
src/comp/metadata/encoder.rs
src/comp/metadata/encoder.rs
+1
-1
src/comp/middle/debuginfo.rs
src/comp/middle/debuginfo.rs
+3
-4
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+6
-13
src/comp/middle/ty.rs
src/comp/middle/ty.rs
+20
-31
未找到文件。
src/comp/metadata/encoder.rs
浏览文件 @
3ee630bb
...
...
@@ -653,7 +653,7 @@ fn encode_hash(ebml_w: ebml::writer, hash: str) {
fn
encode_metadata
(
cx
:
@
crate_ctxt
,
crate
:
@
crate
)
->
str
{
let
abbrevs
=
map
::
mk_hashmap
(
ty
::
hash_ty
,
ty
::
eq_ty
);
let
abbrevs
=
ty
::
new_ty_hash
(
);
let
ecx
=
@
{
ccx
:
cx
,
type_abbrevs
:
abbrevs
};
let
string_w
=
io
::
string_writer
();
...
...
src/comp/middle/debuginfo.rs
浏览文件 @
3ee630bb
...
...
@@ -267,8 +267,7 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
let
cache
=
get_cache
(
cx
);
let
tg
=
BasicTypeDescriptorTag
;
alt
cached_metadata
::
<@
metadata
<
tydesc_md
>>
(
cache
,
tg
,
{|
md
|
ty
::
hash_ty
(
t
)
==
ty
::
hash_ty
(
md
.data.hash
)})
{
cache
,
tg
,
{|
md
|
t
==
md
.data.hash
})
{
option
::
some
(
md
)
{
ret
md
;
}
option
::
none
.
{}
}
...
...
@@ -311,7 +310,7 @@ fn create_basic_type(cx: @crate_ctxt, t: ty::t, ty: @ast::ty)
lli32
(
0
),
//XXX flags?
lli32
(
encoding
)];
let
llnode
=
llmdnode
(
lldata
);
let
mdval
=
@
{
node
:
llnode
,
data
:
{
hash
:
t
y
::
hash_ty
(
t
)
}};
let
mdval
=
@
{
node
:
llnode
,
data
:
{
hash
:
t
}};
update_cache
(
cache
,
tg
,
tydesc_metadata
(
mdval
));
add_named_metadata
(
cx
,
"llvm.dbg.ty"
,
llnode
);
ret
mdval
;
...
...
@@ -333,7 +332,7 @@ fn create_pointer_type(cx: @crate_ctxt, t: ty::t, span: codemap::span,
//let cu_node = create_compile_unit(cx, fname);
let
llnode
=
create_derived_type
(
tg
,
file_node
.node
,
""
,
0
,
size
*
8
,
align
*
8
,
0
,
pointee
.node
);
let
mdval
=
@
{
node
:
llnode
,
data
:
{
hash
:
t
y
::
hash_ty
(
t
)
}};
let
mdval
=
@
{
node
:
llnode
,
data
:
{
hash
:
t
}};
//update_cache(cache, tg, tydesc_metadata(mdval));
add_named_metadata
(
cx
,
"llvm.dbg.ty"
,
llnode
);
ret
mdval
;
...
...
src/comp/middle/trans.rs
浏览文件 @
3ee630bb
...
...
@@ -4348,7 +4348,7 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: span, llfndecl: ValueRef,
lllocals
:
new_int_hash
::
<
local_val
>
(),
llupvars
:
new_int_hash
::
<
ValueRef
>
(),
mutable
lltydescs
:
[],
derived_tydescs
:
map
::
mk_hashmap
(
ty
::
hash_ty
,
ty
::
eq_ty
),
derived_tydescs
:
ty
::
new_ty_hash
(
),
id
:
id
,
ret_style
:
rstyle
,
sp
:
sp
,
...
...
@@ -5642,13 +5642,6 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
tn
.associate
(
"taskptr"
,
taskptr_type
);
let
tydesc_type
=
T_tydesc
(
targ_cfg
);
tn
.associate
(
"tydesc"
,
tydesc_type
);
let
hasher
=
ty
::
hash_ty
;
let
eqer
=
ty
::
eq_ty
;
let
tag_sizes
=
map
::
mk_hashmap
::
<
ty
::
t
,
uint
>
(
hasher
,
eqer
);
let
tydescs
=
map
::
mk_hashmap
::
<
ty
::
t
,
@
tydesc_info
>
(
hasher
,
eqer
);
let
lltypes
=
map
::
mk_hashmap
::
<
ty
::
t
,
TypeRef
>
(
hasher
,
eqer
);
let
sha1s
=
map
::
mk_hashmap
::
<
ty
::
t
,
str
>
(
hasher
,
eqer
);
let
short_names
=
map
::
mk_hashmap
::
<
ty
::
t
,
str
>
(
hasher
,
eqer
);
let
crate_map
=
decl_crate_map
(
sess
,
link_meta
.name
,
llmod
);
let
dbg_cx
=
if
sess
.get_opts
()
.debuginfo
{
option
::
some
(
@
{
llmetadata
:
map
::
new_int_hash
(),
...
...
@@ -5669,18 +5662,18 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
item_symbols
:
new_int_hash
::
<
str
>
(),
mutable
main_fn
:
none
::
<
ValueRef
>
,
link_meta
:
link_meta
,
tag_sizes
:
t
ag_sizes
,
tag_sizes
:
t
y
::
new_ty_hash
()
,
discrims
:
ast_util
::
new_def_id_hash
::
<
ValueRef
>
(),
discrim_symbols
:
new_int_hash
::
<
str
>
(),
consts
:
new_int_hash
::
<
ValueRef
>
(),
obj_methods
:
new_int_hash
::
<
()
>
(),
tydescs
:
ty
descs
,
tydescs
:
ty
::
new_ty_hash
()
,
module_data
:
new_str_hash
::
<
ValueRef
>
(),
lltypes
:
lltypes
,
lltypes
:
ty
::
new_ty_hash
()
,
names
:
namegen
(
0
),
sha
:
sha
,
type_sha1s
:
sha1s
,
type_short_names
:
short_names
,
type_sha1s
:
ty
::
new_ty_hash
()
,
type_short_names
:
ty
::
new_ty_hash
()
,
tcx
:
tcx
,
mut_map
:
mut_map
,
copy_map
:
copy_map
,
...
...
src/comp/middle/ty.rs
浏览文件 @
3ee630bb
...
...
@@ -36,7 +36,6 @@
export
count_ty_params
;
export
ctxt
;
export
def_has_ty_params
;
export
eq_ty
;
export
expr_has_ty_params
;
export
expr_ty
;
export
expr_ty_params_and_ty
;
...
...
@@ -47,7 +46,6 @@
export
get_field
;
export
fm_general
;
export
get_element_type
;
export
hash_ty
;
export
idx_nil
;
export
is_binopable
;
export
is_pred_ty
;
...
...
@@ -103,6 +101,7 @@
export
sty
;
export
substitute_type_params
;
export
t
;
export
new_ty_hash
;
export
tag_variants
;
export
tag_variant_with_id
;
export
ty_param_substs_opt_and_ty
;
...
...
@@ -398,12 +397,16 @@ fn eq_cache_entries(a: val, b: val) -> bool {
ret
map
::
mk_hashmap
(
hash_cache_entry
,
eq_cache_entries
);
}
fn
new_ty_hash
<
copy
V
>
()
->
map
::
hashmap
<
t
,
V
>
{
map
::
new_uint_hash
()
}
fn
mk_ctxt
(
s
:
session
::
session
,
dm
:
resolve
::
def_map
,
amap
:
ast_map
::
map
,
freevars
:
freevars
::
freevar_map
)
->
ctxt
{
let
ntt
:
node_type_table
=
@
smallintmap
::
mk
::
<
ty
::
ty_param_substs_opt_and_ty
>
();
let
tcache
=
new_def_hash
::
<
ty
::
ty_param_kinds_and_ty
>
();
fn
eq_raw_ty
(
&&
a
:
@
raw_t
,
&&
b
:
@
raw_t
)
->
bool
{
ret
a
.hash
==
b
.hash
&&
a
.struct
==
b
.struct
;
}
let
ts
=
@
interner
::
mk
::
<@
raw_t
>
(
hash_raw_ty
,
eq_raw_ty
);
let
cx
=
@
{
ts
:
ts
,
...
...
@@ -414,9 +417,9 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
freevars
:
freevars
,
tcache
:
tcache
,
rcache
:
mk_rcache
(),
short_names_cache
:
map
::
mk_hashmap
(
ty
::
hash_ty
,
ty
::
eq_ty
),
needs_drop_cache
:
map
::
mk_hashmap
(
ty
::
hash_ty
,
ty
::
eq_ty
),
kind_cache
:
map
::
mk_hashmap
(
ty
::
hash_ty
,
ty
::
eq_ty
),
short_names_cache
:
new_ty_hash
(
),
needs_drop_cache
:
new_ty_hash
(
),
kind_cache
:
new_ty_hash
(
),
ast_ty_to_ty_cache
:
map
::
mk_hashmap
(
ast_util
::
hash_ty
,
ast_util
::
eq_ty
),
tag_var_cache
:
@
smallintmap
::
mk
()};
...
...
@@ -1233,8 +1236,7 @@ fn type_autoderef(cx: ctxt, t: ty::t) -> ty::t {
ret
t1
;
}
// Type hashing. This function is private to this module (and slow); external
// users should use `hash_ty()` instead.
// Type hashing.
fn
hash_type_structure
(
st
:
sty
)
->
uint
{
fn
hash_uint
(
id
:
uint
,
n
:
uint
)
->
uint
{
let
h
=
id
;
...
...
@@ -1249,7 +1251,7 @@ fn hash_def(id: uint, did: ast::def_id) -> uint {
}
fn
hash_subty
(
id
:
uint
,
subty
:
t
)
->
uint
{
let
h
=
id
;
h
+=
(
h
<<
5u
)
+
hash_ty
(
subty
)
;
h
+=
(
h
<<
5u
)
+
subty
;
ret
h
;
}
fn
hash_subtys
(
id
:
uint
,
subtys
:
[
t
])
->
uint
{
...
...
@@ -1284,8 +1286,8 @@ fn hash_type_constr_args(id: uint, args: [@ty_constr_arg]) -> uint {
fn
hash_fn
(
id
:
uint
,
args
:
[
arg
],
rty
:
t
)
->
uint
{
let
h
=
id
;
for
a
:
arg
in
args
{
h
+=
(
h
<<
5u
)
+
hash_ty
(
a
.ty
)
;
}
h
+=
(
h
<<
5u
)
+
hash_ty
(
rty
)
;
for
a
:
arg
in
args
{
h
+=
(
h
<<
5u
)
+
a
.ty
;
}
h
+=
(
h
<<
5u
)
+
rty
;
ret
h
;
}
alt
st
{
...
...
@@ -1308,14 +1310,14 @@ fn hash_fn(id: uint, args: [arg], rty: t) -> uint {
ty_str
.
{
ret
17u
;
}
ty_tag
(
did
,
tys
)
{
let
h
=
hash_def
(
18u
,
did
);
for
typ
:
t
in
tys
{
h
+=
(
h
<<
5u
)
+
hash_ty
(
typ
)
;
}
for
typ
:
t
in
tys
{
h
+=
(
h
<<
5u
)
+
typ
;
}
ret
h
;
}
ty_box
(
mt
)
{
ret
hash_subty
(
19u
,
mt
.ty
);
}
ty_vec
(
mt
)
{
ret
hash_subty
(
21u
,
mt
.ty
);
}
ty_rec
(
fields
)
{
let
h
=
26u
;
for
f
:
field
in
fields
{
h
+=
(
h
<<
5u
)
+
hash_ty
(
f
.mt.ty
)
;
}
for
f
:
field
in
fields
{
h
+=
(
h
<<
5u
)
+
f
.mt.ty
;
}
ret
h
;
}
ty_tup
(
ts
)
{
ret
hash_subtys
(
25u
,
ts
);
}
...
...
@@ -1354,13 +1356,6 @@ fn hash_fn(id: uint, args: [arg], rty: t) -> uint {
fn
hash_raw_ty
(
&&
rt
:
@
raw_t
)
->
uint
{
ret
rt
.hash
;
}
fn
hash_ty
(
&&
typ
:
t
)
->
uint
{
ret
typ
;
}
// Type equality. This function is private to this module (and slow); external
// users should use `eq_ty()` instead.
fn
eq_int
(
&&
x
:
uint
,
&&
y
:
uint
)
->
bool
{
ret
x
==
y
;
}
fn
arg_eq
<
T
>
(
eq
:
fn
(
T
,
T
)
->
bool
,
a
:
@
sp_constr_arg
<
T
>
,
b
:
@
sp_constr_arg
<
T
>
)
->
bool
{
alt
a
.node
{
...
...
@@ -1389,6 +1384,7 @@ fn args_eq<T>(eq: fn(T, T) -> bool, a: [@sp_constr_arg<T>],
}
fn
constr_eq
(
c
:
@
constr
,
d
:
@
constr
)
->
bool
{
fn
eq_int
(
&&
x
:
uint
,
&&
y
:
uint
)
->
bool
{
ret
x
==
y
;
}
ret
path_to_str
(
c
.node.path
)
==
path_to_str
(
d
.node.path
)
&&
// FIXME: hack
args_eq
(
eq_int
,
c
.node.args
,
d
.node.args
);
...
...
@@ -1401,16 +1397,6 @@ fn constrs_eq(cs: [@constr], ds: [@constr]) -> bool {
ret
true
;
}
// This function is private to this module.
fn
eq_raw_ty
(
&&
a
:
@
raw_t
,
&&
b
:
@
raw_t
)
->
bool
{
ret
a
.hash
==
b
.hash
&&
a
.struct
==
b
.struct
;
}
// This is the equality function the public should use. It works as long as
// the types are interned.
fn
eq_ty
(
&&
a
:
t
,
&&
b
:
t
)
->
bool
{
a
==
b
}
// Type lookups
fn
node_id_to_ty_param_substs_opt_and_ty
(
cx
:
ctxt
,
id
:
ast
::
node_id
)
->
ty_param_substs_opt_and_ty
{
...
...
@@ -2088,12 +2074,15 @@ fn variance_transform(a: variance, b: variance) -> variance {
fn
unify_step
(
cx
:
@
ctxt
,
expected
:
t
,
actual
:
t
,
variance
:
variance
)
->
result
{
//
TODO
: rewrite this using tuple pattern matching when available, to
//
FIXME
: rewrite this using tuple pattern matching when available, to
// avoid all this rightward drift and spikiness.
// NOTE: we have tuple matching now, but that involves copying the
// matched elements into a tuple first, which is expensive, since sty
// holds vectors, which are currently unique
// Fast path.
if
expected
==
actual
{
ret
ures_ok
(
expected
);
}
if
eq_ty
(
expected
,
actual
)
{
ret
ures_ok
(
expected
);
}
// Stage 1: Handle the cases in which one side or another is a type
// variable.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录