Skip to content

Commit fa1f189

Browse files
authored
Rollup merge of rust-lang#72402 - marmeladema:resolver-outputs-def-id, r=ecstatic-morse
Remove all uses of `NodeId` in `ResolverOutputs` cc rust-lang#50928 r? @ecstatic-morse
2 parents 9d60524 + f31e076 commit fa1f189

File tree

4 files changed

+119
-60
lines changed

4 files changed

+119
-60
lines changed

src/librustc_hir/definitions.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ impl Definitions {
327327

328328
#[inline]
329329
pub fn local_def_id(&self, node: ast::NodeId) -> LocalDefId {
330-
self.opt_local_def_id(node).unwrap()
330+
self.opt_local_def_id(node).unwrap_or_else(|| {
331+
panic!("no entry for node id: `{:?}` / `{:?}`", node, self.opt_node_id_to_hir_id(node))
332+
})
331333
}
332334

333335
#[inline]

src/librustc_middle/ty/context.rs

+7-38
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use crate::ty::{InferTy, ParamTy, PolyFnSig, ProjectionTy};
3535
use crate::ty::{List, TyKind, TyS};
3636
use rustc_ast::ast;
3737
use rustc_ast::expand::allocator::AllocatorKind;
38-
use rustc_ast::node_id::NodeMap;
3938
use rustc_attr as attr;
4039
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
4140
use rustc_data_structures::profiling::SelfProfilerRef;
@@ -926,7 +925,7 @@ pub struct GlobalCtxt<'tcx> {
926925
pub consts: CommonConsts<'tcx>,
927926

928927
/// Resolutions of `extern crate` items produced by resolver.
929-
extern_crate_map: NodeMap<CrateNum>,
928+
extern_crate_map: FxHashMap<DefId, CrateNum>,
930929

931930
/// Map indicating what traits are in scope for places where this
932931
/// is relevant; generated by resolve.
@@ -1116,13 +1115,8 @@ impl<'tcx> TyCtxt<'tcx> {
11161115
};
11171116

11181117
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
1119-
for (k, v) in resolutions.trait_map {
1120-
let hir_id = definitions.node_id_to_hir_id(k);
1118+
for (hir_id, v) in resolutions.trait_map.into_iter() {
11211119
let map = trait_map.entry(hir_id.owner).or_default();
1122-
let v = v
1123-
.into_iter()
1124-
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
1125-
.collect();
11261120
map.insert(hir_id.local_id, StableVec::new(v));
11271121
}
11281122

@@ -1139,32 +1133,10 @@ impl<'tcx> TyCtxt<'tcx> {
11391133
consts: common_consts,
11401134
extern_crate_map: resolutions.extern_crate_map,
11411135
trait_map,
1142-
export_map: resolutions
1143-
.export_map
1144-
.into_iter()
1145-
.map(|(k, v)| {
1146-
let exports: Vec<_> = v
1147-
.into_iter()
1148-
.map(|e| e.map_id(|id| definitions.node_id_to_hir_id(id)))
1149-
.collect();
1150-
(k, exports)
1151-
})
1152-
.collect(),
1153-
maybe_unused_trait_imports: resolutions
1154-
.maybe_unused_trait_imports
1155-
.into_iter()
1156-
.map(|id| definitions.local_def_id(id))
1157-
.collect(),
1158-
maybe_unused_extern_crates: resolutions
1159-
.maybe_unused_extern_crates
1160-
.into_iter()
1161-
.map(|(id, sp)| (definitions.local_def_id(id).to_def_id(), sp))
1162-
.collect(),
1163-
glob_map: resolutions
1164-
.glob_map
1165-
.into_iter()
1166-
.map(|(id, names)| (definitions.local_def_id(id), names))
1167-
.collect(),
1136+
export_map: resolutions.export_map,
1137+
maybe_unused_trait_imports: resolutions.maybe_unused_trait_imports,
1138+
maybe_unused_extern_crates: resolutions.maybe_unused_extern_crates,
1139+
glob_map: resolutions.glob_map,
11681140
extern_prelude: resolutions.extern_prelude,
11691141
untracked_crate: krate,
11701142
definitions,
@@ -2729,10 +2701,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
27292701
let id = tcx.hir().local_def_id_to_hir_id(id.expect_local());
27302702
tcx.stability().local_deprecation_entry(id)
27312703
};
2732-
providers.extern_mod_stmt_cnum = |tcx, id| {
2733-
let id = tcx.hir().as_local_node_id(id).unwrap();
2734-
tcx.extern_crate_map.get(&id).cloned()
2735-
};
2704+
providers.extern_mod_stmt_cnum = |tcx, id| tcx.extern_crate_map.get(&id).cloned();
27362705
providers.all_crate_nums = |tcx, cnum| {
27372706
assert_eq!(cnum, LOCAL_CRATE);
27382707
tcx.arena.alloc_slice(&tcx.cstore.crates_untracked())

src/librustc_middle/ty/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use crate::ty;
1717
use crate::ty::subst::{InternalSubsts, Subst, SubstsRef};
1818
use crate::ty::util::{Discr, IntTypeExt};
1919
use rustc_ast::ast;
20-
use rustc_ast::node_id::{NodeId, NodeMap, NodeSet};
2120
use rustc_attr as attr;
2221
use rustc_data_structures::captures::Captures;
2322
use rustc_data_structures::fingerprint::Fingerprint;
2423
use rustc_data_structures::fx::FxHashMap;
24+
use rustc_data_structures::fx::FxHashSet;
2525
use rustc_data_structures::fx::FxIndexMap;
2626
use rustc_data_structures::sorted_map::SortedIndexMultiMap;
2727
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -31,7 +31,7 @@ use rustc_hir as hir;
3131
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Namespace, Res};
3232
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX};
3333
use rustc_hir::lang_items::{FnMutTraitLangItem, FnOnceTraitLangItem, FnTraitLangItem};
34-
use rustc_hir::{Constness, GlobMap, Node, TraitMap};
34+
use rustc_hir::{Constness, Node};
3535
use rustc_index::vec::{Idx, IndexVec};
3636
use rustc_macros::HashStable;
3737
use rustc_serialize::{self, Encodable, Encoder};
@@ -120,12 +120,12 @@ mod sty;
120120
pub struct ResolverOutputs {
121121
pub definitions: rustc_hir::definitions::Definitions,
122122
pub cstore: Box<CrateStoreDyn>,
123-
pub extern_crate_map: NodeMap<CrateNum>,
124-
pub trait_map: TraitMap<NodeId>,
125-
pub maybe_unused_trait_imports: NodeSet,
126-
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,
127-
pub export_map: ExportMap<NodeId>,
128-
pub glob_map: GlobMap,
123+
pub extern_crate_map: FxHashMap<DefId, CrateNum>,
124+
pub trait_map: FxHashMap<hir::HirId, Vec<hir::TraitCandidate<hir::HirId>>>,
125+
pub maybe_unused_trait_imports: FxHashSet<LocalDefId>,
126+
pub maybe_unused_extern_crates: Vec<(DefId, Span)>,
127+
pub export_map: ExportMap<hir::HirId>,
128+
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
129129
/// Extern prelude entries. The value is `true` if the entry was introduced
130130
/// via `extern crate` item and not `--extern` option or compiler built-in.
131131
pub extern_prelude: FxHashMap<Symbol, bool>,

src/librustc_resolve/lib.rs

+101-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore-tidy-filelength
2+
13
//! This crate is responsible for the part of name resolution that doesn't require type checker.
24
//!
35
//! Module structure of the crate is built here.
@@ -1271,15 +1273,60 @@ impl<'a> Resolver<'a> {
12711273
}
12721274

12731275
pub fn into_outputs(self) -> ResolverOutputs {
1276+
let definitions = self.definitions;
1277+
let extern_crate_map = self
1278+
.extern_crate_map
1279+
.into_iter()
1280+
.map(|(k, v)| (definitions.local_def_id(k).to_def_id(), v))
1281+
.collect();
1282+
let export_map = self
1283+
.export_map
1284+
.into_iter()
1285+
.map(|(k, v)| {
1286+
(
1287+
k,
1288+
v.into_iter()
1289+
.map(|e| e.map_id(|id| definitions.node_id_to_hir_id(id)))
1290+
.collect(),
1291+
)
1292+
})
1293+
.collect();
1294+
let trait_map = self
1295+
.trait_map
1296+
.into_iter()
1297+
.map(|(k, v)| {
1298+
(
1299+
definitions.node_id_to_hir_id(k),
1300+
v.into_iter()
1301+
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
1302+
.collect(),
1303+
)
1304+
})
1305+
.collect();
1306+
let maybe_unused_trait_imports = self
1307+
.maybe_unused_trait_imports
1308+
.into_iter()
1309+
.map(|id| definitions.local_def_id(id))
1310+
.collect();
1311+
let maybe_unused_extern_crates = self
1312+
.maybe_unused_extern_crates
1313+
.into_iter()
1314+
.map(|(id, sp)| (definitions.local_def_id(id).to_def_id(), sp))
1315+
.collect();
1316+
let glob_map = self
1317+
.glob_map
1318+
.into_iter()
1319+
.map(|(id, names)| (definitions.local_def_id(id), names))
1320+
.collect();
12741321
ResolverOutputs {
1275-
definitions: self.definitions,
1322+
definitions: definitions,
12761323
cstore: Box::new(self.crate_loader.into_cstore()),
1277-
extern_crate_map: self.extern_crate_map,
1278-
export_map: self.export_map,
1279-
trait_map: self.trait_map,
1280-
glob_map: self.glob_map,
1281-
maybe_unused_trait_imports: self.maybe_unused_trait_imports,
1282-
maybe_unused_extern_crates: self.maybe_unused_extern_crates,
1324+
extern_crate_map,
1325+
export_map,
1326+
trait_map,
1327+
glob_map,
1328+
maybe_unused_trait_imports,
1329+
maybe_unused_extern_crates,
12831330
extern_prelude: self
12841331
.extern_prelude
12851332
.iter()
@@ -1292,12 +1339,53 @@ impl<'a> Resolver<'a> {
12921339
ResolverOutputs {
12931340
definitions: self.definitions.clone(),
12941341
cstore: Box::new(self.cstore().clone()),
1295-
extern_crate_map: self.extern_crate_map.clone(),
1296-
export_map: self.export_map.clone(),
1297-
trait_map: self.trait_map.clone(),
1298-
glob_map: self.glob_map.clone(),
1299-
maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(),
1300-
maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(),
1342+
extern_crate_map: self
1343+
.extern_crate_map
1344+
.iter()
1345+
.map(|(&k, &v)| (self.definitions.local_def_id(k).to_def_id(), v))
1346+
.collect(),
1347+
export_map: self
1348+
.export_map
1349+
.iter()
1350+
.map(|(&k, v)| {
1351+
(
1352+
k,
1353+
v.iter()
1354+
.map(|e| e.map_id(|id| self.definitions.node_id_to_hir_id(id)))
1355+
.collect(),
1356+
)
1357+
})
1358+
.collect(),
1359+
trait_map: self
1360+
.trait_map
1361+
.iter()
1362+
.map(|(&k, v)| {
1363+
(
1364+
self.definitions.node_id_to_hir_id(k),
1365+
v.iter()
1366+
.cloned()
1367+
.map(|tc| {
1368+
tc.map_import_ids(|id| self.definitions.node_id_to_hir_id(id))
1369+
})
1370+
.collect(),
1371+
)
1372+
})
1373+
.collect(),
1374+
glob_map: self
1375+
.glob_map
1376+
.iter()
1377+
.map(|(&id, names)| (self.definitions.local_def_id(id), names.clone()))
1378+
.collect(),
1379+
maybe_unused_trait_imports: self
1380+
.maybe_unused_trait_imports
1381+
.iter()
1382+
.map(|&id| self.definitions.local_def_id(id))
1383+
.collect(),
1384+
maybe_unused_extern_crates: self
1385+
.maybe_unused_extern_crates
1386+
.iter()
1387+
.map(|&(id, sp)| (self.definitions.local_def_id(id).to_def_id(), sp))
1388+
.collect(),
13011389
extern_prelude: self
13021390
.extern_prelude
13031391
.iter()

0 commit comments

Comments
 (0)