Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
9be526e8
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,发现更多精彩内容 >>
提交
9be526e8
编写于
11月 24, 2019
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc_metadata: Move `has_global_allocator` from session to cstore
上级
4c8105e8
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
29 addition
and
28 deletion
+29
-28
src/librustc/middle/cstore.rs
src/librustc/middle/cstore.rs
+1
-0
src/librustc/session/mod.rs
src/librustc/session/mod.rs
+0
-4
src/librustc/ty/context.rs
src/librustc/ty/context.rs
+4
-0
src/librustc_metadata/creader.rs
src/librustc_metadata/creader.rs
+16
-17
src/librustc_metadata/rmeta/decoder/cstore_impl.rs
src/librustc_metadata/rmeta/decoder/cstore_impl.rs
+4
-0
src/librustc_metadata/rmeta/encoder.rs
src/librustc_metadata/rmeta/encoder.rs
+1
-2
src/libsyntax/expand/allocator.rs
src/libsyntax/expand/allocator.rs
+2
-4
src/test/ui/allocator/two-allocators3.stderr
src/test/ui/allocator/two-allocators3.stderr
+1
-1
未找到文件。
src/librustc/middle/cstore.rs
浏览文件 @
9be526e8
...
...
@@ -237,6 +237,7 @@ pub trait CrateStore {
fn
metadata_encoding_version
(
&
self
)
->
&
[
u8
];
fn
injected_panic_runtime
(
&
self
)
->
Option
<
CrateNum
>
;
fn
allocator_kind
(
&
self
)
->
Option
<
AllocatorKind
>
;
fn
has_global_allocator
(
&
self
)
->
bool
;
}
pub
type
CrateStoreDyn
=
dyn
CrateStore
+
sync
::
Sync
;
...
...
src/librustc/session/mod.rs
浏览文件 @
9be526e8
...
...
@@ -133,9 +133,6 @@ pub struct Session {
/// false positives about a job server in our environment.
pub
jobserver
:
Client
,
/// Metadata about the allocators for the current crate being compiled.
pub
has_global_allocator
:
Once
<
bool
>
,
/// Cap lint level specified by a driver specifically.
pub
driver_lint_caps
:
FxHashMap
<
lint
::
LintId
,
lint
::
Level
>
,
...
...
@@ -1180,7 +1177,6 @@ fn build_session_(
print_fuel_crate
,
print_fuel
,
jobserver
:
jobserver
::
client
(),
has_global_allocator
:
Once
::
new
(),
driver_lint_caps
,
trait_methods_not_found
:
Lock
::
new
(
Default
::
default
()),
confused_type_with_std_module
:
Lock
::
new
(
Default
::
default
()),
...
...
src/librustc/ty/context.rs
浏览文件 @
9be526e8
...
...
@@ -3028,4 +3028,8 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
// We want to check if the panic handler was defined in this crate
tcx
.lang_items
()
.panic_impl
()
.map_or
(
false
,
|
did
|
did
.is_local
())
};
providers
.has_global_allocator
=
|
tcx
,
cnum
|
{
assert_eq!
(
cnum
,
LOCAL_CRATE
);
tcx
.cstore
.has_global_allocator
()
};
}
src/librustc_metadata/creader.rs
浏览文件 @
9be526e8
...
...
@@ -37,7 +37,11 @@
pub
struct
CStore
{
metas
:
IndexVec
<
CrateNum
,
Option
<
Lrc
<
CrateMetadata
>>>
,
injected_panic_runtime
:
Option
<
CrateNum
>
,
/// This crate needs an allocator and either provides it itself, or finds it in a dependency.
/// If the above is true, then this field denotes the kind of the found allocator.
allocator_kind
:
Option
<
AllocatorKind
>
,
/// This crate has a `#[global_allocator]` item.
has_global_allocator
:
bool
,
}
pub
struct
CrateLoader
<
'a
>
{
...
...
@@ -150,6 +154,10 @@ fn crate_dependencies_in_reverse_postorder(&self, cnum: CrateNum) -> Vec<CrateNu
crate
fn
allocator_kind
(
&
self
)
->
Option
<
AllocatorKind
>
{
self
.allocator_kind
}
crate
fn
has_global_allocator
(
&
self
)
->
bool
{
self
.has_global_allocator
}
}
impl
<
'a
>
CrateLoader
<
'a
>
{
...
...
@@ -170,6 +178,7 @@ pub fn new(
metas
:
IndexVec
::
from_elem_n
(
None
,
1
),
injected_panic_runtime
:
None
,
allocator_kind
:
None
,
has_global_allocator
:
false
,
}
}
}
...
...
@@ -562,7 +571,6 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
});
if
!
any_non_rlib
{
info!
(
"panic runtime injection skipped, only generating rlib"
);
self
.cstore.injected_panic_runtime
=
None
;
return
}
...
...
@@ -593,7 +601,6 @@ fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
// we just don't need one at all, then we're done here and there's
// nothing else to do.
if
!
needs_panic_runtime
||
runtime_found
{
self
.cstore.injected_panic_runtime
=
None
;
return
}
...
...
@@ -753,7 +760,7 @@ fn inject_profiler_runtime(&mut self) {
}
fn
inject_allocator_crate
(
&
mut
self
,
krate
:
&
ast
::
Crate
)
{
let
has_global_allocator
=
match
&*
global_allocator_spans
(
krate
)
{
self
.cstore.
has_global_allocator
=
match
&*
global_allocator_spans
(
krate
)
{
[
span1
,
span2
,
..
]
=>
{
self
.sess
.struct_span_err
(
*
span2
,
"cannot define multiple global allocators"
)
.span_label
(
*
span2
,
"cannot define a new global allocator"
)
...
...
@@ -763,7 +770,6 @@ fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
}
spans
=>
!
spans
.is_empty
()
};
self
.sess.has_global_allocator
.set
(
has_global_allocator
);
// Check to see if we actually need an allocator. This desire comes
// about through the `#![needs_allocator]` attribute and is typically
...
...
@@ -774,7 +780,6 @@ fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
needs_allocator
=
needs_allocator
||
data
.needs_allocator
();
});
if
!
needs_allocator
{
self
.cstore.allocator_kind
=
None
;
return
}
...
...
@@ -790,7 +795,6 @@ fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
}
});
if
all_rlib
{
self
.cstore.allocator_kind
=
None
;
return
}
...
...
@@ -801,8 +805,8 @@ fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
// First up we check for global allocators. Look at the crate graph here
// and see what's a global allocator, including if we ourselves are a
// global allocator.
let
mut
global_allocator
=
if
has_global_allocator
{
Some
(
None
)
let
mut
global_allocator
=
if
self
.cstore.
has_global_allocator
{
Some
(
Symbol
::
intern
(
"this crate"
)
)
}
else
{
None
};
...
...
@@ -811,19 +815,14 @@ fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
return
}
match
global_allocator
{
Some
(
Some
(
other_crate
)
)
=>
{
Some
(
other_crate
)
=>
{
self
.sess
.err
(
&
format!
(
"the `#[global_allocator]` in {}
\
conflicts with
this
global
\
conflicts with global
\
allocator in: {}"
,
other_crate
,
data
.name
()));
}
Some
(
None
)
=>
{
self
.sess
.err
(
&
format!
(
"the `#[global_allocator]` in this
\
crate conflicts with global
\
allocator in: {}"
,
data
.name
()));
}
None
=>
global_allocator
=
Some
(
Some
(
data
.name
())),
None
=>
global_allocator
=
Some
(
data
.name
()),
}
});
if
global_allocator
.is_some
()
{
...
...
@@ -848,7 +847,7 @@ fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
add `#[global_allocator]` to a static item
\
that implements the GlobalAlloc trait."
);
}
self
.cstore.allocator_kind
=
Some
(
AllocatorKind
::
Default
Lib
);
self
.cstore.allocator_kind
=
Some
(
AllocatorKind
::
Default
);
}
fn
inject_dependency_if
(
&
self
,
...
...
src/librustc_metadata/rmeta/decoder/cstore_impl.rs
浏览文件 @
9be526e8
...
...
@@ -536,4 +536,8 @@ fn injected_panic_runtime(&self) -> Option<CrateNum> {
fn
allocator_kind
(
&
self
)
->
Option
<
AllocatorKind
>
{
self
.allocator_kind
()
}
fn
has_global_allocator
(
&
self
)
->
bool
{
self
.has_global_allocator
()
}
}
src/librustc_metadata/rmeta/encoder.rs
浏览文件 @
9be526e8
...
...
@@ -496,7 +496,6 @@ fn encode_crate_root(&mut self) -> Lazy<CrateRoot<'tcx>> {
let
attrs
=
tcx
.hir
()
.krate_attrs
();
let
has_default_lib_allocator
=
attr
::
contains_name
(
&
attrs
,
sym
::
default_lib_allocator
);
let
has_global_allocator
=
*
tcx
.sess.has_global_allocator
.get
();
let
root
=
self
.lazy
(
CrateRoot
{
name
:
tcx
.crate_name
(
LOCAL_CRATE
),
...
...
@@ -506,7 +505,7 @@ fn encode_crate_root(&mut self) -> Lazy<CrateRoot<'tcx>> {
disambiguator
:
tcx
.sess
.local_crate_disambiguator
(),
panic_strategy
:
tcx
.sess
.panic_strategy
(),
edition
:
tcx
.sess
.edition
(),
has_global_allocator
:
has_global_allocator
,
has_global_allocator
:
tcx
.has_global_allocator
(
LOCAL_CRATE
)
,
has_panic_handler
:
tcx
.has_panic_handler
(
LOCAL_CRATE
),
has_default_lib_allocator
:
has_default_lib_allocator
,
plugin_registrar_fn
:
tcx
.plugin_registrar_fn
(
LOCAL_CRATE
)
.map
(|
id
|
id
.index
),
...
...
src/libsyntax/expand/allocator.rs
浏览文件 @
9be526e8
...
...
@@ -5,16 +5,14 @@
#[derive(Clone,
Copy)]
pub
enum
AllocatorKind
{
Global
,
DefaultLib
,
DefaultExe
,
Default
,
}
impl
AllocatorKind
{
pub
fn
fn_name
(
&
self
,
base
:
&
str
)
->
String
{
match
*
self
{
AllocatorKind
::
Global
=>
format!
(
"__rg_{}"
,
base
),
AllocatorKind
::
DefaultLib
=>
format!
(
"__rdl_{}"
,
base
),
AllocatorKind
::
DefaultExe
=>
format!
(
"__rde_{}"
,
base
),
AllocatorKind
::
Default
=>
format!
(
"__rdl_{}"
,
base
),
}
}
}
...
...
src/test/ui/allocator/two-allocators3.stderr
浏览文件 @
9be526e8
error: the `#[global_allocator]` in system_allocator conflicts with
this
global allocator in: system_allocator2
error: the `#[global_allocator]` in system_allocator conflicts with global allocator in: system_allocator2
error: aborting due to previous error
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录