rustc_metadata: Move some structs from `cstore` to `decoder`
This allows to privatize their fields.
This commit is contained in:
parent
4b6cef1e32
commit
68985c7613
|
@ -1,8 +1,8 @@
|
|||
//! Validates all used crates and extern libraries and loads their metadata
|
||||
|
||||
use crate::cstore::{self, CStore, MetadataBlob};
|
||||
use crate::cstore::{self, CStore};
|
||||
use crate::locator::{self, CratePaths};
|
||||
use crate::rmeta::{CrateRoot, CrateDep};
|
||||
use crate::rmeta::{CrateRoot, CrateDep, MetadataBlob};
|
||||
use rustc_data_structures::sync::{Lock, Once, AtomicCell};
|
||||
|
||||
use rustc::hir::def_id::CrateNum;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// The crate store - a central repo for information collected about external
|
||||
// crates and libraries
|
||||
|
||||
use crate::rmeta;
|
||||
use crate::rmeta::{CrateRoot, ImportedSourceFile, Lazy, MetadataBlob};
|
||||
use rustc::dep_graph::DepNodeIndex;
|
||||
use rustc::hir::def_id::{CrateNum, DefIndex};
|
||||
use rustc::hir::map::definitions::DefPathTable;
|
||||
|
@ -9,13 +9,12 @@ use rustc::middle::cstore::{CrateSource, DepKind, ExternCrate};
|
|||
use rustc::mir::interpret::AllocDecodingState;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc::util::nodemap::FxHashMap;
|
||||
use rustc_data_structures::sync::{Lrc, Lock, MetadataRef, Once, AtomicCell};
|
||||
use rustc_data_structures::sync::{Lrc, Lock, Once, AtomicCell};
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use syntax::ast;
|
||||
use syntax::edition::Edition;
|
||||
use syntax_expand::base::SyntaxExtension;
|
||||
use syntax::expand::allocator::AllocatorKind;
|
||||
use syntax_pos;
|
||||
use proc_macro::bridge::client::ProcMacro;
|
||||
|
||||
pub use crate::rmeta::{provide, provide_extern};
|
||||
|
@ -26,19 +25,6 @@ pub use crate::rmeta::{provide, provide_extern};
|
|||
// own crate numbers.
|
||||
crate type CrateNumMap = IndexVec<CrateNum, CrateNum>;
|
||||
|
||||
crate struct MetadataBlob(pub MetadataRef);
|
||||
|
||||
/// Holds information about a syntax_pos::SourceFile imported from another crate.
|
||||
/// See `imported_source_files()` for more information.
|
||||
crate struct ImportedSourceFile {
|
||||
/// This SourceFile's byte-offset within the source_map of its original crate
|
||||
pub original_start_pos: syntax_pos::BytePos,
|
||||
/// The end of this SourceFile within the source_map of its original crate
|
||||
pub original_end_pos: syntax_pos::BytePos,
|
||||
/// The imported SourceFile's representation within the local source_map
|
||||
pub translated_source_file: Lrc<syntax_pos::SourceFile>,
|
||||
}
|
||||
|
||||
crate struct CrateMetadata {
|
||||
/// The primary crate data - binary metadata blob.
|
||||
crate blob: MetadataBlob,
|
||||
|
@ -50,7 +36,7 @@ crate struct CrateMetadata {
|
|||
/// 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.
|
||||
crate root: rmeta::CrateRoot<'static>,
|
||||
crate root: CrateRoot<'static>,
|
||||
/// For each definition in this crate, we encode a key. When the
|
||||
/// crate is loaded, we read all the keys and put them in this
|
||||
/// hashmap, which gives the reverse mapping. This allows us to
|
||||
|
@ -60,7 +46,7 @@ crate struct CrateMetadata {
|
|||
/// Trait impl data.
|
||||
/// FIXME: Used only from queries and can use query cache,
|
||||
/// so pre-decoding can probably be avoided.
|
||||
crate trait_impls: FxHashMap<(u32, DefIndex), rmeta::Lazy<[DefIndex]>>,
|
||||
crate trait_impls: FxHashMap<(u32, DefIndex), Lazy<[DefIndex]>>,
|
||||
/// Proc macro descriptions for this crate, if it's a proc macro crate.
|
||||
crate raw_proc_macros: Option<&'static [ProcMacro]>,
|
||||
/// Source maps for code from the crate.
|
||||
|
|
|
@ -212,9 +212,8 @@
|
|||
//! no means all of the necessary details. Take a look at the rest of
|
||||
//! metadata::locator or metadata::creader for all the juicy details!
|
||||
|
||||
use crate::cstore::MetadataBlob;
|
||||
use crate::creader::Library;
|
||||
use crate::rmeta::{METADATA_HEADER, rustc_version};
|
||||
use crate::rmeta::{METADATA_HEADER, rustc_version, MetadataBlob};
|
||||
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
|
@ -907,7 +906,7 @@ fn get_metadata_section_imp(target: &Target,
|
|||
rustc_erase_owner!(OwningRef::new(StableDerefMmap(mmap)).map_owner_box())
|
||||
}
|
||||
};
|
||||
let blob = MetadataBlob(raw_bytes);
|
||||
let blob = MetadataBlob::new(raw_bytes);
|
||||
if blob.is_compatible() {
|
||||
Ok(blob)
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Decoding metadata from a single crate's metadata
|
||||
|
||||
use crate::cstore::{self, CrateMetadata, MetadataBlob};
|
||||
use crate::cstore::CrateMetadata;
|
||||
use crate::rmeta::*;
|
||||
use crate::rmeta::table::{FixedSizeEncoding, PerDefTable};
|
||||
|
||||
|
@ -44,6 +44,19 @@ pub use cstore_impl::{provide, provide_extern};
|
|||
|
||||
mod cstore_impl;
|
||||
|
||||
crate struct MetadataBlob(MetadataRef);
|
||||
|
||||
/// Holds information about a syntax_pos::SourceFile imported from another crate.
|
||||
/// See `imported_source_files()` for more information.
|
||||
crate struct ImportedSourceFile {
|
||||
/// This SourceFile's byte-offset within the source_map of its original crate
|
||||
original_start_pos: syntax_pos::BytePos,
|
||||
/// The end of this SourceFile within the source_map of its original crate
|
||||
original_end_pos: syntax_pos::BytePos,
|
||||
/// The imported SourceFile's representation within the local source_map
|
||||
translated_source_file: Lrc<syntax_pos::SourceFile>,
|
||||
}
|
||||
|
||||
crate struct DecodeContext<'a, 'tcx> {
|
||||
opaque: opaque::Decoder<'a>,
|
||||
cdata: Option<&'a CrateMetadata>,
|
||||
|
@ -393,7 +406,11 @@ for DecodeContext<'a, 'tcx> {
|
|||
|
||||
implement_ty_decoder!( DecodeContext<'a, 'tcx> );
|
||||
|
||||
impl<'tcx> MetadataBlob {
|
||||
impl MetadataBlob {
|
||||
crate fn new(metadata_ref: MetadataRef) -> MetadataBlob {
|
||||
MetadataBlob(metadata_ref)
|
||||
}
|
||||
|
||||
crate fn is_compatible(&self) -> bool {
|
||||
self.raw_bytes().starts_with(METADATA_HEADER)
|
||||
}
|
||||
|
@ -1296,7 +1313,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
fn imported_source_files(
|
||||
&'a self,
|
||||
local_source_map: &source_map::SourceMap,
|
||||
) -> &[cstore::ImportedSourceFile] {
|
||||
) -> &[ImportedSourceFile] {
|
||||
self.source_map_import_info.init_locking(|| {
|
||||
let external_source_map = self.root.source_map.decode(self);
|
||||
|
||||
|
@ -1351,7 +1368,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
local_version.name, start_pos, end_pos,
|
||||
local_version.start_pos, local_version.end_pos);
|
||||
|
||||
cstore::ImportedSourceFile {
|
||||
ImportedSourceFile {
|
||||
original_start_pos: start_pos,
|
||||
original_end_pos: end_pos,
|
||||
translated_source_file: local_version,
|
||||
|
|
|
@ -14,6 +14,7 @@ use rustc::ty::{self, Ty, ReprOptions};
|
|||
use rustc_target::spec::{PanicStrategy, TargetTriple};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_data_structures::sync::MetadataRef;
|
||||
use rustc_serialize::Encodable;
|
||||
use syntax::{ast, attr};
|
||||
use syntax::edition::Edition;
|
||||
|
@ -24,6 +25,7 @@ use std::marker::PhantomData;
|
|||
use std::num::NonZeroUsize;
|
||||
|
||||
pub use decoder::{provide, provide_extern};
|
||||
crate use decoder::{ImportedSourceFile, MetadataBlob};
|
||||
|
||||
mod decoder;
|
||||
mod encoder;
|
||||
|
|
Loading…
Reference in New Issue