Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 34035d2

Browse files
committedSep 10, 2017
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 23 additions & 43 deletions
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

Lines changed: 27 additions & 49 deletions
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
}

‎src/librustc_metadata/cstore_impl.rs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc::ty::maps::Providers;
2727
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
2828
use rustc::hir::map::{DefKey, DefPath, DefPathHash};
2929
use rustc::hir::map::blocks::FnLikeNode;
30-
use rustc::hir::map::definitions::{DefPathTable, GlobalMetaDataKind};
30+
use rustc::hir::map::definitions::DefPathTable;
3131
use rustc::util::nodemap::{NodeSet, DefIdMap};
3232

3333
use std::any::Any;
@@ -148,7 +148,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
148148
lookup_deprecation_entry => {
149149
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
150150
}
151-
item_attrs => { cdata.get_item_attrs(def_id.index, &tcx.dep_graph) }
151+
item_attrs => { cdata.get_item_attrs(def_id.index) }
152152
// FIXME(#38501) We've skipped a `read` on the `HirBody` of
153153
// a `fn` when encoding, so the dep-tracking wouldn't work.
154154
// This is only used by rustdoc anyway, which shouldn't have
@@ -157,27 +157,26 @@ provide! { <'tcx> tcx, def_id, other, cdata,
157157
impl_parent => { cdata.get_parent_impl(def_id.index) }
158158
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
159159
is_exported_symbol => {
160-
let dep_node = cdata.metadata_dep_node(GlobalMetaDataKind::ExportedSymbols);
161-
cdata.exported_symbols.get(&tcx.dep_graph, dep_node).contains(&def_id.index)
160+
cdata.exported_symbols.contains(&def_id.index)
162161
}
163162
item_body_nested_bodies => { Rc::new(cdata.item_body_nested_bodies(def_id.index)) }
164163
const_is_rvalue_promotable_to_static => {
165164
cdata.const_is_rvalue_promotable_to_static(def_id.index)
166165
}
167166
is_mir_available => { cdata.is_item_mir_available(def_id.index) }
168167

169-
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats(&tcx.dep_graph)) }
170-
is_panic_runtime => { cdata.is_panic_runtime(&tcx.dep_graph) }
171-
is_compiler_builtins => { cdata.is_compiler_builtins(&tcx.dep_graph) }
172-
has_global_allocator => { cdata.has_global_allocator(&tcx.dep_graph) }
173-
is_sanitizer_runtime => { cdata.is_sanitizer_runtime(&tcx.dep_graph) }
174-
is_profiler_runtime => { cdata.is_profiler_runtime(&tcx.dep_graph) }
175-
panic_strategy => { cdata.panic_strategy(&tcx.dep_graph) }
168+
dylib_dependency_formats => { Rc::new(cdata.get_dylib_dependency_formats()) }
169+
is_panic_runtime => { cdata.is_panic_runtime() }
170+
is_compiler_builtins => { cdata.is_compiler_builtins() }
171+
has_global_allocator => { cdata.has_global_allocator() }
172+
is_sanitizer_runtime => { cdata.is_sanitizer_runtime() }
173+
is_profiler_runtime => { cdata.is_profiler_runtime() }
174+
panic_strategy => { cdata.panic_strategy() }
176175
extern_crate => { Rc::new(cdata.extern_crate.get()) }
177-
is_no_builtins => { cdata.is_no_builtins(&tcx.dep_graph) }
176+
is_no_builtins => { cdata.is_no_builtins() }
178177
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
179-
exported_symbols => { Rc::new(cdata.get_exported_symbols(&tcx.dep_graph)) }
180-
native_libraries => { Rc::new(cdata.get_native_libraries(&tcx.dep_graph)) }
178+
exported_symbols => { Rc::new(cdata.get_exported_symbols()) }
179+
native_libraries => { Rc::new(cdata.get_native_libraries()) }
181180
plugin_registrar_fn => {
182181
cdata.root.plugin_registrar_fn.map(|index| {
183182
DefId { krate: def_id.krate, index }
@@ -195,18 +194,18 @@ provide! { <'tcx> tcx, def_id, other, cdata,
195194
implementations_of_trait => {
196195
let mut result = vec![];
197196
let filter = Some(other);
198-
cdata.get_implementations_for_trait(filter, &tcx.dep_graph, &mut result);
197+
cdata.get_implementations_for_trait(filter, &mut result);
199198
Rc::new(result)
200199
}
201200

202201
all_trait_implementations => {
203202
let mut result = vec![];
204-
cdata.get_implementations_for_trait(None, &tcx.dep_graph, &mut result);
203+
cdata.get_implementations_for_trait(None, &mut result);
205204
Rc::new(result)
206205
}
207206

208207
is_dllimport_foreign_item => {
209-
cdata.is_dllimport_foreign_item(def_id.index, &tcx.dep_graph)
208+
cdata.is_dllimport_foreign_item(def_id.index)
210209
}
211210
visibility => { cdata.get_visibility(def_id.index) }
212211
dep_kind => { cdata.dep_kind.get() }
@@ -216,8 +215,8 @@ provide! { <'tcx> tcx, def_id, other, cdata,
216215
cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess);
217216
Rc::new(result)
218217
}
219-
defined_lang_items => { Rc::new(cdata.get_lang_items(&tcx.dep_graph)) }
220-
missing_lang_items => { Rc::new(cdata.get_missing_lang_items(&tcx.dep_graph)) }
218+
defined_lang_items => { Rc::new(cdata.get_lang_items()) }
219+
missing_lang_items => { Rc::new(cdata.get_missing_lang_items()) }
221220

222221
extern_const_body => {
223222
debug!("item_body({:?}): inlining item", def_id);
@@ -362,34 +361,25 @@ impl CrateStore for cstore::CStore {
362361
}
363362

364363
fn visibility_untracked(&self, def: DefId) -> ty::Visibility {
365-
self.read_dep_node(def);
366364
self.get_crate_data(def.krate).get_visibility(def.index)
367365
}
368366

369367
fn item_generics_cloned_untracked(&self, def: DefId) -> ty::Generics {
370-
self.read_dep_node(def);
371368
self.get_crate_data(def.krate).get_generics(def.index)
372369
}
373370

374371
fn associated_item_cloned_untracked(&self, def: DefId) -> ty::AssociatedItem
375372
{
376-
self.read_dep_node(def);
377373
self.get_crate_data(def.krate).get_associated_item(def.index)
378374
}
379375

380376
fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind
381377
{
382-
let data = self.get_crate_data(cnum);
383-
let dep_node = data.metadata_dep_node(GlobalMetaDataKind::CrateDeps);
384-
self.dep_graph.read(dep_node);
385-
data.dep_kind.get()
378+
self.get_crate_data(cnum).dep_kind.get()
386379
}
387380

388381
fn export_macros_untracked(&self, cnum: CrateNum) {
389382
let data = self.get_crate_data(cnum);
390-
let dep_node = data.metadata_dep_node(GlobalMetaDataKind::CrateDeps);
391-
392-
self.dep_graph.read(dep_node);
393383
if data.dep_kind.get() == DepKind::UnexportedMacrosOnly {
394384
data.dep_kind.set(DepKind::MacrosOnly)
395385
}
@@ -431,13 +421,11 @@ impl CrateStore for cstore::CStore {
431421

432422
fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name>
433423
{
434-
self.read_dep_node(def);
435424
self.get_crate_data(def.krate).get_struct_field_names(def.index)
436425
}
437426

438427
fn item_children_untracked(&self, def_id: DefId, sess: &Session) -> Vec<def::Export>
439428
{
440-
self.read_dep_node(def_id);
441429
let mut result = vec![];
442430
self.get_crate_data(def_id.krate)
443431
.each_child_of_item(def_id.index, |child| result.push(child), sess);
@@ -462,7 +450,7 @@ impl CrateStore for cstore::CStore {
462450
let body = filemap_to_stream(&sess.parse_sess, filemap, None);
463451

464452
// Mark the attrs as used
465-
let attrs = data.get_item_attrs(id.index, &self.dep_graph);
453+
let attrs = data.get_item_attrs(id.index);
466454
for attr in attrs.iter() {
467455
attr::mark_used(attr);
468456
}

‎src/librustc_metadata/decoder.rs

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary};
1414
use schema::*;
1515

16-
use rustc::dep_graph::{DepGraph, DepNode, DepKind};
1716
use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
18-
use rustc::hir::map::definitions::GlobalMetaDataKind;
1917
use rustc::hir;
2018

2119
use rustc::middle::cstore::LinkagePreference;
@@ -402,7 +400,6 @@ impl<'a, 'tcx> MetadataBlob {
402400
write!(out, "=External Dependencies=\n")?;
403401
let root = self.get_root();
404402
for (i, dep) in root.crate_deps
405-
.get_untracked()
406403
.decode(self)
407404
.enumerate() {
408405
write!(out, "{} {}-{}\n", i + 1, dep.name, dep.hash)?;
@@ -646,11 +643,9 @@ impl<'a, 'tcx> CrateMetadata {
646643
}
647644

648645
/// Iterates over the language items in the given crate.
649-
pub fn get_lang_items(&self, dep_graph: &DepGraph) -> Vec<(DefIndex, usize)> {
650-
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::LangItems);
646+
pub fn get_lang_items(&self) -> Vec<(DefIndex, usize)> {
651647
self.root
652648
.lang_items
653-
.get(dep_graph, dep_node)
654649
.decode(self)
655650
.collect()
656651
}
@@ -869,18 +864,13 @@ impl<'a, 'tcx> CrateMetadata {
869864
}
870865
}
871866

872-
pub fn get_item_attrs(&self,
873-
node_id: DefIndex,
874-
dep_graph: &DepGraph) -> Rc<[ast::Attribute]> {
867+
pub fn get_item_attrs(&self, node_id: DefIndex) -> Rc<[ast::Attribute]> {
875868
let (node_as, node_index) =
876869
(node_id.address_space().index(), node_id.as_array_index());
877870
if self.is_proc_macro(node_id) {
878871
return Rc::new([]);
879872
}
880873

881-
let dep_node = self.def_path_hash(node_id).to_dep_node(DepKind::MetaData);
882-
dep_graph.read(dep_node);
883-
884874
if let Some(&Some(ref val)) =
885875
self.attribute_cache.borrow()[node_as].get(node_index) {
886876
return val.clone();
@@ -947,7 +937,6 @@ impl<'a, 'tcx> CrateMetadata {
947937

948938
pub fn get_implementations_for_trait(&self,
949939
filter: Option<DefId>,
950-
dep_graph: &DepGraph,
951940
result: &mut Vec<DefId>) {
952941
// Do a reverse lookup beforehand to avoid touching the crate_num
953942
// hash map in the loop below.
@@ -958,16 +947,13 @@ impl<'a, 'tcx> CrateMetadata {
958947
None => None,
959948
};
960949

961-
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::Impls);
962-
963950
if let Some(filter) = filter {
964951
if let Some(impls) = self.trait_impls
965-
.get(dep_graph, dep_node)
966952
.get(&filter) {
967953
result.extend(impls.decode(self).map(|idx| self.local_def_id(idx)));
968954
}
969955
} else {
970-
for impls in self.trait_impls.get(dep_graph, dep_node).values() {
956+
for impls in self.trait_impls.values() {
971957
result.extend(impls.decode(self).map(|idx| self.local_def_id(idx)));
972958
}
973959
}
@@ -983,25 +969,13 @@ impl<'a, 'tcx> CrateMetadata {
983969
}
984970

985971

986-
pub fn get_native_libraries(&self,
987-
dep_graph: &DepGraph)
988-
-> Vec<NativeLibrary> {
989-
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::NativeLibraries);
990-
self.root
991-
.native_libraries
992-
.get(dep_graph, dep_node)
993-
.decode(self)
994-
.collect()
972+
pub fn get_native_libraries(&self) -> Vec<NativeLibrary> {
973+
self.root.native_libraries.decode(self).collect()
995974
}
996975

997-
pub fn get_dylib_dependency_formats(&self,
998-
dep_graph: &DepGraph)
999-
-> Vec<(CrateNum, LinkagePreference)> {
1000-
let dep_node =
1001-
self.metadata_dep_node(GlobalMetaDataKind::DylibDependencyFormats);
976+
pub fn get_dylib_dependency_formats(&self) -> Vec<(CrateNum, LinkagePreference)> {
1002977
self.root
1003978
.dylib_dependency_formats
1004-
.get(dep_graph, dep_node)
1005979
.decode(self)
1006980
.enumerate()
1007981
.flat_map(|(i, link)| {
@@ -1011,11 +985,9 @@ impl<'a, 'tcx> CrateMetadata {
1011985
.collect()
1012986
}
1013987

1014-
pub fn get_missing_lang_items(&self, dep_graph: &DepGraph) -> Vec<lang_items::LangItem> {
1015-
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::LangItemsMissing);
988+
pub fn get_missing_lang_items(&self) -> Vec<lang_items::LangItem> {
1016989
self.root
1017990
.lang_items_missing
1018-
.get(dep_graph, dep_node)
1019991
.decode(self)
1020992
.collect()
1021993
}
@@ -1030,10 +1002,8 @@ impl<'a, 'tcx> CrateMetadata {
10301002
arg_names.decode(self).collect()
10311003
}
10321004

1033-
pub fn get_exported_symbols(&self, dep_graph: &DepGraph) -> Vec<DefId> {
1034-
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::ExportedSymbols);
1005+
pub fn get_exported_symbols(&self) -> Vec<DefId> {
10351006
self.exported_symbols
1036-
.get(dep_graph, dep_node)
10371007
.iter()
10381008
.map(|&index| self.local_def_id(index))
10391009
.collect()
@@ -1065,11 +1035,8 @@ impl<'a, 'tcx> CrateMetadata {
10651035
}
10661036
}
10671037

1068-
pub fn is_dllimport_foreign_item(&self, id: DefIndex, dep_graph: &DepGraph) -> bool {
1069-
let dep_node = self.metadata_dep_node(GlobalMetaDataKind::NativeLibraries);
1070-
self.dllimport_foreign_items
1071-
.get(dep_graph, dep_node)
1072-
.contains(&id)
1038+
pub fn is_dllimport_foreign_item(&self, id: DefIndex) -> bool {
1039+
self.dllimport_foreign_items.contains(&id)
10731040
}
10741041

10751042
pub fn is_default_impl(&self, impl_id: DefIndex) -> bool {
@@ -1221,10 +1188,4 @@ impl<'a, 'tcx> CrateMetadata {
12211188
*self.codemap_import_info.borrow_mut() = imported_filemaps;
12221189
self.codemap_import_info.borrow()
12231190
}
1224-
1225-
pub fn metadata_dep_node(&self, kind: GlobalMetaDataKind) -> DepNode {
1226-
let def_index = kind.def_index(&self.def_path_table);
1227-
let def_path_hash = self.def_path_table.def_path_hash(def_index);
1228-
def_path_hash.to_dep_node(DepKind::MetaData)
1229-
}
12301191
}

‎src/librustc_metadata/encoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
248248
def_index: DefIndex,
249249
op: fn(&mut IsolatedEncoder<'x, 'a, 'tcx>, DATA) -> R,
250250
data: DATA)
251-
-> Tracked<R> {
251+
-> R {
252252
let mut entry_builder = IsolatedEncoder::new(self);
253253
let ret = op(&mut entry_builder, data);
254254
let (fingerprint, this) = entry_builder.finish();
@@ -260,7 +260,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
260260
})
261261
}
262262

263-
Tracked::new(ret)
263+
ret
264264
}
265265

266266
fn encode_info_for_items(&mut self) -> Index {
@@ -408,9 +408,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
408408
triple: tcx.sess.opts.target_triple.clone(),
409409
hash: link_meta.crate_hash,
410410
disambiguator: tcx.sess.local_crate_disambiguator(),
411-
panic_strategy: Tracked::new(tcx.sess.panic_strategy()),
412-
has_global_allocator: Tracked::new(has_global_allocator),
413-
has_default_lib_allocator: Tracked::new(has_default_lib_allocator),
411+
panic_strategy: tcx.sess.panic_strategy(),
412+
has_global_allocator: has_global_allocator,
413+
has_default_lib_allocator: has_default_lib_allocator,
414414
plugin_registrar_fn: tcx.sess
415415
.plugin_registrar_fn
416416
.get()

‎src/librustc_metadata/schema.rs

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ use std::mem;
3232
use rustc_data_structures::stable_hasher::{StableHasher, HashStable,
3333
StableHasherResult};
3434

35-
use rustc::dep_graph::{DepGraph, DepNode};
36-
3735
pub fn rustc_version() -> String {
3836
format!("rustc {}",
3937
option_env!("CFG_VERSION").unwrap_or("unknown version"))
@@ -188,75 +186,27 @@ pub enum LazyState {
188186
Previous(usize),
189187
}
190188

191-
/// A `Tracked<T>` wraps a value so that one can only access it when specifying
192-
/// the `DepNode` for that value. This makes it harder to forget registering
193-
/// reads.
194-
#[derive(RustcEncodable, RustcDecodable)]
195-
pub struct Tracked<T> {
196-
state: T,
197-
}
198-
199-
impl<T> Tracked<T> {
200-
pub fn new(state: T) -> Tracked<T> {
201-
Tracked {
202-
state,
203-
}
204-
}
205-
206-
pub fn get(&self, dep_graph: &DepGraph, dep_node: DepNode) -> &T {
207-
dep_graph.read(dep_node);
208-
&self.state
209-
}
210-
211-
pub fn get_untracked(&self) -> &T {
212-
&self.state
213-
}
214-
215-
pub fn map<F, R>(&self, f: F) -> Tracked<R>
216-
where F: FnOnce(&T) -> R
217-
{
218-
Tracked {
219-
state: f(&self.state),
220-
}
221-
}
222-
}
223-
224-
impl<'a, 'gcx, 'tcx, T> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for Tracked<T>
225-
where T: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
226-
{
227-
fn hash_stable<W: StableHasherResult>(&self,
228-
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
229-
hasher: &mut StableHasher<W>) {
230-
let Tracked {
231-
ref state
232-
} = *self;
233-
234-
state.hash_stable(hcx, hasher);
235-
}
236-
}
237-
238-
239189
#[derive(RustcEncodable, RustcDecodable)]
240190
pub struct CrateRoot {
241191
pub name: Symbol,
242192
pub triple: String,
243193
pub hash: hir::svh::Svh,
244194
pub disambiguator: Symbol,
245-
pub panic_strategy: Tracked<PanicStrategy>,
246-
pub has_global_allocator: Tracked<bool>,
247-
pub has_default_lib_allocator: Tracked<bool>,
195+
pub panic_strategy: PanicStrategy,
196+
pub has_global_allocator: bool,
197+
pub has_default_lib_allocator: bool,
248198
pub plugin_registrar_fn: Option<DefIndex>,
249199
pub macro_derive_registrar: Option<DefIndex>,
250200

251-
pub crate_deps: Tracked<LazySeq<CrateDep>>,
252-
pub dylib_dependency_formats: Tracked<LazySeq<Option<LinkagePreference>>>,
253-
pub lang_items: Tracked<LazySeq<(DefIndex, usize)>>,
254-
pub lang_items_missing: Tracked<LazySeq<lang_items::LangItem>>,
255-
pub native_libraries: Tracked<LazySeq<NativeLibrary>>,
201+
pub crate_deps: LazySeq<CrateDep>,
202+
pub dylib_dependency_formats: LazySeq<Option<LinkagePreference>>,
203+
pub lang_items: LazySeq<(DefIndex, usize)>,
204+
pub lang_items_missing: LazySeq<lang_items::LangItem>,
205+
pub native_libraries: LazySeq<NativeLibrary>,
256206
pub codemap: LazySeq<syntax_pos::FileMap>,
257207
pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
258-
pub impls: Tracked<LazySeq<TraitImpls>>,
259-
pub exported_symbols: Tracked<LazySeq<DefIndex>>,
208+
pub impls: LazySeq<TraitImpls>,
209+
pub exported_symbols: LazySeq<DefIndex>,
260210
pub index: LazySeq<index::Index>,
261211
}
262212

‎src/librustdoc/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn run_core(search_paths: SearchPaths,
146146

147147
let dep_graph = DepGraph::new(false);
148148
let _ignore = dep_graph.in_ignore();
149-
let cstore = Rc::new(CStore::new(&dep_graph, box rustc_trans::LlvmMetadataLoader));
149+
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
150150
let mut sess = session::build_session_(
151151
sessopts, &dep_graph, cpath, diagnostic_handler, codemap, cstore.clone()
152152
);

‎src/librustdoc/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn run(input: &str,
8585

8686
let dep_graph = DepGraph::new(false);
8787
let _ignore = dep_graph.in_ignore();
88-
let cstore = Rc::new(CStore::new(&dep_graph, box rustc_trans::LlvmMetadataLoader));
88+
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
8989
let mut sess = session::build_session_(
9090
sessopts, &dep_graph, Some(input_path.clone()), handler, codemap.clone(), cstore.clone(),
9191
);
@@ -238,7 +238,7 @@ fn run_test(test: &str, cratename: &str, filename: &str, cfgs: Vec<String>, libs
238238
let diagnostic_handler = errors::Handler::with_emitter(true, false, box emitter);
239239

240240
let dep_graph = DepGraph::new(false);
241-
let cstore = Rc::new(CStore::new(&dep_graph, box rustc_trans::LlvmMetadataLoader));
241+
let cstore = Rc::new(CStore::new(box rustc_trans::LlvmMetadataLoader));
242242
let mut sess = session::build_session_(
243243
sessopts, &dep_graph, None, diagnostic_handler, codemap, cstore.clone(),
244244
);

‎src/test/run-make/issue-19371/foo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
5959

6060
let descriptions = Registry::new(&rustc::DIAGNOSTICS);
6161
let dep_graph = DepGraph::new(opts.build_dep_graph());
62-
let cstore = Rc::new(CStore::new(&dep_graph, Box::new(rustc_trans::LlvmMetadataLoader)));
62+
let cstore = Rc::new(CStore::new(Box::new(rustc_trans::LlvmMetadataLoader)));
6363
let sess = build_session(opts, &dep_graph, None, descriptions, cstore.clone());
6464
rustc_trans::init(&sess);
6565
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));

0 commit comments

Comments
 (0)
Please sign in to comment.