Skip to content

Commit 68985c7

Browse files
committed
rustc_metadata: Move some structs from cstore to decoder
This allows to privatize their fields.
1 parent 4b6cef1 commit 68985c7

File tree

5 files changed

+31
-27
lines changed

5 files changed

+31
-27
lines changed

src/librustc_metadata/creader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Validates all used crates and extern libraries and loads their metadata
22
3-
use crate::cstore::{self, CStore, MetadataBlob};
3+
use crate::cstore::{self, CStore};
44
use crate::locator::{self, CratePaths};
5-
use crate::rmeta::{CrateRoot, CrateDep};
5+
use crate::rmeta::{CrateRoot, CrateDep, MetadataBlob};
66
use rustc_data_structures::sync::{Lock, Once, AtomicCell};
77

88
use rustc::hir::def_id::CrateNum;

src/librustc_metadata/cstore.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
// The crate store - a central repo for information collected about external
22
// crates and libraries
33

4-
use crate::rmeta;
4+
use crate::rmeta::{CrateRoot, ImportedSourceFile, Lazy, MetadataBlob};
55
use rustc::dep_graph::DepNodeIndex;
66
use rustc::hir::def_id::{CrateNum, DefIndex};
77
use rustc::hir::map::definitions::DefPathTable;
88
use rustc::middle::cstore::{CrateSource, DepKind, ExternCrate};
99
use rustc::mir::interpret::AllocDecodingState;
1010
use rustc_index::vec::IndexVec;
1111
use rustc::util::nodemap::FxHashMap;
12-
use rustc_data_structures::sync::{Lrc, Lock, MetadataRef, Once, AtomicCell};
12+
use rustc_data_structures::sync::{Lrc, Lock, Once, AtomicCell};
1313
use rustc_data_structures::svh::Svh;
1414
use syntax::ast;
1515
use syntax::edition::Edition;
1616
use syntax_expand::base::SyntaxExtension;
1717
use syntax::expand::allocator::AllocatorKind;
18-
use syntax_pos;
1918
use proc_macro::bridge::client::ProcMacro;
2019

2120
pub use crate::rmeta::{provide, provide_extern};
@@ -26,19 +25,6 @@ pub use crate::rmeta::{provide, provide_extern};
2625
// own crate numbers.
2726
crate type CrateNumMap = IndexVec<CrateNum, CrateNum>;
2827

