Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a5173435
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
a5173435
编写于
4月 24, 2017
作者:
A
Ariel Ben-Yehuda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cache symbol names in ty::maps
this fixes a performance regression introduced in commit
39a58c38
.
上级
b0a4074c
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
148 addition
and
176 deletion
+148
-176
src/librustc/dep_graph/dep_node.rs
src/librustc/dep_graph/dep_node.rs
+2
-0
src/librustc/ty/maps.rs
src/librustc/ty/maps.rs
+33
-2
src/librustc/ty/mod.rs
src/librustc/ty/mod.rs
+20
-0
src/librustc_driver/driver.rs
src/librustc_driver/driver.rs
+2
-2
src/librustc_trans/back/symbol_export.rs
src/librustc_trans/back/symbol_export.rs
+7
-10
src/librustc_trans/back/symbol_names.rs
src/librustc_trans/back/symbol_names.rs
+43
-7
src/librustc_trans/base.rs
src/librustc_trans/base.rs
+3
-5
src/librustc_trans/callee.rs
src/librustc_trans/callee.rs
+1
-2
src/librustc_trans/consts.rs
src/librustc_trans/consts.rs
+3
-6
src/librustc_trans/context.rs
src/librustc_trans/context.rs
+5
-45
src/librustc_trans/lib.rs
src/librustc_trans/lib.rs
+1
-1
src/librustc_trans/partitioning.rs
src/librustc_trans/partitioning.rs
+17
-44
src/librustc_trans/symbol_cache.rs
src/librustc_trans/symbol_cache.rs
+0
-42
src/librustc_trans/symbol_map.rs
src/librustc_trans/symbol_map.rs
+2
-2
src/librustc_trans/symbol_names_test.rs
src/librustc_trans/symbol_names_test.rs
+1
-2
src/librustc_trans/trans_item.rs
src/librustc_trans/trans_item.rs
+8
-6
未找到文件。
src/librustc/dep_graph/dep_node.rs
浏览文件 @
a5173435
...
@@ -99,6 +99,7 @@ pub enum DepNode<D: Clone + Debug> {
...
@@ -99,6 +99,7 @@ pub enum DepNode<D: Clone + Debug> {
TypeckTables
(
D
),
TypeckTables
(
D
),
UsedTraitImports
(
D
),
UsedTraitImports
(
D
),
ConstEval
(
D
),
ConstEval
(
D
),
SymbolName
(
D
),
// The set of impls for a given trait. Ultimately, it would be
// The set of impls for a given trait. Ultimately, it would be
// nice to get more fine-grained here (e.g., to include a
// nice to get more fine-grained here (e.g., to include a
...
@@ -236,6 +237,7 @@ pub fn map_def<E, OP>(&self, mut op: OP) -> Option<DepNode<E>>
...
@@ -236,6 +237,7 @@ pub fn map_def<E, OP>(&self, mut op: OP) -> Option<DepNode<E>>
TypeckTables
(
ref
d
)
=>
op
(
d
)
.map
(
TypeckTables
),
TypeckTables
(
ref
d
)
=>
op
(
d
)
.map
(
TypeckTables
),
UsedTraitImports
(
ref
d
)
=>
op
(
d
)
.map
(
UsedTraitImports
),
UsedTraitImports
(
ref
d
)
=>
op
(
d
)
.map
(
UsedTraitImports
),
ConstEval
(
ref
d
)
=>
op
(
d
)
.map
(
ConstEval
),
ConstEval
(
ref
d
)
=>
op
(
d
)
.map
(
ConstEval
),
SymbolName
(
ref
d
)
=>
op
(
d
)
.map
(
SymbolName
),
TraitImpls
(
ref
d
)
=>
op
(
d
)
.map
(
TraitImpls
),
TraitImpls
(
ref
d
)
=>
op
(
d
)
.map
(
TraitImpls
),
TraitItems
(
ref
d
)
=>
op
(
d
)
.map
(
TraitItems
),
TraitItems
(
ref
d
)
=>
op
(
d
)
.map
(
TraitItems
),
ReprHints
(
ref
d
)
=>
op
(
d
)
.map
(
ReprHints
),
ReprHints
(
ref
d
)
=>
op
(
d
)
.map
(
ReprHints
),
...
...
src/librustc/ty/maps.rs
浏览文件 @
a5173435
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
use
std
::
ops
::
Deref
;
use
std
::
ops
::
Deref
;
use
std
::
rc
::
Rc
;
use
std
::
rc
::
Rc
;
use
syntax_pos
::{
Span
,
DUMMY_SP
};
use
syntax_pos
::{
Span
,
DUMMY_SP
};
use
syntax
::
symbol
::
Symbol
;
trait
Key
{
trait
Key
{
fn
map_crate
(
&
self
)
->
CrateNum
;
fn
map_crate
(
&
self
)
->
CrateNum
;
...
@@ -40,6 +41,16 @@ fn default_span(&self, tcx: TyCtxt) -> Span {
...
@@ -40,6 +41,16 @@ fn default_span(&self, tcx: TyCtxt) -> Span {
}
}
}
}
impl
<
'tcx
>
Key
for
ty
::
Instance
<
'tcx
>
{
fn
map_crate
(
&
self
)
->
CrateNum
{
LOCAL_CRATE
}
fn
default_span
(
&
self
,
tcx
:
TyCtxt
)
->
Span
{
tcx
.def_span
(
self
.def_id
())
}
}
impl
Key
for
CrateNum
{
impl
Key
for
CrateNum
{
fn
map_crate
(
&
self
)
->
CrateNum
{
fn
map_crate
(
&
self
)
->
CrateNum
{
*
self
*
self
...
@@ -108,13 +119,18 @@ fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
...
@@ -108,13 +119,18 @@ fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
}
}
}
}
impl
<
'tcx
>
Value
<
'tcx
>
for
ty
::
DtorckConstraint
<
'tcx
>
{
impl
<
'tcx
>
Value
<
'tcx
>
for
ty
::
DtorckConstraint
<
'tcx
>
{
fn
from_cycle_error
<
'a
>
(
_
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
)
->
Self
{
fn
from_cycle_error
<
'a
>
(
_
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
)
->
Self
{
Self
::
empty
()
Self
::
empty
()
}
}
}
}
impl
<
'tcx
>
Value
<
'tcx
>
for
ty
::
SymbolName
{
fn
from_cycle_error
<
'a
>
(
_
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
)
->
Self
{
ty
::
SymbolName
{
name
:
Symbol
::
intern
(
"<error>"
)
.as_str
()
}
}
}
pub
struct
CycleError
<
'a
,
'tcx
:
'a
>
{
pub
struct
CycleError
<
'a
,
'tcx
:
'a
>
{
span
:
Span
,
span
:
Span
,
cycle
:
RefMut
<
'a
,
[(
Span
,
Query
<
'tcx
>
)]
>
,
cycle
:
RefMut
<
'a
,
[(
Span
,
Query
<
'tcx
>
)]
>
,
...
@@ -242,6 +258,12 @@ fn describe(tcx: TyCtxt, (def_id, _): (DefId, &'tcx Substs<'tcx>)) -> String {
...
@@ -242,6 +258,12 @@ fn describe(tcx: TyCtxt, (def_id, _): (DefId, &'tcx Substs<'tcx>)) -> String {
}
}
}
}
impl
<
'tcx
>
QueryDescription
for
queries
::
symbol_name
<
'tcx
>
{
fn
describe
(
_
tcx
:
TyCtxt
,
instance
:
ty
::
Instance
<
'tcx
>
)
->
String
{
format!
(
"computing the symbol for `{}`"
,
instance
)
}
}
macro_rules!
define_maps
{
macro_rules!
define_maps
{
(
<
$tcx:tt
>
(
<
$tcx:tt
>
$
(
$
(
#[
$
attr:meta]
)
*
$
(
$
(
#[
$
attr:meta]
)
*
...
@@ -513,7 +535,10 @@ fn default() -> Self {
...
@@ -513,7 +535,10 @@ fn default() -> Self {
pub
reachable_set
:
reachability_dep_node
(
CrateNum
)
->
Rc
<
NodeSet
>
,
pub
reachable_set
:
reachability_dep_node
(
CrateNum
)
->
Rc
<
NodeSet
>
,
pub
mir_shims
:
mir_shim_dep_node
(
ty
::
InstanceDef
<
'tcx
>
)
->
&
'tcx
RefCell
<
mir
::
Mir
<
'tcx
>>
pub
mir_shims
:
mir_shim_dep_node
(
ty
::
InstanceDef
<
'tcx
>
)
->
&
'tcx
RefCell
<
mir
::
Mir
<
'tcx
>>
,
pub
def_symbol_name
:
SymbolName
(
DefId
)
->
ty
::
SymbolName
,
pub
symbol_name
:
symbol_name_dep_node
(
ty
::
Instance
<
'tcx
>
)
->
ty
::
SymbolName
}
}
fn
coherent_trait_dep_node
((
_
,
def_id
):
(
CrateNum
,
DefId
))
->
DepNode
<
DefId
>
{
fn
coherent_trait_dep_node
((
_
,
def_id
):
(
CrateNum
,
DefId
))
->
DepNode
<
DefId
>
{
...
@@ -532,6 +557,12 @@ fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepNode<DefId> {
...
@@ -532,6 +557,12 @@ fn mir_shim_dep_node(instance: ty::InstanceDef) -> DepNode<DefId> {
instance
.dep_node
()
instance
.dep_node
()
}
}
fn
symbol_name_dep_node
(
instance
:
ty
::
Instance
)
->
DepNode
<
DefId
>
{
// symbol_name uses the substs only to traverse them to find the
// hash, and that does not create any new dep-nodes.
DepNode
::
SymbolName
(
instance
.def
.def_id
())
}
fn
typeck_item_bodies_dep_node
(
_
:
CrateNum
)
->
DepNode
<
DefId
>
{
fn
typeck_item_bodies_dep_node
(
_
:
CrateNum
)
->
DepNode
<
DefId
>
{
DepNode
::
TypeckBodiesKrate
DepNode
::
TypeckBodiesKrate
}
}
...
...
src/librustc/ty/mod.rs
浏览文件 @
a5173435
...
@@ -38,6 +38,7 @@
...
@@ -38,6 +38,7 @@
use
std
::
cell
::{
Cell
,
RefCell
,
Ref
};
use
std
::
cell
::{
Cell
,
RefCell
,
Ref
};
use
std
::
collections
::
BTreeMap
;
use
std
::
collections
::
BTreeMap
;
use
std
::
cmp
;
use
std
::
cmp
;
use
std
::
fmt
;
use
std
::
hash
::{
Hash
,
Hasher
};
use
std
::
hash
::{
Hash
,
Hasher
};
use
std
::
iter
::
FromIterator
;
use
std
::
iter
::
FromIterator
;
use
std
::
ops
::
Deref
;
use
std
::
ops
::
Deref
;
...
@@ -2745,3 +2746,22 @@ fn dedup<'a>(&mut self) {
...
@@ -2745,3 +2746,22 @@ fn dedup<'a>(&mut self) {
self
.dtorck_types
.retain
(|
&
val
|
dtorck_types
.replace
(
val
)
.is_none
());
self
.dtorck_types
.retain
(|
&
val
|
dtorck_types
.replace
(
val
)
.is_none
());
}
}
}
}
#[derive(Clone,
PartialEq,
Eq,
PartialOrd,
Ord)]
pub
struct
SymbolName
{
// FIXME: we don't rely on interning or equality here - better have
// this be a `&'tcx str`.
pub
name
:
InternedString
}
impl
Deref
for
SymbolName
{
type
Target
=
str
;
fn
deref
(
&
self
)
->
&
str
{
&
self
.name
}
}
impl
fmt
::
Display
for
SymbolName
{
fn
fmt
(
&
self
,
fmt
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
fmt
::
Display
::
fmt
(
&
self
.name
,
fmt
)
}
}
src/librustc_driver/driver.rs
浏览文件 @
a5173435
...
@@ -225,8 +225,6 @@ pub fn compile_input(sess: &Session,
...
@@ -225,8 +225,6 @@ pub fn compile_input(sess: &Session,
sess
.code_stats
.borrow
()
.print_type_sizes
();
sess
.code_stats
.borrow
()
.print_type_sizes
();
}
}
if
::
std
::
env
::
var
(
"SKIP_LLVM"
)
.is_ok
()
{
::
std
::
process
::
exit
(
0
);
}
let
phase5_result
=
phase_5_run_llvm_passes
(
sess
,
&
trans
,
&
outputs
);
let
phase5_result
=
phase_5_run_llvm_passes
(
sess
,
&
trans
,
&
outputs
);
controller_entry_point!
(
after_llvm
,
controller_entry_point!
(
after_llvm
,
...
@@ -895,6 +893,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
...
@@ -895,6 +893,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
mir
::
provide
(
&
mut
local_providers
);
mir
::
provide
(
&
mut
local_providers
);
reachable
::
provide
(
&
mut
local_providers
);
reachable
::
provide
(
&
mut
local_providers
);
rustc_privacy
::
provide
(
&
mut
local_providers
);
rustc_privacy
::
provide
(
&
mut
local_providers
);
trans
::
provide
(
&
mut
local_providers
);
typeck
::
provide
(
&
mut
local_providers
);
typeck
::
provide
(
&
mut
local_providers
);
ty
::
provide
(
&
mut
local_providers
);
ty
::
provide
(
&
mut
local_providers
);
reachable
::
provide
(
&
mut
local_providers
);
reachable
::
provide
(
&
mut
local_providers
);
...
@@ -902,6 +901,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
...
@@ -902,6 +901,7 @@ pub fn phase_3_run_analysis_passes<'tcx, F, R>(sess: &'tcx Session,
let
mut
extern_providers
=
ty
::
maps
::
Providers
::
default
();
let
mut
extern_providers
=
ty
::
maps
::
Providers
::
default
();
cstore
::
provide
(
&
mut
extern_providers
);
cstore
::
provide
(
&
mut
extern_providers
);
trans
::
provide
(
&
mut
extern_providers
);
ty
::
provide_extern
(
&
mut
extern_providers
);
ty
::
provide_extern
(
&
mut
extern_providers
);
// FIXME(eddyb) get rid of this once we replace const_eval with miri.
// FIXME(eddyb) get rid of this once we replace const_eval with miri.
rustc_const_eval
::
provide
(
&
mut
extern_providers
);
rustc_const_eval
::
provide
(
&
mut
extern_providers
);
...
...
src/librustc_trans/back/symbol_export.rs
浏览文件 @
a5173435
...
@@ -11,7 +11,6 @@
...
@@ -11,7 +11,6 @@
use
context
::
SharedCrateContext
;
use
context
::
SharedCrateContext
;
use
monomorphize
::
Instance
;
use
monomorphize
::
Instance
;
use
symbol_map
::
SymbolMap
;
use
symbol_map
::
SymbolMap
;
use
back
::
symbol_names
::
symbol_name
;
use
util
::
nodemap
::
FxHashMap
;
use
util
::
nodemap
::
FxHashMap
;
use
rustc
::
hir
::
def_id
::{
DefId
,
CrateNum
,
LOCAL_CRATE
};
use
rustc
::
hir
::
def_id
::{
DefId
,
CrateNum
,
LOCAL_CRATE
};
use
rustc
::
session
::
config
;
use
rustc
::
session
::
config
;
...
@@ -56,7 +55,7 @@ pub fn compute_from<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
...
@@ -56,7 +55,7 @@ pub fn compute_from<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
let
name
=
symbol_for_def_id
(
scx
.tcx
(),
def_id
,
symbol_map
);
let
name
=
symbol_for_def_id
(
scx
.tcx
(),
def_id
,
symbol_map
);
let
export_level
=
export_level
(
scx
,
def_id
);
let
export_level
=
export_level
(
scx
,
def_id
);
debug!
(
"EXPORTED SYMBOL (local): {} ({:?})"
,
name
,
export_level
);
debug!
(
"EXPORTED SYMBOL (local): {} ({:?})"
,
name
,
export_level
);
(
name
,
export_level
)
(
str
::
to_owned
(
&
name
)
,
export_level
)
})
})
.collect
();
.collect
();
...
@@ -108,7 +107,7 @@ pub fn compute_from<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
...
@@ -108,7 +107,7 @@ pub fn compute_from<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
.exported_symbols
(
cnum
)
.exported_symbols
(
cnum
)
.iter
()
.iter
()
.map
(|
&
def_id
|
{
.map
(|
&
def_id
|
{
let
name
=
s
ymbol_name
(
Instance
::
mono
(
scx
.tcx
(),
def_id
),
scx
.tcx
(
));
let
name
=
s
cx
.tcx
()
.symbol_name
(
Instance
::
mono
(
scx
.tcx
(),
def_id
));
let
export_level
=
if
special_runtime_crate
{
let
export_level
=
if
special_runtime_crate
{
// We can probably do better here by just ensuring that
// We can probably do better here by just ensuring that
// it has hidden visibility rather than public
// it has hidden visibility rather than public
...
@@ -117,9 +116,9 @@ pub fn compute_from<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
...
@@ -117,9 +116,9 @@ pub fn compute_from<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
//
//
// In general though we won't link right if these
// In general though we won't link right if these
// symbols are stripped, and LTO currently strips them.
// symbols are stripped, and LTO currently strips them.
if
name
==
"rust_eh_personality"
||
if
&*
name
==
"rust_eh_personality"
||
name
==
"rust_eh_register_frames"
||
&*
name
==
"rust_eh_register_frames"
||
name
==
"rust_eh_unregister_frames"
{
&*
name
==
"rust_eh_unregister_frames"
{
SymbolExportLevel
::
C
SymbolExportLevel
::
C
}
else
{
}
else
{
SymbolExportLevel
::
Rust
SymbolExportLevel
::
Rust
...
@@ -128,7 +127,7 @@ pub fn compute_from<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
...
@@ -128,7 +127,7 @@ pub fn compute_from<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
export_level
(
scx
,
def_id
)
export_level
(
scx
,
def_id
)
};
};
debug!
(
"EXPORTED SYMBOL (re-export): {} ({:?})"
,
name
,
export_level
);
debug!
(
"EXPORTED SYMBOL (re-export): {} ({:?})"
,
name
,
export_level
);
(
name
,
export_level
)
(
str
::
to_owned
(
&
name
)
,
export_level
)
})
})
.collect
();
.collect
();
...
@@ -228,7 +227,5 @@ fn symbol_for_def_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
...
@@ -228,7 +227,5 @@ fn symbol_for_def_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let
instance
=
Instance
::
mono
(
tcx
,
def_id
);
let
instance
=
Instance
::
mono
(
tcx
,
def_id
);
symbol_map
.get
(
TransItem
::
Fn
(
instance
))
str
::
to_owned
(
&
tcx
.symbol_name
(
instance
))
.map
(
str
::
to_owned
)
.unwrap_or_else
(||
symbol_name
(
instance
,
tcx
))
}
}
src/librustc_trans/back/symbol_names.rs
浏览文件 @
a5173435
...
@@ -105,14 +105,24 @@
...
@@ -105,14 +105,24 @@
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
,
TypeFoldable
};
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
,
TypeFoldable
};
use
rustc
::
ty
::
fold
::
TypeVisitor
;
use
rustc
::
ty
::
fold
::
TypeVisitor
;
use
rustc
::
ty
::
item_path
::{
self
,
ItemPathBuffer
,
RootMode
};
use
rustc
::
ty
::
item_path
::{
self
,
ItemPathBuffer
,
RootMode
};
use
rustc
::
ty
::
maps
::
Providers
;
use
rustc
::
ty
::
subst
::
Substs
;
use
rustc
::
ty
::
subst
::
Substs
;
use
rustc
::
hir
::
map
::
definitions
::
DefPathData
;
use
rustc
::
hir
::
map
::
definitions
::
DefPathData
;
use
rustc
::
util
::
common
::
record_time
;
use
rustc
::
util
::
common
::
record_time
;
use
syntax
::
attr
;
use
syntax
::
attr
;
use
syntax_pos
::
symbol
::
Symbol
;
use
std
::
fmt
::
Write
;
use
std
::
fmt
::
Write
;
pub
fn
provide
(
providers
:
&
mut
Providers
)
{
*
providers
=
Providers
{
def_symbol_name
,
symbol_name
,
..*
providers
};
}
fn
get_symbol_hash
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
fn
get_symbol_hash
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
// the DefId of the item this name is for
// the DefId of the item this name is for
...
@@ -165,8 +175,25 @@ fn get_symbol_hash<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
...
@@ -165,8 +175,25 @@ fn get_symbol_hash<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
format!
(
"h{:016x}"
,
hasher
.finish
())
format!
(
"h{:016x}"
,
hasher
.finish
())
}
}
pub
fn
symbol_name
<
'a
,
'tcx
>
(
instance
:
Instance
<
'tcx
>
,
fn
def_symbol_name
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
def_id
:
DefId
)
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
)
->
String
{
->
ty
::
SymbolName
{
let
mut
buffer
=
SymbolPathBuffer
::
new
();
item_path
::
with_forced_absolute_paths
(||
{
tcx
.push_item_path
(
&
mut
buffer
,
def_id
);
});
buffer
.into_interned
()
}
fn
symbol_name
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
instance
:
Instance
<
'tcx
>
)
->
ty
::
SymbolName
{
ty
::
SymbolName
{
name
:
Symbol
::
intern
(
&
compute_symbol_name
(
tcx
,
instance
))
.as_str
()
}
}
fn
compute_symbol_name
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
instance
:
Instance
<
'tcx
>
)
->
String
{
let
def_id
=
instance
.def_id
();
let
def_id
=
instance
.def_id
();
let
substs
=
instance
.substs
;
let
substs
=
instance
.substs
;
...
@@ -253,11 +280,7 @@ pub fn symbol_name<'a, 'tcx>(instance: Instance<'tcx>,
...
@@ -253,11 +280,7 @@ pub fn symbol_name<'a, 'tcx>(instance: Instance<'tcx>,
let
hash
=
get_symbol_hash
(
tcx
,
Some
(
def_id
),
instance_ty
,
Some
(
substs
));
let
hash
=
get_symbol_hash
(
tcx
,
Some
(
def_id
),
instance_ty
,
Some
(
substs
));
let
mut
buffer
=
SymbolPathBuffer
::
new
();
SymbolPathBuffer
::
from_interned
(
tcx
.def_symbol_name
(
def_id
))
.finish
(
&
hash
)
item_path
::
with_forced_absolute_paths
(||
{
tcx
.push_item_path
(
&
mut
buffer
,
def_id
);
});
buffer
.finish
(
&
hash
)
}
}
// Follow C++ namespace-mangling style, see
// Follow C++ namespace-mangling style, see
...
@@ -288,6 +311,19 @@ fn new() -> Self {
...
@@ -288,6 +311,19 @@ fn new() -> Self {
result
result
}
}
fn
from_interned
(
symbol
:
ty
::
SymbolName
)
->
Self
{
let
mut
result
=
SymbolPathBuffer
{
result
:
String
::
with_capacity
(
64
),
temp_buf
:
String
::
with_capacity
(
16
)
};
result
.result
.push_str
(
&
symbol
.name
);
result
}
fn
into_interned
(
self
)
->
ty
::
SymbolName
{
ty
::
SymbolName
{
name
:
Symbol
::
intern
(
&
self
.result
)
.as_str
()
}
}
fn
finish
(
mut
self
,
hash
:
&
str
)
->
String
{
fn
finish
(
mut
self
,
hash
:
&
str
)
->
String
{
// end name-sequence
// end name-sequence
self
.push
(
hash
);
self
.push
(
hash
);
...
...
src/librustc_trans/base.rs
浏览文件 @
a5173435
...
@@ -65,7 +65,6 @@
...
@@ -65,7 +65,6 @@
use
mir
;
use
mir
;
use
monomorphize
::{
self
,
Instance
};
use
monomorphize
::{
self
,
Instance
};
use
partitioning
::{
self
,
PartitioningStrategy
,
CodegenUnit
};
use
partitioning
::{
self
,
PartitioningStrategy
,
CodegenUnit
};
use
symbol_cache
::
SymbolCache
;
use
symbol_map
::
SymbolMap
;
use
symbol_map
::
SymbolMap
;
use
symbol_names_test
;
use
symbol_names_test
;
use
trans_item
::{
TransItem
,
DefPathBasedNames
};
use
trans_item
::{
TransItem
,
DefPathBasedNames
};
...
@@ -1139,8 +1138,7 @@ fn module_translation<'a, 'tcx>(
...
@@ -1139,8 +1138,7 @@ fn module_translation<'a, 'tcx>(
let
cgu_name
=
String
::
from
(
cgu
.name
());
let
cgu_name
=
String
::
from
(
cgu
.name
());
let
cgu_id
=
cgu
.work_product_id
();
let
cgu_id
=
cgu
.work_product_id
();
let
symbol_cache
=
SymbolCache
::
new
(
scx
.tcx
());
let
symbol_name_hash
=
cgu
.compute_symbol_name_hash
(
scx
);
let
symbol_name_hash
=
cgu
.compute_symbol_name_hash
(
scx
,
&
symbol_cache
);
// Check whether there is a previous work-product we can
// Check whether there is a previous work-product we can
// re-use. Not only must the file exist, and the inputs not
// re-use. Not only must the file exist, and the inputs not
...
@@ -1175,11 +1173,11 @@ fn module_translation<'a, 'tcx>(
...
@@ -1175,11 +1173,11 @@ fn module_translation<'a, 'tcx>(
}
}
// Instantiate translation items without filling out definitions yet...
// Instantiate translation items without filling out definitions yet...
let
lcx
=
LocalCrateContext
::
new
(
scx
,
cgu
,
&
symbol_cache
);
let
lcx
=
LocalCrateContext
::
new
(
scx
,
cgu
);
let
module
=
{
let
module
=
{
let
ccx
=
CrateContext
::
new
(
scx
,
&
lcx
);
let
ccx
=
CrateContext
::
new
(
scx
,
&
lcx
);
let
trans_items
=
ccx
.codegen_unit
()
let
trans_items
=
ccx
.codegen_unit
()
.items_in_deterministic_order
(
ccx
.tcx
()
,
&
symbol_cache
);
.items_in_deterministic_order
(
ccx
.tcx
());
for
&
(
trans_item
,
linkage
)
in
&
trans_items
{
for
&
(
trans_item
,
linkage
)
in
&
trans_items
{
trans_item
.predefine
(
&
ccx
,
linkage
);
trans_item
.predefine
(
&
ccx
,
linkage
);
}
}
...
...
src/librustc_trans/callee.rs
浏览文件 @
a5173435
...
@@ -23,7 +23,6 @@
...
@@ -23,7 +23,6 @@
use
rustc
::
hir
::
def_id
::
DefId
;
use
rustc
::
hir
::
def_id
::
DefId
;
use
rustc
::
ty
::
TypeFoldable
;
use
rustc
::
ty
::
TypeFoldable
;
use
rustc
::
ty
::
subst
::
Substs
;
use
rustc
::
ty
::
subst
::
Substs
;
use
trans_item
::
TransItem
;
use
type_of
;
use
type_of
;
/// Translates a reference to a fn/method item, monomorphizing and
/// Translates a reference to a fn/method item, monomorphizing and
...
@@ -50,7 +49,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
...
@@ -50,7 +49,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
return
llfn
;
return
llfn
;
}
}
let
sym
=
ccx
.symbol_cache
()
.get
(
TransItem
::
Fn
(
instance
)
);
let
sym
=
tcx
.symbol_name
(
instance
);
debug!
(
"get_fn({:?}: {:?}) => {}"
,
instance
,
fn_ty
,
sym
);
debug!
(
"get_fn({:?}: {:?}) => {}"
,
instance
,
fn_ty
,
sym
);
// This is subtle and surprising, but sometimes we have to bitcast
// This is subtle and surprising, but sometimes we have to bitcast
...
...
src/librustc_trans/consts.rs
浏览文件 @
a5173435
...
@@ -8,8 +8,6 @@
...
@@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// except according to those terms.
use
back
::
symbol_names
;
use
llvm
;
use
llvm
;
use
llvm
::{
SetUnnamedAddr
};
use
llvm
::{
SetUnnamedAddr
};
use
llvm
::{
ValueRef
,
True
};
use
llvm
::{
ValueRef
,
True
};
...
@@ -93,8 +91,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
...
@@ -93,8 +91,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
hir_map
::
NodeItem
(
&
hir
::
Item
{
hir_map
::
NodeItem
(
&
hir
::
Item
{
ref
attrs
,
span
,
node
:
hir
::
ItemStatic
(
..
),
..
ref
attrs
,
span
,
node
:
hir
::
ItemStatic
(
..
),
..
})
=>
{
})
=>
{
let
sym
=
ccx
.symbol_cache
()
let
sym
=
TransItem
::
Static
(
id
)
.symbol_name
(
ccx
.tcx
());
.get
(
TransItem
::
Static
(
id
));
let
defined_in_current_codegen_unit
=
ccx
.codegen_unit
()
let
defined_in_current_codegen_unit
=
ccx
.codegen_unit
()
.items
()
.items
()
...
@@ -113,7 +110,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
...
@@ -113,7 +110,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
hir_map
::
NodeForeignItem
(
&
hir
::
ForeignItem
{
hir_map
::
NodeForeignItem
(
&
hir
::
ForeignItem
{
ref
attrs
,
span
,
node
:
hir
::
ForeignItemStatic
(
..
),
..
ref
attrs
,
span
,
node
:
hir
::
ForeignItemStatic
(
..
),
..
})
=>
{
})
=>
{
let
sym
=
symbol_names
::
symbol_name
(
instance
,
ccx
.tcx
()
);
let
sym
=
ccx
.tcx
()
.symbol_name
(
instance
);
let
g
=
if
let
Some
(
name
)
=
let
g
=
if
let
Some
(
name
)
=
attr
::
first_attr_value_str_by_name
(
&
attrs
,
"linkage"
)
{
attr
::
first_attr_value_str_by_name
(
&
attrs
,
"linkage"
)
{
// If this is a static with a linkage specified, then we need to handle
// If this is a static with a linkage specified, then we need to handle
...
@@ -173,7 +170,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
...
@@ -173,7 +170,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
g
g
}
else
{
}
else
{
let
sym
=
symbol_names
::
symbol_name
(
instance
,
ccx
.tcx
()
);
let
sym
=
ccx
.tcx
()
.symbol_name
(
instance
);
// FIXME(nagisa): perhaps the map of externs could be offloaded to llvm somehow?
// FIXME(nagisa): perhaps the map of externs could be offloaded to llvm somehow?
// FIXME(nagisa): investigate whether it can be changed into define_global
// FIXME(nagisa): investigate whether it can be changed into define_global
...
...
src/librustc_trans/context.rs
浏览文件 @
a5173435
...
@@ -29,7 +29,6 @@
...
@@ -29,7 +29,6 @@
use
session
::
config
::
NoDebugInfo
;
use
session
::
config
::
NoDebugInfo
;
use
session
::
Session
;
use
session
::
Session
;
use
session
::
config
;
use
session
::
config
;
use
symbol_cache
::
SymbolCache
;
use
util
::
nodemap
::{
NodeSet
,
DefIdMap
,
FxHashMap
};
use
util
::
nodemap
::{
NodeSet
,
DefIdMap
,
FxHashMap
};
use
std
::
ffi
::{
CStr
,
CString
};
use
std
::
ffi
::{
CStr
,
CString
};
...
@@ -37,6 +36,7 @@
...
@@ -37,6 +36,7 @@
use
std
::
ptr
;
use
std
::
ptr
;
use
std
::
iter
;
use
std
::
iter
;
use
std
::
str
;
use
std
::
str
;
use
std
::
marker
::
PhantomData
;
use
syntax
::
ast
;
use
syntax
::
ast
;
use
syntax
::
symbol
::
InternedString
;
use
syntax
::
symbol
::
InternedString
;
use
syntax_pos
::
DUMMY_SP
;
use
syntax_pos
::
DUMMY_SP
;
...
@@ -94,7 +94,6 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
...
@@ -94,7 +94,6 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
llcx
:
ContextRef
,
llcx
:
ContextRef
,
stats
:
Stats
,
stats
:
Stats
,
codegen_unit
:
CodegenUnit
<
'tcx
>
,
codegen_unit
:
CodegenUnit
<
'tcx
>
,
needs_unwind_cleanup_cache
:
RefCell
<
FxHashMap
<
Ty
<
'tcx
>
,
bool
>>
,
/// Cache instances of monomorphic and polymorphic items
/// Cache instances of monomorphic and polymorphic items
instances
:
RefCell
<
FxHashMap
<
Instance
<
'tcx
>
,
ValueRef
>>
,
instances
:
RefCell
<
FxHashMap
<
Instance
<
'tcx
>
,
ValueRef
>>
,
/// Cache generated vtables
/// Cache generated vtables
...
@@ -125,11 +124,6 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
...
@@ -125,11 +124,6 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
/// Mapping from static definitions to their DefId's.
/// Mapping from static definitions to their DefId's.
statics
:
RefCell
<
FxHashMap
<
ValueRef
,
DefId
>>
,
statics
:
RefCell
<
FxHashMap
<
ValueRef
,
DefId
>>
,
impl_method_cache
:
RefCell
<
FxHashMap
<
(
DefId
,
ast
::
Name
),
DefId
>>
,
/// Cache of closure wrappers for bare fn's.
closure_bare_wrapper_cache
:
RefCell
<
FxHashMap
<
ValueRef
,
ValueRef
>>
,
/// List of globals for static variables which need to be passed to the
/// List of globals for static variables which need to be passed to the
/// LLVM function ReplaceAllUsesWith (RAUW) when translation is complete.
/// LLVM function ReplaceAllUsesWith (RAUW) when translation is complete.
/// (We have to make sure we don't invalidate any ValueRefs referring
/// (We have to make sure we don't invalidate any ValueRefs referring
...
@@ -141,15 +135,11 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
...
@@ -141,15 +135,11 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
used_statics
:
RefCell
<
Vec
<
ValueRef
>>
,
used_statics
:
RefCell
<
Vec
<
ValueRef
>>
,
lltypes
:
RefCell
<
FxHashMap
<
Ty
<
'tcx
>
,
Type
>>
,
lltypes
:
RefCell
<
FxHashMap
<
Ty
<
'tcx
>
,
Type
>>
,
llsizingtypes
:
RefCell
<
FxHashMap
<
Ty
<
'tcx
>
,
Type
>>
,
type_hashcodes
:
RefCell
<
FxHashMap
<
Ty
<
'tcx
>
,
String
>>
,
type_hashcodes
:
RefCell
<
FxHashMap
<
Ty
<
'tcx
>
,
String
>>
,
int_type
:
Type
,
int_type
:
Type
,
opaque_vec_type
:
Type
,
opaque_vec_type
:
Type
,
str_slice_type
:
Type
,
str_slice_type
:
Type
,
/// Holds the LLVM values for closure IDs.
closure_vals
:
RefCell
<
FxHashMap
<
Instance
<
'tcx
>
,
ValueRef
>>
,
dbg_cx
:
Option
<
debuginfo
::
CrateDebugContext
<
'tcx
>>
,
dbg_cx
:
Option
<
debuginfo
::
CrateDebugContext
<
'tcx
>>
,
eh_personality
:
Cell
<
Option
<
ValueRef
>>
,
eh_personality
:
Cell
<
Option
<
ValueRef
>>
,
...
@@ -164,7 +154,8 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
...
@@ -164,7 +154,8 @@ pub struct LocalCrateContext<'a, 'tcx: 'a> {
/// A counter that is used for generating local symbol names
/// A counter that is used for generating local symbol names
local_gen_sym_counter
:
Cell
<
usize
>
,
local_gen_sym_counter
:
Cell
<
usize
>
,
symbol_cache
:
&
'a
SymbolCache
<
'a
,
'tcx
>
,
/// A placeholder so we can add lifetimes
placeholder
:
PhantomData
<&
'a
()
>
,
}
}
/// A CrateContext value binds together one LocalCrateContext with the
/// A CrateContext value binds together one LocalCrateContext with the
...
@@ -366,8 +357,7 @@ pub fn use_dll_storage_attrs(&self) -> bool {
...
@@ -366,8 +357,7 @@ pub fn use_dll_storage_attrs(&self) -> bool {
impl
<
'a
,
'tcx
>
LocalCrateContext
<
'a
,
'tcx
>
{
impl
<
'a
,
'tcx
>
LocalCrateContext
<
'a
,
'tcx
>
{
pub
fn
new
(
shared
:
&
SharedCrateContext
<
'a
,
'tcx
>
,
pub
fn
new
(
shared
:
&
SharedCrateContext
<
'a
,
'tcx
>
,
codegen_unit
:
CodegenUnit
<
'tcx
>
,
codegen_unit
:
CodegenUnit
<
'tcx
>
)
symbol_cache
:
&
'a
SymbolCache
<
'a
,
'tcx
>
)
->
LocalCrateContext
<
'a
,
'tcx
>
{
->
LocalCrateContext
<
'a
,
'tcx
>
{
unsafe
{
unsafe
{
// Append ".rs" to LLVM module identifier.
// Append ".rs" to LLVM module identifier.
...
@@ -396,7 +386,6 @@ pub fn new(shared: &SharedCrateContext<'a, 'tcx>,
...
@@ -396,7 +386,6 @@ pub fn new(shared: &SharedCrateContext<'a, 'tcx>,
llcx
:
llcx
,
llcx
:
llcx
,
stats
:
Stats
::
default
(),
stats
:
Stats
::
default
(),
codegen_unit
:
codegen_unit
,
codegen_unit
:
codegen_unit
,
needs_unwind_cleanup_cache
:
RefCell
::
new
(
FxHashMap
()),
instances
:
RefCell
::
new
(
FxHashMap
()),
instances
:
RefCell
::
new
(
FxHashMap
()),
vtables
:
RefCell
::
new
(
FxHashMap
()),
vtables
:
RefCell
::
new
(
FxHashMap
()),
const_cstr_cache
:
RefCell
::
new
(
FxHashMap
()),
const_cstr_cache
:
RefCell
::
new
(
FxHashMap
()),
...
@@ -405,17 +394,13 @@ pub fn new(shared: &SharedCrateContext<'a, 'tcx>,
...
@@ -405,17 +394,13 @@ pub fn new(shared: &SharedCrateContext<'a, 'tcx>,
const_values
:
RefCell
::
new
(
FxHashMap
()),
const_values
:
RefCell
::
new
(
FxHashMap
()),
extern_const_values
:
RefCell
::
new
(
DefIdMap
()),
extern_const_values
:
RefCell
::
new
(
DefIdMap
()),
statics
:
RefCell
::
new
(
FxHashMap
()),
statics
:
RefCell
::
new
(
FxHashMap
()),
impl_method_cache
:
RefCell
::
new
(
FxHashMap
()),
closure_bare_wrapper_cache
:
RefCell
::
new
(
FxHashMap
()),
statics_to_rauw
:
RefCell
::
new
(
Vec
::
new
()),
statics_to_rauw
:
RefCell
::
new
(
Vec
::
new
()),
used_statics
:
RefCell
::
new
(
Vec
::
new
()),
used_statics
:
RefCell
::
new
(
Vec
::
new
()),
lltypes
:
RefCell
::
new
(
FxHashMap
()),
lltypes
:
RefCell
::
new
(
FxHashMap
()),
llsizingtypes
:
RefCell
::
new
(
FxHashMap
()),
type_hashcodes
:
RefCell
::
new
(
FxHashMap
()),
type_hashcodes
:
RefCell
::
new
(
FxHashMap
()),
int_type
:
Type
::
from_ref
(
ptr
::
null_mut
()),
int_type
:
Type
::
from_ref
(
ptr
::
null_mut
()),
opaque_vec_type
:
Type
::
from_ref
(
ptr
::
null_mut
()),
opaque_vec_type
:
Type
::
from_ref
(
ptr
::
null_mut
()),
str_slice_type
:
Type
::
from_ref
(
ptr
::
null_mut
()),
str_slice_type
:
Type
::
from_ref
(
ptr
::
null_mut
()),
closure_vals
:
RefCell
::
new
(
FxHashMap
()),
dbg_cx
:
dbg_cx
,
dbg_cx
:
dbg_cx
,
eh_personality
:
Cell
::
new
(
None
),
eh_personality
:
Cell
::
new
(
None
),
eh_unwind_resume
:
Cell
::
new
(
None
),
eh_unwind_resume
:
Cell
::
new
(
None
),
...
@@ -423,7 +408,7 @@ pub fn new(shared: &SharedCrateContext<'a, 'tcx>,
...
@@ -423,7 +408,7 @@ pub fn new(shared: &SharedCrateContext<'a, 'tcx>,
intrinsics
:
RefCell
::
new
(
FxHashMap
()),
intrinsics
:
RefCell
::
new
(
FxHashMap
()),
type_of_depth
:
Cell
::
new
(
0
),
type_of_depth
:
Cell
::
new
(
0
),
local_gen_sym_counter
:
Cell
::
new
(
0
),
local_gen_sym_counter
:
Cell
::
new
(
0
),
symbol_cache
:
symbol_cache
,
placeholder
:
PhantomData
,
};
};
let
(
int_type
,
opaque_vec_type
,
str_slice_ty
,
mut
local_ccx
)
=
{
let
(
int_type
,
opaque_vec_type
,
str_slice_ty
,
mut
local_ccx
)
=
{
...
@@ -515,10 +500,6 @@ pub fn td(&self) -> llvm::TargetDataRef {
...
@@ -515,10 +500,6 @@ pub fn td(&self) -> llvm::TargetDataRef {
unsafe
{
llvm
::
LLVMRustGetModuleDataLayout
(
self
.llmod
())
}
unsafe
{
llvm
::
LLVMRustGetModuleDataLayout
(
self
.llmod
())
}
}
}
pub
fn
needs_unwind_cleanup_cache
(
&
self
)
->
&
RefCell
<
FxHashMap
<
Ty
<
'tcx
>
,
bool
>>
{
&
self
.local
()
.needs_unwind_cleanup_cache
}
pub
fn
instances
<
'a
>
(
&
'a
self
)
->
&
'a
RefCell
<
FxHashMap
<
Instance
<
'tcx
>
,
ValueRef
>>
{
pub
fn
instances
<
'a
>
(
&
'a
self
)
->
&
'a
RefCell
<
FxHashMap
<
Instance
<
'tcx
>
,
ValueRef
>>
{
&
self
.local
()
.instances
&
self
.local
()
.instances
}
}
...
@@ -554,15 +535,6 @@ pub fn statics<'a>(&'a self) -> &'a RefCell<FxHashMap<ValueRef, DefId>> {
...
@@ -554,15 +535,6 @@ pub fn statics<'a>(&'a self) -> &'a RefCell<FxHashMap<ValueRef, DefId>> {
&
self
.local
()
.statics
&
self
.local
()
.statics
}
}
pub
fn
impl_method_cache
<
'a
>
(
&
'a
self
)
->
&
'a
RefCell
<
FxHashMap
<
(
DefId
,
ast
::
Name
),
DefId
>>
{
&
self
.local
()
.impl_method_cache
}
pub
fn
closure_bare_wrapper_cache
<
'a
>
(
&
'a
self
)
->
&
'a
RefCell
<
FxHashMap
<
ValueRef
,
ValueRef
>>
{
&
self
.local
()
.closure_bare_wrapper_cache
}
pub
fn
statics_to_rauw
<
'a
>
(
&
'a
self
)
->
&
'a
RefCell
<
Vec
<
(
ValueRef
,
ValueRef
)
>>
{
pub
fn
statics_to_rauw
<
'a
>
(
&
'a
self
)
->
&
'a
RefCell
<
Vec
<
(
ValueRef
,
ValueRef
)
>>
{
&
self
.local
()
.statics_to_rauw
&
self
.local
()
.statics_to_rauw
}
}
...
@@ -575,10 +547,6 @@ pub fn lltypes<'a>(&'a self) -> &'a RefCell<FxHashMap<Ty<'tcx>, Type>> {
...
@@ -575,10 +547,6 @@ pub fn lltypes<'a>(&'a self) -> &'a RefCell<FxHashMap<Ty<'tcx>, Type>> {
&
self
.local
()
.lltypes
&
self
.local
()
.lltypes
}
}
pub
fn
llsizingtypes
<
'a
>
(
&
'a
self
)
->
&
'a
RefCell
<
FxHashMap
<
Ty
<
'tcx
>
,
Type
>>
{
&
self
.local
()
.llsizingtypes
}
pub
fn
type_hashcodes
<
'a
>
(
&
'a
self
)
->
&
'a
RefCell
<
FxHashMap
<
Ty
<
'tcx
>
,
String
>>
{
pub
fn
type_hashcodes
<
'a
>
(
&
'a
self
)
->
&
'a
RefCell
<
FxHashMap
<
Ty
<
'tcx
>
,
String
>>
{
&
self
.local
()
.type_hashcodes
&
self
.local
()
.type_hashcodes
}
}
...
@@ -599,10 +567,6 @@ pub fn str_slice_type(&self) -> Type {
...
@@ -599,10 +567,6 @@ pub fn str_slice_type(&self) -> Type {
self
.local
()
.str_slice_type
self
.local
()
.str_slice_type
}
}
pub
fn
closure_vals
<
'a
>
(
&
'a
self
)
->
&
'a
RefCell
<
FxHashMap
<
Instance
<
'tcx
>
,
ValueRef
>>
{
&
self
.local
()
.closure_vals
}
pub
fn
dbg_cx
<
'a
>
(
&
'a
self
)
->
&
'a
Option
<
debuginfo
::
CrateDebugContext
<
'tcx
>>
{
pub
fn
dbg_cx
<
'a
>
(
&
'a
self
)
->
&
'a
Option
<
debuginfo
::
CrateDebugContext
<
'tcx
>>
{
&
self
.local
()
.dbg_cx
&
self
.local
()
.dbg_cx
}
}
...
@@ -644,10 +608,6 @@ pub fn use_dll_storage_attrs(&self) -> bool {
...
@@ -644,10 +608,6 @@ pub fn use_dll_storage_attrs(&self) -> bool {
self
.shared
.use_dll_storage_attrs
()
self
.shared
.use_dll_storage_attrs
()
}
}
pub
fn
symbol_cache
(
&
self
)
->
&
'b
SymbolCache
<
'b
,
'tcx
>
{
self
.local
()
.symbol_cache
}
/// Given the def-id of some item that has no type parameters, make
/// Given the def-id of some item that has no type parameters, make
/// a suitable "empty substs" for it.
/// a suitable "empty substs" for it.
pub
fn
empty_substs_for_def_id
(
&
self
,
item_def_id
:
DefId
)
->
&
'tcx
Substs
<
'tcx
>
{
pub
fn
empty_substs_for_def_id
(
&
self
,
item_def_id
:
DefId
)
->
&
'tcx
Substs
<
'tcx
>
{
...
...
src/librustc_trans/lib.rs
浏览文件 @
a5173435
...
@@ -67,6 +67,7 @@
...
@@ -67,6 +67,7 @@
pub
use
rustc
::
util
;
pub
use
rustc
::
util
;
pub
use
base
::
trans_crate
;
pub
use
base
::
trans_crate
;
pub
use
back
::
symbol_names
::
provide
;
pub
mod
back
{
pub
mod
back
{
pub
use
rustc
::
hir
::
svh
;
pub
use
rustc
::
hir
::
svh
;
...
@@ -124,7 +125,6 @@ pub mod back {
...
@@ -124,7 +125,6 @@ pub mod back {
mod
mir
;
mod
mir
;
mod
monomorphize
;
mod
monomorphize
;
mod
partitioning
;
mod
partitioning
;
mod
symbol_cache
;
mod
symbol_map
;
mod
symbol_map
;
mod
symbol_names_test
;
mod
symbol_names_test
;
mod
trans_item
;
mod
trans_item
;
...
...
src/librustc_trans/partitioning.rs
浏览文件 @
a5173435
...
@@ -113,10 +113,8 @@
...
@@ -113,10 +113,8 @@
use
rustc
::
ty
::{
self
,
TyCtxt
};
use
rustc
::
ty
::{
self
,
TyCtxt
};
use
rustc
::
ty
::
item_path
::
characteristic_def_id_of_type
;
use
rustc
::
ty
::
item_path
::
characteristic_def_id_of_type
;
use
rustc_incremental
::
IchHasher
;
use
rustc_incremental
::
IchHasher
;
use
std
::
cmp
::
Ordering
;
use
std
::
hash
::
Hash
;
use
std
::
hash
::
Hash
;
use
std
::
sync
::
Arc
;
use
std
::
sync
::
Arc
;
use
symbol_cache
::
SymbolCache
;
use
syntax
::
ast
::
NodeId
;
use
syntax
::
ast
::
NodeId
;
use
syntax
::
symbol
::{
Symbol
,
InternedString
};
use
syntax
::
symbol
::{
Symbol
,
InternedString
};
use
trans_item
::{
TransItem
,
InstantiationMode
};
use
trans_item
::{
TransItem
,
InstantiationMode
};
...
@@ -175,14 +173,13 @@ pub fn work_product_dep_node(&self) -> DepNode<DefId> {
...
@@ -175,14 +173,13 @@ pub fn work_product_dep_node(&self) -> DepNode<DefId> {
}
}
pub
fn
compute_symbol_name_hash
<
'a
>
(
&
self
,
pub
fn
compute_symbol_name_hash
<
'a
>
(
&
self
,
scx
:
&
SharedCrateContext
<
'a
,
'tcx
>
,
scx
:
&
SharedCrateContext
<
'a
,
'tcx
>
)
symbol_cache
:
&
SymbolCache
<
'a
,
'tcx
>
)
->
u64
{
->
u64
{
let
mut
state
=
IchHasher
::
new
();
let
mut
state
=
IchHasher
::
new
();
let
exported_symbols
=
scx
.exported_symbols
();
let
exported_symbols
=
scx
.exported_symbols
();
let
all_items
=
self
.items_in_deterministic_order
(
scx
.tcx
()
,
symbol_cache
);
let
all_items
=
self
.items_in_deterministic_order
(
scx
.tcx
());
for
(
item
,
_
)
in
all_items
{
for
(
item
,
_
)
in
all_items
{
let
symbol_name
=
symbol_cache
.get
(
item
);
let
symbol_name
=
item
.symbol_name
(
scx
.tcx
()
);
symbol_name
.len
()
.hash
(
&
mut
state
);
symbol_name
.len
()
.hash
(
&
mut
state
);
symbol_name
.hash
(
&
mut
state
);
symbol_name
.hash
(
&
mut
state
);
let
exported
=
match
item
{
let
exported
=
match
item
{
...
@@ -203,53 +200,30 @@ pub fn compute_symbol_name_hash<'a>(&self,
...
@@ -203,53 +200,30 @@ pub fn compute_symbol_name_hash<'a>(&self,
}
}
pub
fn
items_in_deterministic_order
<
'a
>
(
&
self
,
pub
fn
items_in_deterministic_order
<
'a
>
(
&
self
,
tcx
:
TyCtxt
,
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
)
symbol_cache
:
&
SymbolCache
<
'a
,
'tcx
>
)
->
Vec
<
(
TransItem
<
'tcx
>
,
llvm
::
Linkage
)
>
{
->
Vec
<
(
TransItem
<
'tcx
>
,
llvm
::
Linkage
)
>
{
let
mut
items
:
Vec
<
(
TransItem
<
'tcx
>
,
llvm
::
Linkage
)
>
=
self
.items
.iter
()
.map
(|(
item
,
linkage
)|
(
*
item
,
*
linkage
))
.collect
();
// The codegen tests rely on items being process in the same order as
// The codegen tests rely on items being process in the same order as
// they appear in the file, so for local items, we sort by node_id first
// they appear in the file, so for local items, we sort by node_id first
items
.sort_by
(|
&
(
trans_item1
,
_
),
&
(
trans_item2
,
_
)|
{
#[derive(PartialEq,
Eq,
PartialOrd,
Ord)]
let
node_id1
=
local_node_id
(
tcx
,
trans_item1
);
pub
struct
ItemSortKey
(
Option
<
NodeId
>
,
ty
::
SymbolName
);
let
node_id2
=
local_node_id
(
tcx
,
trans_item2
);
match
(
node_id1
,
node_id2
)
{
(
None
,
None
)
=>
{
let
symbol_name1
=
symbol_cache
.get
(
trans_item1
);
let
symbol_name2
=
symbol_cache
.get
(
trans_item2
);
symbol_name1
.cmp
(
&
symbol_name2
)
}
// In the following two cases we can avoid looking up the symbol
(
None
,
Some
(
_
))
=>
Ordering
::
Less
,
(
Some
(
_
),
None
)
=>
Ordering
::
Greater
,
(
Some
(
node_id1
),
Some
(
node_id2
))
=>
{
let
ordering
=
node_id1
.cmp
(
&
node_id2
);
if
ordering
!=
Ordering
::
Equal
{
return
ordering
;
}
let
symbol_name1
=
symbol_cache
.get
(
trans_item1
);
let
symbol_name2
=
symbol_cache
.get
(
trans_item2
);
symbol_name1
.cmp
(
&
symbol_name2
)
}
}
});
return
items
;
fn
local_node_id
(
tcx
:
TyCtxt
,
trans_item
:
TransItem
)
->
Option
<
NodeId
>
{
fn
item_sort_key
<
'a
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
match
trans_item
{
item
:
TransItem
<
'tcx
>
)
->
ItemSortKey
{
ItemSortKey
(
match
item
{
TransItem
::
Fn
(
instance
)
=>
{
TransItem
::
Fn
(
instance
)
=>
{
tcx
.hir
.as_local_node_id
(
instance
.def_id
())
tcx
.hir
.as_local_node_id
(
instance
.def_id
())
}
}
TransItem
::
Static
(
node_id
)
|
TransItem
::
GlobalAsm
(
node_id
)
=>
{
TransItem
::
Static
(
node_id
)
|
TransItem
::
GlobalAsm
(
node_id
)
=>
{
Some
(
node_id
)
Some
(
node_id
)
}
}
}
}
,
item
.symbol_name
(
tcx
))
}
}
let
items
:
Vec
<
_
>
=
self
.items
.iter
()
.map
(|(
&
i
,
&
l
)|
(
i
,
l
))
.collect
();
let
mut
items
:
Vec
<
_
>
=
items
.iter
()
.map
(|
il
|
(
il
,
item_sort_key
(
tcx
,
il
.0
)))
.collect
();
items
.sort_by
(|
&
(
_
,
ref
key1
),
&
(
_
,
ref
key2
)|
key1
.cmp
(
key2
));
items
.into_iter
()
.map
(|(
&
item_linkage
,
_
)|
item_linkage
)
.collect
()
}
}
}
}
...
@@ -537,12 +511,11 @@ fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
...
@@ -537,12 +511,11 @@ fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
{
{
if
cfg!
(
debug_assertions
)
{
if
cfg!
(
debug_assertions
)
{
debug!
(
"{}"
,
label
);
debug!
(
"{}"
,
label
);
let
symbol_cache
=
SymbolCache
::
new
(
tcx
);
for
cgu
in
cgus
{
for
cgu
in
cgus
{
debug!
(
"CodegenUnit {}:"
,
cgu
.name
);
debug!
(
"CodegenUnit {}:"
,
cgu
.name
);
for
(
trans_item
,
linkage
)
in
&
cgu
.items
{
for
(
trans_item
,
linkage
)
in
&
cgu
.items
{
let
symbol_name
=
symbol_cache
.get
(
*
trans_item
);
let
symbol_name
=
trans_item
.symbol_name
(
tcx
);
let
symbol_hash_start
=
symbol_name
.rfind
(
'h'
);
let
symbol_hash_start
=
symbol_name
.rfind
(
'h'
);
let
symbol_hash
=
symbol_hash_start
.map
(|
i
|
&
symbol_name
[
i
..
])
let
symbol_hash
=
symbol_hash_start
.map
(|
i
|
&
symbol_name
[
i
..
])
.unwrap_or
(
"<no hash>"
);
.unwrap_or
(
"<no hash>"
);
...
...
src/librustc_trans/symbol_cache.rs
已删除
100644 → 0
浏览文件 @
b0a4074c
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
rustc
::
ty
::
TyCtxt
;
use
std
::
cell
::
RefCell
;
use
syntax_pos
::
symbol
::{
InternedString
,
Symbol
};
use
trans_item
::
TransItem
;
use
util
::
nodemap
::
FxHashMap
;
// In the SymbolCache we collect the symbol names of translation items
// and cache them for later reference. This is just a performance
// optimization and the cache is populated lazilly; symbol names of
// translation items are deterministic and fully defined by the item.
// Thus they can always be recomputed if needed.
pub
struct
SymbolCache
<
'a
,
'tcx
:
'a
>
{
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
,
index
:
RefCell
<
FxHashMap
<
TransItem
<
'tcx
>
,
Symbol
>>
,
}
impl
<
'a
,
'tcx
>
SymbolCache
<
'a
,
'tcx
>
{
pub
fn
new
(
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
)
->
Self
{
SymbolCache
{
tcx
:
tcx
,
index
:
RefCell
::
new
(
FxHashMap
())
}
}
pub
fn
get
(
&
self
,
trans_item
:
TransItem
<
'tcx
>
)
->
InternedString
{
let
mut
index
=
self
.index
.borrow_mut
();
index
.entry
(
trans_item
)
.or_insert_with
(||
Symbol
::
intern
(
&
trans_item
.compute_symbol_name
(
self
.tcx
)))
.as_str
()
}
}
src/librustc_trans/symbol_map.rs
浏览文件 @
a5173435
...
@@ -36,7 +36,7 @@ pub fn build<'a, I>(scx: &SharedCrateContext<'a, 'tcx>,
...
@@ -36,7 +36,7 @@ pub fn build<'a, I>(scx: &SharedCrateContext<'a, 'tcx>,
// Check for duplicate symbol names
// Check for duplicate symbol names
let
tcx
=
scx
.tcx
();
let
tcx
=
scx
.tcx
();
let
mut
symbols
:
Vec
<
_
>
=
trans_items
.map
(|
trans_item
|
{
let
mut
symbols
:
Vec
<
_
>
=
trans_items
.map
(|
trans_item
|
{
(
trans_item
,
trans_item
.
compute_
symbol_name
(
tcx
))
(
trans_item
,
trans_item
.symbol_name
(
tcx
))
})
.collect
();
})
.collect
();
(
&
mut
symbols
[
..
])
.sort_by
(|
&
(
_
,
ref
sym1
),
&
(
_
,
ref
sym2
)|{
(
&
mut
symbols
[
..
])
.sort_by
(|
&
(
_
,
ref
sym1
),
&
(
_
,
ref
sym2
)|{
...
@@ -125,7 +125,7 @@ pub fn get_or_compute<'map, 'scx>(&'map self,
...
@@ -125,7 +125,7 @@ pub fn get_or_compute<'map, 'scx>(&'map self,
if
let
Some
(
sym
)
=
self
.get
(
trans_item
)
{
if
let
Some
(
sym
)
=
self
.get
(
trans_item
)
{
Cow
::
from
(
sym
)
Cow
::
from
(
sym
)
}
else
{
}
else
{
Cow
::
from
(
trans_item
.compute_symbol_name
(
scx
.tcx
(
)))
Cow
::
from
(
str
::
to_owned
(
&
trans_item
.symbol_name
(
scx
.tcx
()
)))
}
}
}
}
}
}
src/librustc_trans/symbol_names_test.rs
浏览文件 @
a5173435
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
//! item-path. This is used for unit testing the code that generates
//! item-path. This is used for unit testing the code that generates
//! paths etc in all kinds of annoying scenarios.
//! paths etc in all kinds of annoying scenarios.
use
back
::
symbol_names
;
use
rustc
::
hir
;
use
rustc
::
hir
;
use
rustc
::
hir
::
intravisit
::{
self
,
Visitor
,
NestedVisitorMap
};
use
rustc
::
hir
::
intravisit
::{
self
,
Visitor
,
NestedVisitorMap
};
use
rustc
::
ty
::
TyCtxt
;
use
rustc
::
ty
::
TyCtxt
;
...
@@ -52,7 +51,7 @@ fn process_attrs(&mut self,
...
@@ -52,7 +51,7 @@ fn process_attrs(&mut self,
if
attr
.check_name
(
SYMBOL_NAME
)
{
if
attr
.check_name
(
SYMBOL_NAME
)
{
// for now, can only use on monomorphic names
// for now, can only use on monomorphic names
let
instance
=
Instance
::
mono
(
tcx
,
def_id
);
let
instance
=
Instance
::
mono
(
tcx
,
def_id
);
let
name
=
s
ymbol_names
::
symbol_name
(
instance
,
self
.tcx
);
let
name
=
s
elf
.tcx
.symbol_name
(
instance
);
tcx
.sess
.span_err
(
attr
.span
,
&
format!
(
"symbol-name({})"
,
name
));
tcx
.sess
.span_err
(
attr
.span
,
&
format!
(
"symbol-name({})"
,
name
));
}
else
if
attr
.check_name
(
ITEM_PATH
)
{
}
else
if
attr
.check_name
(
ITEM_PATH
)
{
let
path
=
tcx
.item_path_str
(
def_id
);
let
path
=
tcx
.item_path_str
(
def_id
);
...
...
src/librustc_trans/trans_item.rs
浏览文件 @
a5173435
...
@@ -28,10 +28,10 @@
...
@@ -28,10 +28,10 @@
use
rustc
::
hir
::
def_id
::
DefId
;
use
rustc
::
hir
::
def_id
::
DefId
;
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
,
TypeFoldable
};
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
,
TypeFoldable
};
use
rustc
::
ty
::
subst
::
Substs
;
use
rustc
::
ty
::
subst
::
Substs
;
use
syntax_pos
::
symbol
::
Symbol
;
use
syntax
::
ast
::{
self
,
NodeId
};
use
syntax
::
ast
::{
self
,
NodeId
};
use
syntax
::
attr
;
use
syntax
::
attr
;
use
type_of
;
use
type_of
;
use
back
::
symbol_names
;
use
std
::
fmt
::
Write
;
use
std
::
fmt
::
Write
;
use
std
::
iter
;
use
std
::
iter
;
...
@@ -118,7 +118,7 @@ pub fn predefine(&self,
...
@@ -118,7 +118,7 @@ pub fn predefine(&self,
self
.to_raw_string
(),
self
.to_raw_string
(),
ccx
.codegen_unit
()
.name
());
ccx
.codegen_unit
()
.name
());
let
symbol_name
=
ccx
.symbol_cache
()
.get
(
*
self
);
let
symbol_name
=
self
.symbol_name
(
ccx
.tcx
()
);
debug!
(
"symbol {}"
,
&
symbol_name
);
debug!
(
"symbol {}"
,
&
symbol_name
);
...
@@ -184,16 +184,18 @@ fn predefine_fn(ccx: &CrateContext<'a, 'tcx>,
...
@@ -184,16 +184,18 @@ fn predefine_fn(ccx: &CrateContext<'a, 'tcx>,
ccx
.instances
()
.borrow_mut
()
.insert
(
instance
,
lldecl
);
ccx
.instances
()
.borrow_mut
()
.insert
(
instance
,
lldecl
);
}
}
pub
fn
compute_symbol_name
(
&
self
,
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
)
->
String
{
pub
fn
symbol_name
(
&
self
,
tcx
:
TyCtxt
<
'a
,
'tcx
,
'tcx
>
)
->
ty
::
SymbolName
{
match
*
self
{
match
*
self
{
TransItem
::
Fn
(
instance
)
=>
symbol_names
::
symbol_name
(
instance
,
tcx
),
TransItem
::
Fn
(
instance
)
=>
tcx
.symbol_name
(
instance
),
TransItem
::
Static
(
node_id
)
=>
{
TransItem
::
Static
(
node_id
)
=>
{
let
def_id
=
tcx
.hir
.local_def_id
(
node_id
);
let
def_id
=
tcx
.hir
.local_def_id
(
node_id
);
symbol_names
::
symbol_name
(
Instance
::
mono
(
tcx
,
def_id
),
tcx
)
tcx
.symbol_name
(
Instance
::
mono
(
tcx
,
def_id
)
)
}
}
TransItem
::
GlobalAsm
(
node_id
)
=>
{
TransItem
::
GlobalAsm
(
node_id
)
=>
{
let
def_id
=
tcx
.hir
.local_def_id
(
node_id
);
let
def_id
=
tcx
.hir
.local_def_id
(
node_id
);
format!
(
"global_asm_{:?}"
,
def_id
)
ty
::
SymbolName
{
name
:
Symbol
::
intern
(
&
format!
(
"global_asm_{:?}"
,
def_id
))
.as_str
()
}
}
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录