Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a1d45d94
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,发现更多精彩内容 >>
提交
a1d45d94
编写于
10月 27, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor `explicitly_linked: bool` -> `dep_kind: DepKind`.
上级
c102d7fb
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
43 addition
and
36 deletion
+43
-36
src/librustc/middle/cstore.rs
src/librustc/middle/cstore.rs
+12
-2
src/librustc/middle/dependency_format.rs
src/librustc/middle/dependency_format.rs
+3
-2
src/librustc_metadata/creader.rs
src/librustc_metadata/creader.rs
+17
-16
src/librustc_metadata/cstore.rs
src/librustc_metadata/cstore.rs
+2
-7
src/librustc_metadata/cstore_impl.rs
src/librustc_metadata/cstore_impl.rs
+6
-6
src/librustc_metadata/encoder.rs
src/librustc_metadata/encoder.rs
+1
-1
src/librustc_metadata/schema.rs
src/librustc_metadata/schema.rs
+2
-2
未找到文件。
src/librustc/middle/cstore.rs
浏览文件 @
a1d45d94
...
...
@@ -63,6 +63,16 @@ pub struct CrateSource {
pub
rlib
:
Option
<
(
PathBuf
,
PathKind
)
>
,
}
#[derive(RustcEncodable,
RustcDecodable,
Copy,
Clone,
Ord,
PartialOrd,
Eq,
PartialEq,
Debug)]
pub
enum
DepKind
{
/// A dependency that is always injected into the dependency list and so
/// doesn't need to be linked to an rlib, e.g. the injected allocator.
Implicit
,
/// A dependency that is required by an rlib version of this crate.
/// Ordinary `extern crate`s result in `Explicit` dependencies.
Explicit
,
}
#[derive(Copy,
Debug,
PartialEq,
Clone,
RustcEncodable,
RustcDecodable)]
pub
enum
LinkagePreference
{
RequireDynamic
,
...
...
@@ -169,10 +179,10 @@ fn associated_item<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
// crate metadata
fn
dylib_dependency_formats
(
&
self
,
cnum
:
CrateNum
)
->
Vec
<
(
CrateNum
,
LinkagePreference
)
>
;
fn
dep_kind
(
&
self
,
cnum
:
CrateNum
)
->
DepKind
;
fn
lang_items
(
&
self
,
cnum
:
CrateNum
)
->
Vec
<
(
DefIndex
,
usize
)
>
;
fn
missing_lang_items
(
&
self
,
cnum
:
CrateNum
)
->
Vec
<
lang_items
::
LangItem
>
;
fn
is_staged_api
(
&
self
,
cnum
:
CrateNum
)
->
bool
;
fn
is_explicitly_linked
(
&
self
,
cnum
:
CrateNum
)
->
bool
;
fn
is_allocator
(
&
self
,
cnum
:
CrateNum
)
->
bool
;
fn
is_panic_runtime
(
&
self
,
cnum
:
CrateNum
)
->
bool
;
fn
is_compiler_builtins
(
&
self
,
cnum
:
CrateNum
)
->
bool
;
...
...
@@ -341,7 +351,7 @@ fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>
fn
missing_lang_items
(
&
self
,
cnum
:
CrateNum
)
->
Vec
<
lang_items
::
LangItem
>
{
bug!
(
"missing_lang_items"
)
}
fn
is_staged_api
(
&
self
,
cnum
:
CrateNum
)
->
bool
{
bug!
(
"is_staged_api"
)
}
fn
is_explicitly_linked
(
&
self
,
cnum
:
CrateNum
)
->
bool
{
bug!
(
"is_explicitly_linked"
)
}
fn
dep_kind
(
&
self
,
cnum
:
CrateNum
)
->
DepKind
{
bug!
(
"is_explicitly_linked"
)
}
fn
is_allocator
(
&
self
,
cnum
:
CrateNum
)
->
bool
{
bug!
(
"is_allocator"
)
}
fn
is_panic_runtime
(
&
self
,
cnum
:
CrateNum
)
->
bool
{
bug!
(
"is_panic_runtime"
)
}
fn
is_compiler_builtins
(
&
self
,
cnum
:
CrateNum
)
->
bool
{
bug!
(
"is_compiler_builtins"
)
}
...
...
src/librustc/middle/dependency_format.rs
浏览文件 @
a1d45d94
...
...
@@ -65,6 +65,7 @@
use
session
;
use
session
::
config
;
use
middle
::
cstore
::
DepKind
;
use
middle
::
cstore
::
LinkagePreference
::{
self
,
RequireStatic
,
RequireDynamic
};
use
util
::
nodemap
::
FxHashMap
;
use
rustc_back
::
PanicStrategy
;
...
...
@@ -188,7 +189,7 @@ fn calculate_type(sess: &session::Session,
let
src
=
sess
.cstore
.used_crate_source
(
cnum
);
if
src
.dylib
.is_none
()
&&
!
formats
.contains_key
(
&
cnum
)
&&
sess
.cstore
.
is_explicitly_linked
(
cnum
)
{
sess
.cstore
.
dep_kind
(
cnum
)
==
DepKind
::
Explicit
{
assert
!
(
src
.rlib
.is_some
());
info!
(
"adding staticlib: {}"
,
sess
.cstore
.crate_name
(
cnum
));
add_library
(
sess
,
cnum
,
RequireStatic
,
&
mut
formats
);
...
...
@@ -272,7 +273,7 @@ fn attempt_static(sess: &session::Session) -> Option<DependencyList> {
// everything in explicitly so long as it's actually required.
let
last_crate
=
sess
.cstore
.crates
()
.len
();
let
mut
ret
=
(
1
..
last_crate
+
1
)
.map
(|
cnum
|
{
if
sess
.cstore
.
is_explicitly_linked
(
CrateNum
::
new
(
cnum
))
{
if
sess
.cstore
.
dep_kind
(
CrateNum
::
new
(
cnum
))
==
DepKind
::
Explicit
{
Linkage
::
Static
}
else
{
Linkage
::
NotLinked
...
...
src/librustc_metadata/creader.rs
浏览文件 @
a1d45d94
...
...
@@ -16,7 +16,7 @@
use
rustc
::
hir
::
def_id
::{
CrateNum
,
DefIndex
};
use
rustc
::
hir
::
svh
::
Svh
;
use
rustc
::
middle
::
cstore
::
LoadedMacros
;
use
rustc
::
middle
::
cstore
::
{
DepKind
,
LoadedMacros
}
;
use
rustc
::
session
::{
config
,
Session
};
use
rustc_back
::
PanicStrategy
;
use
rustc
::
session
::
search_paths
::
PathKind
;
...
...
@@ -29,7 +29,7 @@
use
std
::
ops
::
Deref
;
use
std
::
path
::
PathBuf
;
use
std
::
rc
::
Rc
;
use
std
::
fs
;
use
std
::
{
cmp
,
fs
}
;
use
syntax
::
ast
;
use
syntax
::
abi
::
Abi
;
...
...
@@ -60,7 +60,7 @@ fn dump_crates(cstore: &CStore) {
info!
(
" name: {}"
,
data
.name
());
info!
(
" cnum: {}"
,
data
.cnum
);
info!
(
" hash: {}"
,
data
.hash
());
info!
(
" reqd: {
}"
,
data
.explicitly_linke
d
.get
());
info!
(
" reqd: {
:?}"
,
data
.dep_kin
d
.get
());
let
CrateSource
{
dylib
,
rlib
}
=
data
.source
.clone
();
dylib
.map
(|
dl
|
info!
(
" dylib: {}"
,
dl
.0
.display
()));
rlib
.map
(|
rl
|
info!
(
" rlib: {}"
,
rl
.0
.display
()));
...
...
@@ -258,7 +258,7 @@ fn register_crate(&mut self,
name
:
&
str
,
span
:
Span
,
lib
:
Library
,
explicitly_linked
:
bool
)
dep_kind
:
DepKind
)
->
(
CrateNum
,
Rc
<
cstore
::
CrateMetadata
>
)
{
info!
(
"register crate `extern crate {} as {}`"
,
name
,
ident
);
let
crate_root
=
lib
.metadata
.get_root
();
...
...
@@ -299,7 +299,7 @@ fn register_crate(&mut self,
cnum_map
:
RefCell
::
new
(
cnum_map
),
cnum
:
cnum
,
codemap_import_info
:
RefCell
::
new
(
vec!
[]),
explicitly_linked
:
Cell
::
new
(
explicitly_linke
d
),
dep_kind
:
Cell
::
new
(
dep_kin
d
),
source
:
cstore
::
CrateSource
{
dylib
:
dylib
,
rlib
:
rlib
,
...
...
@@ -317,7 +317,7 @@ fn resolve_crate(&mut self,
hash
:
Option
<&
Svh
>
,
span
:
Span
,
kind
:
PathKind
,
explicitly_linked
:
bool
)
dep_kind
:
DepKind
)
->
(
CrateNum
,
Rc
<
cstore
::
CrateMetadata
>
)
{
info!
(
"resolving crate `extern crate {} as {}`"
,
name
,
ident
);
let
result
=
match
self
.existing_match
(
name
,
hash
,
kind
)
{
...
...
@@ -350,12 +350,11 @@ fn resolve_crate(&mut self,
match
result
{
LoadResult
::
Previous
(
cnum
)
=>
{
let
data
=
self
.cstore
.get_crate_data
(
cnum
);
data
.
explicitly_linked
.set
(
explicitly_linked
||
data
.explicitly_linked
.get
(
));
data
.
dep_kind
.set
(
cmp
::
max
(
data
.dep_kind
.get
(),
dep_kind
));
(
cnum
,
data
)
}
LoadResult
::
Loaded
(
library
)
=>
{
self
.register_crate
(
root
,
ident
,
name
,
span
,
library
,
explicitly_linked
)
self
.register_crate
(
root
,
ident
,
name
,
span
,
library
,
dep_kind
)
}
}
}
...
...
@@ -442,7 +441,7 @@ fn resolve_crate_deps(&mut self,
Some
(
&
dep
.hash
),
span
,
PathKind
::
Dependency
,
dep
.
explicitly_linke
d
);
dep
.
kin
d
);
(
CrateNum
::
new
(
crate_num
+
1
),
local_cnum
)
})
.collect
();
...
...
@@ -716,7 +715,7 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
// #![panic_runtime] crate.
self
.inject_dependency_if
(
cnum
,
"a panic runtime"
,
&
|
data
|
data
.needs_panic_runtime
());
runtime_found
=
runtime_found
||
data
.
explicitly_linked
.get
()
;
runtime_found
=
runtime_found
||
data
.
dep_kind
.get
()
==
DepKind
::
Explicit
;
}
});
...
...
@@ -745,8 +744,9 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
};
info!
(
"panic runtime not found -- loading {}"
,
name
);
let
dep_kind
=
DepKind
::
Implicit
;
let
(
cnum
,
data
)
=
self
.resolve_crate
(
&
None
,
name
,
name
,
None
,
DUMMY_SP
,
PathKind
::
Crate
,
false
);
self
.resolve_crate
(
&
None
,
name
,
name
,
None
,
DUMMY_SP
,
PathKind
::
Crate
,
dep_kind
);
// Sanity check the loaded crate to ensure it is indeed a panic runtime
// and the panic strategy is indeed what we thought it was.
...
...
@@ -780,7 +780,7 @@ fn inject_allocator_crate(&mut self) {
self
.inject_dependency_if
(
cnum
,
"an allocator"
,
&
|
data
|
data
.needs_allocator
());
found_required_allocator
=
found_required_allocator
||
data
.
explicitly_linked
.get
()
;
data
.
dep_kind
.get
()
==
DepKind
::
Explicit
;
}
});
if
!
needs_allocator
||
found_required_allocator
{
return
}
...
...
@@ -826,8 +826,9 @@ fn inject_allocator_crate(&mut self) {
}
else
{
&
self
.sess.target.target.options.exe_allocation_crate
};
let
dep_kind
=
DepKind
::
Implicit
;
let
(
cnum
,
data
)
=
self
.resolve_crate
(
&
None
,
name
,
name
,
None
,
DUMMY_SP
,
PathKind
::
Crate
,
false
);
self
.resolve_crate
(
&
None
,
name
,
name
,
None
,
DUMMY_SP
,
PathKind
::
Crate
,
dep_kind
);
// Sanity check the crate we loaded to ensure that it is indeed an
// allocator.
...
...
@@ -993,7 +994,7 @@ fn process_item(&mut self, item: &ast::Item, definitions: &Definitions, load_mac
if
let
PMDSource
::
Owned
(
lib
)
=
ekrate
.metadata
{
if
ekrate
.target_only
||
config
::
host_triple
()
==
self
.sess.opts.target_triple
{
let
ExternCrateInfo
{
ref
ident
,
ref
name
,
..
}
=
info
;
self
.register_crate
(
&
None
,
ident
,
name
,
item
.span
,
lib
,
true
);
self
.register_crate
(
&
None
,
ident
,
name
,
item
.span
,
lib
,
DepKind
::
Explicit
);
}
}
...
...
@@ -1006,7 +1007,7 @@ fn process_item(&mut self, item: &ast::Item, definitions: &Definitions, load_mac
};
let
(
cnum
,
..
)
=
self
.resolve_crate
(
&
None
,
&
info
.ident
,
&
info
.name
,
None
,
item
.span
,
PathKind
::
Crate
,
true
,
&
None
,
&
info
.ident
,
&
info
.name
,
None
,
item
.span
,
PathKind
::
Crate
,
DepKind
::
Explicit
,
);
let
def_id
=
definitions
.opt_local_def_id
(
item
.id
)
.unwrap
();
...
...
src/librustc_metadata/cstore.rs
浏览文件 @
a1d45d94
...
...
@@ -18,7 +18,7 @@
use
rustc
::
hir
::
def_id
::{
CRATE_DEF_INDEX
,
CrateNum
,
DefIndex
,
DefId
};
use
rustc
::
hir
::
map
::
DefKey
;
use
rustc
::
hir
::
svh
::
Svh
;
use
rustc
::
middle
::
cstore
::
ExternCrate
;
use
rustc
::
middle
::
cstore
::
{
DepKind
,
ExternCrate
}
;
use
rustc_back
::
PanicStrategy
;
use
rustc_data_structures
::
indexed_vec
::
IndexVec
;
use
rustc
::
util
::
nodemap
::{
FxHashMap
,
NodeMap
,
NodeSet
,
DefIdMap
};
...
...
@@ -78,12 +78,7 @@ pub struct CrateMetadata {
/// compilation support.
pub
key_map
:
FxHashMap
<
DefKey
,
DefIndex
>
,
/// Flag if this crate is required by an rlib version of this crate, or in
/// other words whether it was explicitly linked to. An example of a crate
/// where this is false is when an allocator crate is injected into the
/// dependency list, and therefore isn't actually needed to link an rlib.
pub
explicitly_linked
:
Cell
<
bool
>
,
pub
dep_kind
:
Cell
<
DepKind
>
,
pub
source
:
CrateSource
,
}
...
...
src/librustc_metadata/cstore_impl.rs
浏览文件 @
a1d45d94
...
...
@@ -13,7 +13,7 @@
use
locator
;
use
schema
;
use
rustc
::
middle
::
cstore
::{
InlinedItem
,
CrateStore
,
CrateSource
,
ExternCrate
};
use
rustc
::
middle
::
cstore
::{
InlinedItem
,
CrateStore
,
CrateSource
,
DepKind
,
ExternCrate
};
use
rustc
::
middle
::
cstore
::{
NativeLibraryKind
,
LinkMeta
,
LinkagePreference
};
use
rustc
::
hir
::
def
::{
self
,
Def
};
use
rustc
::
middle
::
lang_items
;
...
...
@@ -221,6 +221,11 @@ fn dylib_dependency_formats(&self, cnum: CrateNum)
self
.get_crate_data
(
cnum
)
.get_dylib_dependency_formats
()
}
fn
dep_kind
(
&
self
,
cnum
:
CrateNum
)
->
DepKind
{
self
.get_crate_data
(
cnum
)
.dep_kind
.get
()
}
fn
lang_items
(
&
self
,
cnum
:
CrateNum
)
->
Vec
<
(
DefIndex
,
usize
)
>
{
self
.get_crate_data
(
cnum
)
.get_lang_items
()
...
...
@@ -237,11 +242,6 @@ fn is_staged_api(&self, cnum: CrateNum) -> bool
self
.get_crate_data
(
cnum
)
.is_staged_api
()
}
fn
is_explicitly_linked
(
&
self
,
cnum
:
CrateNum
)
->
bool
{
self
.get_crate_data
(
cnum
)
.explicitly_linked
.get
()
}
fn
is_allocator
(
&
self
,
cnum
:
CrateNum
)
->
bool
{
self
.get_crate_data
(
cnum
)
.is_allocator
()
...
...
src/librustc_metadata/encoder.rs
浏览文件 @
a1d45d94
...
...
@@ -1080,7 +1080,7 @@ fn get_ordered_deps(cstore: &cstore::CStore) -> Vec<(CrateNum, Rc<cstore::CrateM
CrateDep
{
name
:
syntax
::
parse
::
token
::
intern
(
dep
.name
()),
hash
:
dep
.hash
(),
explicitly_linked
:
dep
.explicitly_linke
d
.get
(),
kind
:
dep
.dep_kin
d
.get
(),
}
}))
}
...
...
src/librustc_metadata/schema.rs
浏览文件 @
a1d45d94
...
...
@@ -14,7 +14,7 @@
use
rustc
::
hir
;
use
rustc
::
hir
::
def
::{
self
,
CtorKind
};
use
rustc
::
hir
::
def_id
::{
DefIndex
,
DefId
};
use
rustc
::
middle
::
cstore
::{
LinkagePreference
,
NativeLibraryKind
};
use
rustc
::
middle
::
cstore
::{
DepKind
,
LinkagePreference
,
NativeLibraryKind
};
use
rustc
::
middle
::
lang_items
;
use
rustc
::
mir
;
use
rustc
::
ty
::{
self
,
Ty
};
...
...
@@ -187,7 +187,7 @@ pub struct CrateRoot {
pub
struct
CrateDep
{
pub
name
:
ast
::
Name
,
pub
hash
:
hir
::
svh
::
Svh
,
pub
explicitly_linked
:
bool
,
pub
kind
:
DepKind
,
}
#[derive(RustcEncodable,
RustcDecodable)]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录