Skip to content

Commit

Permalink
Make fields with sync types on CrateMetadata private
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Nov 1, 2019
1 parent bcd13d4 commit 147d03c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
20 changes: 7 additions & 13 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
use crate::cstore::{self, CStore, MetadataBlob};
use crate::locator::{self, CratePaths};
use crate::schema::{CrateRoot, CrateDep};
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};
Expand Down Expand Up @@ -241,24 +238,21 @@ impl<'a> CrateLoader<'a> {
crate_root.def_path_table.decode((&metadata, self.sess))
});

self.cstore.set_crate_data(cnum, cstore::CrateMetadata {
extern_crate: Lock::new(None),
self.cstore.set_crate_data(cnum, cstore::CrateMetadata::new(
def_path_table,
trait_impls,
root: crate_root,
crate_root,
host_hash,
blob: metadata,
metadata,
cnum_map,
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),
dependencies,
interpret_alloc_index,
dep_kind,
source,
private_dep,
raw_proc_macros,
dep_node_index: AtomicCell::new(DepNodeIndex::INVALID),
});
));

cnum
}
Expand Down
39 changes: 37 additions & 2 deletions src/librustc_metadata/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ crate struct CrateMetadata {
/// 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.
crate source_map_import_info: Once<Vec<ImportedSourceFile>>,
source_map_import_info: Once<Vec<ImportedSourceFile>>,
/// Used for decoding interpret::AllocIds in a cached & thread-safe manner.
crate alloc_decoding_state: AllocDecodingState,
/// The `DepNodeIndex` of the `DepNode` representing this upstream crate.
/// It is initialized on the first access in `get_crate_dep_node_index()`.
/// Do not access the value directly, as it might not have been initialized yet.
/// The field must always be initialized to `DepNodeIndex::INVALID`.
crate dep_node_index: AtomicCell<DepNodeIndex>,
dep_node_index: AtomicCell<DepNodeIndex>,

// --- Other significant crate properties ---

Expand Down Expand Up @@ -113,6 +113,41 @@ crate struct CrateMetadata {
}

impl<'a, 'tcx> CrateMetadata {
crate fn new(
def_path_table: DefPathTable,
trait_impls: FxHashMap<(u32, DefIndex), schema::Lazy<[DefIndex]>>,
root: schema::CrateRoot<'static>,
host_hash: Option<Svh>,
blob: MetadataBlob,
cnum_map: CrateNumMap,
cnum: CrateNum,
dependencies: Vec<CrateNum>,
interpret_alloc_index: Vec<u32>,
dep_kind: DepKind,
source: CrateSource,
private_dep: bool,
raw_proc_macros: Option<&'static [ProcMacro]>,
) -> Self {
Self {
extern_crate: Lock::new(None),
def_path_table,
trait_impls,
root,
host_hash,
blob,
cnum_map,
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),
source,
private_dep,
raw_proc_macros,
dep_node_index: AtomicCell::new(DepNodeIndex::INVALID),
}
}

crate fn is_proc_macro_crate(&self) -> bool {
self.root.proc_macro_decls_static.is_some()
}
Expand Down

0 comments on commit 147d03c

Please sign in to comment.