29-
crate struct MetadataBlob(pub MetadataRef);
30-
31-
/// Holds information about a syntax_pos::SourceFile imported from another crate.
32-
/// See `imported_source_files()` for more information.
33-
crate struct ImportedSourceFile {
34-
/// This SourceFile's byte-offset within the source_map of its original crate
35-
pub original_start_pos: syntax_pos::BytePos,
36-
/// The end of this SourceFile within the source_map of its original crate
37-
pub original_end_pos: syntax_pos::BytePos,
38-
/// The imported SourceFile's representation within the local source_map
39-
pub translated_source_file: Lrc<syntax_pos::SourceFile>,
40-
}
41-
4228
crate struct CrateMetadata {
4329
/// The primary crate data - binary metadata blob.
4430
crate blob: MetadataBlob,
@@ -50,7 +36,7 @@ crate struct CrateMetadata {
5036
/// lifetime is only used behind `Lazy`, and therefore acts like an
5137
/// universal (`for<'tcx>`), that is paired up with whichever `TyCtxt`
5238
/// is being used to decode those values.
53-
crate root: rmeta::CrateRoot<'static>,
39+
crate root: CrateRoot<'static>,
5440
/// For each definition in this crate, we encode a key. When the
5541
/// crate is loaded, we read all the keys and put them in this
5642
/// hashmap, which gives the reverse mapping. This allows us to
@@ -60,7 +46,7 @@ crate struct CrateMetadata {
6046
/// Trait impl data.
6147
/// FIXME: Used only from queries and can use query cache,
6248
/// so pre-decoding can probably be avoided.
63-
crate trait_impls: FxHashMap<(u32, DefIndex), rmeta::Lazy<[DefIndex]>>,
49+
crate trait_impls: FxHashMap<(u32, DefIndex), Lazy<[DefIndex]>>,
6450
/// Proc macro descriptions for this crate, if it's a proc macro crate.
6551
crate raw_proc_macros: Option<&'static [ProcMacro]>,
6652
/// Source maps for code from the crate.

src/librustc_metadata/locator.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,8 @@
212212
//! no means all of the necessary details. Take a look at the rest of
213213
//! metadata::locator or metadata::creader for all the juicy details!
214214
215-
use crate::cstore::MetadataBlob;
216215
use crate::creader::Library;
217-
use crate::rmeta::{METADATA_HEADER, rustc_version};
216+
use crate::rmeta::{METADATA_HEADER, rustc_version, MetadataBlob};
218217

219218
use rustc_data_structures::fx::FxHashSet;
220219
use rustc_data_structures::svh::Svh;
@@ -907,7 +906,7 @@ fn get_metadata_section_imp(target: &Target,
907906
rustc_erase_owner!(OwningRef::new(StableDerefMmap(mmap)).map_owner_box())
908907
}
909908
};
910-
let blob = MetadataBlob(raw_bytes);
909+
let blob = MetadataBlob::new(raw_bytes);
911910
if blob.is_compatible() {
912911
Ok(blob)
913912
} else {

src/librustc_metadata/rmeta/decoder.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Decoding metadata from a single crate's metadata
22

3-
use crate::cstore::{self, CrateMetadata, MetadataBlob};
3+
use crate::cstore::CrateMetadata;
44
use crate::rmeta::*;
55
use crate::rmeta::table::{FixedSizeEncoding, PerDefTable};
66

@@ -44,6 +44,19 @@ pub use cstore_impl::{provide, provide_extern};
4444

4545
mod cstore_impl;
4646

47+
crate struct MetadataBlob(MetadataRef);
48+
49+
/// Holds information about a syntax_pos::SourceFile imported from another crate.
50+
/// See `imported_source_files()` for more information.
51+
crate struct ImportedSourceFile {
52+
/// This SourceFile's byte-offset within the source_map of its original crate
53+
original_start_pos: syntax_pos::BytePos,
54+
/// The end of this SourceFile within the source_map of its original crate
55+
original_end_pos: syntax_pos::BytePos,
56+
/// The imported SourceFile's representation within the local source_map
57+
translated_source_file: Lrc<syntax_pos::SourceFile>,
58+
}
59+
4760
crate struct DecodeContext<'a, 'tcx> {
4861
opaque: opaque::Decoder<'a>,
4962
cdata: Option<&'a CrateMetadata>,
@@ -393,7 +406,11 @@ for DecodeContext<'a, 'tcx> {
393406

394407
implement_ty_decoder!( DecodeContext<'a, 'tcx> );
395408

396-
impl<'tcx> MetadataBlob {
409+
impl MetadataBlob {
410+
crate fn new(metadata_ref: MetadataRef) -> MetadataBlob {
411+
MetadataBlob(metadata_ref)
412+
}
413+
397414
crate fn is_compatible(&self) -> bool {
398415
self.raw_bytes().starts_with(METADATA_HEADER)
399416
}
@@ -1296,7 +1313,7 @@ impl<'a, 'tcx> CrateMetadata {
12961313
fn imported_source_files(
12971314
&'a self,
12981315
local_source_map: &source_map::SourceMap,
1299-
) -> &[cstore::ImportedSourceFile] {
1316+
) -> &[ImportedSourceFile] {
13001317
self.source_map_import_info.init_locking(|| {
13011318
let external_source_map = self.root.source_map.decode(self);
13021319

@@ -1351,7 +1368,7 @@ impl<'a, 'tcx> CrateMetadata {
13511368
local_version.name, start_pos, end_pos,
13521369
local_version.start_pos, local_version.end_pos);
13531370

1354-
cstore::ImportedSourceFile {
1371+
ImportedSourceFile {
13551372
original_start_pos: start_pos,
13561373
original_end_pos: end_pos,
13571374
translated_source_file: local_version,

src/librustc_metadata/rmeta/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc::ty::{self, Ty, ReprOptions};
1414
use rustc_target::spec::{PanicStrategy, TargetTriple};
1515
use rustc_index::vec::IndexVec;
1616
use rustc_data_structures::svh::Svh;
17+
use rustc_data_structures::sync::MetadataRef;
1718
use rustc_serialize::Encodable;
1819
use syntax::{ast, attr};
1920
use syntax::edition::Edition;
@@ -24,6 +25,7 @@ use std::marker::PhantomData;
2425
use std::num::NonZeroUsize;
2526

2627
pub use decoder::{provide, provide_extern};
28+
crate use decoder::{ImportedSourceFile, MetadataBlob};
2729

2830
mod decoder;
2931
mod encoder;

0 commit comments

Comments
 (0)