rustc: Flag some CrateStore methods as "untracked"

The main use of `CrateStore` *before* the `TyCtxt` is created is during
resolution, but we want to be sure that any methods used before resolution are
not used after the `TyCtxt` is created. This commit starts moving the methods
used by resolve to all be named `{name}_untracked` where the rest of the
compiler uses just `{name}` as a query.

During this transition a number of new queries were added to account for
post-resolve usage of these methods.
This commit is contained in:
Alex Crichton 2017-08-31 08:07:39 -07:00
parent fd61fa5aef
commit 43ae380191
27 changed files with 152 additions and 99 deletions

View File

@ -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 {

View File

@ -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));

View File

@ -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<Any>;
@ -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<DefId>>;
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<lang_items::LangItem>;
/// 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<DefPathTable>;
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
fn item_children(&self, did: DefId, sess: &Session) -> Vec<def::Export>;
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<ast::Name>;
fn item_children_untracked(&self, did: DefId, sess: &Session) -> Vec<def::Export>;
fn load_macro_untracked(&self, did: DefId, sess: &Session) -> LoadedMacro;
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
// 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<CrateNum>;
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<Any>
{ 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<DefId>>
{
@ -328,9 +336,9 @@ impl CrateStore for DummyCrateStore {
{ bug!("lang_items") }
fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>
{ 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<DefPathTable> {
bug!("def_path_table")
}
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { bug!("struct_field_names") }
fn item_children(&self, did: DefId, sess: &Session) -> Vec<def::Export> {
fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name> {
bug!("struct_field_names")
}
fn item_children_untracked(&self, did: DefId, sess: &Session) -> Vec<def::Export> {
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<CrateNum> { None }
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum> { None }
fn encode_metadata<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
link_meta: &LinkMeta,

View File

@ -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<CrateNum, LinkagePreference>) {
@ -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<DependencyLis
// everything in explicitly so long as it's actually required.
let last_crate = sess.cstore.crates().len();
let mut ret = (1..last_crate+1).map(|cnum| {
if sess.cstore.dep_kind(CrateNum::new(cnum)) == DepKind::Explicit {
if tcx.dep_kind(CrateNum::new(cnum)) == DepKind::Explicit {
Linkage::Static
} else {
Linkage::NotLinked
@ -357,8 +356,8 @@ fn verify_ok<'a, 'tcx>(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()));
}

View File

@ -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();
}

View File

@ -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,
};

View File

@ -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
};
}

View File

@ -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<Rc<Vec<ObjectLifetimeDefault>>>,
[] visibility: Visibility(DefId) -> ty::Visibility,
[] dep_kind: DepKind(CrateNum) -> DepKind,
[] crate_name: CrateName(CrateNum) -> Symbol,
[] item_children: ItemChildren(DefId) -> Rc<Vec<Export>>,
[] extern_mod_stmt_cnum: ExternModStmtCnum(HirId) -> Option<CrateNum>,
}
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {

View File

@ -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))
}
}

View File

@ -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.

View File

@ -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<ast::Name>
fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name>
{
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<def::Export>
fn item_children_untracked(&self, def_id: DefId, sess: &Session) -> Vec<def::Export>
{
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<CrateNum>
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum>
{
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);
}
}

View File

@ -1288,8 +1288,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
}
fn encode_crate_deps(&mut self, _: ()) -> LazySeq<CrateDep> {
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)
})

View File

@ -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),
}
}

View File

@ -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 {

View File

@ -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: \

View File

@ -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()) {

View File

@ -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),
});

View File

@ -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

View File

@ -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
}

View File

@ -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);
}

View File

@ -234,6 +234,7 @@ pub struct CrateInfo {
sanitizer_runtime: Option<CrateNum>,
is_no_builtins: FxHashSet<CrateNum>,
native_libraries: FxHashMap<CrateNum, Rc<Vec<NativeLibrary>>>,
crate_name: FxHashMap<CrateNum, String>,
used_libraries: Rc<Vec<NativeLibrary>>,
link_args: Rc<Vec<String>>,
}

View File

@ -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)
}
}

View File

@ -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) {

View File

@ -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)

View File

@ -244,7 +244,7 @@ impl Clean<ExternalCrate> 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()
};

View File

@ -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()),

View File

@ -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<DefId>>,
// 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 {