Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aadba95

Browse files
committedJan 2, 2020
Use Arena for interning
1 parent 8f52664 commit aadba95

File tree

5 files changed

+16
-28
lines changed

5 files changed

+16
-28
lines changed
 

‎src/librustc/arena.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ macro_rules! arena_types {
123123
[few] inferred_outlives_crate: rustc::ty::CratePredicatesMap<'tcx>,
124124
[] upvars: rustc_data_structures::fx::FxIndexMap<rustc::hir::HirId, rustc::hir::Upvar>,
125125

126+
// Interned types
127+
[] tys: rustc::ty::TyS<$tcx>,
128+
126129
// HIR types
127130
[few] hir_forest: rustc::hir::map::Forest<$tcx>,
128131
[] arm: rustc::hir::Arm<$tcx>,
@@ -176,7 +179,7 @@ macro_rules! declare_arena {
176179
([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => {
177180
#[derive(Default)]
178181
pub struct Arena<$tcx> {
179-
dropless: DroplessArena,
182+
pub dropless: DroplessArena,
180183
drop: DropArena,
181184
$($name: arena_for_type!($a[$ty]),)*
182185
}

‎src/librustc/ty/context.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ use crate::util::common::ErrorReported;
4949
use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet, NodeMap};
5050
use crate::util::nodemap::{FxHashMap, FxHashSet};
5151

52-
use arena::SyncDroplessArena;
5352
use errors::DiagnosticBuilder;
5453
use rustc_data_structures::profiling::SelfProfilerRef;
5554
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
@@ -78,21 +77,11 @@ use syntax::expand::allocator::AllocatorKind;
7877
use syntax::source_map::MultiSpan;
7978
use syntax::symbol::{kw, sym, Symbol};
8079

81-
pub struct AllArenas {
82-
pub interner: SyncDroplessArena,
83-
}
84-
85-
impl AllArenas {
86-
pub fn new() -> Self {
87-
AllArenas { interner: SyncDroplessArena::default() }
88-
}
89-
}
90-
9180
type InternedSet<'tcx, T> = ShardedHashMap<Interned<'tcx, T>, ()>;
9281

9382
pub struct CtxtInterners<'tcx> {
9483
/// The arena that types, regions, etc. are allocated from.
95-
arena: &'tcx SyncDroplessArena,
84+
arena: &'tcx WorkerLocal<Arena<'tcx>>,
9685

9786
/// Specifically use a speedy hash algorithm for these hash sets, since
9887
/// they're accessed quite often.
@@ -112,7 +101,7 @@ pub struct CtxtInterners<'tcx> {
112101
}
113102

114103
impl<'tcx> CtxtInterners<'tcx> {
115-
fn new(arena: &'tcx SyncDroplessArena) -> CtxtInterners<'tcx> {
104+
fn new(arena: &'tcx WorkerLocal<Arena<'tcx>>) -> CtxtInterners<'tcx> {
116105
CtxtInterners {
117106
arena,
118107
type_: Default::default(),
@@ -1115,7 +1104,6 @@ impl<'tcx> TyCtxt<'tcx> {
11151104
lint_store: Lrc<lint::LintStore>,
11161105
local_providers: ty::query::Providers<'tcx>,
11171106
extern_providers: ty::query::Providers<'tcx>,
1118-
arenas: &'tcx AllArenas,
11191107
arena: &'tcx WorkerLocal<Arena<'tcx>>,
11201108
resolutions: ty::ResolverOutputs,
11211109
hir: hir_map::Map<'tcx>,
@@ -1126,7 +1114,7 @@ impl<'tcx> TyCtxt<'tcx> {
11261114
let data_layout = TargetDataLayout::parse(&s.target.target).unwrap_or_else(|err| {
11271115
s.fatal(&err);
11281116
});
1129-
let interners = CtxtInterners::new(&arenas.interner);
1117+
let interners = CtxtInterners::new(arena);
11301118
let common_types = CommonTypes::new(&interners);
11311119
let common_lifetimes = CommonLifetimes::new(&interners);
11321120
let common_consts = CommonConsts::new(&interners, &common_types);
@@ -2084,7 +2072,7 @@ macro_rules! slice_interners {
20842072
$(impl<'tcx> TyCtxt<'tcx> {
20852073
pub fn $method(self, v: &[$ty]) -> &'tcx List<$ty> {
20862074
self.interners.$field.intern_ref(v, || {
2087-
Interned(List::from_arena(&self.interners.arena, v))
2075+
Interned(List::from_arena(&*self.arena, v))
20882076
}).0
20892077
}
20902078
})+

‎src/librustc/ty/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub use self::BorrowKind::*;
66
pub use self::IntVarValue::*;
77
pub use self::Variance::*;
88

9+
use crate::arena::Arena;
910
use crate::hir::def::{CtorKind, CtorOf, DefKind, ExportMap, Res};
1011
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
1112
use crate::hir::Node;
@@ -29,7 +30,6 @@ use crate::ty::util::{Discr, IntTypeExt};
2930
use crate::ty::walk::TypeWalker;
3031
use crate::util::captures::Captures;
3132
use crate::util::nodemap::{DefIdMap, FxHashMap, NodeMap, NodeSet};
32-
use arena::SyncDroplessArena;
3333
use rustc_data_structures::svh::Svh;
3434
use rustc_macros::HashStable;
3535

@@ -76,7 +76,7 @@ pub use crate::ty::diagnostics::*;
7676
pub use self::binding::BindingMode;
7777
pub use self::binding::BindingMode::*;
7878

79-
pub use self::context::{keep_local, tls, AllArenas, FreeRegionInfo, TyCtxt};
79+
pub use self::context::{keep_local, tls, FreeRegionInfo, TyCtxt};
8080
pub use self::context::{
8181
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, ResolvedOpaqueTy,
8282
UserType, UserTypeAnnotationIndex,
@@ -611,7 +611,7 @@ unsafe impl<T: Sync> Sync for List<T> {}
611611

612612
impl<T: Copy> List<T> {
613613
#[inline]
614-
fn from_arena<'tcx>(arena: &'tcx SyncDroplessArena, slice: &[T]) -> &'tcx List<T> {
614+
fn from_arena<'tcx>(arena: &'tcx Arena<'tcx>, slice: &[T]) -> &'tcx List<T> {
615615
assert!(!mem::needs_drop::<T>());
616616
assert!(mem::size_of::<T>() != 0);
617617
assert!(slice.len() != 0);
@@ -624,7 +624,9 @@ impl<T: Copy> List<T> {
624624

625625
let size = offset + slice.len() * mem::size_of::<T>();
626626

627-
let mem = arena.alloc_raw(size, cmp::max(mem::align_of::<T>(), mem::align_of::<usize>()));
627+
let mem = arena
628+
.dropless
629+
.alloc_raw(size, cmp::max(mem::align_of::<T>(), mem::align_of::<usize>()));
628630
unsafe {
629631
let result = &mut *(mem.as_mut_ptr() as *mut List<T>);
630632
// Write the length

‎src/librustc_interface/passes.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc::session::search_paths::PathKind;
1616
use rustc::session::Session;
1717
use rustc::traits;
1818
use rustc::ty::steal::Steal;
19-
use rustc::ty::{self, AllArenas, GlobalCtxt, ResolverOutputs, TyCtxt};
19+
use rustc::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt};
2020
use rustc::util::common::{time, ErrorReported};
2121
use rustc_builtin_macros;
2222
use rustc_codegen_ssa::back::link::emit_metadata;
@@ -726,7 +726,6 @@ pub fn create_global_ctxt<'tcx>(
726726
outputs: OutputFilenames,
727727
crate_name: &str,
728728
global_ctxt: &'tcx Once<GlobalCtxt<'tcx>>,
729-
all_arenas: &'tcx AllArenas,
730729
arena: &'tcx WorkerLocal<Arena<'tcx>>,
731730
) -> QueryContext<'tcx> {
732731
let sess = &compiler.session();
@@ -759,7 +758,6 @@ pub fn create_global_ctxt<'tcx>(
759758
lint_store,
760759
local_providers,
761760
extern_providers,
762-
&all_arenas,
763761
arena,
764762
resolver_outputs,
765763
hir_map,

‎src/librustc_interface/queries.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc::lint::LintStore;
1010
use rustc::session::config::{OutputFilenames, OutputType};
1111
use rustc::session::Session;
1212
use rustc::ty::steal::Steal;
13-
use rustc::ty::{AllArenas, GlobalCtxt, ResolverOutputs};
13+
use rustc::ty::{GlobalCtxt, ResolverOutputs};
1414
use rustc::util::common::{time, ErrorReported};
1515
use rustc_codegen_utils::codegen_backend::CodegenBackend;
1616
use rustc_data_structures::sync::{Lrc, Once, WorkerLocal};
@@ -67,7 +67,6 @@ pub struct Queries<'tcx> {
6767
compiler: &'tcx Compiler,
6868
gcx: Once<GlobalCtxt<'tcx>>,
6969

70-
all_arenas: AllArenas,
7170
arena: WorkerLocal<Arena<'tcx>>,
7271

7372
dep_graph_future: Query<Option<DepGraphFuture>>,
@@ -87,7 +86,6 @@ impl<'tcx> Queries<'tcx> {
8786
Queries {
8887
compiler,
8988
gcx: Once::new(),
90-
all_arenas: AllArenas::new(),
9189
arena: WorkerLocal::new(|_| Arena::default()),
9290
dep_graph_future: Default::default(),
9391
parse: Default::default(),
@@ -264,7 +262,6 @@ impl<'tcx> Queries<'tcx> {
264262
outputs,
265263
&crate_name,
266264
&self.gcx,
267-
&self.all_arenas,
268265
&self.arena,
269266
))
270267
})

0 commit comments

Comments
 (0)
Please sign in to comment.