From b308c3f909692b1a7fa28f785fedfe4f43b9e47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Fri, 30 Nov 2018 22:26:57 +0100 Subject: [PATCH] Update resolve_lifetimes, named_region_map, is_late_bound_map and object_lifetime_defaults_map --- src/librustc/arena.rs | 1 + src/librustc/middle/resolve_lifetime.rs | 23 +++++++++-------------- src/librustc/query/mod.rs | 8 ++++---- src/librustc/ty/context.rs | 4 ++-- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index e9751a23f1218..a15532c106ae2 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -16,6 +16,7 @@ macro_rules! arena_types { )>, [few] mir_keys: rustc::util::nodemap::DefIdSet, [decode] specialization_graph: rustc::traits::specialization_graph::Graph, + [few] resolve_lifetimes: rustc::middle::resolve_lifetime::ResolveLifetimes, ], $tcx); ) } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 3306bcae2123d..72ad6525b0c6c 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -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>>, - late_bound: FxHashMap>>, + defs: FxHashMap>, + late_bound: FxHashMap>, object_lifetime_defaults: - FxHashMap>>>>, + FxHashMap>>, } 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 { +) -> &'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 { diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index 8c1e345cdaec5..7c5a155c2c94f 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -754,19 +754,19 @@ rustc_queries! { BorrowChecking { // Lifetime resolution. See `middle::resolve_lifetimes`. - query resolve_lifetimes(_: CrateNum) -> Lrc { + query resolve_lifetimes(_: CrateNum) -> &'tcx ResolveLifetimes { desc { "resolving lifetimes" } } query named_region_map(_: DefIndex) -> - Option>> { + Option<&'tcx FxHashMap> { desc { "looking up a named region" } } query is_late_bound_map(_: DefIndex) -> - Option>> { + Option<&'tcx FxHashSet> { desc { "testing if a region is late bound" } } query object_lifetime_defaults_map(_: DefIndex) - -> Option>>>> { + -> Option<&'tcx FxHashMap>> { desc { "looking up lifetime defaults for a region" } } } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 1ce9ffd94330d..8e8c41d7abde8 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -2991,10 +2991,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } pub fn object_lifetime_defaults(self, id: HirId) - -> Option>> + -> 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)) } }