Skip to content

Commit e11dd47

Browse files
committed
rustc: use LocalDefId instead of DefIndex for query keys.
1 parent 6724d58 commit e11dd47

File tree

7 files changed

+31
-39
lines changed

7 files changed

+31
-39
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use crate::ty::subst::SubstsRef;
6363
use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
6464

6565
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
66-
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
66+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
6767
use rustc_hir::HirId;
6868
use rustc_span::symbol::Symbol;
6969
use std::fmt;
@@ -413,19 +413,19 @@ impl<'tcx> DepNodeParams<'tcx> for DefId {
413413
}
414414
}
415415

416-
impl<'tcx> DepNodeParams<'tcx> for DefIndex {
416+
impl<'tcx> DepNodeParams<'tcx> for LocalDefId {
417417
const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
418418

419419
fn to_fingerprint(&self, tcx: TyCtxt<'_>) -> Fingerprint {
420-
tcx.hir().definitions().def_path_hash(*self).0
420+
self.to_def_id().to_fingerprint(tcx)
421421
}
422422

423423
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
424-
tcx.def_path_str(DefId::local(*self))
424+
self.to_def_id().to_debug_str(tcx)
425425
}
426426

427427
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
428-
dep_node.extract_def_id(tcx).map(|id| id.index)
428+
dep_node.extract_def_id(tcx).map(|id| id.to_local())
429429
}
430430
}
431431

src/librustc/query/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::ty::query::queries;
1111
use crate::ty::query::QueryDescription;
1212
use crate::ty::subst::SubstsRef;
1313
use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
14-
use rustc_hir::def_id::{CrateNum, DefId, DefIndex};
14+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
1515

1616
use rustc_span::symbol::Symbol;
1717
use std::borrow::Cow;
@@ -791,7 +791,7 @@ rustc_queries! {
791791
query specializes(_: (DefId, DefId)) -> bool {
792792
desc { "computing whether impls specialize one another" }
793793
}
794-
query in_scope_traits_map(_: DefIndex)
794+
query in_scope_traits_map(_: LocalDefId)
795795
-> Option<&'tcx FxHashMap<ItemLocalId, StableVec<TraitCandidate>>> {
796796
eval_always
797797
desc { "traits in scope at a block" }
@@ -948,15 +948,15 @@ rustc_queries! {
948948
query resolve_lifetimes(_: CrateNum) -> &'tcx ResolveLifetimes {
949949
desc { "resolving lifetimes" }
950950
}
951-
query named_region_map(_: DefIndex) ->
951+
query named_region_map(_: LocalDefId) ->
952952
Option<&'tcx FxHashMap<ItemLocalId, Region>> {
953953
desc { "looking up a named region" }
954954
}
955-
query is_late_bound_map(_: DefIndex) ->
955+
query is_late_bound_map(_: LocalDefId) ->
956956
Option<&'tcx FxHashSet<ItemLocalId>> {
957957
desc { "testing if a region is late bound" }
958958
}
959-
query object_lifetime_defaults_map(_: DefIndex)
959+
query object_lifetime_defaults_map(_: LocalDefId)
960960
-> Option<&'tcx FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>> {
961961
desc { "looking up lifetime defaults for a region" }
962962
}

src/librustc/ty/context.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ use rustc_data_structures::stable_hasher::{
5555
use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal};
5656
use rustc_hir as hir;
5757
use rustc_hir::def::{DefKind, Res};
58-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex, LOCAL_CRATE};
58+
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LOCAL_CRATE};
5959
use rustc_hir::{HirId, Node, TraitCandidate};
6060
use rustc_hir::{ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet};
6161
use rustc_index::vec::{Idx, IndexVec};
@@ -958,7 +958,7 @@ pub struct GlobalCtxt<'tcx> {
958958

959959
/// Map indicating what traits are in scope for places where this
960960
/// is relevant; generated by resolve.
961-
trait_map: FxHashMap<DefIndex, FxHashMap<ItemLocalId, StableVec<TraitCandidate>>>,
961+
trait_map: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, StableVec<TraitCandidate>>>,
962962

963963
/// Export map produced by name resolution.
964964
export_map: FxHashMap<DefId, Vec<Export<hir::HirId>>>,
@@ -1153,7 +1153,7 @@ impl<'tcx> TyCtxt<'tcx> {
11531153
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
11541154
for (k, v) in resolutions.trait_map {
11551155
let hir_id = definitions.node_to_hir_id(k);
1156-
let map = trait_map.entry(hir_id.owner).or_default();
1156+
let map = trait_map.entry(hir_id.owner_local_def_id()).or_default();
11571157
let v = v
11581158
.into_iter()
11591159
.map(|tc| tc.map_import_ids(|id| definitions.node_to_hir_id(id)))
@@ -2631,19 +2631,22 @@ impl<'tcx> TyCtxt<'tcx> {
26312631
}
26322632

26332633
pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx StableVec<TraitCandidate>> {
2634-
self.in_scope_traits_map(id.owner).and_then(|map| map.get(&id.local_id))
2634+
self.in_scope_traits_map(id.owner_local_def_id()).and_then(|map| map.get(&id.local_id))
26352635
}
26362636

26372637
pub fn named_region(self, id: HirId) -> Option<resolve_lifetime::Region> {
2638-
self.named_region_map(id.owner).and_then(|map| map.get(&id.local_id).cloned())
2638+
self.named_region_map(id.owner_local_def_id())
2639+
.and_then(|map| map.get(&id.local_id).cloned())
26392640
}
26402641

26412642
pub fn is_late_bound(self, id: HirId) -> bool {
2642-
self.is_late_bound_map(id.owner).map(|set| set.contains(&id.local_id)).unwrap_or(false)
2643+
self.is_late_bound_map(id.owner_local_def_id())
2644+
.map(|set| set.contains(&id.local_id))
2645+
.unwrap_or(false)
26432646
}
26442647

26452648
pub fn object_lifetime_defaults(self, id: HirId) -> Option<&'tcx [ObjectLifetimeDefault]> {
2646-
self.object_lifetime_defaults_map(id.owner)
2649+
self.object_lifetime_defaults_map(id.owner_local_def_id())
26472650
.and_then(|map| map.get(&id.local_id).map(|v| &**v))
26482651
}
26492652
}

