Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2fbbaf2f
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,发现更多精彩内容 >>
提交
2fbbaf2f
编写于
3月 23, 2016
作者:
E
Eduard Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: Use set recovery APIs in the TyCtxt interners.
上级
513d392f
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
49 addition
and
36 deletion
+49
-36
src/librustc/ty/context.rs
src/librustc/ty/context.rs
+49
-36
未找到文件。
src/librustc/ty/context.rs
浏览文件 @
2fbbaf2f
...
...
@@ -35,7 +35,7 @@
use
ty
::
maps
;
use
util
::
common
::
MemoizationMap
;
use
util
::
nodemap
::{
NodeMap
,
NodeSet
,
DefIdMap
,
DefIdSet
};
use
util
::
nodemap
::
FnvHashMap
;
use
util
::
nodemap
::
{
FnvHashMap
,
FnvHashSet
}
;
use
arena
::
TypedArena
;
use
std
::
borrow
::
Borrow
;
...
...
@@ -191,7 +191,7 @@ pub fn closure_type(this: &RefCell<Self>,
impl
<
'tcx
>
CommonTypes
<
'tcx
>
{
fn
new
(
arena
:
&
'tcx
TypedArena
<
TyS
<
'tcx
>>
,
interner
:
&
RefCell
<
FnvHash
Map
<
InternedTy
<
'tcx
>
,
Ty
<
'tcx
>>>
)
interner
:
&
RefCell
<
FnvHash
Set
<
Interned
Ty
<
'tcx
>>>
)
->
CommonTypes
<
'tcx
>
{
let
mk
=
|
sty
|
TyCtxt
::
intern_ty
(
arena
,
interner
,
sty
);
...
...
@@ -220,7 +220,8 @@ fn new(arena: &'tcx TypedArena<TyS<'tcx>>,
/// later on.
#[derive(Copy,
Clone)]
pub
struct
TyCtxt
<
'a
,
'tcx
:
'a
>
{
gcx
:
&
'a
GlobalCtxt
<
'tcx
>
gcx
:
&
'a
GlobalCtxt
<
'tcx
>
,
}
impl
<
'a
,
'tcx
>
Deref
for
TyCtxt
<
'a
,
'tcx
>
{
...
...
@@ -236,16 +237,12 @@ pub struct GlobalCtxt<'tcx> {
/// Specifically use a speedy hash algorithm for this hash map, it's used
/// quite often.
// FIXME(eddyb) use a FnvHashSet<InternedTy<'tcx>> when equivalent keys can
// queried from a HashSet.
interner
:
RefCell
<
FnvHashMap
<
InternedTy
<
'tcx
>
,
Ty
<
'tcx
>>>
,
// FIXME as above, use a hashset if equivalent elements can be queried.
substs_interner
:
RefCell
<
FnvHashMap
<&
'tcx
Substs
<
'tcx
>
,
&
'tcx
Substs
<
'tcx
>>>
,
bare_fn_interner
:
RefCell
<
FnvHashMap
<&
'tcx
BareFnTy
<
'tcx
>
,
&
'tcx
BareFnTy
<
'tcx
>>>
,
region_interner
:
RefCell
<
FnvHashMap
<&
'tcx
Region
,
&
'tcx
Region
>>
,
stability_interner
:
RefCell
<
FnvHashMap
<&
'tcx
attr
::
Stability
,
&
'tcx
attr
::
Stability
>>
,
layout_interner
:
RefCell
<
FnvHashMap
<&
'tcx
Layout
,
&
'tcx
Layout
>>
,
interner
:
RefCell
<
FnvHashSet
<
InternedTy
<
'tcx
>>>
,
substs_interner
:
RefCell
<
FnvHashSet
<
InternedSubsts
<
'tcx
>>>
,
bare_fn_interner
:
RefCell
<
FnvHashSet
<&
'tcx
BareFnTy
<
'tcx
>>>
,
region_interner
:
RefCell
<
FnvHashSet
<&
'tcx
Region
>>
,
stability_interner
:
RefCell
<
FnvHashSet
<&
'tcx
attr
::
Stability
>>
,
layout_interner
:
RefCell
<
FnvHashSet
<&
'tcx
Layout
>>
,
pub
dep_graph
:
DepGraph
,
...
...
@@ -518,7 +515,7 @@ pub fn intern_stability(self, stab: attr::Stability) -> &'tcx attr::Stability {
let
interned
=
self
.arenas.stability
.alloc
(
stab
);
if
let
Some
(
prev
)
=
self
.stability_interner
.borrow_mut
()
.
insert
(
interned
,
interned
)
{
.
replace
(
interned
)
{
bug!
(
"Tried to overwrite interned Stability: {:?}"
,
prev
)
}
interned
...
...
@@ -532,7 +529,7 @@ pub fn intern_layout(self, layout: Layout) -> &'tcx Layout {
let
interned
=
self
.arenas.layout
.alloc
(
layout
);
if
let
Some
(
prev
)
=
self
.layout_interner
.borrow_mut
()
.
insert
(
interned
,
interned
)
{
.
replace
(
interned
)
{
bug!
(
"Tried to overwrite interned Layout: {:?}"
,
prev
)
}
interned
...
...
@@ -571,18 +568,18 @@ pub fn create_and_enter<F, R>(s: &'tcx Session,
where
F
:
for
<
'b
>
FnOnce
(
TyCtxt
<
'b
,
'tcx
>
)
->
R
{
let
data_layout
=
TargetDataLayout
::
parse
(
s
);
let
interner
=
RefCell
::
new
(
FnvHash
Map
());
let
interner
=
RefCell
::
new
(
FnvHash
Set
());
let
common_types
=
CommonTypes
::
new
(
&
arenas
.type_
,
&
interner
);
let
dep_graph
=
map
.dep_graph
.clone
();
let
fulfilled_predicates
=
traits
::
GlobalFulfilledPredicates
::
new
(
dep_graph
.clone
());
tls
::
enter
(
GlobalCtxt
{
arenas
:
arenas
,
interner
:
interner
,
substs_interner
:
RefCell
::
new
(
FnvHash
Map
()),
bare_fn_interner
:
RefCell
::
new
(
FnvHash
Map
()),
region_interner
:
RefCell
::
new
(
FnvHash
Map
()),
stability_interner
:
RefCell
::
new
(
FnvHash
Map
()),
layout_interner
:
RefCell
::
new
(
FnvHash
Map
()),
substs_interner
:
RefCell
::
new
(
FnvHash
Set
()),
bare_fn_interner
:
RefCell
::
new
(
FnvHash
Set
()),
region_interner
:
RefCell
::
new
(
FnvHash
Set
()),
stability_interner
:
RefCell
::
new
(
FnvHash
Set
()),
layout_interner
:
RefCell
::
new
(
FnvHash
Set
()),
dep_graph
:
dep_graph
.clone
(),
types
:
common_types
,
named_region_map
:
named_region_map
,
...
...
@@ -656,7 +653,7 @@ pub trait Lift<'tcx> {
impl
<
'a
,
'tcx
>
Lift
<
'tcx
>
for
Ty
<
'a
>
{
type
Lifted
=
Ty
<
'tcx
>
;
fn
lift_to_tcx
<
'b
>
(
&
self
,
tcx
:
TyCtxt
<
'b
,
'tcx
>
)
->
Option
<
Ty
<
'tcx
>>
{
if
let
Some
(
&
ty
)
=
tcx
.interner
.borrow
()
.get
(
&
self
.sty
)
{
if
let
Some
(
&
InternedTy
{
ty
}
)
=
tcx
.interner
.borrow
()
.get
(
&
self
.sty
)
{
if
*
self
as
*
const
_
==
ty
as
*
const
_
{
return
Some
(
ty
);
}
...
...
@@ -668,7 +665,7 @@ fn lift_to_tcx<'b>(&self, tcx: TyCtxt<'b, 'tcx>) -> Option<Ty<'tcx>> {
impl
<
'a
,
'tcx
>
Lift
<
'tcx
>
for
&
'a
Substs
<
'a
>
{
type
Lifted
=
&
'tcx
Substs
<
'tcx
>
;
fn
lift_to_tcx
<
'b
>
(
&
self
,
tcx
:
TyCtxt
<
'b
,
'tcx
>
)
->
Option
<&
'tcx
Substs
<
'tcx
>>
{
if
let
Some
(
&
substs
)
=
tcx
.substs_interner
.borrow
()
.get
(
*
self
)
{
if
let
Some
(
&
InternedSubsts
{
substs
}
)
=
tcx
.substs_interner
.borrow
()
.get
(
*
self
)
{
if
*
self
as
*
const
_
==
substs
as
*
const
_
{
return
Some
(
substs
);
}
...
...
@@ -745,6 +742,8 @@ pub fn with_opt<F: FnOnce(Option<TyCtxt>) -> R, R>(f: F) -> R {
#[allow(non_snake_case)]
mod
inner
{
use
ty
::{
self
,
TyCtxt
};
use
ty
::
context
::
InternedTy
;
#[derive(Copy,
Clone)]
struct
DebugStat
{
total
:
usize
,
...
...
@@ -761,7 +760,7 @@ pub fn go(tcx: TyCtxt) {
$
(
let
mut
$variant
=
total
;)
*
for
(
_
,
t
)
in
tcx
.interner
.borrow
()
.iter
()
{
for
&
InternedTy
{
ty
:
t
}
in
tcx
.interner
.borrow
()
.iter
()
{
let
variant
=
match
t
.sty
{
ty
::
TyBool
|
ty
::
TyChar
|
ty
::
TyInt
(
..
)
|
ty
::
TyUint
(
..
)
|
ty
::
TyFloat
(
..
)
|
ty
::
TyStr
=>
continue
,
...
...
@@ -817,7 +816,7 @@ pub fn print_debug_stats(self) {
/// An entry in the type interner.
pub
struct
InternedTy
<
'tcx
>
{
struct
InternedTy
<
'tcx
>
{
ty
:
Ty
<
'tcx
>
}
...
...
@@ -836,12 +835,24 @@ fn hash<H: Hasher>(&self, s: &mut H) {
}
}
impl
<
'tcx
>
Borrow
<
TypeVariants
<
't
cx
>>
for
InternedTy
<
'tcx
>
{
fn
borrow
<
'a
>
(
&
'a
self
)
->
&
'a
TypeVariants
<
'
t
cx
>
{
impl
<
'tcx
:
'lcx
,
'lcx
>
Borrow
<
TypeVariants
<
'l
cx
>>
for
InternedTy
<
'tcx
>
{
fn
borrow
<
'a
>
(
&
'a
self
)
->
&
'a
TypeVariants
<
'
l
cx
>
{
&
self
.ty.sty
}
}
/// An entry in the substs interner.
#[derive(PartialEq,
Eq,
Hash)]
struct
InternedSubsts
<
'tcx
>
{
substs
:
&
'tcx
Substs
<
'tcx
>
}
impl
<
'tcx
:
'lcx
,
'lcx
>
Borrow
<
Substs
<
'lcx
>>
for
InternedSubsts
<
'tcx
>
{
fn
borrow
<
'a
>
(
&
'a
self
)
->
&
'a
Substs
<
'lcx
>
{
self
.substs
}
}
fn
bound_list_is_sorted
(
bounds
:
&
[
ty
::
PolyProjectionPredicate
])
->
bool
{
bounds
.is_empty
()
||
bounds
[
1
..
]
.iter
()
.enumerate
()
.all
(
...
...
@@ -851,12 +862,14 @@ fn bound_list_is_sorted(bounds: &[ty::PolyProjectionPredicate]) -> bool {
impl
<
'a
,
'tcx
>
TyCtxt
<
'a
,
'tcx
>
{
// Type constructors
pub
fn
mk_substs
(
self
,
substs
:
Substs
<
'tcx
>
)
->
&
'tcx
Substs
<
'tcx
>
{
if
let
Some
(
substs
)
=
self
.substs_interner
.borrow
()
.get
(
&
substs
)
{
return
*
substs
;
if
let
Some
(
interned
)
=
self
.substs_interner
.borrow
()
.get
(
&
substs
)
{
return
interned
.
substs
;
}
let
substs
=
self
.arenas.substs
.alloc
(
substs
);
self
.substs_interner
.borrow_mut
()
.insert
(
substs
,
substs
);
self
.substs_interner
.borrow_mut
()
.insert
(
InternedSubsts
{
substs
:
substs
});
substs
}
...
...
@@ -876,7 +889,7 @@ pub fn mk_bare_fn(self, bare_fn: BareFnTy<'tcx>) -> &'tcx BareFnTy<'tcx> {
}
let
bare_fn
=
self
.arenas.bare_fn
.alloc
(
bare_fn
);
self
.bare_fn_interner
.borrow_mut
()
.insert
(
bare_fn
,
bare_fn
);
self
.bare_fn_interner
.borrow_mut
()
.insert
(
bare_fn
);
bare_fn
}
...
...
@@ -886,19 +899,19 @@ pub fn mk_region(self, region: Region) -> &'tcx Region {
}
let
region
=
self
.arenas.region
.alloc
(
region
);
self
.region_interner
.borrow_mut
()
.insert
(
region
,
region
);
self
.region_interner
.borrow_mut
()
.insert
(
region
);
region
}
fn
intern_ty
(
type_arena
:
&
'tcx
TypedArena
<
TyS
<
'tcx
>>
,
interner
:
&
RefCell
<
FnvHash
Map
<
InternedTy
<
'tcx
>
,
Ty
<
'tcx
>>>
,
interner
:
&
RefCell
<
FnvHash
Set
<
Interned
Ty
<
'tcx
>>>
,
st
:
TypeVariants
<
'tcx
>
)
->
Ty
<
'tcx
>
{
let
ty
:
Ty
/* don't be &mut TyS */
=
{
let
mut
interner
=
interner
.borrow_mut
();
match
interner
.get
(
&
st
)
{
Some
(
ty
)
=>
return
*
ty
,
_
=>
()
Some
(
&
InternedTy
{
ty
})
=>
return
ty
,
None
=>
()
}
let
flags
=
super
::
flags
::
FlagComputation
::
for_sty
(
&
st
);
...
...
@@ -909,7 +922,7 @@ fn intern_ty(type_arena: &'tcx TypedArena<TyS<'tcx>>,
region_depth
:
flags
.depth
,
}),
};
interner
.insert
(
InternedTy
{
ty
:
ty
}
,
ty
);
interner
.insert
(
InternedTy
{
ty
:
ty
});
ty
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录