Skip to content

Commit 147d03c

Browse files
committed
Make fields with sync types on CrateMetadata private
1 parent bcd13d4 commit 147d03c

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

src/librustc_metadata/creader.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
use crate::cstore::{self, CStore, MetadataBlob};
44
use crate::locator::{self, CratePaths};
55
use crate::schema::{CrateRoot, CrateDep};
6-
use rustc_data_structures::sync::{Lock, Once, AtomicCell};
76

87
use rustc::hir::def_id::CrateNum;
98
use rustc_data_structures::svh::Svh;
10-
use rustc::dep_graph::DepNodeIndex;
119
use rustc::middle::cstore::DepKind;
12-
use rustc::mir::interpret::AllocDecodingState;
1310
use rustc::session::{Session, CrateDisambiguator};
1411
use rustc::session::config::{Sanitizer, self};
1512
use rustc_target::spec::{PanicStrategy, TargetTriple};
@@ -241,24 +238,21 @@ impl<'a> CrateLoader<'a> {
241238
crate_root.def_path_table.decode((&metadata, self.sess))
242239
});
243240

244-
self.cstore.set_crate_data(cnum, cstore::CrateMetadata {
245-
extern_crate: Lock::new(None),
241+
self.cstore.set_crate_data(cnum, cstore::CrateMetadata::new(
246242
def_path_table,
247243
trait_impls,
248-
root: crate_root,
244+
crate_root,
249245
host_hash,
250-
blob: metadata,
246+
metadata,
251247
cnum_map,
252248
cnum,
253-
dependencies: Lock::new(dependencies),
254-
source_map_import_info: Once::new(),
255-
alloc_decoding_state: AllocDecodingState::new(interpret_alloc_index),
256-
dep_kind: Lock::new(dep_kind),
249+
dependencies,
250+
interpret_alloc_index,
251+
dep_kind,
257252
source,
258253
private_dep,
259254
raw_proc_macros,
260-
dep_node_index: AtomicCell::new(DepNodeIndex::INVALID),
261-
});
255+
));
262256

263257
cnum
264258
}

src/librustc_metadata/cstore.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ crate struct CrateMetadata {
7777
/// Proc macro descriptions for this crate, if it's a proc macro crate.
7878
crate raw_proc_macros: Option<&'static [ProcMacro]>,
7979
/// Source maps for code from the crate.
80-
crate source_map_import_info: Once<Vec<ImportedSourceFile>>,
80+
source_map_import_info: Once<Vec<ImportedSourceFile>>,
8181
/// Used for decoding interpret::AllocIds in a cached & thread-safe manner.
8282
crate alloc_decoding_state: AllocDecodingState,
8383
/// The `DepNodeIndex` of the `DepNode` representing this upstream crate.
8484
/// It is initialized on the first access in `get_crate_dep_node_index()`.
8585
/// Do not access the value directly, as it might not have been initialized yet.
8686
/// The field must always be initialized to `DepNodeIndex::INVALID`.
87-
crate dep_node_index: AtomicCell<DepNodeIndex>,
87+
dep_node_index: AtomicCell<DepNodeIndex>,
8888

8989
// --- Other significant crate properties ---
9090

@@ -113,6 +113,41 @@ crate struct CrateMetadata {
113113
}
114114

115115
impl<'a, 'tcx> CrateMetadata {
116+
crate fn new(
117+
def_path_table: DefPathTable,
118+
trait_impls: FxHashMap<(u32, DefIndex), schema::Lazy<[DefIndex]>>,
119+
root: schema::CrateRoot<'static>,
120+
host_hash: Option<Svh>,
121+
blob: MetadataBlob,
122+
cnum_map: CrateNumMap,
123+
cnum: CrateNum,
124+
dependencies: Vec<CrateNum>,
125+
interpret_alloc_index: Vec<u32>,
126+
dep_kind: DepKind,
127+
source: CrateSource,
128+
private_dep: bool,
129+
raw_proc_macros: Option<&'static [ProcMacro]>,
130+
) -> Self {
131+
Self {
132+
extern_crate: Lock::new(None),
133+
def_path_table,
134+
trait_impls,
135+
root,
136+
host_hash,
137+
blob,
138+
cnum_map,
139+
cnum,
140+
dependencies: Lock::new(dependencies),
141+
source_map_import_info: Once::new(),
142+
alloc_decoding_state: AllocDecodingState::new(interpret_alloc_index),
143+
dep_kind: Lock::new(dep_kind),
144+
source,
145+
private_dep,
146+
raw_proc_macros,
147+
dep_node_index: AtomicCell::new(DepNodeIndex::INVALID),
148+
}
149+
}
150+
116151
crate fn is_proc_macro_crate(&self) -> bool {
117152
self.root.proc_macro_decls_static.is_some()
118153
}

0 commit comments

Comments
 (0)