src/librustc/ty/query/keys.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::ty::fast_reject::SimplifiedType;
77
use crate::ty::query::caches::DefaultCacheSelector;
88
use crate::ty::subst::SubstsRef;
99
use crate::ty::{self, Ty, TyCtxt};
10-
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
10+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
1111
use rustc_span::symbol::Symbol;
1212
use rustc_span::{Span, DUMMY_SP};
1313

@@ -84,14 +84,14 @@ impl Key for CrateNum {
8484
}
8585
}
8686

87-
impl Key for DefIndex {
87+
impl Key for LocalDefId {
8888
type CacheSelector = DefaultCacheSelector;
8989

9090
fn query_crate(&self) -> CrateNum {
91-
LOCAL_CRATE
91+
self.to_def_id().query_crate()
9292
}
93-
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
94-
DUMMY_SP
93+
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
94+
self.to_def_id().default_span(tcx)
9595
}
9696
}
9797

src/librustc/ty/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use rustc_data_structures::svh::Svh;
4444
use rustc_data_structures::sync::Lrc;
4545
use rustc_hir as hir;
4646
use rustc_hir::def::DefKind;
47-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, DefIndex};
47+
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId};
4848
use rustc_hir::{Crate, HirIdSet, ItemLocalId, TraitCandidate};
4949
use rustc_index::vec::IndexVec;
5050
use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
@@ -147,7 +147,7 @@ rustc_query_append! { [define_queries!][<'tcx>] }
147147
///
148148
/// When you implement a new query, it will likely have a corresponding new
149149
/// `DepKind`, and you'll have to support it here in `force_from_dep_node()`. As
150-
/// a rule of thumb, if your query takes a `DefId` or `DefIndex` as sole parameter,
150+
/// a rule of thumb, if your query takes a `DefId` or `LocalDefId` as sole parameter,
151151
/// then `force_from_dep_node()` should not fail for it. Otherwise, you can just
152152
/// add it to the "We don't have enough information to reconstruct..." group in
153153
/// the match below.

src/librustc_mir/borrow_check/universal_regions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ fn for_each_late_bound_region_defined_on<'tcx>(
774774
fn_def_id: DefId,
775775
mut f: impl FnMut(ty::Region<'tcx>),
776776
) {
777-
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.index) {
777+
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.to_local()) {
778778
for late_bound in late_bounds.iter() {
779779
let hir_id = HirId { owner: fn_def_id.index, local_id: *late_bound };
780780
let name = tcx.hir().name(hir_id);

src/librustc_resolve/late/lifetimes.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1717
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
1818
use rustc_hir as hir;
1919
use rustc_hir::def::{DefKind, Res};
20-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
20+
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE};
2121
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
2222
use rustc_hir::{GenericArg, GenericParam, LifetimeName, Node, ParamName, QPath};
2323
use rustc_hir::{GenericParamKind, HirIdMap, HirIdSet, LifetimeParamKind};
@@ -280,25 +280,14 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
280280
*providers = ty::query::Providers {
281281
resolve_lifetimes,
282282

283-
named_region_map: |tcx, id| {
284-
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
285-
tcx.resolve_lifetimes(LOCAL_CRATE).defs.get(&id)
286-
},
287-
288-
is_late_bound_map: |tcx, id| {
289-
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
290-
tcx.resolve_lifetimes(LOCAL_CRATE).late_bound.get(&id)
291-
},
292-
283+
named_region_map: |tcx, id| tcx.resolve_lifetimes(LOCAL_CRATE).defs.get(&id),
284+
is_late_bound_map: |tcx, id| tcx.resolve_lifetimes(LOCAL_CRATE).late_bound.get(&id),
293285
object_lifetime_defaults_map: |tcx, id| {
294-
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
295286
tcx.resolve_lifetimes(LOCAL_CRATE).object_lifetime_defaults.get(&id)
296287
},
297288

298289
..*providers
299290
};
300-
301-
// (*) FIXME the query should be defined to take a LocalDefId
302291
}
303292

304293
/// Computes the `ResolveLifetimes` map that contains data for the

0 commit comments

Comments
 (0)