Skip to content

Commit 8d9d928

Browse files
committed
rustc: use LocalDefId instead of DefIndex for query keys.
1 parent 61a551b commit 8d9d928

File tree

8 files changed

+26
-29
lines changed

8 files changed

+26
-29
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
5252
use crate::mir;
5353
use crate::mir::interpret::GlobalId;
54-
use crate::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
54+
use crate::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LocalDefId};
5555
use crate::hir::map::DefPathHash;
5656
use crate::hir::HirId;
5757

@@ -447,9 +447,9 @@ impl RecoverKey<'tcx> for DefId {
447447
}
448448
}
449449

450-
impl RecoverKey<'tcx> for DefIndex {
450+
impl RecoverKey<'tcx> for LocalDefId {
451451
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
452-
dep_node.extract_def_id(tcx).map(|id| id.index)
452+
dep_node.extract_def_id(tcx).map(|id| id.to_local())
453453
}
454454
}
455455

@@ -501,15 +501,15 @@ impl<'tcx> DepNodeParams<'tcx> for DefId {
501501
}
502502
}
503503

504-
impl<'tcx> DepNodeParams<'tcx> for DefIndex {
504+
impl<'tcx> DepNodeParams<'tcx> for LocalDefId {
505505
const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
506506

507507
fn to_fingerprint(&self, tcx: TyCtxt<'_>) -> Fingerprint {
508-
tcx.hir().definitions().def_path_hash(*self).0
508+
self.to_def_id().to_fingerprint(tcx)
509509
}
510510

511511
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
512-
tcx.def_path_str(DefId::local(*self))
512+
self.to_def_id().to_debug_str(tcx)
513513
}
514514
}
515515

src/librustc/middle/resolve_lifetime.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,19 +342,16 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
342342
resolve_lifetimes,
343343

344344
named_region_map: |tcx, id| {
345-
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
346345
tcx.resolve_lifetimes(LOCAL_CRATE).defs.get(&id)
347346
},
348347

349348
is_late_bound_map: |tcx, id| {
350-
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
351349
tcx.resolve_lifetimes(LOCAL_CRATE)
352350
.late_bound
353351
.get(&id)
354352
},
355353

356354
object_lifetime_defaults_map: |tcx, id| {
357-
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
358355
tcx.resolve_lifetimes(LOCAL_CRATE)
359356
.object_lifetime_defaults
360357
.get(&id)

src/librustc/query/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::ty::query::queries;
33
use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt};
44
use crate::ty::subst::SubstsRef;
55
use crate::dep_graph::{RecoverKey,DepKind, DepNode, SerializedDepNodeIndex};
6-
use crate::hir::def_id::{CrateNum, DefId, DefIndex};
6+
use crate::hir::def_id::{CrateNum, DefId, LocalDefId};
77
use crate::mir;
88
use crate::mir::interpret::GlobalId;
99
use crate::traits;
@@ -672,7 +672,7 @@ rustc_queries! {
672672
no_force
673673
desc { "computing whether impls specialize one another" }
674674
}
675-
query in_scope_traits_map(_: DefIndex)
675+
query in_scope_traits_map(_: LocalDefId)
676676
-> Option<&'tcx FxHashMap<ItemLocalId, StableVec<TraitCandidate>>> {
677677
eval_always
678678
desc { "traits in scope at a block" }
@@ -797,15 +797,15 @@ rustc_queries! {
797797
query resolve_lifetimes(_: CrateNum) -> &'tcx ResolveLifetimes {
798798
desc { "resolving lifetimes" }
799799
}
800-
query named_region_map(_: DefIndex) ->
800+
query named_region_map(_: LocalDefId) ->
801801
Option<&'tcx FxHashMap<ItemLocalId, Region>> {
802802
desc { "looking up a named region" }
803803
}
804-
query is_late_bound_map(_: DefIndex) ->
804+
query is_late_bound_map(_: LocalDefId) ->
805805
Option<&'tcx FxHashSet<ItemLocalId>> {
806806
desc { "testing if a region is late bound" }
807807
}
808-
query object_lifetime_defaults_map(_: DefIndex)
808+
query object_lifetime_defaults_map(_: LocalDefId)
809809
-> Option<&'tcx FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>> {
810810
desc { "looking up lifetime defaults for a region" }
811811
}

src/librustc/ty/context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::session::config::CrateType;
1010
use crate::middle;
1111
use crate::hir::{self, TraitCandidate, HirId, ItemKind, ItemLocalId, Node};
1212
use crate::hir::def::{Res, DefKind, Export};
13-
use crate::hir::def_id::{CrateNum, DefId, DefIndex, LOCAL_CRATE};
13+
use crate::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId};
1414
use crate::hir::map as hir_map;
1515
use crate::hir::map::DefPathHash;
1616
use crate::lint::{self, Lint};
@@ -1054,7 +1054,7 @@ pub struct GlobalCtxt<'tcx> {
10541054

