Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c1df945a
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,发现更多精彩内容 >>
提交
c1df945a
编写于
3月 03, 2020
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc_metadata: Give decoder access to whole crate store
上级
c79f5f06
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
22 deletion
+43
-22
src/librustc_metadata/creader.rs
src/librustc_metadata/creader.rs
+20
-4
src/librustc_metadata/rmeta/decoder.rs
src/librustc_metadata/rmeta/decoder.rs
+22
-17
src/librustc_metadata/rmeta/decoder/cstore_impl.rs
src/librustc_metadata/rmeta/decoder/cstore_impl.rs
+1
-1
未找到文件。
src/librustc_metadata/creader.rs
浏览文件 @
c1df945a
...
...
@@ -76,6 +76,21 @@ fn report(self) -> ! {
}
}
/// A reference to `CrateMetadata` that can also give access to whole crate store when necessary.
#[derive(Clone,
Copy)]
crate
struct
CrateMetadataRef
<
'a
>
{
pub
cdata
:
&
'a
CrateMetadata
,
pub
cstore
:
&
'a
CStore
,
}
impl
std
::
ops
::
Deref
for
CrateMetadataRef
<
'_
>
{
type
Target
=
CrateMetadata
;
fn
deref
(
&
self
)
->
&
Self
::
Target
{
self
.cdata
}
}
fn
dump_crates
(
cstore
:
&
CStore
)
{
info!
(
"resolved crates:"
);
cstore
.iter_crate_data
(|
cnum
,
data
|
{
...
...
@@ -100,10 +115,11 @@ fn alloc_new_crate_num(&mut self) -> CrateNum {
CrateNum
::
new
(
self
.metas
.len
()
-
1
)
}
crate
fn
get_crate_data
(
&
self
,
cnum
:
CrateNum
)
->
&
CrateMetadata
{
self
.metas
[
cnum
]
crate
fn
get_crate_data
(
&
self
,
cnum
:
CrateNum
)
->
CrateMetadataRef
<
'_
>
{
let
cdata
=
self
.metas
[
cnum
]
.as_ref
()
.unwrap_or_else
(||
panic!
(
"Failed to get crate data for {:?}"
,
cnum
))
.unwrap_or_else
(||
panic!
(
"Failed to get crate data for {:?}"
,
cnum
));
CrateMetadataRef
{
cdata
,
cstore
:
self
}
}
fn
set_crate_data
(
&
mut
self
,
cnum
:
CrateNum
,
data
:
CrateMetadata
)
{
...
...
@@ -217,7 +233,7 @@ fn existing_match(&self, name: Symbol, hash: Option<Svh>, kind: PathKind) -> Opt
// We're also sure to compare *paths*, not actual byte slices. The
// `source` stores paths which are normalized which may be different
// from the strings on the command line.
let
source
=
self
.cstore
.get_crate_data
(
cnum
)
.source
();
let
source
=
self
.cstore
.get_crate_data
(
cnum
)
.
cdata
.
source
();
if
let
Some
(
entry
)
=
self
.sess.opts.externs
.get
(
&
name
.as_str
())
{
// Only use `--extern crate_name=path` here, not `--extern crate_name`.
if
let
Some
(
mut
files
)
=
entry
.files
()
{
...
...
src/librustc_metadata/rmeta/decoder.rs
浏览文件 @
c1df945a
// Decoding metadata from a single crate's metadata
use
crate
::
creader
::
CrateMetadataRef
;
use
crate
::
rmeta
::
table
::{
FixedSizeEncoding
,
Table
};
use
crate
::
rmeta
::
*
;
...
...
@@ -125,7 +126,7 @@ struct ImportedSourceFile {
pub
(
super
)
struct
DecodeContext
<
'a
,
'tcx
>
{
opaque
:
opaque
::
Decoder
<
'a
>
,
cdata
:
Option
<
&
'a
CrateMetadata
>
,
cdata
:
Option
<
CrateMetadataRef
<
'a
>
>
,
sess
:
Option
<&
'tcx
Session
>
,
tcx
:
Option
<
TyCtxt
<
'tcx
>>
,
...
...
@@ -141,7 +142,7 @@ pub(super) struct DecodeContext<'a, 'tcx> {
/// Abstract over the various ways one can create metadata decoders.
pub
(
super
)
trait
Metadata
<
'a
,
'tcx
>
:
Copy
{
fn
raw_bytes
(
self
)
->
&
'a
[
u8
];
fn
cdata
(
self
)
->
Option
<
&
'a
CrateMetadata
>
{
fn
cdata
(
self
)
->
Option
<
CrateMetadataRef
<
'a
>
>
{
None
}
fn
sess
(
self
)
->
Option
<&
'tcx
Session
>
{
...
...
@@ -162,7 +163,7 @@ fn decoder(self, pos: usize) -> DecodeContext<'a, 'tcx> {
lazy_state
:
LazyState
::
NoNode
,
alloc_decoding_session
:
self
.cdata
()
.map
(|
cdata
|
cdata
.alloc_decoding_state
.new_decoding_session
()),
.map
(|
cdata
|
cdata
.
cdata.
alloc_decoding_state
.new_decoding_session
()),
}
}
}
...
...
@@ -185,33 +186,33 @@ fn sess(self) -> Option<&'tcx Session> {
}
}
impl
<
'a
,
'tcx
>
Metadata
<
'a
,
'tcx
>
for
&
'a
CrateMetadata
{
impl
<
'a
,
'tcx
>
Metadata
<
'a
,
'tcx
>
for
&
'a
CrateMetadata
Ref
<
'a
>
{
fn
raw_bytes
(
self
)
->
&
'a
[
u8
]
{
self
.blob
.raw_bytes
()
}
fn
cdata
(
self
)
->
Option
<
&
'a
CrateMetadata
>
{
Some
(
self
)
fn
cdata
(
self
)
->
Option
<
CrateMetadataRef
<
'a
>
>
{
Some
(
*
self
)
}
}
impl
<
'a
,
'tcx
>
Metadata
<
'a
,
'tcx
>
for
(
&
'a
CrateMetadata
,
&
'tcx
Session
)
{
impl
<
'a
,
'tcx
>
Metadata
<
'a
,
'tcx
>
for
(
&
'a
CrateMetadata
Ref
<
'a
>
,
&
'tcx
Session
)
{
fn
raw_bytes
(
self
)
->
&
'a
[
u8
]
{
self
.0
.raw_bytes
()
}
fn
cdata
(
self
)
->
Option
<
&
'a
CrateMetadata
>
{
Some
(
self
.0
)
fn
cdata
(
self
)
->
Option
<
CrateMetadataRef
<
'a
>
>
{
Some
(
*
self
.0
)
}
fn
sess
(
self
)
->
Option
<&
'tcx
Session
>
{
Some
(
&
self
.1
)
}
}
impl
<
'a
,
'tcx
>
Metadata
<
'a
,
'tcx
>
for
(
&
'a
CrateMetadata
,
TyCtxt
<
'tcx
>
)
{
impl
<
'a
,
'tcx
>
Metadata
<
'a
,
'tcx
>
for
(
&
'a
CrateMetadata
Ref
<
'a
>
,
TyCtxt
<
'tcx
>
)
{
fn
raw_bytes
(
self
)
->
&
'a
[
u8
]
{
self
.0
.raw_bytes
()
}
fn
cdata
(
self
)
->
Option
<
&
'a
CrateMetadata
>
{
Some
(
self
.0
)
fn
cdata
(
self
)
->
Option
<
CrateMetadataRef
<
'a
>
>
{
Some
(
*
self
.0
)
}
fn
tcx
(
self
)
->
Option
<
TyCtxt
<
'tcx
>>
{
Some
(
self
.1
)
...
...
@@ -242,7 +243,7 @@ fn tcx(&self) -> TyCtxt<'tcx> {
self
.tcx
.expect
(
"missing TyCtxt in DecodeContext"
)
}
fn
cdata
(
&
self
)
->
&
'a
CrateMetadata
{
fn
cdata
(
&
self
)
->
CrateMetadataRef
<
'a
>
{
self
.cdata
.expect
(
"missing CrateMetadata in DecodeContext"
)
}
...
...
@@ -558,7 +559,7 @@ impl CrateRoot<'_> {
}
}
impl
<
'a
,
'tcx
>
CrateMetadata
{
impl
CrateMetadata
{
crate
fn
new
(
sess
:
&
Session
,
blob
:
MetadataBlob
,
...
...
@@ -601,7 +602,9 @@ impl<'a, 'tcx> CrateMetadata {
extern_crate
:
Lock
::
new
(
None
),
}
}
}
impl
<
'a
,
'tcx
>
CrateMetadataRef
<
'a
>
{
fn
is_proc_macro
(
&
self
,
id
:
DefIndex
)
->
bool
{
self
.root.proc_macro_data
.and_then
(|
data
|
data
.decode
(
self
)
.find
(|
x
|
*
x
==
id
))
.is_some
()
}
...
...
@@ -1440,10 +1443,10 @@ fn def_path_hash(&self, index: DefIndex) -> DefPathHash {
/// Proc macro crates don't currently export spans, so this function does not have
/// to work for them.
fn
imported_source_files
(
&
'a
self
,
&
self
,
local_source_map
:
&
source_map
::
SourceMap
,
)
->
&
[
ImportedSourceFile
]
{
self
.source_map_import_info
.init_locking
(||
{
)
->
&
'a
[
ImportedSourceFile
]
{
self
.
cdata.
source_map_import_info
.init_locking
(||
{
let
external_source_map
=
self
.root.source_map
.decode
(
self
);
external_source_map
...
...
@@ -1540,7 +1543,9 @@ fn get_crate_dep_node_index(&self, tcx: TyCtxt<'tcx>) -> DepNodeIndex {
dep_node_index
}
}
impl
CrateMetadata
{
crate
fn
dependencies
(
&
self
)
->
LockGuard
<
'_
,
Vec
<
CrateNum
>>
{
self
.dependencies
.borrow
()
}
...
...
src/librustc_metadata/rmeta/decoder/cstore_impl.rs
浏览文件 @
c1df945a
...
...
@@ -517,7 +517,7 @@ fn def_path_hash(&self, def: DefId) -> DefPathHash {
}
fn
def_path_table
(
&
self
,
cnum
:
CrateNum
)
->
&
DefPathTable
{
&
self
.get_crate_data
(
cnum
)
.def_path_table
&
self
.get_crate_data
(
cnum
)
.
cdata.
def_path_table
}
fn
crates_untracked
(
&
self
)
->
Vec
<
CrateNum
>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录