Skip to content

Commit 34035d2

Browse files
committed
Auto merge of #44418 - alexcrichton:remove-dep-graph, r=michaelwoerister
rustc: Remove `DepGraph` handling from rustc_metadata This should now be entirely tracked through queries, so no need to have a `DepGraph` in the `CStore` object any more! cc #44390
2 parents 6d445e1 + d724d03 commit 34035d2

File tree

11 files changed

+102
-245
lines changed

11 files changed

+102
-245
lines changed

src/librustc_driver/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub fn run_compiler<'a>(args: &[String],
294294
};
295295

296296
let dep_graph = DepGraph::new(sopts.build_dep_graph());
297-
let cstore = Rc::new(CStore::new(&dep_graph, box ::MetadataLoader));
297+
let cstore = Rc::new(CStore::new(box ::MetadataLoader));
298298

299299
let loader = file_loader.unwrap_or(box RealFileLoader);
300300
let codemap = Rc::new(CodeMap::with_file_loader(loader, sopts.file_path_mapping()));
@@ -574,7 +574,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
574574
return None;
575575
}
576576
let dep_graph = DepGraph::new(sopts.build_dep_graph());
577-
let cstore = Rc::new(CStore::new(&dep_graph, box ::MetadataLoader));
577+
let cstore = Rc::new(CStore::new(box ::MetadataLoader));
578578
let mut sess = build_session(sopts.clone(),
579579
&dep_graph,
580580
None,

src/librustc_driver/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn test_env<F>(source_string: &str,
104104

105105
let dep_graph = DepGraph::new(false);
106106
let _ignore = dep_graph.in_ignore();
107-
let cstore = Rc::new(CStore::new(&dep_graph, box ::MetadataLoader));
107+
let cstore = Rc::new(CStore::new(box ::MetadataLoader));
108108
let sess = session::build_session_(options,
109109
&dep_graph,
110110
None,

src/librustc_metadata/creader.rs

+23-43
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use cstore::{self, CStore, CrateSource, MetadataBlob};
1414
use locator::{self, CratePaths};
1515
use native_libs::relevant_lib;
16-
use schema::{CrateRoot, Tracked};
16+
use schema::CrateRoot;
1717

1818
use rustc::hir::def_id::{CrateNum, DefIndex};
1919
use rustc::hir::svh::Svh;
@@ -261,16 +261,13 @@ impl<'a> CrateLoader<'a> {
261261
crate_root.def_path_table.decode(&metadata)
262262
});
263263

264-
let exported_symbols = crate_root.exported_symbols
265-
.map(|x| x.decode(&metadata).collect());
264+
let exported_symbols = crate_root.exported_symbols.decode(&metadata).collect();
266265

267266
let trait_impls = crate_root
268267
.impls
269-
.map(|impls| {
270-
impls.decode(&metadata)
271-
.map(|trait_impls| (trait_impls.trait_id, trait_impls.impls))
272-
.collect()
273-
});
268+
.decode(&metadata)
269+
.map(|trait_impls| (trait_impls.trait_id, trait_impls.impls))
270+
.collect();
274271

275272
let mut cmeta = cstore::CrateMetadata {
276273
name,
@@ -295,23 +292,17 @@ impl<'a> CrateLoader<'a> {
295292
},
296293
// Initialize this with an empty set. The field is populated below
297294
// after we were able to deserialize its contents.
298-
dllimport_foreign_items: Tracked::new(FxHashSet()),
295+
dllimport_foreign_items: FxHashSet(),
299296
};
300297

301-
let dllimports: Tracked<FxHashSet<_>> = cmeta
298+
let dllimports: FxHashSet<_> = cmeta
302299
.root
303300
.native_libraries
304-
.map(|native_libraries| {
305-
let native_libraries: Vec<_> = native_libraries.decode(&cmeta)
306-
.collect();
307-
native_libraries
308-
.iter()
309-
.filter(|lib| relevant_lib(self.sess, lib) &&
310-
lib.kind == cstore::NativeLibraryKind::NativeUnknown)
311-
.flat_map(|lib| lib.foreign_items.iter())
312-
.map(|id| *id)
313-
.collect()
314-
});
301+
.decode(&cmeta)
302+
.filter(|lib| relevant_lib(self.sess, lib) &&
303+
lib.kind == cstore::NativeLibraryKind::NativeUnknown)
304+
.flat_map(|lib| lib.foreign_items.into_iter())
305+
.collect();
315306

316307
cmeta.dllimport_foreign_items = dllimports;
317308

@@ -469,7 +460,6 @@ impl<'a> CrateLoader<'a> {
469460
// We map 0 and all other holes in the map to our parent crate. The "additional"
470461
// self-dependencies should be harmless.
471462
::std::iter::once(krate).chain(crate_root.crate_deps
472-
.get_untracked()
473463
.decode(metadata)
474464
.map(|dep| {
475465
debug!("resolving dep crate {} hash: `{}`", dep.name, dep.hash);
@@ -692,16 +682,14 @@ impl<'a> CrateLoader<'a> {
692682
let mut needs_panic_runtime = attr::contains_name(&krate.attrs,
693683
"needs_panic_runtime");
694684

695-
let dep_graph = &self.sess.dep_graph;
696-
697685
self.cstore.iter_crate_data(|cnum, data| {
698686
needs_panic_runtime = needs_panic_runtime ||
699-
data.needs_panic_runtime(dep_graph);
700-
if data.is_panic_runtime(dep_graph) {
687+
data.needs_panic_runtime();
688+
if data.is_panic_runtime() {
701689
// Inject a dependency from all #![needs_panic_runtime] to this
702690
// #![panic_runtime] crate.
703691
self.inject_dependency_if(cnum, "a panic runtime",
704-
&|data| data.needs_panic_runtime(dep_graph));
692+
&|data| data.needs_panic_runtime());
705693
runtime_found = runtime_found || data.dep_kind.get() == DepKind::Explicit;
706694
}
707695
});
@@ -737,19 +725,19 @@ impl<'a> CrateLoader<'a> {
737725

738726
// Sanity check the loaded crate to ensure it is indeed a panic runtime
739727
// and the panic strategy is indeed what we thought it was.
740-
if !data.is_panic_runtime(dep_graph) {
728+
if !data.is_panic_runtime() {
741729
self.sess.err(&format!("the crate `{}` is not a panic runtime",
742730
name));
743731
}
744-
if data.panic_strategy(dep_graph) != desired_strategy {
732+
if data.panic_strategy() != desired_strategy {
745733
self.sess.err(&format!("the crate `{}` does not have the panic \
746734
strategy `{}`",
747735
name, desired_strategy.desc()));
748736
}
749737

750738
self.sess.injected_panic_runtime.set(Some(cnum));
751739
self.inject_dependency_if(cnum, "a panic runtime",
752-
&|data| data.needs_panic_runtime(dep_graph));
740+
&|data| data.needs_panic_runtime());
753741
}
754742

755743
fn inject_sanitizer_runtime(&mut self) {
@@ -844,7 +832,7 @@ impl<'a> CrateLoader<'a> {
844832
PathKind::Crate, dep_kind);
845833

846834
// Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
847-
if !data.is_sanitizer_runtime(&self.sess.dep_graph) {
835+
if !data.is_sanitizer_runtime() {
848836
self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
849837
name));
850838
}
@@ -865,7 +853,7 @@ impl<'a> CrateLoader<'a> {
865853
PathKind::Crate, dep_kind);
866854

867855
// Sanity check the loaded crate to ensure it is indeed a profiler runtime
868-
if !data.is_profiler_runtime(&self.sess.dep_graph) {
856+
if !data.is_profiler_runtime() {
869857
self.sess.err(&format!("the crate `profiler_builtins` is not \
870858
a profiler runtime"));
871859
}
@@ -883,9 +871,8 @@ impl<'a> CrateLoader<'a> {
883871
// written down in liballoc.
884872
let mut needs_allocator = attr::contains_name(&krate.attrs,
885873
"needs_allocator");
886-
let dep_graph = &self.sess.dep_graph;
887874
self.cstore.iter_crate_data(|_, data| {
888-
needs_allocator = needs_allocator || data.needs_allocator(dep_graph);
875+
needs_allocator = needs_allocator || data.needs_allocator();
889876
});
890877
if !needs_allocator {
891878
return
@@ -917,14 +904,13 @@ impl<'a> CrateLoader<'a> {
917904
// First up we check for global allocators. Look at the crate graph here
918905
// and see what's a global allocator, including if we ourselves are a
919906
// global allocator.
920-
let dep_graph = &self.sess.dep_graph;
921907
let mut global_allocator = if has_global_allocator {
922908
Some(None)
923909
} else {
924910
None
925911
};
926912
self.cstore.iter_crate_data(|_, data| {
927-
if !data.has_global_allocator(dep_graph) {
913+
if !data.has_global_allocator() {
928914
return
929915
}
930916
match global_allocator {
@@ -983,12 +969,6 @@ impl<'a> CrateLoader<'a> {
983969
DUMMY_SP,
984970
PathKind::Crate, dep_kind);
985971
self.sess.injected_allocator.set(Some(cnum));
986-
// self.cstore.iter_crate_data(|_, data| {
987-
// if !data.needs_allocator(dep_graph) {
988-
// return
989-
// }
990-
// data.cnum_map.borrow_mut().push(cnum);
991-
// });
992972
}
993973

994974
// We're not actually going to inject an allocator, we're going to
@@ -1001,7 +981,7 @@ impl<'a> CrateLoader<'a> {
1001981
attr::contains_name(&krate.attrs, "default_lib_allocator");
1002982
self.cstore.iter_crate_data(|_, data| {
1003983
if !found_lib_allocator {
1004-
if data.has_default_lib_allocator(dep_graph) {
984+
if data.has_default_lib_allocator() {
1005985
found_lib_allocator = true;
1006986
}
1007987
}

src/librustc_metadata/cstore.rs

+27-49
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
// The crate store - a central repo for information collected about external
1212
// crates and libraries
1313

14-
use schema::{self, Tracked};
14+
use schema;
1515

16-
use rustc::dep_graph::DepGraph;
17-
use rustc::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex, DefId};
18-
use rustc::hir::map::definitions::{DefPathTable, GlobalMetaDataKind};
16+
use rustc::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex};
17+
use rustc::hir::map::definitions::DefPathTable;
1918
use rustc::hir::svh::Svh;
2019
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
2120
use rustc_back::PanicStrategy;
@@ -78,30 +77,28 @@ pub struct CrateMetadata {
7877
/// compilation support.
7978
pub def_path_table: Rc<DefPathTable>,
8079

81-
pub exported_symbols: Tracked<FxHashSet<DefIndex>>,
80+
pub exported_symbols: FxHashSet<DefIndex>,
8281

83-
pub trait_impls: Tracked<FxHashMap<(u32, DefIndex), schema::LazySeq<DefIndex>>>,
82+
pub trait_impls: FxHashMap<(u32, DefIndex), schema::LazySeq<DefIndex>>,
8483

8584
pub dep_kind: Cell<DepKind>,
8685
pub source: CrateSource,
8786

8887
pub proc_macros: Option<Vec<(ast::Name, Rc<SyntaxExtension>)>>,
8988
// Foreign items imported from a dylib (Windows only)
90-
pub dllimport_foreign_items: Tracked<FxHashSet<DefIndex>>,
89+
pub dllimport_foreign_items: FxHashSet<DefIndex>,
9190
}
9291

9392
pub struct CStore {
94-
pub dep_graph: DepGraph,
9593
metas: RefCell<FxHashMap<CrateNum, Rc<CrateMetadata>>>,
9694
/// Map from NodeId's of local extern crate statements to crate numbers
9795
extern_mod_crate_map: RefCell<NodeMap<CrateNum>>,
9896
pub metadata_loader: Box<MetadataLoader>,
9997
}
10098

10199
impl CStore {
102-
pub fn new(dep_graph: &DepGraph, metadata_loader: Box<MetadataLoader>) -> CStore {
100+
pub fn new(metadata_loader: Box<MetadataLoader>) -> CStore {
103101
CStore {
104-
dep_graph: dep_graph.clone(),
105102
metas: RefCell::new(FxHashMap()),
106103
extern_mod_crate_map: RefCell::new(FxHashMap()),
107104
metadata_loader,
@@ -165,13 +162,6 @@ impl CStore {
165162
pub fn do_extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> {
166163
self.extern_mod_crate_map.borrow().get(&emod_id).cloned()
167164
}
168-
169-
pub fn read_dep_node(&self, def_id: DefId) {
170-
use rustc::middle::cstore::CrateStore;
171-
let def_path_hash = self.def_path_hash(def_id);
172-
let dep_node = def_path_hash.to_dep_node(::rustc::dep_graph::DepKind::MetaData);
173-
self.dep_graph.read(dep_node);
174-
}
175165
}
176166

177167
impl CrateMetadata {
@@ -185,62 +175,50 @@ impl CrateMetadata {
185175
self.root.disambiguator
186176
}
187177

188-
pub fn needs_allocator(&self, dep_graph: &DepGraph) -> bool {
189-
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
178+
pub fn needs_allocator(&self) -> bool {
179+
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
190180
attr::contains_name(&attrs, "needs_allocator")
191181
}
192182

193-
pub fn has_global_allocator(&self, dep_graph: &DepGraph) -> bool {
194-
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::Krate);
195-
self.root
196-
.has_global_allocator
197-
.get(dep_graph, dep_node)
198-
.clone()
183+
pub fn has_global_allocator(&self) -> bool {
184+
self.root.has_global_allocator.clone()
199185
}
200186

201-
pub fn has_default_lib_allocator(&self, dep_graph: &DepGraph) -> bool {
202-
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::Krate);
203-
self.root
204-
.has_default_lib_allocator
205-
.get(dep_graph, dep_node)
206-
.clone()
187+
pub fn has_default_lib_allocator(&self) -> bool {
188+
self.root.has_default_lib_allocator.clone()
207189
}
208190

209-
pub fn is_panic_runtime(&self, dep_graph: &DepGraph) -> bool {
210-
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
191+
pub fn is_panic_runtime(&self) -> bool {
192+
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
211193
attr::contains_name(&attrs, "panic_runtime")
212194
}
213195

214-
pub fn needs_panic_runtime(&self, dep_graph: &DepGraph) -> bool {
215-
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
196+
pub fn needs_panic_runtime(&self) -> bool {
197+
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
216198
attr::contains_name(&attrs, "needs_panic_runtime")
217199
}
218200

219-
pub fn is_compiler_builtins(&self, dep_graph: &DepGraph) -> bool {
220-
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
201+
pub fn is_compiler_builtins(&self) -> bool {
202+
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
221203
attr::contains_name(&attrs, "compiler_builtins")
222204
}
223205

224-
pub fn is_sanitizer_runtime(&self, dep_graph: &DepGraph) -> bool {
225-
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
206+
pub fn is_sanitizer_runtime(&self) -> bool {
207+
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
226208
attr::contains_name(&attrs, "sanitizer_runtime")
227209
}
228210

229-
pub fn is_profiler_runtime(&self, dep_graph: &DepGraph) -> bool {
230-
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
211+
pub fn is_profiler_runtime(&self) -> bool {
212+
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
231213
attr::contains_name(&attrs, "profiler_runtime")
232214
}
233215

234-
pub fn is_no_builtins(&self, dep_graph: &DepGraph) -> bool {
235-
let attrs = self.get_item_attrs(CRATE_DEF_INDEX, dep_graph);
216+
pub fn is_no_builtins(&self) -> bool {
217+
let attrs = self.get_item_attrs(CRATE_DEF_INDEX);
236218
attr::contains_name(&attrs, "no_builtins")
237219
}
238220

239-
pub fn panic_strategy(&self, dep_graph: &DepGraph) -> PanicStrategy {
240-
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::Krate);
241-
self.root
242-
.panic_strategy
243-
.get(dep_graph, dep_node)
244-
.clone()
221+
pub fn panic_strategy(&self) -> PanicStrategy {
222+
self.root.panic_strategy.clone()
245223
}
246224
}

0 commit comments

Comments
 (0)