Skip to content

Commit

Permalink
Auto merge of #44142 - alexcrichton:dllimport-query, r=nikomatsakis
Browse files Browse the repository at this point in the history
Migrate a slew of metadata methods to queries

This PR intends to make more progress on #41417, knocking off some low-hanging fruit.

Closes #44190
cc #44137
  • Loading branch information
bors committed Sep 8, 2017
2 parents d6ad402 + fd0aa64 commit dead08c
Show file tree
Hide file tree
Showing 114 changed files with 1,854 additions and 1,460 deletions.
58 changes: 51 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,60 @@ 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,
[] AllCrateNums,
);

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

0 comments on commit dead08c

Please sign in to comment.