Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e7ceaa97
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,发现更多精彩内容 >>
提交
e7ceaa97
编写于
5月 22, 2019
作者:
E
Eduard-Mihai Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc_metadata: replace LazySeq<T> with Lazy<[T]>.
上级
7858dc23
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
301 addition
and
296 deletion
+301
-296
src/librustc_metadata/cstore.rs
src/librustc_metadata/cstore.rs
+4
-4
src/librustc_metadata/decoder.rs
src/librustc_metadata/decoder.rs
+19
-16
src/librustc_metadata/encoder.rs
src/librustc_metadata/encoder.rs
+195
-196
src/librustc_metadata/index.rs
src/librustc_metadata/index.rs
+5
-5
src/librustc_metadata/schema.rs
src/librustc_metadata/schema.rs
+78
-75
未找到文件。
src/librustc_metadata/cstore.rs
浏览文件 @
e7ceaa97
...
...
@@ -68,9 +68,9 @@ pub struct CrateMetadata {
pub
alloc_decoding_state
:
AllocDecodingState
,
// NOTE(eddyb) we pass `'static` to a `'tcx` parameter because this
// lifetime is only used behind `Lazy`
/ `LazySeq`, and therefore
//
acts like an universal (`for<'tcx>`), that is paired up with
//
whichever `TyCtxt`
is being used to decode those values.
// lifetime is only used behind `Lazy`
, and therefore acts like an
//
universal (`for<'tcx>`), that is paired up with whichever `TyCtxt`
// is being used to decode those values.
pub
root
:
schema
::
CrateRoot
<
'static
>
,
/// For each definition in this crate, we encode a key. When the
...
...
@@ -80,7 +80,7 @@ pub struct CrateMetadata {
/// compilation support.
pub
def_path_table
:
Lrc
<
DefPathTable
>
,
pub
trait_impls
:
FxHashMap
<
(
u32
,
DefIndex
),
schema
::
Lazy
Seq
<
DefIndex
>>
,
pub
trait_impls
:
FxHashMap
<
(
u32
,
DefIndex
),
schema
::
Lazy
<
[
DefIndex
]
>>
,
pub
dep_kind
:
Lock
<
DepKind
>
,
pub
source
:
CrateSource
,
...
...
src/librustc_metadata/decoder.rs
浏览文件 @
e7ceaa97
...
...
@@ -134,14 +134,14 @@ pub fn decode<M: Metadata<'a, 'tcx>>(self, meta: M) -> T {
}
}
impl
<
'a
:
'x
,
'tcx
:
'x
,
'x
,
T
:
Decodable
>
Lazy
Seq
<
T
>
{
impl
<
'a
:
'x
,
'tcx
:
'x
,
'x
,
T
:
Decodable
>
Lazy
<
[
T
]
>
{
pub
fn
decode
<
M
:
Metadata
<
'a
,
'tcx
>>
(
self
,
meta
:
M
,
)
->
impl
ExactSizeIterator
<
Item
=
T
>
+
Captures
<
'a
>
+
Captures
<
'tcx
>
+
'x
{
let
mut
dcx
=
meta
.decoder
(
self
.position
);
dcx
.lazy_state
=
LazyState
::
NodeStart
(
self
.position
);
(
0
..
self
.
len
)
.map
(
move
|
_
|
T
::
decode
(
&
mut
dcx
)
.unwrap
())
(
0
..
self
.
meta
)
.map
(
move
|
_
|
T
::
decode
(
&
mut
dcx
)
.unwrap
())
}
}
...
...
@@ -154,10 +154,14 @@ pub fn cdata(&self) -> &'a CrateMetadata {
self
.cdata
.expect
(
"missing CrateMetadata in DecodeContext"
)
}
fn
read_lazy_distance
(
&
mut
self
,
min_size
:
usize
)
->
Result
<
usize
,
<
Self
as
Decoder
>
::
Error
>
{
fn
read_lazy_with_meta
<
T
:
?
Sized
+
LazyMeta
>
(
&
mut
self
,
meta
:
T
::
Meta
,
)
->
Result
<
Lazy
<
T
>
,
<
Self
as
Decoder
>
::
Error
>
{
let
min_size
=
T
::
min_size
(
meta
);
let
distance
=
self
.read_usize
()
?
;
let
position
=
match
self
.lazy_state
{
LazyState
::
NoNode
=>
bug!
(
"read_lazy_
distance
: outside of a metadata node"
),
LazyState
::
NoNode
=>
bug!
(
"read_lazy_
with_meta
: outside of a metadata node"
),
LazyState
::
NodeStart
(
start
)
=>
{
assert
!
(
distance
+
min_size
<=
start
);
start
-
distance
-
min_size
...
...
@@ -165,7 +169,7 @@ fn read_lazy_distance(&mut self, min_size: usize) -> Result<usize, <Self as Deco
LazyState
::
Previous
(
last_min_end
)
=>
last_min_end
+
distance
,
};
self
.lazy_state
=
LazyState
::
Previous
(
position
+
min_size
);
Ok
(
position
)
Ok
(
Lazy
::
from_position_and_meta
(
position
,
meta
)
)
}
}
...
...
@@ -230,19 +234,18 @@ fn map_encoded_cnum_to_current(&self, cnum: CrateNum) -> CrateNum {
impl
<
'a
,
'tcx
,
T
>
SpecializedDecoder
<
Lazy
<
T
>>
for
DecodeContext
<
'a
,
'tcx
>
{
fn
specialized_decode
(
&
mut
self
)
->
Result
<
Lazy
<
T
>
,
Self
::
Error
>
{
Ok
(
Lazy
::
with_position
(
self
.read_lazy_distance
(
Lazy
::
<
T
>
::
min_size
())
?
))
self
.read_lazy_with_meta
((
))
}
}
impl
<
'a
,
'tcx
,
T
>
SpecializedDecoder
<
Lazy
Seq
<
T
>>
for
DecodeContext
<
'a
,
'tcx
>
{
fn
specialized_decode
(
&
mut
self
)
->
Result
<
Lazy
Seq
<
T
>
,
Self
::
Error
>
{
impl
<
'a
,
'tcx
,
T
>
SpecializedDecoder
<
Lazy
<
[
T
]
>>
for
DecodeContext
<
'a
,
'tcx
>
{
fn
specialized_decode
(
&
mut
self
)
->
Result
<
Lazy
<
[
T
]
>
,
Self
::
Error
>
{
let
len
=
self
.read_usize
()
?
;
let
position
=
if
len
==
0
{
0
if
len
==
0
{
Ok
(
Lazy
::
empty
())
}
else
{
self
.read_lazy_distance
(
LazySeq
::
<
T
>
::
min_size
(
len
))
?
};
Ok
(
LazySeq
::
with_position_and_length
(
position
,
len
))
self
.read_lazy_with_meta
(
len
)
}
}
}
...
...
@@ -378,7 +381,7 @@ pub fn is_compatible(&self) -> bool {
}
pub
fn
get_rustc_version
(
&
self
)
->
String
{
Lazy
::
with
_position
(
METADATA_HEADER
.len
()
+
4
)
.decode
(
self
)
Lazy
::
<
String
>
::
from
_position
(
METADATA_HEADER
.len
()
+
4
)
.decode
(
self
)
}
pub
fn
get_root
(
&
self
)
->
CrateRoot
<
'tcx
>
{
...
...
@@ -387,7 +390,7 @@ pub fn get_root(&self) -> CrateRoot<'tcx> {
let
pos
=
(((
slice
[
offset
+
0
]
as
u32
)
<<
24
)
|
((
slice
[
offset
+
1
]
as
u32
)
<<
16
)
|
((
slice
[
offset
+
2
]
as
u32
)
<<
8
)
|
((
slice
[
offset
+
3
]
as
u32
)
<<
0
))
as
usize
;
Lazy
::
with
_position
(
pos
)
.decode
(
self
)
Lazy
::
<
CrateRoot
<
'tcx
>>
::
from
_position
(
pos
)
.decode
(
self
)
}
pub
fn
list_crate_metadata
(
&
self
,
...
...
@@ -1140,7 +1143,7 @@ pub fn get_fn_arg_names(&self, id: DefIndex) -> Vec<ast::Name> {
EntryKind
::
Fn
(
data
)
|
EntryKind
::
ForeignFn
(
data
)
=>
data
.decode
(
self
)
.arg_names
,
EntryKind
::
Method
(
data
)
=>
data
.decode
(
self
)
.fn_data.arg_names
,
_
=>
Lazy
Seq
::
empty
(),
_
=>
Lazy
::
empty
(),
};
arg_names
.decode
(
self
)
.collect
()
}
...
...
src/librustc_metadata/encoder.rs
浏览文件 @
e7ceaa97
此差异已折叠。
点击以展开。
src/librustc_metadata/index.rs
浏览文件 @
e7ceaa97
...
...
@@ -108,18 +108,18 @@ pub fn record_index(&mut self, item: DefIndex, entry: Lazy<Entry<'tcx>>) {
position
.write_to_bytes_at
(
positions
,
array_index
)
}
pub
fn
write_index
(
&
self
,
buf
:
&
mut
Encoder
)
->
Lazy
Seq
<
Self
>
{
pub
fn
write_index
(
&
self
,
buf
:
&
mut
Encoder
)
->
Lazy
<
[
Self
]
>
{
let
pos
=
buf
.position
();
// First we write the length of the lower range ...
buf
.emit_raw_bytes
(
&
(
self
.positions
.len
()
as
u32
/
4
)
.to_le_bytes
());
// ... then the values.
buf
.emit_raw_bytes
(
&
self
.positions
);
Lazy
Seq
::
with_position_and_length
(
pos
as
usize
,
self
.positions
.len
()
/
4
+
1
)
Lazy
::
from_position_and_meta
(
pos
as
usize
,
self
.positions
.len
()
/
4
+
1
)
}
}
impl
Lazy
Seq
<
Index
<
'tcx
>
>
{
impl
Lazy
<
[
Index
<
'tcx
>
]
>
{
/// Given the metadata, extract out the offset of a particular
/// DefIndex (if any).
#[inline(never)]
...
...
@@ -127,7 +127,7 @@ pub fn lookup(&self, bytes: &[u8], def_index: DefIndex) -> Option<Lazy<Entry<'tc
let
bytes
=
&
bytes
[
self
.position
..
];
debug!
(
"Index::lookup: index={:?} len={:?}"
,
def_index
,
self
.
len
);
self
.
meta
);
let
position
=
u32
::
read_from_bytes_at
(
bytes
,
1
+
def_index
.index
());
if
position
==
u32
::
MAX
{
...
...
@@ -135,7 +135,7 @@ pub fn lookup(&self, bytes: &[u8], def_index: DefIndex) -> Option<Lazy<Entry<'tc
None
}
else
{
debug!
(
"Index::lookup: position={:?}"
,
position
);
Some
(
Lazy
::
with
_position
(
position
as
usize
))
Some
(
Lazy
::
from
_position
(
position
as
usize
))
}
}
}
src/librustc_metadata/schema.rs
浏览文件 @
e7ceaa97
...
...
@@ -41,6 +41,33 @@ pub fn rustc_version() -> String {
pub
const
METADATA_HEADER
:
&
[
u8
;
12
]
=
&
[
0
,
0
,
0
,
0
,
b
'r'
,
b
'u'
,
b
's'
,
b
't'
,
0
,
0
,
0
,
METADATA_VERSION
];
/// Additional metadata for a `Lazy<T>` where `T` may not be `Sized`,
/// e.g. for `Lazy<[T]>`, this is the length (count of `T` values).
pub
trait
LazyMeta
{
type
Meta
:
Copy
+
'static
;
/// Returns the minimum encoded size.
// FIXME(eddyb) Give better estimates for certain types.
fn
min_size
(
meta
:
Self
::
Meta
)
->
usize
;
}
impl
<
T
>
LazyMeta
for
T
{
type
Meta
=
();
fn
min_size
(
_
:
())
->
usize
{
assert_ne!
(
std
::
mem
::
size_of
::
<
T
>
(),
0
);
1
}
}
impl
<
T
>
LazyMeta
for
[
T
]
{
type
Meta
=
usize
;
fn
min_size
(
len
:
usize
)
->
usize
{
len
*
T
::
min_size
(())
}
}
/// A value of type T referred to by its absolute position
/// in the metadata, and which can be decoded lazily.
///
...
...
@@ -56,40 +83,8 @@ pub fn rustc_version() -> String {
/// Distances start at 1, as 0-byte nodes are invalid.
/// Also invalid are nodes being referred in a different
/// order than they were encoded in.
#[must_use]
pub
struct
Lazy
<
T
>
{
pub
position
:
usize
,
_
marker
:
PhantomData
<
T
>
,
}
impl
<
T
>
Lazy
<
T
>
{
pub
fn
with_position
(
position
:
usize
)
->
Lazy
<
T
>
{
Lazy
{
position
,
_
marker
:
PhantomData
,
}
}
/// Returns the minimum encoded size of a value of type `T`.
// FIXME(eddyb) Give better estimates for certain types.
pub
fn
min_size
()
->
usize
{
1
}
}
impl
<
T
>
Copy
for
Lazy
<
T
>
{}
impl
<
T
>
Clone
for
Lazy
<
T
>
{
fn
clone
(
&
self
)
->
Self
{
*
self
}
}
impl
<
T
>
rustc_serialize
::
UseSpecializedEncodable
for
Lazy
<
T
>
{}
impl
<
T
>
rustc_serialize
::
UseSpecializedDecodable
for
Lazy
<
T
>
{}
/// A sequence of type T referred to by its absolute position
/// in the metadata and length, and which can be decoded lazily.
/// The sequence is a single node for the purposes of `Lazy`.
///
/// # Sequences (`Lazy<[T]>`)
///
/// Unlike `Lazy<Vec<T>>`, the length is encoded next to the
/// position, not at the position, which means that the length
...
...
@@ -100,54 +95,62 @@ impl<T> rustc_serialize::UseSpecializedDecodable for Lazy<T> {}
/// the minimal distance the length of the sequence, i.e.
/// it's assumed there's no 0-byte element in the sequence.
#[must_use]
pub
struct
LazySeq
<
T
>
{
pub
len
:
usize
,
// FIXME(#59875) the `Meta` parameter only exists to dodge
// invariance wrt `T` (coming from the `meta: T::Meta` field).
pub
struct
Lazy
<
T
,
Meta
=
<
T
as
LazyMeta
>
::
Meta
>
where
T
:
?
Sized
+
LazyMeta
<
Meta
=
Meta
>
,
Meta
:
'static
+
Copy
,
{
pub
position
:
usize
,
pub
meta
:
Meta
,
_
marker
:
PhantomData
<
T
>
,
}
impl
<
T
>
LazySeq
<
T
>
{
pub
fn
empty
()
->
LazySeq
<
T
>
{
LazySeq
::
with_position_and_length
(
0
,
0
)
}
pub
fn
with_position_and_length
(
position
:
usize
,
len
:
usize
)
->
LazySeq
<
T
>
{
LazySeq
{
len
,
impl
<
T
:
?
Sized
+
LazyMeta
>
Lazy
<
T
>
{
pub
fn
from_position_and_meta
(
position
:
usize
,
meta
:
T
::
Meta
)
->
Lazy
<
T
>
{
Lazy
{
position
,
meta
,
_
marker
:
PhantomData
,
}
}
}
impl
<
T
>
Lazy
<
T
>
{
pub
fn
from_position
(
position
:
usize
)
->
Lazy
<
T
>
{
Lazy
::
from_position_and_meta
(
position
,
())
}
}
/// Returns the minimum encoded size of `length` values of type `T`.
pub
fn
min_size
(
length
:
usize
)
->
usize
{
length
impl
<
T
>
Lazy
<
[
T
]
>
{
pub
fn
empty
()
->
Lazy
<
[
T
]
>
{
Lazy
::
from_position_and_meta
(
0
,
0
)
}
}
impl
<
T
>
Copy
for
LazySeq
<
T
>
{}
impl
<
T
>
Clone
for
LazySeq
<
T
>
{
impl
<
T
:
?
Sized
+
LazyMeta
>
Copy
for
Lazy
<
T
>
{}
impl
<
T
:
?
Sized
+
LazyMeta
>
Clone
for
Lazy
<
T
>
{
fn
clone
(
&
self
)
->
Self
{
*
self
}
}
impl
<
T
>
rustc_serialize
::
UseSpecializedEncodable
for
LazySeq
<
T
>
{}
impl
<
T
>
rustc_serialize
::
UseSpecializedDecodable
for
LazySeq
<
T
>
{}
impl
<
T
:
?
Sized
+
LazyMeta
>
rustc_serialize
::
UseSpecializedEncodable
for
Lazy
<
T
>
{}
impl
<
T
:
?
Sized
+
LazyMeta
>
rustc_serialize
::
UseSpecializedDecodable
for
Lazy
<
T
>
{}
/// Encoding / decoding state for `Lazy`
and `LazySeq`
.
/// Encoding / decoding state for `Lazy`.
#[derive(Copy,
Clone,
PartialEq,
Eq,
Debug)]
pub
enum
LazyState
{
/// Outside of a metadata node.
NoNode
,
/// Inside a metadata node, and before any `Lazy`
or `LazySeq`
.
/// Inside a metadata node, and before any `Lazy`.
/// The position is that of the node itself.
NodeStart
(
usize
),
/// Inside a metadata node, with a previous `Lazy`
or `LazySeq`
.
/// Inside a metadata node, with a previous `Lazy`.
/// The position is a conservative estimate of where that
/// previous `Lazy`
/ `LazySeq`
would end (see their comments).
/// previous `Lazy` would end (see their comments).
Previous
(
usize
),
}
...
...
@@ -167,24 +170,24 @@ pub struct CrateRoot<'tcx> {
pub
proc_macro_decls_static
:
Option
<
DefIndex
>
,
pub
proc_macro_stability
:
Option
<
attr
::
Stability
>
,
pub
crate_deps
:
Lazy
Seq
<
CrateDep
>
,
pub
dylib_dependency_formats
:
Lazy
Seq
<
Option
<
LinkagePreference
>
>
,
pub
lib_features
:
Lazy
Seq
<
(
Symbol
,
Option
<
Symbol
>
)
>
,
pub
lang_items
:
Lazy
Seq
<
(
DefIndex
,
usize
)
>
,
pub
lang_items_missing
:
Lazy
Seq
<
lang_items
::
LangItem
>
,
pub
native_libraries
:
Lazy
Seq
<
NativeLibrary
>
,
pub
foreign_modules
:
Lazy
Seq
<
ForeignModule
>
,
pub
source_map
:
Lazy
Seq
<
syntax_pos
::
SourceFile
>
,
pub
crate_deps
:
Lazy
<
[
CrateDep
]
>
,
pub
dylib_dependency_formats
:
Lazy
<
[
Option
<
LinkagePreference
>
]
>
,
pub
lib_features
:
Lazy
<
[(
Symbol
,
Option
<
Symbol
>
)]
>
,
pub
lang_items
:
Lazy
<
[(
DefIndex
,
usize
)]
>
,
pub
lang_items_missing
:
Lazy
<
[
lang_items
::
LangItem
]
>
,
pub
native_libraries
:
Lazy
<
[
NativeLibrary
]
>
,
pub
foreign_modules
:
Lazy
<
[
ForeignModule
]
>
,
pub
source_map
:
Lazy
<
[
syntax_pos
::
SourceFile
]
>
,
pub
def_path_table
:
Lazy
<
hir
::
map
::
definitions
::
DefPathTable
>
,
pub
impls
:
Lazy
Seq
<
TraitImpls
>
,
pub
exported_symbols
:
Lazy
Seq
<
(
ExportedSymbol
<
'tcx
>
,
SymbolExportLevel
)
>
,
pub
interpret_alloc_index
:
Lazy
Seq
<
u32
>
,
pub
impls
:
Lazy
<
[
TraitImpls
]
>
,
pub
exported_symbols
:
Lazy
<
[(
ExportedSymbol
<
'tcx
>
,
SymbolExportLevel
)]
>
,
pub
interpret_alloc_index
:
Lazy
<
[
u32
]
>
,
pub
entries_index
:
Lazy
Seq
<
index
::
Index
<
'tcx
>
>
,
pub
entries_index
:
Lazy
<
[
index
::
Index
<
'tcx
>
]
>
,
/// The DefIndex's of any proc macros delcared by
/// this crate
pub
proc_macro_data
:
Option
<
Lazy
Seq
<
DefIndex
>>
,
pub
proc_macro_data
:
Option
<
Lazy
<
[
DefIndex
]
>>
,
pub
compiler_builtins
:
bool
,
pub
needs_allocator
:
bool
,
...
...
@@ -207,7 +210,7 @@ pub struct CrateDep {
#[derive(RustcEncodable,
RustcDecodable)]
pub
struct
TraitImpls
{
pub
trait_id
:
(
u32
,
DefIndex
),
pub
impls
:
Lazy
Seq
<
DefIndex
>
,
pub
impls
:
Lazy
<
[
DefIndex
]
>
,
}
#[derive(RustcEncodable,
RustcDecodable)]
...
...
@@ -215,14 +218,14 @@ pub struct Entry<'tcx> {
pub
kind
:
EntryKind
<
'tcx
>
,
pub
visibility
:
Lazy
<
ty
::
Visibility
>
,
pub
span
:
Lazy
<
Span
>
,
pub
attributes
:
Lazy
Seq
<
ast
::
Attribute
>
,
pub
children
:
Lazy
Seq
<
DefIndex
>
,
pub
attributes
:
Lazy
<
[
ast
::
Attribute
]
>
,
pub
children
:
Lazy
<
[
DefIndex
]
>
,
pub
stability
:
Option
<
Lazy
<
attr
::
Stability
>>
,
pub
deprecation
:
Option
<
Lazy
<
attr
::
Deprecation
>>
,
pub
ty
:
Option
<
Lazy
<
Ty
<
'tcx
>>>
,
pub
inherent_impls
:
Lazy
Seq
<
DefIndex
>
,
pub
variances
:
Lazy
Seq
<
ty
::
Variance
>
,
pub
inherent_impls
:
Lazy
<
[
DefIndex
]
>
,
pub
variances
:
Lazy
<
[
ty
::
Variance
]
>
,
pub
generics
:
Option
<
Lazy
<
ty
::
Generics
>>
,
pub
predicates
:
Option
<
Lazy
<
ty
::
GenericPredicates
<
'tcx
>>>
,
pub
predicates_defined_on
:
Option
<
Lazy
<
ty
::
GenericPredicates
<
'tcx
>>>
,
...
...
@@ -278,7 +281,7 @@ pub struct ConstQualif {
#[derive(RustcEncodable,
RustcDecodable)]
pub
struct
ModData
{
pub
reexports
:
Lazy
Seq
<
def
::
Export
<
hir
::
HirId
>
>
,
pub
reexports
:
Lazy
<
[
def
::
Export
<
hir
::
HirId
>
]
>
,
}
#[derive(RustcEncodable,
RustcDecodable)]
...
...
@@ -290,7 +293,7 @@ pub struct MacroDef {
#[derive(RustcEncodable,
RustcDecodable)]
pub
struct
FnData
<
'tcx
>
{
pub
constness
:
hir
::
Constness
,
pub
arg_names
:
Lazy
Seq
<
ast
::
Name
>
,
pub
arg_names
:
Lazy
<
[
ast
::
Name
]
>
,
pub
sig
:
Lazy
<
ty
::
PolyFnSig
<
'tcx
>>
,
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录