Update resolve_lifetimes, named_region_map, is_late_bound_map and object_lifetime_defaults_map
This commit is contained in:
parent
093940ddc4
commit
529aed81de
4 changed files with 16 additions and 20 deletions
|
|
@ -67,6 +67,7 @@ macro_rules! arena_types {
|
|||
rustc::hir::def_id::CrateNum
|
||||
>
|
||||
>,
|
||||
[few] resolve_lifetimes: rustc::middle::resolve_lifetime::ResolveLifetimes,
|
||||
], $tcx);
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ use crate::rustc::lint;
|
|||
use crate::session::Session;
|
||||
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet};
|
||||
use errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_macros::HashStable;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::Cell;
|
||||
|
|
@ -211,10 +210,10 @@ struct NamedRegionMap {
|
|||
/// See [`NamedRegionMap`].
|
||||
#[derive(Default)]
|
||||
pub struct ResolveLifetimes {
|
||||
defs: FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Region>>>,
|
||||
late_bound: FxHashMap<LocalDefId, Lrc<FxHashSet<ItemLocalId>>>,
|
||||
defs: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Region>>,
|
||||
late_bound: FxHashMap<LocalDefId, FxHashSet<ItemLocalId>>,
|
||||
object_lifetime_defaults:
|
||||
FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
|
||||
FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>>,
|
||||
}
|
||||
|
||||
impl_stable_hash_for!(struct crate::middle::resolve_lifetime::ResolveLifetimes {
|
||||
|
|
@ -347,7 +346,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
|
|||
|
||||
named_region_map: |tcx, id| {
|
||||
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
|
||||
tcx.resolve_lifetimes(LOCAL_CRATE).defs.get(&id).cloned()
|
||||
tcx.resolve_lifetimes(LOCAL_CRATE).defs.get(&id)
|
||||
},
|
||||
|
||||
is_late_bound_map: |tcx, id| {
|
||||
|
|
@ -355,7 +354,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
|
|||
tcx.resolve_lifetimes(LOCAL_CRATE)
|
||||
.late_bound
|
||||
.get(&id)
|
||||
.cloned()
|
||||
},
|
||||
|
||||
object_lifetime_defaults_map: |tcx, id| {
|
||||
|
|
@ -363,7 +361,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
|
|||
tcx.resolve_lifetimes(LOCAL_CRATE)
|
||||
.object_lifetime_defaults
|
||||
.get(&id)
|
||||
.cloned()
|
||||
},
|
||||
|
||||
..*providers
|
||||
|
|
@ -379,7 +376,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
|
|||
fn resolve_lifetimes<'tcx>(
|
||||
tcx: TyCtxt<'_, 'tcx, 'tcx>,
|
||||
for_krate: CrateNum,
|
||||
) -> Lrc<ResolveLifetimes> {
|
||||
) -> &'tcx ResolveLifetimes {
|
||||
assert_eq!(for_krate, LOCAL_CRATE);
|
||||
|
||||
let named_region_map = krate(tcx);
|
||||
|
|
@ -388,24 +385,22 @@ fn resolve_lifetimes<'tcx>(
|
|||
|
||||
for (hir_id, v) in named_region_map.defs {
|
||||
let map = rl.defs.entry(hir_id.owner_local_def_id()).or_default();
|
||||
Lrc::get_mut(map).unwrap().insert(hir_id.local_id, v);
|
||||
map.insert(hir_id.local_id, v);
|
||||
}
|
||||
for hir_id in named_region_map.late_bound {
|
||||
let map = rl.late_bound
|
||||
.entry(hir_id.owner_local_def_id())
|
||||
.or_default();
|
||||
Lrc::get_mut(map).unwrap().insert(hir_id.local_id);
|
||||
map.insert(hir_id.local_id);
|
||||
}
|
||||
for (hir_id, v) in named_region_map.object_lifetime_defaults {
|
||||
let map = rl.object_lifetime_defaults
|
||||
.entry(hir_id.owner_local_def_id())
|
||||
.or_default();
|
||||
Lrc::get_mut(map)
|
||||
.unwrap()
|
||||
.insert(hir_id.local_id, Lrc::new(v));
|
||||
map.insert(hir_id.local_id, v);
|
||||
}
|
||||
|
||||
Lrc::new(rl)
|
||||
tcx.arena.alloc(rl)
|
||||
}
|
||||
|
||||
fn krate<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> NamedRegionMap {
|
||||
|
|
|
|||
|
|
@ -754,19 +754,19 @@ rustc_queries! {
|
|||
|
||||
BorrowChecking {
|
||||
// Lifetime resolution. See `middle::resolve_lifetimes`.
|
||||
query resolve_lifetimes(_: CrateNum) -> Lrc<ResolveLifetimes> {
|
||||
query resolve_lifetimes(_: CrateNum) -> &'tcx ResolveLifetimes {
|
||||
desc { "resolving lifetimes" }
|
||||
}
|
||||
query named_region_map(_: DefIndex) ->
|
||||
Option<Lrc<FxHashMap<ItemLocalId, Region>>> {
|
||||
Option<&'tcx FxHashMap<ItemLocalId, Region>> {
|
||||
desc { "looking up a named region" }
|
||||
}
|
||||
query is_late_bound_map(_: DefIndex) ->
|
||||
Option<Lrc<FxHashSet<ItemLocalId>>> {
|
||||
Option<&'tcx FxHashSet<ItemLocalId>> {
|
||||
desc { "testing if a region is late bound" }
|
||||
}
|
||||
query object_lifetime_defaults_map(_: DefIndex)
|
||||
-> Option<Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>> {
|
||||
-> Option<&'tcx FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>> {
|
||||
desc { "looking up lifetime defaults for a region" }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2982,10 +2982,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
pub fn object_lifetime_defaults(self, id: HirId)
|
||||
-> Option<Lrc<Vec<ObjectLifetimeDefault>>>
|
||||
-> Option<&'gcx [ObjectLifetimeDefault]>
|
||||
{
|
||||
self.object_lifetime_defaults_map(id.owner)
|
||||
.and_then(|map| map.get(&id.local_id).cloned())
|
||||
.and_then(|map| map.get(&id.local_id).map(|v| &**v))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue