diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 3efba6a5f22..aa1a8726f9d 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -554,6 +554,12 @@ define_dep_nodes!( <'tcx> [] NamedRegion(HirId), [] IsLateBound(HirId), [] ObjectLifetimeDefaults(HirId), + + [] Visibility(DefId), + [] DepKind(CrateNum), + [] CrateName(CrateNum), + [] ItemChildren(DefId), + [] ExternModStmtCnum(HirId), ); trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug { diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 476bf947142..ff52f1e4e39 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -357,7 +357,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // for imported and non-imported crates if exp_path == found_path || exp_abs_path == found_abs_path { - let crate_name = self.tcx.sess.cstore.crate_name(did1.krate); + let crate_name = self.tcx.crate_name(did1.krate); err.span_note(sp, &format!("Perhaps two different versions \ of crate `{}` are being used?", crate_name)); diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 97b04747410..61a923a5954 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -222,6 +222,14 @@ pub trait MetadataLoader { /// A store of Rust crates, through with their metadata /// can be accessed. +/// +/// Note that this trait should probably not be expanding today. All new +/// functionality should be driven through queries instead! +/// +/// If you find a method on this trait named `{name}_untracked` it signifies +/// that it's *not* tracked for dependency information throughout compilation +/// (it'd break incremental compilation) and should only be called pre-HIR (e.g. +/// during resolve) pub trait CrateStore { fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc; @@ -229,7 +237,6 @@ pub trait CrateStore { fn metadata_loader(&self) -> &MetadataLoader; // item info - fn visibility(&self, def: DefId) -> ty::Visibility; fn visible_parent_map<'a>(&'a self, sess: &Session) -> ::std::cell::Ref<'a, DefIdMap>; fn item_generics_cloned(&self, def: DefId) -> ty::Generics; @@ -237,22 +244,24 @@ pub trait CrateStore { fn associated_item_cloned(&self, def: DefId) -> ty::AssociatedItem; // crate metadata - fn dep_kind(&self, cnum: CrateNum) -> DepKind; - fn export_macros(&self, cnum: CrateNum); fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>; fn missing_lang_items(&self, cnum: CrateNum) -> Vec; - /// The name of the crate as it is referred to in source code of the current - /// crate. - fn crate_name(&self, cnum: CrateNum) -> Symbol; // resolve fn def_key(&self, def: DefId) -> DefKey; fn def_path(&self, def: DefId) -> hir_map::DefPath; fn def_path_hash(&self, def: DefId) -> hir_map::DefPathHash; fn def_path_table(&self, cnum: CrateNum) -> Rc; - fn struct_field_names(&self, def: DefId) -> Vec; - fn item_children(&self, did: DefId, sess: &Session) -> Vec; - fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro; + + // "queries" used in resolve that aren't tracked for incremental compilation + fn visibility_untracked(&self, def: DefId) -> ty::Visibility; + fn export_macros_untracked(&self, cnum: CrateNum); + fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind; + fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol; + fn struct_field_names_untracked(&self, def: DefId) -> Vec; + fn item_children_untracked(&self, did: DefId, sess: &Session) -> Vec; + fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro; + fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option; // misc. metadata fn item_body<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) @@ -265,7 +274,6 @@ pub trait CrateStore { // utility functions fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>; fn used_crate_source(&self, cnum: CrateNum) -> CrateSource; - fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option; fn encode_metadata<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, link_meta: &LinkMeta, @@ -310,7 +318,7 @@ impl CrateStore for DummyCrateStore { fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc { bug!("crate_data_as_rc_any") } // item info - fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") } + fn visibility_untracked(&self, def: DefId) -> ty::Visibility { bug!("visibility") } fn visible_parent_map<'a>(&'a self, session: &Session) -> ::std::cell::Ref<'a, DefIdMap> { @@ -328,9 +336,9 @@ impl CrateStore for DummyCrateStore { { bug!("lang_items") } fn missing_lang_items(&self, cnum: CrateNum) -> Vec { bug!("missing_lang_items") } - fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") } - fn export_macros(&self, cnum: CrateNum) { bug!("export_macros") } - fn crate_name(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") } + fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") } + fn export_macros_untracked(&self, cnum: CrateNum) { bug!("export_macros") } + fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") } // resolve fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") } @@ -343,11 +351,13 @@ impl CrateStore for DummyCrateStore { fn def_path_table(&self, cnum: CrateNum) -> Rc { bug!("def_path_table") } - fn struct_field_names(&self, def: DefId) -> Vec { bug!("struct_field_names") } - fn item_children(&self, did: DefId, sess: &Session) -> Vec { + fn struct_field_names_untracked(&self, def: DefId) -> Vec { + bug!("struct_field_names") + } + fn item_children_untracked(&self, did: DefId, sess: &Session) -> Vec { bug!("item_children") } - fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") } + fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") } // misc. metadata fn item_body<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) @@ -363,7 +373,7 @@ impl CrateStore for DummyCrateStore { fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)> { vec![] } fn used_crate_source(&self, cnum: CrateNum) -> CrateSource { bug!("used_crate_source") } - fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option { None } + fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option { None } fn encode_metadata<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, link_meta: &LinkMeta, diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs index 323c069ef0c..a34ef099344 100644 --- a/src/librustc/middle/dependency_format.rs +++ b/src/librustc/middle/dependency_format.rs @@ -133,11 +133,11 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, return v; } for cnum in sess.cstore.crates() { - if sess.cstore.dep_kind(cnum).macros_only() { continue } + if tcx.dep_kind(cnum).macros_only() { continue } let src = sess.cstore.used_crate_source(cnum); if src.rlib.is_some() { continue } sess.err(&format!("dependency `{}` not found in rlib format", - sess.cstore.crate_name(cnum))); + tcx.crate_name(cnum))); } return Vec::new(); } @@ -166,17 +166,16 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // dependencies, ensuring there are no conflicts. The only valid case for a // dependency to be relied upon twice is for both cases to rely on a dylib. for cnum in sess.cstore.crates() { - if sess.cstore.dep_kind(cnum).macros_only() { continue } - let name = sess.cstore.crate_name(cnum); + if tcx.dep_kind(cnum).macros_only() { continue } + let name = tcx.crate_name(cnum); let src = sess.cstore.used_crate_source(cnum); if src.dylib.is_some() { info!("adding dylib: {}", name); - add_library(sess, cnum, RequireDynamic, &mut formats); + add_library(tcx, cnum, RequireDynamic, &mut formats); let deps = tcx.dylib_dependency_formats(cnum); for &(depnum, style) in deps.iter() { - info!("adding {:?}: {}", style, - sess.cstore.crate_name(depnum)); - add_library(sess, depnum, style, &mut formats); + info!("adding {:?}: {}", style, tcx.crate_name(depnum)); + add_library(tcx, depnum, style, &mut formats); } } } @@ -200,10 +199,10 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let src = sess.cstore.used_crate_source(cnum); if src.dylib.is_none() && !formats.contains_key(&cnum) && - sess.cstore.dep_kind(cnum) == DepKind::Explicit { + tcx.dep_kind(cnum) == DepKind::Explicit { assert!(src.rlib.is_some() || src.rmeta.is_some()); - info!("adding staticlib: {}", sess.cstore.crate_name(cnum)); - add_library(sess, cnum, RequireStatic, &mut formats); + info!("adding staticlib: {}", tcx.crate_name(cnum)); + add_library(tcx, cnum, RequireStatic, &mut formats); ret[cnum.as_usize() - 1] = Linkage::Static; } } @@ -237,7 +236,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, Linkage::Static => "rlib", _ => "dylib", }; - let name = sess.cstore.crate_name(cnum); + let name = tcx.crate_name(cnum); sess.err(&format!("crate `{}` required to be available in {}, \ but it was not available in this form", name, kind)); @@ -248,7 +247,7 @@ fn calculate_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, return ret; } -fn add_library(sess: &session::Session, +fn add_library(tcx: TyCtxt, cnum: CrateNum, link: LinkagePreference, m: &mut FxHashMap) { @@ -262,8 +261,8 @@ fn add_library(sess: &session::Session, // This error is probably a little obscure, but I imagine that it // can be refined over time. if link2 != link || link == RequireStatic { - sess.struct_err(&format!("cannot satisfy dependencies so `{}` only \ - shows up once", sess.cstore.crate_name(cnum))) + tcx.sess.struct_err(&format!("cannot satisfy dependencies so `{}` only \ + shows up once", tcx.crate_name(cnum))) .help("having upstream crates all available in one format \ will likely make this go away") .emit(); @@ -284,7 +283,7 @@ fn attempt_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) { if tcx.is_panic_runtime(cnum) { if let Some((prev, _)) = panic_runtime { - let prev_name = sess.cstore.crate_name(prev); - let cur_name = sess.cstore.crate_name(cnum); + let prev_name = tcx.crate_name(prev); + let cur_name = tcx.crate_name(cnum); sess.err(&format!("cannot link together two \ panic runtimes: {} and {}", prev_name, cur_name)); @@ -379,7 +378,7 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) { sess.err(&format!("the linked panic runtime `{}` is \ not compiled with this crate's \ panic strategy `{}`", - sess.cstore.crate_name(cnum), + tcx.crate_name(cnum), desired_strategy.desc())); } @@ -405,7 +404,7 @@ fn verify_ok<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, list: &[Linkage]) { panic strategy `{}` which is \ incompatible with this crate's \ strategy of `{}`", - sess.cstore.crate_name(cnum), + tcx.crate_name(cnum), found_strategy.desc(), desired_strategy.desc())); } diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index ae3e3a30f37..351daa198e8 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -179,7 +179,7 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> { name), None => self.session.struct_err(&format!( "duplicate lang item in crate `{}`: `{}`.", - cstore.crate_name(item_def_id.krate), + cstore.crate_name_untracked(item_def_id.krate), name)), }; if let Some(span) = self.hir_map.span_if_local(original_def_id) { @@ -187,7 +187,7 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> { "first defined here."); } else { err.note(&format!("first defined in crate `{}`.", - cstore.crate_name(original_def_id.krate))); + cstore.crate_name_untracked(original_def_id.krate))); } err.emit(); } diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index d2ed29a3a0f..6d7d028d286 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -476,7 +476,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { _ => {} } - let visibility = self.sess.cstore.visibility(def_id); + let visibility = self.visibility(def_id); match visibility { // must check stability for pub items. @@ -610,7 +610,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> { // compiler-generated `extern crate` items have a dummy span. if item.span == DUMMY_SP { return } - let cnum = match self.tcx.sess.cstore.extern_mod_stmt_cnum(item.id) { + let hir_id = self.tcx.hir.node_to_hir_id(item.id); + let cnum = match self.tcx.extern_mod_stmt_cnum(hir_id) { Some(cnum) => cnum, None => return, }; diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index f2e40e3693a..dbd288c6f2d 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -909,14 +909,6 @@ impl<'tcx> GlobalCtxt<'tcx> { } impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { - pub fn crate_name(self, cnum: CrateNum) -> Symbol { - if cnum == LOCAL_CRATE { - self.crate_name - } else { - self.sess.cstore.crate_name(cnum) - } - } - pub fn alloc_generics(self, generics: ty::Generics) -> &'gcx ty::Generics { self.global_arenas.generics.alloc(generics) } @@ -2008,4 +2000,8 @@ pub fn provide(providers: &mut ty::maps::Providers) { providers.object_lifetime_defaults = |tcx, id| { tcx.gcx.named_region_map.object_lifetime_defaults.get(&id).cloned() }; + providers.crate_name = |tcx, id| { + assert_eq!(id, LOCAL_CRATE); + tcx.crate_name + }; } diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index d4bd434add4..762b35793de 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -17,7 +17,7 @@ use hir::svh::Svh; use lint; use middle::const_val; use middle::cstore::{ExternCrate, LinkagePreference, NativeLibrary}; -use middle::cstore::NativeLibraryKind; +use middle::cstore::{NativeLibraryKind, DepKind}; use middle::privacy::AccessLevels; use middle::region; use middle::region::RegionMaps; @@ -669,6 +669,24 @@ impl<'tcx> QueryDescription for queries::object_lifetime_defaults<'tcx> { } } +impl<'tcx> QueryDescription for queries::dep_kind<'tcx> { + fn describe(_tcx: TyCtxt, _: CrateNum) -> String { + format!("fetching what a dependency looks like") + } +} + +impl<'tcx> QueryDescription for queries::crate_name<'tcx> { + fn describe(_tcx: TyCtxt, _: CrateNum) -> String { + format!("fetching what a crate is named") + } +} + +impl<'tcx> QueryDescription for queries::extern_mod_stmt_cnum<'tcx> { + fn describe(_tcx: TyCtxt, _: HirId) -> String { + format!("looking up the CrateNum for an `extern mod` statement") + } +} + // If enabled, send a message to the profile-queries thread macro_rules! profq_msg { ($tcx:expr, $msg:expr) => { @@ -1268,6 +1286,12 @@ define_maps! { <'tcx> [] is_late_bound: IsLateBound(HirId) -> bool, [] object_lifetime_defaults: ObjectLifetimeDefaults(HirId) -> Option>>, + + [] visibility: Visibility(DefId) -> ty::Visibility, + [] dep_kind: DepKind(CrateNum) -> DepKind, + [] crate_name: CrateName(CrateNum) -> Symbol, + [] item_children: ItemChildren(DefId) -> Rc>, + [] extern_mod_stmt_cnum: ExternModStmtCnum(HirId) -> Option, } fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index d3cfd114451..c58d9814704 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2315,7 +2315,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let node_id = self.hir.as_local_node_id(impl_did).unwrap(); Ok(self.hir.span(node_id)) } else { - Err(self.sess.cstore.crate_name(impl_did.krate)) + Err(self.crate_name(impl_did.krate)) } } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 27ee8fd5cdd..60d7a4ce87e 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1063,7 +1063,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PluginAsLibrary { _ => return, }; - let prfn = match cx.sess().cstore.extern_mod_stmt_cnum(it.id) { + let hir_id = cx.tcx.hir.node_to_hir_id(it.id); + let prfn = match cx.tcx.extern_mod_stmt_cnum(hir_id) { Some(cnum) => cx.tcx.plugin_registrar_fn(cnum), None => { // Probably means we aren't linking the crate for some reason. diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index 3f7a314c755..326ec839808 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -205,6 +205,14 @@ provide! { <'tcx> tcx, def_id, other, cdata, is_dllimport_foreign_item => { cdata.is_dllimport_foreign_item(def_id.index, &tcx.dep_graph) } + visibility => { cdata.get_visibility(def_id.index) } + dep_kind => { cdata.dep_kind.get() } + crate_name => { cdata.name } + item_children => { + let mut result = vec![]; + cdata.each_child_of_item(def_id.index, |child| result.push(child), tcx.sess); + Rc::new(result) + } } pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) { @@ -246,6 +254,10 @@ pub fn provide_local<'tcx>(providers: &mut Providers<'tcx>) { assert_eq!(cnum, LOCAL_CRATE); Rc::new(link_args::collect(tcx)) }, + extern_mod_stmt_cnum: |tcx, id| { + let id = tcx.hir.definitions().find_node_for_hir_id(id); + tcx.sess.cstore.extern_mod_stmt_cnum_untracked(id) + }, ..*providers }; } @@ -259,7 +271,7 @@ impl CrateStore for cstore::CStore { &*self.metadata_loader } - fn visibility(&self, def: DefId) -> ty::Visibility { + fn visibility_untracked(&self, def: DefId) -> ty::Visibility { self.read_dep_node(def); self.get_crate_data(def.krate).get_visibility(def.index) } @@ -275,7 +287,7 @@ impl CrateStore for cstore::CStore { self.get_crate_data(def.krate).get_associated_item(def.index) } - fn dep_kind(&self, cnum: CrateNum) -> DepKind + fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind { let data = self.get_crate_data(cnum); let dep_node = data.metadata_dep_node(GlobalMetaDataKind::CrateDeps); @@ -283,7 +295,7 @@ impl CrateStore for cstore::CStore { data.dep_kind.get() } - fn export_macros(&self, cnum: CrateNum) { + fn export_macros_untracked(&self, cnum: CrateNum) { let data = self.get_crate_data(cnum); let dep_node = data.metadata_dep_node(GlobalMetaDataKind::CrateDeps); @@ -304,7 +316,7 @@ impl CrateStore for cstore::CStore { self.get_crate_data(cnum).get_missing_lang_items(&self.dep_graph) } - fn crate_name(&self, cnum: CrateNum) -> Symbol + fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol { self.get_crate_data(cnum).name } @@ -338,13 +350,13 @@ impl CrateStore for cstore::CStore { self.get_crate_data(cnum).def_path_table.clone() } - fn struct_field_names(&self, def: DefId) -> Vec + fn struct_field_names_untracked(&self, def: DefId) -> Vec { self.read_dep_node(def); self.get_crate_data(def.krate).get_struct_field_names(def.index) } - fn item_children(&self, def_id: DefId, sess: &Session) -> Vec + fn item_children_untracked(&self, def_id: DefId, sess: &Session) -> Vec { self.read_dep_node(def_id); let mut result = vec![]; @@ -353,7 +365,7 @@ impl CrateStore for cstore::CStore { result } - fn load_macro(&self, id: DefId, sess: &Session) -> LoadedMacro { + fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro { let data = self.get_crate_data(id.krate); if let Some(ref proc_macros) = data.proc_macros { return LoadedMacro::ProcMacro(proc_macros[id.index.as_usize() - 1].1.clone()); @@ -427,7 +439,7 @@ impl CrateStore for cstore::CStore { self.get_crate_data(cnum).source.clone() } - fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option + fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option { self.do_extern_mod_stmt_cnum(emod_id) } @@ -475,7 +487,7 @@ impl CrateStore for cstore::CStore { let mut add_child = |bfs_queue: &mut VecDeque<_>, child: def::Export, parent: DefId| { let child = child.def.def_id(); - if self.visibility(child) != ty::Visibility::Public { + if self.visibility_untracked(child) != ty::Visibility::Public { return; } @@ -499,7 +511,7 @@ impl CrateStore for cstore::CStore { index: CRATE_DEF_INDEX }); while let Some(def) = bfs_queue.pop_front() { - for child in self.item_children(def, sess) { + for child in self.item_children_untracked(def, sess) { add_child(bfs_queue, child, def); } } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 4fd610ac79b..0893842eff0 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -1288,8 +1288,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { } fn encode_crate_deps(&mut self, _: ()) -> LazySeq { - let cstore = &*self.tcx.sess.cstore; - let crates = cstore.crates(); + let crates = self.tcx.sess.cstore.crates(); let mut deps = crates .iter() @@ -1297,7 +1296,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { let dep = CrateDep { name: self.tcx.original_crate_name(cnum), hash: self.tcx.crate_hash(cnum), - kind: cstore.dep_kind(cnum), + kind: self.tcx.dep_kind(cnum), }; (cnum, dep) }) diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 872a29e7bc0..139cb61bd9b 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -630,7 +630,7 @@ impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> { }; ty::Visibility::from_hir(vis, node_id, self.tcx) } - None => self.tcx.sess.cstore.visibility(did), + None => self.tcx.visibility(did), } } diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 47fa5357abf..776ec3fd3f9 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -253,7 +253,7 @@ impl<'a> Resolver<'a> { self.crate_loader.process_item(item, &self.definitions); // n.b. we don't need to look at the path option here, because cstore already did - let crate_id = self.session.cstore.extern_mod_stmt_cnum(item.id).unwrap(); + let crate_id = self.session.cstore.extern_mod_stmt_cnum_untracked(item.id).unwrap(); let module = self.get_module(DefId { krate: crate_id, index: CRATE_DEF_INDEX }); self.populate_module_if_necessary(module); @@ -449,7 +449,7 @@ impl<'a> Resolver<'a> { let ident = child.ident; let def = child.def; let def_id = def.def_id(); - let vis = self.session.cstore.visibility(def_id); + let vis = self.session.cstore.visibility_untracked(def_id); let span = child.span; let expansion = Mark::root(); // FIXME(jseyfried) intercrate hygiene match def { @@ -485,7 +485,7 @@ impl<'a> Resolver<'a> { span); self.define(parent, ident, TypeNS, (module, vis, DUMMY_SP, expansion)); - for child in self.session.cstore.item_children(def_id, self.session) { + for child in self.session.cstore.item_children_untracked(def_id, self.session) { let ns = if let Def::AssociatedTy(..) = child.def { TypeNS } else { ValueNS }; self.define(module, child.ident, ns, (child.def, ty::Visibility::Public, DUMMY_SP, expansion)); @@ -501,7 +501,7 @@ impl<'a> Resolver<'a> { self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion)); // Record field names for error reporting. - let field_names = self.session.cstore.struct_field_names(def_id); + let field_names = self.session.cstore.struct_field_names_untracked(def_id); self.insert_field_names(def_id, field_names); } Def::Macro(..) => { @@ -516,13 +516,13 @@ impl<'a> Resolver<'a> { return self.module_map[&def_id] } - let macros_only = self.session.cstore.dep_kind(def_id.krate).macros_only(); + let macros_only = self.session.cstore.dep_kind_untracked(def_id.krate).macros_only(); if let Some(&module) = self.extern_module_map.get(&(def_id, macros_only)) { return module; } let (name, parent) = if def_id.index == CRATE_DEF_INDEX { - (self.session.cstore.crate_name(def_id.krate), None) + (self.session.cstore.crate_name_untracked(def_id.krate), None) } else { let def_key = self.session.cstore.def_key(def_id); (def_key.disambiguated_data.data.get_opt_name().unwrap(), @@ -558,7 +558,7 @@ impl<'a> Resolver<'a> { return ext.clone(); } - let macro_def = match self.session.cstore.load_macro(def_id, &self.session) { + let macro_def = match self.session.cstore.load_macro_untracked(def_id, &self.session) { LoadedMacro::MacroDef(macro_def) => macro_def, LoadedMacro::ProcMacro(ext) => return ext, }; @@ -574,7 +574,8 @@ impl<'a> Resolver<'a> { /// is built, building it if it is not. pub fn populate_module_if_necessary(&mut self, module: Module<'a>) { if module.populated.get() { return } - for child in self.session.cstore.item_children(module.def_id().unwrap(), self.session) { + let def_id = module.def_id().unwrap(); + for child in self.session.cstore.item_children_untracked(def_id, self.session) { self.build_reduced_graph_for_external_crate_def(module, child); } module.populated.set(true) @@ -605,7 +606,8 @@ impl<'a> Resolver<'a> { span_err!(self.session, item.span, E0468, "an `extern crate` loading macros must be at the crate root"); } else if !self.use_extern_macros && !used && - self.session.cstore.dep_kind(module.def_id().unwrap().krate).macros_only() { + self.session.cstore.dep_kind_untracked(module.def_id().unwrap().krate) + .macros_only() { let msg = "proc macro crates and `#[no_link]` crates have no effect without \ `#[macro_use]`"; self.session.span_warn(item.span, msg); @@ -648,7 +650,7 @@ impl<'a> Resolver<'a> { } } for (name, span) in legacy_imports.reexports { - self.session.cstore.export_macros(module.def_id().unwrap().krate); + self.session.cstore.export_macros_untracked(module.def_id().unwrap().krate); let ident = Ident::with_empty_ctxt(name); let result = self.resolve_ident_in_module(module, ident, MacroNS, false, false, span); if let Ok(binding) = result { diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 9531c8baa0b..c083a0ff588 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -778,7 +778,7 @@ impl<'a> Resolver<'a> { _ => return, }; - let crate_name = self.session.cstore.crate_name(krate); + let crate_name = self.session.cstore.crate_name_untracked(krate); self.session.struct_span_err(use_span, warn_msg) .help(&format!("instead, import the procedural macro like any other item: \ diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 71bcee56ecc..7524b7e8c6c 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -844,7 +844,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { let def = binding.def(); if def != Def::Err { if !def.def_id().is_local() { - self.session.cstore.export_macros(def.def_id().krate); + self.session.cstore.export_macros_untracked(def.def_id().krate); } if let Def::Macro(..) = def { if let Some(&span) = exported_macro_names.get(&ident.modern()) { diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 9ee38dd86c1..3dc3bad602a 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -119,7 +119,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { }; let lo_loc = self.span_utils.sess.codemap().lookup_char_pos(span.lo()); result.push(ExternalCrateData { - name: self.tcx.sess.cstore.crate_name(n).to_string(), + name: self.tcx.crate_name(n).to_string(), num: n.as_u32(), file_name: SpanUtils::make_path_string(&lo_loc.file.name), }); diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index d5d980da39f..6be7968dba4 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -216,6 +216,7 @@ fn filename_for_metadata(sess: &Session, crate_name: &str, outputs: &OutputFilen } pub fn each_linked_rlib(sess: &Session, + info: &CrateInfo, f: &mut FnMut(CrateNum, &Path)) -> Result<(), String> { let crates = sess.cstore.used_crates(LinkagePreference::RequireStatic).into_iter(); let fmts = sess.dependency_formats.borrow(); @@ -234,7 +235,7 @@ pub fn each_linked_rlib(sess: &Session, Some(_) => {} None => return Err(format!("could not find formats for rlibs")) } - let name = sess.cstore.crate_name(cnum).clone(); + let name = &info.crate_name[&cnum]; let path = match path { LibSource::Some(p) => p, LibSource::MetadataOnly => { @@ -611,8 +612,8 @@ fn link_staticlib(sess: &Session, tempdir); let mut all_native_libs = vec![]; - let res = each_linked_rlib(sess, &mut |cnum, path| { - let name = sess.cstore.crate_name(cnum); + let res = each_linked_rlib(sess, &trans.crate_info, &mut |cnum, path| { + let name = &trans.crate_info.crate_name[&cnum]; let native_libs = &trans.crate_info.native_libraries[&cnum]; // Here when we include the rlib into our staticlib we need to make a diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index ed7a745e440..72e1fc34789 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -1130,7 +1130,7 @@ fn start_executing_work(sess: &Session, }).expect("failed to spawn helper thread"); let mut each_linked_rlib_for_lto = Vec::new(); - drop(link::each_linked_rlib(sess, &mut |cnum, path| { + drop(link::each_linked_rlib(sess, crate_info, &mut |cnum, path| { if link::ignored_for_lto(crate_info, cnum) { return } diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 28929afc281..687d3cff48e 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -1518,10 +1518,12 @@ impl CrateInfo { native_libraries: FxHashMap(), used_libraries: tcx.native_libraries(LOCAL_CRATE), link_args: tcx.link_args(LOCAL_CRATE), + crate_name: FxHashMap(), }; for cnum in tcx.sess.cstore.crates() { info.native_libraries.insert(cnum, tcx.native_libraries(cnum)); + info.crate_name.insert(cnum, tcx.crate_name(cnum).to_string()); if tcx.is_panic_runtime(cnum) { info.panic_runtime = Some(cnum); } diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index babc030b59c..588141290f1 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -234,6 +234,7 @@ pub struct CrateInfo { sanitizer_runtime: Option, is_no_builtins: FxHashSet, native_libraries: FxHashMap>>, + crate_name: FxHashMap, used_libraries: Rc>, link_args: Rc>, } diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index f2d7842e473..5c8f237b2a7 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -552,7 +552,7 @@ pub fn all_traits<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> AllTraits<'a> if !external_mods.insert(def_id) { return; } - for child in tcx.sess.cstore.item_children(def_id, tcx.sess) { + for child in tcx.item_children(def_id).iter() { handle_external_def(tcx, traits, external_mods, child.def) } } diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index eca7aabb46d..efcb9a0f8d0 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -74,7 +74,8 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { tcx.hir.krate().visit_all_item_likes(&mut visitor); for &(id, span) in &tcx.maybe_unused_extern_crates { - let cnum = tcx.sess.cstore.extern_mod_stmt_cnum(id).unwrap(); + let hir_id = tcx.hir.node_to_hir_id(id); + let cnum = tcx.extern_mod_stmt_cnum(hir_id).unwrap(); if !tcx.is_compiler_builtins(cnum) && !tcx.is_panic_runtime(cnum) && !tcx.has_global_allocator(cnum) { diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index bd49e46f6fb..e9c6c0ce02a 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -120,7 +120,7 @@ pub fn load_attrs(cx: &DocContext, did: DefId) -> clean::Attributes { /// These names are used later on by HTML rendering to generate things like /// source links back to the original item. pub fn record_extern_fqn(cx: &DocContext, did: DefId, kind: clean::TypeKind) { - let crate_name = cx.tcx.sess.cstore.crate_name(did.krate).to_string(); + let crate_name = cx.tcx.crate_name(did.krate).to_string(); let relative = cx.tcx.def_path(did).data.into_iter().filter_map(|elem| { // extern blocks have an empty name let s = elem.data.to_string(); @@ -445,9 +445,9 @@ fn build_module(cx: &DocContext, did: DefId) -> clean::Module { // two namespaces, so the target may be listed twice. Make sure we only // visit each node at most once. let mut visited = FxHashSet(); - for item in cx.tcx.sess.cstore.item_children(did, cx.tcx.sess) { + for &item in cx.tcx.item_children(did).iter() { let def_id = item.def.def_id(); - if cx.tcx.sess.cstore.visibility(def_id) == ty::Visibility::Public { + if cx.tcx.visibility(def_id) == ty::Visibility::Public { if !visited.insert(def_id) { continue } if let Some(i) = try_inline(cx, item.def, item.ident.name) { items.extend(i) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f446bf587bd..0a9583278c6 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -244,7 +244,7 @@ impl Clean for CrateNum { } }).collect() } else { - cx.tcx.sess.cstore.item_children(root, cx.tcx.sess).iter().map(|item| item.def) + cx.tcx.item_children(root).iter().map(|item| item.def) .filter_map(as_primitive).collect() }; diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index d55d98d1fde..d354d726ff7 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -208,7 +208,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } let imported_from = self.cx.tcx.original_crate_name(def_id.krate); - let def = match self.cx.sess().cstore.load_macro(def_id, self.cx.sess()) { + let cstore = &self.cx.sess().cstore; + let def = match cstore.load_macro_untracked(def_id, self.cx.sess()) { LoadedMacro::MacroDef(macro_def) => macro_def, // FIXME(jseyfried): document proc macro reexports LoadedMacro::ProcMacro(..) => continue, @@ -371,9 +372,9 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { _ if self.inlining && item.vis != hir::Public => {} hir::ItemGlobalAsm(..) => {} hir::ItemExternCrate(ref p) => { - let cstore = &self.cx.sess().cstore; + let hir_id = self.cx.tcx.hir.node_to_hir_id(item.id); om.extern_crates.push(ExternCrate { - cnum: cstore.extern_mod_stmt_cnum(item.id) + cnum: self.cx.tcx.extern_mod_stmt_cnum(hir_id) .unwrap_or(LOCAL_CRATE), name, path: p.map(|x|x.to_string()), diff --git a/src/librustdoc/visit_lib.rs b/src/librustdoc/visit_lib.rs index 7b5b27c5565..9f75388238f 100644 --- a/src/librustdoc/visit_lib.rs +++ b/src/librustdoc/visit_lib.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use rustc::middle::cstore::CrateStore; use rustc::middle::privacy::{AccessLevels, AccessLevel}; use rustc::hir::def::Def; use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId}; @@ -25,7 +24,6 @@ use clean::{AttributesExt, NestedAttributesExt}; /// specific rustdoc annotations into account (i.e. `doc(hidden)`) pub struct LibEmbargoVisitor<'a, 'b: 'a, 'tcx: 'b> { cx: &'a ::core::DocContext<'b, 'tcx>, - cstore: &'a CrateStore, // Accessibility levels for reachable nodes access_levels: RefMut<'a, AccessLevels>, // Previous accessibility level, None means unreachable @@ -38,7 +36,6 @@ impl<'a, 'b, 'tcx> LibEmbargoVisitor<'a, 'b, 'tcx> { pub fn new(cx: &'a ::core::DocContext<'b, 'tcx>) -> LibEmbargoVisitor<'a, 'b, 'tcx> { LibEmbargoVisitor { cx, - cstore: &*cx.sess().cstore, access_levels: cx.access_levels.borrow_mut(), prev_level: Some(AccessLevel::Public), visited_mods: FxHashSet() @@ -70,14 +67,14 @@ impl<'a, 'b, 'tcx> LibEmbargoVisitor<'a, 'b, 'tcx> { return; } - for item in self.cstore.item_children(def_id, self.cx.tcx.sess) { + for item in self.cx.tcx.item_children(def_id).iter() { self.visit_item(item.def); } } fn visit_item(&mut self, def: Def) { let def_id = def.def_id(); - let vis = self.cstore.visibility(def_id); + let vis = self.cx.tcx.visibility(def_id); let inherited_item_level = if vis == Visibility::Public { self.prev_level } else {