10551055
/// Map indicating what traits are in scope for places where this
10561056
/// is relevant; generated by resolve.
1057-
trait_map: FxHashMap<DefIndex,
1057+
trait_map: FxHashMap<LocalDefId,
10581058
FxHashMap<ItemLocalId,
10591059
StableVec<TraitCandidate>>>,
10601060

@@ -1248,7 +1248,7 @@ impl<'tcx> TyCtxt<'tcx> {
12481248
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
12491249
for (k, v) in resolutions.trait_map {
12501250
let hir_id = hir.node_to_hir_id(k);
1251-
let map = trait_map.entry(hir_id.owner).or_default();
1251+
let map = trait_map.entry(hir_id.owner_local_def_id()).or_default();
12521252
map.insert(hir_id.local_id, StableVec::new(v));
12531253
}
12541254

@@ -2868,23 +2868,23 @@ impl<'tcx> TyCtxt<'tcx> {
28682868
}
28692869

28702870
pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx StableVec<TraitCandidate>> {
2871-
self.in_scope_traits_map(id.owner)
2871+
self.in_scope_traits_map(id.owner_local_def_id())
28722872
.and_then(|map| map.get(&id.local_id))
28732873
}
28742874

28752875
pub fn named_region(self, id: HirId) -> Option<resolve_lifetime::Region> {
2876-
self.named_region_map(id.owner)
2876+
self.named_region_map(id.owner_local_def_id())
28772877
.and_then(|map| map.get(&id.local_id).cloned())
28782878
}
28792879

28802880
pub fn is_late_bound(self, id: HirId) -> bool {
2881-
self.is_late_bound_map(id.owner)
2881+
self.is_late_bound_map(id.owner_local_def_id())
28822882
.map(|set| set.contains(&id.local_id))
28832883
.unwrap_or(false)
28842884
}
28852885

28862886
pub fn object_lifetime_defaults(self, id: HirId) -> Option<&'tcx [ObjectLifetimeDefault]> {
2887-
self.object_lifetime_defaults_map(id.owner)
2887+
self.object_lifetime_defaults_map(id.owner_local_def_id())
28882888
.and_then(|map| map.get(&id.local_id).map(|v| &**v))
28892889
}
28902890
}

src/librustc/ty/query/keys.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Defines the set of legal keys that can be used in queries.
22
33
use crate::infer::canonical::Canonical;
4-
use crate::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, DefIndex};
4+
use crate::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId};
55
use crate::traits;
66
use crate::ty::{self, Ty, TyCtxt};
77
use crate::ty::subst::SubstsRef;
@@ -62,12 +62,12 @@ impl Key for CrateNum {
6262
}
6363
}
6464

65-
impl Key for DefIndex {
65+
impl Key for LocalDefId {
6666
fn query_crate(&self) -> CrateNum {
67-
LOCAL_CRATE
67+
self.to_def_id().query_crate()
6868
}
69-
fn default_span(&self, _tcx: TyCtxt<'_>) -> Span {
70-
DUMMY_SP
69+
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
70+
self.to_def_id().default_span(tcx)
7171
}
7272
}
7373

src/librustc/ty/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::dep_graph::{self, DepNode};
2-
use crate::hir::def_id::{CrateNum, DefId, DefIndex};
2+
use crate::hir::def_id::{CrateNum, DefId, LocalDefId};
33
use crate::hir::def::{DefKind, Export};
44
use crate::hir::{self, TraitCandidate, ItemLocalId, CodegenFnAttrs};
55
use crate::infer::canonical::{self, Canonical};

src/librustc/ty/query/plumbing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ macro_rules! define_provider_struct {
11171117
///
11181118
/// When you implement a new query, it will likely have a corresponding new
11191119
/// `DepKind`, and you'll have to support it here in `force_from_dep_node()`. As
1120-
/// a rule of thumb, if your query takes a `DefId` or `DefIndex` as sole parameter,
1120+
/// a rule of thumb, if your query takes a `DefId` or `LocalDefId` as sole parameter,
11211121
/// then `force_from_dep_node()` should not fail for it. Otherwise, you can just
11221122
/// add it to the "We don't have enough information to reconstruct..." group in
11231123
/// the match below.

src/librustc_mir/borrow_check/nll/universal_regions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ fn for_each_late_bound_region_defined_on<'tcx>(
784784
fn_def_id: DefId,
785785
mut f: impl FnMut(ty::Region<'tcx>),
786786
) {
787-
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.index) {
787+
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.to_local()) {
788788
for late_bound in late_bounds.iter() {
789789
let hir_id = HirId {
790790
owner: fn_def_id.index,

0 commit comments

Comments
 (0)