Skip to content

Commit 81c72bc

Browse files
committed
Auto merge of #44142 - alexcrichton:dllimport-query, r=nikomatsakis
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
2 parents d93036a + fd0aa64 commit 81c72bc

File tree

114 files changed

+1854
-1460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+1854
-1460
lines changed

src/librustc/dep_graph/dep_node.rs

+51-7
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ define_dep_nodes!( <'tcx>
511511
[] ParamEnv(DefId),
512512
[] DescribeDef(DefId),
513513
[] DefSpan(DefId),
514-
[] Stability(DefId),
515-
[] Deprecation(DefId),
514+
[] LookupStability(DefId),
515+
[] LookupDeprecationEntry(DefId),
516516
[] ItemBodyNestedBodies(DefId),
517517
[] ConstIsRvaluePromotableToStatic(DefId),
518518
[] ImplParent(DefId),
@@ -521,16 +521,60 @@ define_dep_nodes!( <'tcx>
521521
[] IsMirAvailable(DefId),
522522
[] ItemAttrs(DefId),
523523
[] FnArgNames(DefId),
524-
[] DylibDepFormats(DefId),
525-
[] IsAllocator(DefId),
526-
[] IsPanicRuntime(DefId),
527-
[] IsCompilerBuiltins(DefId),
528-
[] HasGlobalAllocator(DefId),
524+
[] DylibDepFormats(CrateNum),
525+
[] IsPanicRuntime(CrateNum),
526+
[] IsCompilerBuiltins(CrateNum),
527+
[] HasGlobalAllocator(CrateNum),
529528
[] ExternCrate(DefId),
530529
[] LintLevels,
531530
[] Specializes { impl1: DefId, impl2: DefId },
532531
[] InScopeTraits(HirId),
533532
[] ModuleExports(HirId),
533+
[] IsSanitizerRuntime(CrateNum),
534+
[] IsProfilerRuntime(CrateNum),
535+
[] GetPanicStrategy(CrateNum),
536+
[] IsNoBuiltins(CrateNum),
537+
[] ImplDefaultness(DefId),
538+
[] ExportedSymbols(CrateNum),
539+
[] NativeLibraries(CrateNum),
540+
[] PluginRegistrarFn(CrateNum),
541+
[] DeriveRegistrarFn(CrateNum),
542+
[] CrateDisambiguator(CrateNum),
543+
[] CrateHash(CrateNum),
544+
[] OriginalCrateName(CrateNum),
545+
546+
[] ImplementationsOfTrait { krate: CrateNum, trait_id: DefId },
547+
[] AllTraitImplementations(CrateNum),
548+
549+
[] IsDllimportForeignItem(DefId),
550+
[] IsStaticallyIncludedForeignItem(DefId),
551+
[] NativeLibraryKind(DefId),
552+
[] LinkArgs,
553+
554+
[] NamedRegion(HirId),
555+
[] IsLateBound(HirId),
556+
[] ObjectLifetimeDefaults(HirId),
557+
558+
[] Visibility(DefId),
559+
[] DepKind(CrateNum),
560+
[] CrateName(CrateNum),
561+
[] ItemChildren(DefId),
562+
[] ExternModStmtCnum(HirId),
563+
[] GetLangItems,
564+
[] DefinedLangItems(CrateNum),
565+
[] MissingLangItems(CrateNum),
566+
[] ExternConstBody(DefId),
567+
[] VisibleParentMap,
568+
[] IsDirectExternCrate(CrateNum),
569+
[] MissingExternCrateItem(CrateNum),
570+
[] UsedCrateSource(CrateNum),
571+
[] PostorderCnums,
572+
573+
[] Freevars(HirId),
574+
[] MaybeUnusedTraitImport(HirId),
575+
[] MaybeUnusedExternCrates,
576+
[] StabilityIndex,
577+
[] AllCrateNums,
534578
);
535579

536580
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

src/librustc/dep_graph/graph.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,13 @@ impl DepGraph {
235235
debug_str_gen: F)
236236
where F: FnOnce() -> String
237237
{
238-
let mut dep_node_debug = self.data.as_ref().unwrap().dep_node_debug.borrow_mut();
238+
let dep_node_debug = &self.data.as_ref().unwrap().dep_node_debug;
239239

240-
dep_node_debug.entry(dep_node)
241-
.or_insert_with(debug_str_gen);
240+
if dep_node_debug.borrow().contains_key(&dep_node) {
241+
return
242+
}
243+
let debug_str = debug_str_gen();
244+
dep_node_debug.borrow_mut().insert(dep_node, debug_str);
242245
}
243246

244247
pub(super) fn dep_node_debug_str(&self, dep_node: DepNode) -> Option<String> {

src/librustc/hir/lowering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ impl<'a> LoweringContext<'a> {
787787
return n;
788788
}
789789
assert!(!def_id.is_local());
790-
let n = self.sess.cstore.item_generics_cloned(def_id).regions.len();
790+
let n = self.sess.cstore.item_generics_cloned_untracked(def_id).regions.len();
791791
self.type_def_lifetime_params.insert(def_id, n);
792792
n
793793
});
@@ -2863,7 +2863,7 @@ impl<'a> LoweringContext<'a> {
28632863
let parent_def = self.parent_def.unwrap();
28642864
let def_id = {
28652865
let defs = self.resolver.definitions();
2866-
let def_path_data = DefPathData::Binding(name);
2866+
let def_path_data = DefPathData::Binding(name.as_str());
28672867
let def_index = defs.create_def_with_parent(parent_def,
28682868
node_id,
28692869
def_path_data,

src/librustc/hir/map/def_collector.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
104104
DefPathData::Impl,
105105
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) | ItemKind::Trait(..) |
106106
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
107-
DefPathData::TypeNs(i.ident.name),
107+
DefPathData::TypeNs(i.ident.name.as_str()),
108108
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
109109
return visit::walk_item(self, i);
110110
}
111-
ItemKind::Mod(..) => DefPathData::Module(i.ident.name),
111+
ItemKind::Mod(..) => DefPathData::Module(i.ident.name.as_str()),
112112
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
113-
DefPathData::ValueNs(i.ident.name),
114-
ItemKind::MacroDef(..) => DefPathData::MacroDef(i.ident.name),
113+
DefPathData::ValueNs(i.ident.name.as_str()),
114+
ItemKind::MacroDef(..) => DefPathData::MacroDef(i.ident.name.as_str()),
115115
ItemKind::Mac(..) => return self.visit_macro_invoc(i.id, false),
116116
ItemKind::GlobalAsm(..) => DefPathData::Misc,
117117
ItemKind::Use(ref view_path) => {
@@ -139,13 +139,15 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
139139
for v in &enum_definition.variants {
140140
let variant_def_index =
141141
this.create_def(v.node.data.id(),
142-
DefPathData::EnumVariant(v.node.name.name),
142+
DefPathData::EnumVariant(v.node.name.name.as_str()),
143143
REGULAR_SPACE);
144144
this.with_parent(variant_def_index, |this| {
145145
for (index, field) in v.node.data.fields().iter().enumerate() {
146146
let name = field.ident.map(|ident| ident.name)
147147
.unwrap_or_else(|| Symbol::intern(&index.to_string()));
148-
this.create_def(field.id, DefPathData::Field(name), REGULAR_SPACE);
148+
this.create_def(field.id,
149+
DefPathData::Field(name.as_str()),
150+
REGULAR_SPACE);
149151
}
150152

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

177179
fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
178180
let def = self.create_def(foreign_item.id,
179-
DefPathData::ValueNs(foreign_item.ident.name),
181+
DefPathData::ValueNs(foreign_item.ident.name.as_str()),
180182
REGULAR_SPACE);
181183

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

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

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

@@ -237,7 +239,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
237239
PatKind::Mac(..) => return self.visit_macro_invoc(pat.id, false),
238240
PatKind::Ident(_, id, _) => {
239241
let def = self.create_def(pat.id,
240-
DefPathData::Binding(id.node.name),
242+
DefPathData::Binding(id.node.name.as_str()),
241243
REGULAR_SPACE);
242244
self.parent_def = Some(def);
243245
}
@@ -282,7 +284,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
282284

283285
fn visit_lifetime_def(&mut self, def: &'a LifetimeDef) {
284286
self.create_def(def.lifetime.id,
285-
DefPathData::LifetimeDef(def.lifetime.ident.name),
287+
DefPathData::LifetimeDef(def.lifetime.ident.name.as_str()),
286288
REGULAR_SPACE);
287289
}
288290

src/librustc/hir/map/definitions.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ impl DefPathTable {
8080

8181
#[inline(always)]
8282
pub fn def_path_hash(&self, index: DefIndex) -> DefPathHash {
83-
self.def_path_hashes[index.address_space().index()]
84-
[index.as_array_index()]
83+
let ret = self.def_path_hashes[index.address_space().index()]
84+
[index.as_array_index()];
85+
debug!("def_path_hash({:?}) = {:?}", index, ret);
86+
return ret
8587
}
8688

8789
pub fn add_def_path_hashes_to(&self,
@@ -213,7 +215,7 @@ impl DefKey {
213215
DefPathData::Binding(name) |
214216
DefPathData::Field(name) |
215217
DefPathData::GlobalMetaData(name) => {
216-
(*name.as_str()).hash(&mut hasher);
218+
name.hash(&mut hasher);
217219
}
218220

219221
DefPathData::Impl |
@@ -347,31 +349,31 @@ pub enum DefPathData {
347349
/// An impl
348350
Impl,
349351
/// Something in the type NS
350-
TypeNs(Symbol),
352+
TypeNs(InternedString),
351353
/// Something in the value NS
352-
ValueNs(Symbol),
354+
ValueNs(InternedString),
353355
/// A module declaration
354-
Module(Symbol),
356+
Module(InternedString),
355357
/// A macro rule
356-
MacroDef(Symbol),
358+
MacroDef(InternedString),
357359
/// A closure expression
358360
ClosureExpr,
359361

360362
// Subportions of items
361363
/// A type parameter (generic parameter)
362-
TypeParam(Symbol),
364+
TypeParam(InternedString),
363365
/// A lifetime definition
364-
LifetimeDef(Symbol),
366+
LifetimeDef(InternedString),
365367
/// A variant of a enum
366-
EnumVariant(Symbol),
368+
EnumVariant(InternedString),
367369
/// A struct field
368-
Field(Symbol),
370+
Field(InternedString),
369371
/// Implicit ctor for a tuple-like struct
370372
StructCtor,
371373
/// Initializer for a const
372374
Initializer,
373375
/// Pattern binding
374-
Binding(Symbol),
376+
Binding(InternedString),
375377
/// An `impl Trait` type node.
376378
ImplTrait,
377379
/// A `typeof` type node.
@@ -380,7 +382,7 @@ pub enum DefPathData {
380382
/// GlobalMetaData identifies a piece of crate metadata that is global to
381383
/// a whole crate (as opposed to just one item). GlobalMetaData components
382384
/// are only supposed to show up right below the crate root.
383-
GlobalMetaData(Symbol)
385+
GlobalMetaData(InternedString)
384386
}
385387

386388
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
@@ -601,7 +603,7 @@ impl Definitions {
601603
}
602604

603605
impl DefPathData {
604-
pub fn get_opt_name(&self) -> Option<Symbol> {
606+
pub fn get_opt_name(&self) -> Option<InternedString> {
605607
use self::DefPathData::*;
606608
match *self {
607609
TypeNs(name) |
@@ -639,7 +641,7 @@ impl DefPathData {
639641
Binding(name) |
640642
Field(name) |
641643
GlobalMetaData(name) => {
642-
return name.as_str();
644+
return name
643645
}
644646

645647
// note that this does not show up in user printouts
@@ -684,7 +686,7 @@ macro_rules! define_global_metadata_kind {
684686
definitions.create_def_with_parent(
685687
CRATE_DEF_INDEX,
686688
ast::DUMMY_NODE_ID,
687-
DefPathData::GlobalMetaData(instance.name()),
689+
DefPathData::GlobalMetaData(instance.name().as_str()),
688690
GLOBAL_MD_ADDRESS_SPACE,
689691
Mark::root()
690692
);
@@ -698,7 +700,7 @@ macro_rules! define_global_metadata_kind {
698700
let def_key = DefKey {
699701
parent: Some(CRATE_DEF_INDEX),
700702
disambiguated_data: DisambiguatedDefPathData {
701-
data: DefPathData::GlobalMetaData(self.name()),
703+
data: DefPathData::GlobalMetaData(self.name().as_str()),
702704
disambiguator: 0,
703705
}
704706
};

src/librustc/hir/map/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,17 @@ impl<'hir> Map<'hir> {
878878

879879
Some(RootCrate(_)) => self.forest.krate.span,
880880
Some(NotPresent) | None => {
881-
bug!("hir::map::Map::span: id not in map: {:?}", id)
881+
// Some nodes, notably macro definitions, are not
882+
// present in the map for whatever reason, but
883+
// they *do* have def-ids. So if we encounter an
884+
// empty hole, check for that case.
885+
if let Some(def_index) = self.definitions.opt_def_index(id) {
886+
let def_path_hash = self.definitions.def_path_hash(def_index);
887+
self.dep_graph.read(def_path_hash.to_dep_node(DepKind::Hir));
888+
DUMMY_SP
889+
} else {
890+
bug!("hir::map::Map::span: id not in map: {:?}", id)
891+
}
882892
}
883893
}
884894
}

src/librustc/infer/error_reporting/anon_anon_conflict.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,19 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
209209

210210
match arg.node {
211211
hir::TyRptr(ref lifetime, _) => {
212-
match self.infcx.tcx.named_region_map.defs.get(&lifetime.id) {
212+
let hir_id = self.infcx.tcx.hir.node_to_hir_id(lifetime.id);
213+
match self.infcx.tcx.named_region(hir_id) {
213214
// the lifetime of the TyRptr
214-
Some(&rl::Region::LateBoundAnon(debruijn_index, anon_index)) => {
215+
Some(rl::Region::LateBoundAnon(debruijn_index, anon_index)) => {
215216
if debruijn_index.depth == 1 && anon_index == br_index {
216217
self.found_type = Some(arg);
217218
return; // we can stop visiting now
218219
}
219220
}
220-
Some(&rl::Region::Static) |
221-
Some(&rl::Region::EarlyBound(_, _)) |
222-
Some(&rl::Region::LateBound(_, _)) |
223-
Some(&rl::Region::Free(_, _)) |
221+
Some(rl::Region::Static) |
222+
Some(rl::Region::EarlyBound(_, _)) |
223+
Some(rl::Region::LateBound(_, _)) |
224+
Some(rl::Region::Free(_, _)) |
224225
None => {
225226
debug!("no arg found");
226227
}
@@ -272,17 +273,18 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
272273
_ => return,
273274
};
274275

275-
match self.infcx.tcx.named_region_map.defs.get(&lifetime.id) {
276+
let hir_id = self.infcx.tcx.hir.node_to_hir_id(lifetime.id);
277+
match self.infcx.tcx.named_region(hir_id) {
276278
// the lifetime of the TyPath!
277-
Some(&rl::Region::LateBoundAnon(debruijn_index, anon_index)) => {
279+
Some(rl::Region::LateBoundAnon(debruijn_index, anon_index)) => {
278280
if debruijn_index.depth == 1 && anon_index == br_index {
279281
self.found_it = true;
280282
}
281283
}
282-
Some(&rl::Region::Static) |
283-
Some(&rl::Region::EarlyBound(_, _)) |
284-
Some(&rl::Region::LateBound(_, _)) |
285-
Some(&rl::Region::Free(_, _)) |
284+
Some(rl::Region::Static) |
285+
Some(rl::Region::EarlyBound(_, _)) |
286+
Some(rl::Region::LateBound(_, _)) |
287+
Some(rl::Region::Free(_, _)) |
286288
None => {
287289
debug!("no arg found");
288290
}

0 commit comments

Comments
 (0)