Skip to content

Commit af8da1f

Browse files
committed
Auto merge of #59540 - Zoxc:the-arena-2, r=<try>
[WIP] Use arenas to avoid Lrc in queries #1 Based on #59536.
2 parents 247b505 + b308c3f commit af8da1f

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

src/librustc/arena.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ macro_rules! arena_types {
1616
)>,
1717
[few] mir_keys: rustc::util::nodemap::DefIdSet,
1818
[decode] specialization_graph: rustc::traits::specialization_graph::Graph,
19+
[few] resolve_lifetimes: rustc::middle::resolve_lifetime::ResolveLifetimes,
1920
], $tcx);
2021
)
2122
}

src/librustc/middle/resolve_lifetime.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::rustc::lint;
1515
use crate::session::Session;
1616
use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet};
1717
use errors::{Applicability, DiagnosticBuilder};
18-
use rustc_data_structures::sync::Lrc;
1918
use rustc_macros::HashStable;
2019
use std::borrow::Cow;
2120
use std::cell::Cell;
@@ -211,10 +210,10 @@ struct NamedRegionMap {
211210
/// See [`NamedRegionMap`].
212211
#[derive(Default)]
213212
pub struct ResolveLifetimes {
214-
defs: FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Region>>>,
215-
late_bound: FxHashMap<LocalDefId, Lrc<FxHashSet<ItemLocalId>>>,
213+
defs: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Region>>,
214+
late_bound: FxHashMap<LocalDefId, FxHashSet<ItemLocalId>>,
216215
object_lifetime_defaults:
217-
FxHashMap<LocalDefId, Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>>,
216+
FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>>,
218217
}
219218

220219
impl_stable_hash_for!(struct crate::middle::resolve_lifetime::ResolveLifetimes {
@@ -347,23 +346,21 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
347346

348347
named_region_map: |tcx, id| {
349348
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
350-
tcx.resolve_lifetimes(LOCAL_CRATE).defs.get(&id).cloned()
349+
tcx.resolve_lifetimes(LOCAL_CRATE).defs.get(&id)
351350
},
352351

353352
is_late_bound_map: |tcx, id| {
354353
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
355354
tcx.resolve_lifetimes(LOCAL_CRATE)
356355
.late_bound
357356
.get(&id)
358-
.cloned()
359357
},
360358

361359
object_lifetime_defaults_map: |tcx, id| {
362360
let id = LocalDefId::from_def_id(DefId::local(id)); // (*)
363361
tcx.resolve_lifetimes(LOCAL_CRATE)
364362
.object_lifetime_defaults
365363
.get(&id)
366-
.cloned()
367364
},
368365

369366
..*providers
@@ -379,7 +376,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
379376
fn resolve_lifetimes<'tcx>(
380377
tcx: TyCtxt<'_, 'tcx, 'tcx>,
381378
for_krate: CrateNum,
382-
) -> Lrc<ResolveLifetimes> {
379+
) -> &'tcx ResolveLifetimes {
383380
assert_eq!(for_krate, LOCAL_CRATE);
384381

385382
let named_region_map = krate(tcx);
@@ -388,24 +385,22 @@ fn resolve_lifetimes<'tcx>(
388385

389386
for (hir_id, v) in named_region_map.defs {
390387
let map = rl.defs.entry(hir_id.owner_local_def_id()).or_default();
391-
Lrc::get_mut(map).unwrap().insert(hir_id.local_id, v);
388+
map.insert(hir_id.local_id, v);
392389
}
393390
for hir_id in named_region_map.late_bound {
394391
let map = rl.late_bound
395392
.entry(hir_id.owner_local_def_id())
396393
.or_default();
397-
Lrc::get_mut(map).unwrap().insert(hir_id.local_id);
394+
map.insert(hir_id.local_id);
398395
}
399396
for (hir_id, v) in named_region_map.object_lifetime_defaults {
400397
let map = rl.object_lifetime_defaults
401398
.entry(hir_id.owner_local_def_id())
402399
.or_default();
403-
Lrc::get_mut(map)
404-
.unwrap()
405-
.insert(hir_id.local_id, Lrc::new(v));
400+
map.insert(hir_id.local_id, v);
406401
}
407402

408-
Lrc::new(rl)
403+
tcx.arena.alloc(rl)
409404
}
410405

411406
fn krate<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>) -> NamedRegionMap {

src/librustc/query/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -754,19 +754,19 @@ rustc_queries! {
754754

755755
BorrowChecking {
756756
// Lifetime resolution. See `middle::resolve_lifetimes`.
757-
query resolve_lifetimes(_: CrateNum) -> Lrc<ResolveLifetimes> {
757+
query resolve_lifetimes(_: CrateNum) -> &'tcx ResolveLifetimes {
758758
desc { "resolving lifetimes" }
759759
}
760760
query named_region_map(_: DefIndex) ->
761-
Option<Lrc<FxHashMap<ItemLocalId, Region>>> {
761+
Option<&'tcx FxHashMap<ItemLocalId, Region>> {
762762
desc { "looking up a named region" }
763763
}
764764
query is_late_bound_map(_: DefIndex) ->
765-
Option<Lrc<FxHashSet<ItemLocalId>>> {
765+
Option<&'tcx FxHashSet<ItemLocalId>> {
766766
desc { "testing if a region is late bound" }
767767
}
768768
query object_lifetime_defaults_map(_: DefIndex)
769-
-> Option<Lrc<FxHashMap<ItemLocalId, Lrc<Vec<ObjectLifetimeDefault>>>>> {
769+
-> Option<&'tcx FxHashMap<ItemLocalId, Vec<ObjectLifetimeDefault>>> {
770770
desc { "looking up lifetime defaults for a region" }
771771
}
772772
}

src/librustc/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2991,10 +2991,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
29912991
}
29922992

29932993
pub fn object_lifetime_defaults(self, id: HirId)
2994-
-> Option<Lrc<Vec<ObjectLifetimeDefault>>>
2994+
-> Option<&'gcx [ObjectLifetimeDefault]>
29952995
{
29962996
self.object_lifetime_defaults_map(id.owner)
2997-
.and_then(|map| map.get(&id.local_id).cloned())
2997+
.and_then(|map| map.get(&id.local_id).map(|v| &**v))
29982998
}
29992999
}
30003000

0 commit comments

Comments
 (0)