Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7def3768
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,发现更多精彩内容 >>
提交
7def3768
编写于
2月 15, 2016
作者:
M
Michael Woerister
提交者:
Niko Matsakis
3月 25, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use new symbol names for items of various kinds.
上级
68de1718
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
17 addition
and
107 deletion
+17
-107
src/librustc_trans/back/link.rs
src/librustc_trans/back/link.rs
+3
-94
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/base.rs
+7
-6
src/librustc_trans/trans/callee.rs
src/librustc_trans/trans/callee.rs
+1
-1
src/librustc_trans/trans/consts.rs
src/librustc_trans/trans/consts.rs
+1
-1
src/test/auxiliary/issue-17718-aux.rs
src/test/auxiliary/issue-17718-aux.rs
+0
-0
src/test/run-pass/backtrace.rs
src/test/run-pass/backtrace.rs
+3
-3
src/test/run-pass/issue-17718.rs
src/test/run-pass/issue-17718.rs
+2
-2
未找到文件。
src/librustc_trans/back/link.rs
浏览文件 @
7def3768
...
...
@@ -24,11 +24,9 @@
use
middle
::
cstore
::{
LinkagePreference
,
NativeLibraryKind
};
use
middle
::
def_id
::
DefId
;
use
middle
::
dependency_format
::
Linkage
;
use
middle
::
ty
::{
Ty
,
TyCtxt
};
use
rustc
::
front
::
map
::
DefPath
;
use
trans
::{
CrateContext
,
CrateTranslation
,
gensym_name
};
use
middle
::
ty
::
TyCtxt
;
use
trans
::
CrateTranslation
;
use
util
::
common
::
time
;
use
util
::
sha2
::{
Digest
,
Sha256
};
use
util
::
fs
::
fix_windows_verbatim_for_gcc
;
use
rustc_back
::
tempdir
::
TempDir
;
...
...
@@ -38,16 +36,14 @@
use
std
::
ffi
::
OsString
;
use
std
::
fs
;
use
std
::
io
::{
self
,
Read
,
Write
};
use
std
::
iter
::
once
;
use
std
::
mem
;
use
std
::
path
::{
Path
,
PathBuf
};
use
std
::
process
::
Command
;
use
std
::
str
;
use
flate
;
use
serialize
::
hex
::
ToHex
;
use
syntax
::
ast
;
use
syntax
::
codemap
::
Span
;
use
syntax
::
parse
::
token
::
{
self
,
InternedString
}
;
use
syntax
::
parse
::
token
::
InternedString
;
use
syntax
::
attr
::
AttrMetaMethods
;
use
rustc_front
::
hir
;
...
...
@@ -195,50 +191,10 @@ pub fn build_link_meta(sess: &Session,
return
r
;
}
fn
truncated_hash_result
(
symbol_hasher
:
&
mut
Sha256
)
->
String
{
let
output
=
symbol_hasher
.result_bytes
();
// 64 bits should be enough to avoid collisions.
output
[
..
8
]
.to_hex
()
.to_string
()
}
pub
fn
def_to_string
(
_
tcx
:
&
TyCtxt
,
did
:
DefId
)
->
String
{
format!
(
"{}:{}"
,
did
.krate
,
did
.index
.as_usize
())
}
// This calculates STH for a symbol, as defined above
fn
symbol_hash
<
'tcx
>
(
tcx
:
&
TyCtxt
<
'tcx
>
,
symbol_hasher
:
&
mut
Sha256
,
t
:
Ty
<
'tcx
>
,
link_meta
:
&
LinkMeta
)
->
String
{
// NB: do *not* use abbrevs here as we want the symbol names
// to be independent of one another in the crate.
symbol_hasher
.reset
();
symbol_hasher
.input_str
(
&
link_meta
.crate_name
);
symbol_hasher
.input_str
(
"-"
);
symbol_hasher
.input_str
(
link_meta
.crate_hash
.as_str
());
symbol_hasher
.input_str
(
&
tcx
.sess.crate_disambiguator
.borrow
()[
..
]);
symbol_hasher
.input_str
(
"-"
);
symbol_hasher
.input
(
&
tcx
.sess.cstore
.encode_type
(
tcx
,
t
,
def_to_string
));
// Prefix with 'h' so that it never blends into adjacent digits
let
mut
hash
=
String
::
from
(
"h"
);
hash
.push_str
(
&
truncated_hash_result
(
symbol_hasher
));
hash
}
fn
get_symbol_hash
<
'a
,
'tcx
>
(
ccx
:
&
CrateContext
<
'a
,
'tcx
>
,
t
:
Ty
<
'tcx
>
)
->
String
{
if
let
Some
(
h
)
=
ccx
.type_hashcodes
()
.borrow
()
.get
(
&
t
)
{
return
h
.to_string
()
}
let
mut
symbol_hasher
=
ccx
.symbol_hasher
()
.borrow_mut
();
let
hash
=
symbol_hash
(
ccx
.tcx
(),
&
mut
*
symbol_hasher
,
t
,
ccx
.link_meta
());
ccx
.type_hashcodes
()
.borrow_mut
()
.insert
(
t
,
hash
.clone
());
hash
}
// Name sanitation. LLVM will happily accept identifiers with weird names, but
// gas doesn't!
// gas accepts the following characters in symbols: a-z, A-Z, 0-9, ., _, $
...
...
@@ -324,53 +280,6 @@ fn push(n: &mut String, s: &str) {
n
}
pub
fn
exported_name
(
path
:
DefPath
,
hash
:
&
str
)
->
String
{
let
path
=
path
.into_iter
()
.map
(|
e
|
e
.data
.as_interned_str
());
mangle
(
path
,
Some
(
hash
))
}
pub
fn
mangle_exported_name
<
'a
,
'tcx
>
(
ccx
:
&
CrateContext
<
'a
,
'tcx
>
,
path
:
DefPath
,
t
:
Ty
<
'tcx
>
,
id
:
ast
::
NodeId
)
->
String
{
let
mut
hash
=
get_symbol_hash
(
ccx
,
t
);
// Paths can be completely identical for different nodes,
// e.g. `fn foo() { { fn a() {} } { fn a() {} } }`, so we
// generate unique characters from the node id. For now
// hopefully 3 characters is enough to avoid collisions.
const
EXTRA_CHARS
:
&
'static
str
=
"abcdefghijklmnopqrstuvwxyz
\
ABCDEFGHIJKLMNOPQRSTUVWXYZ
\
0123456789"
;
let
id
=
id
as
usize
;
let
extra1
=
id
%
EXTRA_CHARS
.len
();
let
id
=
id
/
EXTRA_CHARS
.len
();
let
extra2
=
id
%
EXTRA_CHARS
.len
();
let
id
=
id
/
EXTRA_CHARS
.len
();
let
extra3
=
id
%
EXTRA_CHARS
.len
();
hash
.push
(
EXTRA_CHARS
.as_bytes
()[
extra1
]
as
char
);
hash
.push
(
EXTRA_CHARS
.as_bytes
()[
extra2
]
as
char
);
hash
.push
(
EXTRA_CHARS
.as_bytes
()[
extra3
]
as
char
);
exported_name
(
path
,
&
hash
[
..
])
}
pub
fn
mangle_internal_name_by_type_and_seq
<
'a
,
'tcx
>
(
ccx
:
&
CrateContext
<
'a
,
'tcx
>
,
t
:
Ty
<
'tcx
>
,
name
:
&
str
)
->
String
{
let
path
=
[
token
::
intern
(
&
t
.to_string
())
.as_str
(),
gensym_name
(
name
)
.as_str
()];
let
hash
=
get_symbol_hash
(
ccx
,
t
);
mangle
(
path
.iter
()
.cloned
(),
Some
(
&
hash
[
..
]))
}
pub
fn
mangle_internal_name_by_path_and_seq
(
path
:
DefPath
,
flav
:
&
str
)
->
String
{
let
names
=
path
.into_iter
()
.map
(|
e
|
e
.data
.as_interned_str
())
.chain
(
once
(
gensym_name
(
flav
)
.as_str
()));
// append unique version of "flav"
mangle
(
names
,
None
)
}
pub
fn
get_linker
(
sess
:
&
Session
)
->
(
String
,
Command
)
{
if
let
Some
(
ref
linker
)
=
sess
.opts.cg.linker
{
(
linker
.clone
(),
Command
::
new
(
linker
))
...
...
src/librustc_trans/trans/base.rs
浏览文件 @
7def3768
...
...
@@ -7,6 +7,7 @@
// <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.
//! Translate the completed AST to the LLVM IR.
//!
//! Some functions here, such as trans_block and trans_expr, return a value --
...
...
@@ -29,8 +30,7 @@
use
super
::
CrateTranslation
;
use
super
::
ModuleTranslation
;
use
back
::
link
::
mangle_exported_name
;
use
back
::
link
;
use
back
::{
link
,
symbol_names
};
use
lint
;
use
llvm
::{
BasicBlockRef
,
Linkage
,
ValueRef
,
Vector
,
get_param
};
use
llvm
;
...
...
@@ -2421,10 +2421,11 @@ fn create_entry_fn(ccx: &CrateContext,
}
pub
fn
exported_name
<
'a
,
'tcx
>
(
ccx
:
&
CrateContext
<
'a
,
'tcx
>
,
id
:
ast
::
NodeId
,
ty
:
Ty
<
'tcx
>
,
instance
:
Instance
<
'tcx
>
,
attrs
:
&
[
ast
::
Attribute
])
->
String
{
let
id
=
ccx
.tcx
()
.map
.as_local_node_id
(
instance
.def
)
.unwrap
();
match
ccx
.external_srcs
()
.borrow
()
.get
(
&
id
)
{
Some
(
&
did
)
=>
{
let
sym
=
ccx
.sess
()
.cstore
.item_symbol
(
did
);
...
...
@@ -2438,16 +2439,16 @@ pub fn exported_name<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// Use provided name
Some
(
name
)
=>
name
.to_string
(),
_
=>
{
let
path
=
ccx
.tcx
()
.map
.def_path_from_id
(
id
);
if
attr
::
contains_name
(
attrs
,
"no_mangle"
)
{
// Don't mangle
let
path
=
ccx
.tcx
()
.map
.def_path_from_id
(
id
);
path
.last
()
.unwrap
()
.data
.to_string
()
}
else
{
match
weak_lang_items
::
link_name
(
attrs
)
{
Some
(
name
)
=>
name
.to_string
(),
None
=>
{
// Usual name mangling
mangle_exported_name
(
ccx
,
path
,
ty
,
id
)
symbol_names
::
exported_name
(
ccx
,
&
instance
)
}
}
}
...
...
src/librustc_trans/trans/callee.rs
浏览文件 @
7def3768
...
...
@@ -515,7 +515,7 @@ fn is_named_tuple_constructor(tcx: &TyCtxt, def_id: DefId) -> bool {
Some
(
hir_map
::
NodeImplItem
(
&
hir
::
ImplItem
{
ref
attrs
,
id
,
span
,
node
:
hir
::
ImplItemKind
::
Method
(
..
),
..
}))
=>
{
let
sym
=
exported_name
(
ccx
,
i
d
,
ty
,
attrs
);
let
sym
=
exported_name
(
ccx
,
i
nstance
,
attrs
);
if
declare
::
get_defined_value
(
ccx
,
&
sym
)
.is_some
()
{
ccx
.sess
()
.span_fatal
(
span
,
...
...
src/librustc_trans/trans/consts.rs
浏览文件 @
7def3768
...
...
@@ -1032,7 +1032,7 @@ pub fn get_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, def_id: DefId)
// we need to get the symbol from metadata instead of
// using the current crate's name/version
// information in the hash of the symbol
let
sym
=
exported_name
(
ccx
,
i
d
,
ty
,
attrs
);
let
sym
=
exported_name
(
ccx
,
i
nstance
,
attrs
);
debug!
(
"making {}"
,
sym
);
// Create the global before evaluating the initializer;
...
...
src/test/auxiliary/issue-17718.rs
→
src/test/auxiliary/issue-17718
-aux
.rs
浏览文件 @
7def3768
文件已移动
src/test/run-pass/backtrace.rs
浏览文件 @
7def3768
...
...
@@ -57,7 +57,7 @@ fn runtest(me: &str) {
let
out
=
p
.wait_with_output
()
.unwrap
();
assert
!
(
!
out
.status
.success
());
let
s
=
str
::
from_utf8
(
&
out
.stderr
)
.unwrap
();
assert
!
(
s
.contains
(
"stack backtrace"
)
&&
s
.contains
(
" - foo"
),
assert
!
(
s
.contains
(
"stack backtrace"
)
&&
s
.contains
(
" -
backtrace::
foo"
),
"bad output: {}"
,
s
);
// Make sure the stack trace is *not* printed
...
...
@@ -67,7 +67,7 @@ fn runtest(me: &str) {
let
out
=
p
.wait_with_output
()
.unwrap
();
assert
!
(
!
out
.status
.success
());
let
s
=
str
::
from_utf8
(
&
out
.stderr
)
.unwrap
();
assert
!
(
!
s
.contains
(
"stack backtrace"
)
&&
!
s
.contains
(
" - foo"
),
assert
!
(
!
s
.contains
(
"stack backtrace"
)
&&
!
s
.contains
(
" -
backtrace::
foo"
),
"bad output2: {}"
,
s
);
// Make sure a stack trace is printed
...
...
@@ -77,7 +77,7 @@ fn runtest(me: &str) {
let
s
=
str
::
from_utf8
(
&
out
.stderr
)
.unwrap
();
// loosened the following from double::h to double:: due to
// spurious failures on mac, 32bit, optimized
assert
!
(
s
.contains
(
"stack backtrace"
)
&&
s
.contains
(
" - double"
),
assert
!
(
s
.contains
(
"stack backtrace"
)
&&
s
.contains
(
" -
backtrace::
double"
),
"bad output3: {}"
,
s
);
// Make sure a stack trace isn't printed too many times
...
...
src/test/run-pass/issue-17718.rs
浏览文件 @
7def3768
...
...
@@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:issue-17718.rs
// aux-build:issue-17718
-aux
.rs
#![feature(core)]
#![feature(const_fn)]
extern
crate
issue_17718
as
other
;
extern
crate
issue_17718
_aux
as
other
;
use
std
::
sync
::
atomic
::{
AtomicUsize
,
Ordering
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录