Skip to content

Commit 95c4583

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 94fcccc + f31e076 commit 95c4583

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.
@@ -1266,15 +1268,60 @@ impl<'a> Resolver<'a> {
12661268
}
12671269

12681270
pub fn into_outputs(self) -> ResolverOutputs {
1271+
let definitions = self.definitions;
1272+
let extern_crate_map = self
1273+
.extern_crate_map
1274+
.into_iter()
1275+
.map(|(k, v)| (definitions.local_def_id(k).to_def_id(), v))
1276+
.collect();
1277+
let export_map = self
1278+
.export_map
1279+
.into_iter()
1280+
.map(|(k, v)| {
1281+
(
1282+
k,
1283+
v.into_iter()
1284+
.map(|e| e.map_id(|id| definitions.node_id_to_hir_id(id)))
1285+
.collect(),
1286+
)
1287+
})
1288+
.collect();
1289+
let trait_map = self
1290+
.trait_map
1291+
.into_iter()
1292+
.map(|(k, v)| {
1293+
(
1294+
definitions.node_id_to_hir_id(k),
1295+
v.into_iter()
1296+
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
1297+
.collect(),
1298+
)
1299+
})
1300+
.collect();
1301+
let maybe_unused_trait_imports = self
1302+
.maybe_unused_trait_imports
1303+
.into_iter()
1304+
.map(|id| definitions.local_def_id(id))
1305+
.collect();
1306+
let maybe_unused_extern_crates = self
1307+
.maybe_unused_extern_crates
1308+
.into_iter()
1309+
.map(|(id, sp)| (definitions.local_def_id(id).to_def_id(), sp))
1310+
.collect();
1311+
let glob_map = self
1312+
.glob_map
1313+
.into_iter()
1314+
.map(|(id, names)| (definitions.local_def_id(id), names))
1315+
.collect();
12691316
ResolverOutputs {
1270-
definitions: self.definitions,
1317+
definitions: definitions,
12711318
cstore: Box::new(self.crate_loader.into_cstore()),
1272-
extern_crate_map: self.extern_crate_map,
1273-
export_map: self.export_map,
1274-
trait_map: self.trait_map,
1275-
glob_map: self.glob_map,
1276-
maybe_unused_trait_imports: self.maybe_unused_trait_imports,
1277-
maybe_unused_extern_crates: self.maybe_unused_extern_crates,
1319+
extern_crate_map,
1320+
export_map,
1321+
trait_map,
1322+
glob_map,
1323+
maybe_unused_trait_imports,
1324+
maybe_unused_extern_crates,
12781325
extern_prelude: self
12791326
.extern_prelude
12801327
.iter()
@@ -1287,12 +1334,53 @@ impl<'a> Resolver<'a> {
12871334
ResolverOutputs {
12881335
definitions: self.definitions.clone(),
12891336
cstore: Box::new(self.cstore().clone()),
1290-
extern_crate_map: self.extern_crate_map.clone(),
1291-
export_map: self.export_map.clone(),
1292-
trait_map: self.trait_map.clone(),
1293-
glob_map: self.glob_map.clone(),
1294-
maybe_unused_trait_imports: self.maybe_unused_trait_imports.clone(),
1295-
maybe_unused_extern_crates: self.maybe_unused_extern_crates.clone(),
1337+
extern_crate_map: self
1338+
.extern_crate_map
1339+
.iter()
1340+
.map(|(&k, &v)| (self.definitions.local_def_id(k).to_def_id(), v))
1341+
.collect(),
1342+
export_map: self
1343+
.export_map
1344+
.iter()
1345+
.map(|(&k, v)| {
1346+
(
1347+
k,
1348+
v.iter()
1349+
.map(|e| e.map_id(|id| self.definitions.node_id_to_hir_id(id)))
1350+
.collect(),
1351+
)
1352+
})
1353+
.collect(),
1354+
trait_map: self
1355+
.trait_map
1356+
.iter()
1357+
.map(|(&k, v)| {
1358+
(
1359+
self.definitions.node_id_to_hir_id(k),
1360+
v.iter()
1361+
.cloned()
1362+
.map(|tc| {
1363+
tc.map_import_ids(|id| self.definitions.node_id_to_hir_id(id))
1364+
})
1365+
.collect(),
1366+
)
1367+
})
1368+
.collect(),
1369+
glob_map: self
1370+
.glob_map
1371+
.iter()
1372+
.map(|(&id, names)| (self.definitions.local_def_id(id), names.clone()))
1373+
.collect(),
1374+
maybe_unused_trait_imports: self
1375+
.maybe_unused_trait_imports
1376+
.iter()
1377+
.map(|&id| self.definitions.local_def_id(id))
1378+
.collect(),
1379+
maybe_unused_extern_crates: self
1380+
.maybe_unused_extern_crates
1381+
.iter()
1382+
.map(|&(id, sp)| (self.definitions.local_def_id(id).to_def_id(), sp))
1383+
.collect(),
12961384
extern_prelude: self
12971385
.extern_prelude
12981386
.iter()

0 commit comments

Comments
 (0)