Skip to content

Commit

Permalink
rustc_metadata: Give a constructor to CrateMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Nov 17, 2019
1 parent bdce69d commit ff3e06f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 34 deletions.
43 changes: 9 additions & 34 deletions src/librustc_metadata/creader.rs
Expand Up @@ -3,19 +3,15 @@
use crate::cstore::{self, CStore};
use crate::locator::{CrateLocator, CratePaths};
use crate::rmeta::{CrateRoot, CrateDep, MetadataBlob};
use rustc_data_structures::sync::{Lock, Once, AtomicCell};

use rustc::hir::def_id::CrateNum;
use rustc_data_structures::svh::Svh;
use rustc::dep_graph::DepNodeIndex;
use rustc::middle::cstore::DepKind;
use rustc::mir::interpret::AllocDecodingState;
use rustc::session::{Session, CrateDisambiguator};
use rustc::session::config::{Sanitizer, self};
use rustc_target::spec::{PanicStrategy, TargetTriple};
use rustc::session::search_paths::PathKind;
use rustc::middle::cstore::{CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn};
use rustc::util::common::record_time;
use rustc::util::nodemap::FxHashSet;
use rustc::hir::map::Definitions;
use rustc::hir::def_id::LOCAL_CRATE;
Expand Down Expand Up @@ -217,8 +213,6 @@ impl<'a> CrateLoader<'a> {

let cnum_map = self.resolve_crate_deps(root, &crate_root, &metadata, cnum, span, dep_kind);

let dependencies: Vec<CrateNum> = cnum_map.iter().cloned().collect();

let raw_proc_macros = crate_root.proc_macro_data.map(|_| {
let temp_root;
let (dlsym_source, dlsym_root) = match &host_lib {
Expand All @@ -230,37 +224,18 @@ impl<'a> CrateLoader<'a> {
self.dlsym_proc_macros(&dlsym_dylib.0, dlsym_root.disambiguator, span)
});

let interpret_alloc_index: Vec<u32> = crate_root.interpret_alloc_index
.decode(&metadata)
.collect();
let trait_impls = crate_root
.impls
.decode((&metadata, self.sess))
.map(|trait_impls| (trait_impls.trait_id, trait_impls.impls))
.collect();

let def_path_table = record_time(&self.sess.perf_stats.decode_def_path_tables_time, || {
crate_root.def_path_table.decode((&metadata, self.sess))
});

self.cstore.set_crate_data(cnum, cstore::CrateMetadata {
extern_crate: Lock::new(None),
def_path_table,
trait_impls,
root: crate_root,
host_hash,
blob: metadata,
cnum_map,
self.cstore.set_crate_data(cnum, cstore::CrateMetadata::new(
self.sess,
metadata,
crate_root,
raw_proc_macros,
cnum,
dependencies: Lock::new(dependencies),
source_map_import_info: Once::new(),
alloc_decoding_state: AllocDecodingState::new(interpret_alloc_index),
dep_kind: Lock::new(dep_kind),
cnum_map,
dep_kind,
source,
private_dep,
raw_proc_macros,
dep_node_index: AtomicCell::new(DepNodeIndex::INVALID),
});
host_hash,
));

cnum
}
Expand Down
44 changes: 44 additions & 0 deletions src/librustc_metadata/cstore.rs
Expand Up @@ -7,7 +7,9 @@ use rustc::hir::def_id::{CrateNum, DefIndex};
use rustc::hir::map::definitions::DefPathTable;
use rustc::middle::cstore::{CrateSource, DepKind, ExternCrate};
use rustc::mir::interpret::AllocDecodingState;
use rustc::session::Session;
use rustc_index::vec::IndexVec;
use rustc::util::common::record_time;
use rustc::util::nodemap::FxHashMap;
use rustc_data_structures::sync::{Lrc, Lock, Once, AtomicCell};
use rustc_data_structures::svh::Svh;
Expand Down Expand Up @@ -97,6 +99,48 @@ pub enum LoadedMacro {
ProcMacro(SyntaxExtension),
}

impl CrateMetadata {
crate fn new(
sess: &Session,
blob: MetadataBlob,
root: CrateRoot<'static>,
raw_proc_macros: Option<&'static [ProcMacro]>,
cnum: CrateNum,
cnum_map: CrateNumMap,
dep_kind: DepKind,
source: CrateSource,
private_dep: bool,
host_hash: Option<Svh>,
) -> CrateMetadata {
let def_path_table = record_time(&sess.perf_stats.decode_def_path_tables_time, || {
root.def_path_table.decode((&blob, sess))
});
let trait_impls = root.impls.decode((&blob, sess))
.map(|trait_impls| (trait_impls.trait_id, trait_impls.impls)).collect();
let alloc_decoding_state =
AllocDecodingState::new(root.interpret_alloc_index.decode(&blob).collect());
let dependencies = Lock::new(cnum_map.iter().cloned().collect());
CrateMetadata {
blob,
root,
def_path_table,
trait_impls,
raw_proc_macros,
source_map_import_info: Once::new(),
alloc_decoding_state,
dep_node_index: AtomicCell::new(DepNodeIndex::INVALID),
cnum,
cnum_map,
dependencies,
dep_kind: Lock::new(dep_kind),
source,
private_dep,
host_hash,
extern_crate: Lock::new(None),
}
}
}

impl Default for CStore {
fn default() -> Self {
CStore {
Expand Down

0 comments on commit ff3e06f

Please sign in to comment.