Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate a slew of metadata methods to queries #44142

Merged
merged 29 commits into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dff0c07
rustc: Move a few more cstore methods to queries
alexcrichton Aug 28, 2017
ed6f868
rustc: Move `impl_defaultness` to a query
alexcrichton Aug 28, 2017
98b74c5
rustc: Migrate `CStore::expored_symbols` to a query
alexcrichton Aug 29, 2017
205bc9a
rustc: Migrate `CStore::native_libraries` to a query
alexcrichton Aug 29, 2017
2d4445f
rustc: Move {plugin,derive}_registrar_fn to queries
alexcrichton Aug 29, 2017
ebc1fd3
rustc: Move crate_disambiguator to queries
alexcrichton Aug 29, 2017
d6c88f4
rustc: Move crate_hash to a query
alexcrichton Aug 29, 2017
52b67f9
rustc: Move original_crate_name to a query
alexcrichton Aug 29, 2017
4af1284
Ignore failing incremental tests
alexcrichton Aug 29, 2017
4dec2a8
rustc: Fix a borrow mut error with debug assertions
alexcrichton Aug 30, 2017
1c7294e
rustc: Move implementations_of_trait to a query
alexcrichton Aug 30, 2017
87ea0a1
Ignore failing tests harder
alexcrichton Aug 30, 2017
64a7034
rustc: Remove a number of mutable fields in cstore
alexcrichton Aug 30, 2017
fd61fa5
rustc: Hide the `named_region_map` behind queries
alexcrichton Aug 30, 2017
43ae380
rustc: Flag some CrateStore methods as "untracked"
alexcrichton Aug 31, 2017
a2e2aba
rustc: Migrate lang items to a query
alexcrichton Aug 31, 2017
953490d
rustc: Remove lang item methods from CrateStore
alexcrichton Aug 31, 2017
84ae4b7
rustc: Migrate `CrateStore::item_body` to a query
alexcrichton Aug 31, 2017
88399a9
rustc: Migrate `visible_parent_map` to a query
alexcrichton Aug 31, 2017
0b7e0aa
rustc: Classify two more CrateStore methods untracked
alexcrichton Aug 31, 2017
490f34a
rustc: Remove `CrateStore::used_crate*`
alexcrichton Aug 31, 2017
bf5550b
rustc: Convert `freevars` to a query
alexcrichton Aug 31, 2017
7d9c98e
rustc: Hide `maybe_unused_*` fields in queries
alexcrichton Aug 31, 2017
0182c8b
rustc: Rename item_body query to extern_const_body
alexcrichton Aug 31, 2017
9a23196
rustc: Move stability functionality into queries
alexcrichton Aug 31, 2017
0cdc58a
rustc: Store InternedString in `DefPathData`
alexcrichton Sep 1, 2017
c6445ba
Clarify failure condition on tests
alexcrichton Sep 5, 2017
2ee7493
Add some more with_ignore to get tests passing
alexcrichton Sep 7, 2017
fd0aa64
rustc: Remove `CrateStore::crates` as a method
alexcrichton Sep 7, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ define_dep_nodes!( <'tcx>
[] ParamEnv(DefId),
[] DescribeDef(DefId),
[] DefSpan(DefId),
[] Stability(DefId),
[] Deprecation(DefId),
[] LookupStability(DefId),
[] LookupDeprecationEntry(DefId),
[] ItemBodyNestedBodies(DefId),
[] ConstIsRvaluePromotableToStatic(DefId),
[] ImplParent(DefId),
Expand All @@ -521,16 +521,59 @@ define_dep_nodes!( <'tcx>
[] IsMirAvailable(DefId),
[] ItemAttrs(DefId),
[] FnArgNames(DefId),
[] DylibDepFormats(DefId),
[] IsAllocator(DefId),
[] IsPanicRuntime(DefId),
[] IsCompilerBuiltins(DefId),
[] HasGlobalAllocator(DefId),
[] DylibDepFormats(CrateNum),
[] IsPanicRuntime(CrateNum),
[] IsCompilerBuiltins(CrateNum),
[] HasGlobalAllocator(CrateNum),
[] ExternCrate(DefId),
[] LintLevels,
[] Specializes { impl1: DefId, impl2: DefId },
[] InScopeTraits(HirId),
[] ModuleExports(HirId),
[] IsSanitizerRuntime(CrateNum),
[] IsProfilerRuntime(CrateNum),
[] GetPanicStrategy(CrateNum),
[] IsNoBuiltins(CrateNum),
[] ImplDefaultness(DefId),
[] ExportedSymbols(CrateNum),
[] NativeLibraries(CrateNum),
[] PluginRegistrarFn(CrateNum),
[] DeriveRegistrarFn(CrateNum),
[] CrateDisambiguator(CrateNum),
[] CrateHash(CrateNum),
[] OriginalCrateName(CrateNum),

[] ImplementationsOfTrait { krate: CrateNum, trait_id: DefId },
[] AllTraitImplementations(CrateNum),

[] IsDllimportForeignItem(DefId),
[] IsStaticallyIncludedForeignItem(DefId),
[] NativeLibraryKind(DefId),
[] LinkArgs,

[] NamedRegion(HirId),
[] IsLateBound(HirId),
[] ObjectLifetimeDefaults(HirId),

[] Visibility(DefId),
[] DepKind(CrateNum),
[] CrateName(CrateNum),
[] ItemChildren(DefId),
[] ExternModStmtCnum(HirId),
[] GetLangItems,
[] DefinedLangItems(CrateNum),
[] MissingLangItems(CrateNum),
[] ExternConstBody(DefId),
[] VisibleParentMap,
[] IsDirectExternCrate(CrateNum),
[] MissingExternCrateItem(CrateNum),
[] UsedCrateSource(CrateNum),
[] PostorderCnums,

[] Freevars(HirId),
[] MaybeUnusedTraitImport(HirId),
[] MaybeUnusedExternCrates,
[] StabilityIndex,
);

trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
Expand Down
9 changes: 6 additions & 3 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,13 @@ impl DepGraph {
debug_str_gen: F)
where F: FnOnce() -> String
{
let mut dep_node_debug = self.data.as_ref().unwrap().dep_node_debug.borrow_mut();
let dep_node_debug = &self.data.as_ref().unwrap().dep_node_debug;

dep_node_debug.entry(dep_node)
.or_insert_with(debug_str_gen);
if dep_node_debug.borrow().contains_key(&dep_node) {
return
}
let debug_str = debug_str_gen();
dep_node_debug.borrow_mut().insert(dep_node, debug_str);
}

pub(super) fn dep_node_debug_str(&self, dep_node: DepNode) -> Option<String> {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ impl<'a> LoweringContext<'a> {
return n;
}
assert!(!def_id.is_local());
let n = self.sess.cstore.item_generics_cloned(def_id).regions.len();
let n = self.sess.cstore.item_generics_cloned_untracked(def_id).regions.len();
self.type_def_lifetime_params.insert(def_id, n);
n
});
Expand Down Expand Up @@ -2863,7 +2863,7 @@ impl<'a> LoweringContext<'a> {
let parent_def = self.parent_def.unwrap();
let def_id = {
let defs = self.resolver.definitions();
let def_path_data = DefPathData::Binding(name);
let def_path_data = DefPathData::Binding(name.as_str());
let def_index = defs.create_def_with_parent(parent_def,
node_id,
def_path_data,
Expand Down
32 changes: 17 additions & 15 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
DefPathData::Impl,
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) | ItemKind::Trait(..) |
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
DefPathData::TypeNs(i.ident.name),
DefPathData::TypeNs(i.ident.name.as_str()),
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
return visit::walk_item(self, i);
}
ItemKind::Mod(..) => DefPathData::Module(i.ident.name),
ItemKind::Mod(..) => DefPathData::Module(i.ident.name.as_str()),
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
DefPathData::ValueNs(i.ident.name),
ItemKind::MacroDef(..) => DefPathData::MacroDef(i.ident.name),
DefPathData::ValueNs(i.ident.name.as_str()),
ItemKind::MacroDef(..) => DefPathData::MacroDef(i.ident.name.as_str()),
ItemKind::Mac(..) => return self.visit_macro_invoc(i.id, false),
ItemKind::GlobalAsm(..) => DefPathData::Misc,
ItemKind::Use(ref view_path) => {
Expand Down Expand Up @@ -139,13 +139,15 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
for v in &enum_definition.variants {
let variant_def_index =
this.create_def(v.node.data.id(),
DefPathData::EnumVariant(v.node.name.name),
DefPathData::EnumVariant(v.node.name.name.as_str()),
REGULAR_SPACE);
this.with_parent(variant_def_index, |this| {
for (index, field) in v.node.data.fields().iter().enumerate() {
let name = field.ident.map(|ident| ident.name)
.unwrap_or_else(|| Symbol::intern(&index.to_string()));
this.create_def(field.id, DefPathData::Field(name), REGULAR_SPACE);
this.create_def(field.id,
DefPathData::Field(name.as_str()),
REGULAR_SPACE);
}

if let Some(ref expr) = v.node.disr_expr {
Expand All @@ -165,7 +167,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
for (index, field) in struct_def.fields().iter().enumerate() {
let name = field.ident.map(|ident| ident.name)
.unwrap_or_else(|| Symbol::intern(&index.to_string()));
this.create_def(field.id, DefPathData::Field(name), REGULAR_SPACE);
this.create_def(field.id, DefPathData::Field(name.as_str()), REGULAR_SPACE);
}
}
_ => {}
Expand All @@ -176,7 +178,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {

fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
let def = self.create_def(foreign_item.id,
DefPathData::ValueNs(foreign_item.ident.name),
DefPathData::ValueNs(foreign_item.ident.name.as_str()),
REGULAR_SPACE);

self.with_parent(def, |this| {
Expand All @@ -187,7 +189,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_generics(&mut self, generics: &'a Generics) {
for ty_param in generics.ty_params.iter() {
self.create_def(ty_param.id,
DefPathData::TypeParam(ty_param.ident.name),
DefPathData::TypeParam(ty_param.ident.name.as_str()),
REGULAR_SPACE);
}

Expand All @@ -197,8 +199,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_trait_item(&mut self, ti: &'a TraitItem) {
let def_data = match ti.node {
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
DefPathData::ValueNs(ti.ident.name),
TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.name),
DefPathData::ValueNs(ti.ident.name.as_str()),
TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.name.as_str()),
TraitItemKind::Macro(..) => return self.visit_macro_invoc(ti.id, false),
};

Expand All @@ -215,8 +217,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_impl_item(&mut self, ii: &'a ImplItem) {
let def_data = match ii.node {
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
DefPathData::ValueNs(ii.ident.name),
ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.name),
DefPathData::ValueNs(ii.ident.name.as_str()),
ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.name.as_str()),
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id, false),
};

Expand All @@ -237,7 +239,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
PatKind::Mac(..) => return self.visit_macro_invoc(pat.id, false),
PatKind::Ident(_, id, _) => {
let def = self.create_def(pat.id,
DefPathData::Binding(id.node.name),
DefPathData::Binding(id.node.name.as_str()),
REGULAR_SPACE);
self.parent_def = Some(def);
}
Expand Down Expand Up @@ -282,7 +284,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {

fn visit_lifetime_def(&mut self, def: &'a LifetimeDef) {
self.create_def(def.lifetime.id,
DefPathData::LifetimeDef(def.lifetime.ident.name),
DefPathData::LifetimeDef(def.lifetime.ident.name.as_str()),
REGULAR_SPACE);
}

Expand Down
36 changes: 19 additions & 17 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ impl DefPathTable {

#[inline(always)]
pub fn def_path_hash(&self, index: DefIndex) -> DefPathHash {
self.def_path_hashes[index.address_space().index()]
[index.as_array_index()]
let ret = self.def_path_hashes[index.address_space().index()]
[index.as_array_index()];
debug!("def_path_hash({:?}) = {:?}", index, ret);
return ret
}

pub fn add_def_path_hashes_to(&self,
Expand Down Expand Up @@ -213,7 +215,7 @@ impl DefKey {
DefPathData::Binding(name) |
DefPathData::Field(name) |
DefPathData::GlobalMetaData(name) => {
(*name.as_str()).hash(&mut hasher);
name.hash(&mut hasher);
}

DefPathData::Impl |
Expand Down Expand Up @@ -347,31 +349,31 @@ pub enum DefPathData {
/// An impl
Impl,
/// Something in the type NS
TypeNs(Symbol),
TypeNs(InternedString),
/// Something in the value NS
ValueNs(Symbol),
ValueNs(InternedString),
/// A module declaration
Module(Symbol),
Module(InternedString),
/// A macro rule
MacroDef(Symbol),
MacroDef(InternedString),
/// A closure expression
ClosureExpr,

// Subportions of items
/// A type parameter (generic parameter)
TypeParam(Symbol),
TypeParam(InternedString),
/// A lifetime definition
LifetimeDef(Symbol),
LifetimeDef(InternedString),
/// A variant of a enum
EnumVariant(Symbol),
EnumVariant(InternedString),
/// A struct field
Field(Symbol),
Field(InternedString),
/// Implicit ctor for a tuple-like struct
StructCtor,
/// Initializer for a const
Initializer,
/// Pattern binding
Binding(Symbol),
Binding(InternedString),
/// An `impl Trait` type node.
ImplTrait,
/// A `typeof` type node.
Expand All @@ -380,7 +382,7 @@ pub enum DefPathData {
/// GlobalMetaData identifies a piece of crate metadata that is global to
/// a whole crate (as opposed to just one item). GlobalMetaData components
/// are only supposed to show up right below the crate root.
GlobalMetaData(Symbol)
GlobalMetaData(InternedString)
}

#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
Expand Down Expand Up @@ -601,7 +603,7 @@ impl Definitions {
}

impl DefPathData {
pub fn get_opt_name(&self) -> Option<Symbol> {
pub fn get_opt_name(&self) -> Option<InternedString> {
use self::DefPathData::*;
match *self {
TypeNs(name) |
Expand Down Expand Up @@ -639,7 +641,7 @@ impl DefPathData {
Binding(name) |
Field(name) |
GlobalMetaData(name) => {
return name.as_str();
return name
}

// note that this does not show up in user printouts
Expand Down Expand Up @@ -684,7 +686,7 @@ macro_rules! define_global_metadata_kind {
definitions.create_def_with_parent(
CRATE_DEF_INDEX,
ast::DUMMY_NODE_ID,
DefPathData::GlobalMetaData(instance.name()),
DefPathData::GlobalMetaData(instance.name().as_str()),
GLOBAL_MD_ADDRESS_SPACE,
Mark::root()
);
Expand All @@ -698,7 +700,7 @@ macro_rules! define_global_metadata_kind {
let def_key = DefKey {
parent: Some(CRATE_DEF_INDEX),
disambiguated_data: DisambiguatedDefPathData {
data: DefPathData::GlobalMetaData(self.name()),
data: DefPathData::GlobalMetaData(self.name().as_str()),
disambiguator: 0,
}
};
Expand Down
12 changes: 11 additions & 1 deletion src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,17 @@ impl<'hir> Map<'hir> {

Some(RootCrate(_)) => self.forest.krate.span,
Some(NotPresent) | None => {
bug!("hir::map::Map::span: id not in map: {:?}", id)
// Some nodes, notably macro definitions, are not
// present in the map for whatever reason, but
// they *do* have def-ids. So if we encounter an
// empty hole, check for that case.
if let Some(def_index) = self.definitions.opt_def_index(id) {
let def_path_hash = self.definitions.def_path_hash(def_index);
self.dep_graph.read(def_path_hash.to_dep_node(DepKind::Hir));
DUMMY_SP
} else {
bug!("hir::map::Map::span: id not in map: {:?}", id)
}
}
}
}
Expand Down
26 changes: 14 additions & 12 deletions src/librustc/infer/error_reporting/anon_anon_conflict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,19 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {

match arg.node {
hir::TyRptr(ref lifetime, _) => {
match self.infcx.tcx.named_region_map.defs.get(&lifetime.id) {
let hir_id = self.infcx.tcx.hir.node_to_hir_id(lifetime.id);
match self.infcx.tcx.named_region(hir_id) {
// the lifetime of the TyRptr
Some(&rl::Region::LateBoundAnon(debruijn_index, anon_index)) => {
Some(rl::Region::LateBoundAnon(debruijn_index, anon_index)) => {
if debruijn_index.depth == 1 && anon_index == br_index {
self.found_type = Some(arg);
return; // we can stop visiting now
}
}
Some(&rl::Region::Static) |
Some(&rl::Region::EarlyBound(_, _)) |
Some(&rl::Region::LateBound(_, _)) |
Some(&rl::Region::Free(_, _)) |
Some(rl::Region::Static) |
Some(rl::Region::EarlyBound(_, _)) |
Some(rl::Region::LateBound(_, _)) |
Some(rl::Region::Free(_, _)) |
None => {
debug!("no arg found");
}
Expand Down Expand Up @@ -272,17 +273,18 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
_ => return,
};

match self.infcx.tcx.named_region_map.defs.get(&lifetime.id) {
let hir_id = self.infcx.tcx.hir.node_to_hir_id(lifetime.id);
match self.infcx.tcx.named_region(hir_id) {
// the lifetime of the TyPath!
Some(&rl::Region::LateBoundAnon(debruijn_index, anon_index)) => {
Some(rl::Region::LateBoundAnon(debruijn_index, anon_index)) => {
if debruijn_index.depth == 1 && anon_index == br_index {
self.found_it = true;
}
}
Some(&rl::Region::Static) |
Some(&rl::Region::EarlyBound(_, _)) |
Some(&rl::Region::LateBound(_, _)) |
Some(&rl::Region::Free(_, _)) |
Some(rl::Region::Static) |
Some(rl::Region::EarlyBound(_, _)) |
Some(rl::Region::LateBound(_, _)) |
Some(rl::Region::Free(_, _)) |
None => {
debug!("no arg found");
}
Expand Down
Loading