]> git.lizzy.rs Git - rust.git/commitdiff
separate out an arena for HIR
authorMazdak Farrokhzad <twingoow@gmail.com>
Sat, 21 Mar 2020 01:21:21 +0000 (02:21 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sat, 21 Mar 2020 21:18:57 +0000 (22:18 +0100)
Cargo.lock
src/libarena/lib.rs
src/librustc/arena.rs
src/librustc/ty/codec.rs
src/librustc_ast_lowering/Cargo.toml
src/librustc_ast_lowering/item.rs
src/librustc_ast_lowering/lib.rs
src/librustc_hir/arena.rs [new file with mode: 0644]
src/librustc_hir/lib.rs
src/librustc_interface/passes.rs
src/librustc_interface/queries.rs

index 5f6cda66ebff1a362341d27727a0a7cca17c386b..e256ccfd44639b35ff90c09c435ec50329098efa 100644 (file)
@@ -3477,6 +3477,7 @@ dependencies = [
 name = "rustc_ast_lowering"
 version = "0.0.0"
 dependencies = [
+ "arena",
  "log",
  "rustc",
  "rustc_ast",
index 18200af8b66e7d6fb42069491b3b7648b3d6ea1f..0f0bd617f439c6cd8491b57addf70682e2582936 100644 (file)
@@ -624,7 +624,8 @@ unsafe impl<'tcx, T> ArenaField<'tcx> for T {
         }
 
         $(
-            impl ArenaAllocatable for $ty {}
+            #[allow(unused_lifetimes)]
+            impl<$tcx> ArenaAllocatable for $ty {}
             unsafe impl<$tcx> ArenaField<$tcx> for $ty {
                 #[inline]
                 fn arena<'a>(_arena: &'a Arena<$tcx>) -> Option<&'a $crate::TypedArena<Self>> {
@@ -653,7 +654,7 @@ pub fn alloc_slice<T: ::std::marker::Copy>(&self, value: &[T]) -> &mut [T] {
                 self.dropless.alloc_slice(value)
             }
 
-            pub fn alloc_from_iter<T: ArenaAllocatable>(
+            pub fn alloc_from_iter<'a, T: ArenaAllocatable>(
                 &'a self,
                 iter: impl ::std::iter::IntoIterator<Item = T>,
             ) -> &'a mut [T] {
index 5644a65c42bb22bb81078a839938d7b02e7011f4..c4214a0f5a2f800ea38eab698be885480b4a1efb 100644 (file)
@@ -120,40 +120,6 @@ macro_rules! arena_types {
             // Interned types
             [] tys: rustc::ty::TyS<$tcx>,
 
-            // HIR types
-            [few] hir_krate: rustc_hir::Crate<$tcx>,
-            [] arm: rustc_hir::Arm<$tcx>,
-            [] attribute: rustc_ast::ast::Attribute,
-            [] block: rustc_hir::Block<$tcx>,
-            [] bare_fn_ty: rustc_hir::BareFnTy<$tcx>,
-            [few] global_asm: rustc_hir::GlobalAsm,
-            [] generic_arg: rustc_hir::GenericArg<$tcx>,
-            [] generic_args: rustc_hir::GenericArgs<$tcx>,
-            [] generic_bound: rustc_hir::GenericBound<$tcx>,
-            [] generic_param: rustc_hir::GenericParam<$tcx>,
-            [] expr: rustc_hir::Expr<$tcx>,
-            [] field: rustc_hir::Field<$tcx>,
-            [] field_pat: rustc_hir::FieldPat<$tcx>,
-            [] fn_decl: rustc_hir::FnDecl<$tcx>,
-            [] foreign_item: rustc_hir::ForeignItem<$tcx>,
-            [] impl_item_ref: rustc_hir::ImplItemRef<$tcx>,
-            [] inline_asm: rustc_hir::InlineAsm<$tcx>,
-            [] local: rustc_hir::Local<$tcx>,
-            [few] macro_def: rustc_hir::MacroDef<$tcx>,
-            [] param: rustc_hir::Param<$tcx>,
-            [] pat: rustc_hir::Pat<$tcx>,
-            [] path: rustc_hir::Path<$tcx>,
-            [] path_segment: rustc_hir::PathSegment<$tcx>,
-            [] poly_trait_ref: rustc_hir::PolyTraitRef<$tcx>,
-            [] qpath: rustc_hir::QPath<$tcx>,
-            [] stmt: rustc_hir::Stmt<$tcx>,
-            [] struct_field: rustc_hir::StructField<$tcx>,
-            [] trait_item_ref: rustc_hir::TraitItemRef,
-            [] ty: rustc_hir::Ty<$tcx>,
-            [] type_binding: rustc_hir::TypeBinding<$tcx>,
-            [] variant: rustc_hir::Variant<$tcx>,
-            [] where_predicate: rustc_hir::WherePredicate<$tcx>,
-
             // HIR query types
             [few] indexed_hir: rustc::hir::map::IndexedHir<$tcx>,
             [few] hir_definitions: rustc::hir::map::definitions::Definitions,
index c305999a64ba7ffd60b89984a7bb049b27283f4c..cbbc937ed7d31427975605919f0e3459ca1a7494 100644 (file)
@@ -396,6 +396,7 @@ fn error(&mut self, err: &str) -> Self::Error {
             // the caller to pick any lifetime for `'tcx`, including `'static`,
             // by using the unspecialized proxies to them.
 
+            rustc_hir::arena_types!(impl_arena_allocatable_decoders, [$DecoderName [$($typaram),*]], 'tcx);
             arena_types!(impl_arena_allocatable_decoders, [$DecoderName [$($typaram),*]], 'tcx);
 
             impl<$($typaram),*> SpecializedDecoder<CrateNum>
index 23dc80facae1d0bba5cee248a620500ccc4e8ac3..75547ccb814cbd9c4d7832312141f9f81aab7399 100644 (file)
@@ -10,6 +10,7 @@ path = "lib.rs"
 doctest = false
 
 [dependencies]
+arena = { path = "../libarena" }
 log = { version = "0.4", features = ["release_max_level_info", "std"] }
 rustc = { path = "../librustc" }
 rustc_ast_pretty = { path = "../librustc_ast_pretty" }
index c22b2812a9e3c43af282e70656bbd213f201c2b6..bf78d6e4aecf78f764eaad49eeb061102fa96676 100644 (file)
@@ -1,7 +1,7 @@
 use super::{AnonymousLifetimeMode, LoweringContext, ParamMode};
 use super::{ImplTraitContext, ImplTraitPosition, ImplTraitTypeIdVisitor};
+use crate::Arena;
 
-use rustc::arena::Arena;
 use rustc::bug;
 use rustc_ast::ast::*;
 use rustc_ast::attr;
index 24fe51fc4d0d1290bcc8d57de4d043d09ac807f0..c541ddb7398cdb36bcf0fbb0dc0dd959e0c8d81c 100644 (file)
 
 #![feature(array_value_iter)]
 #![feature(crate_visibility_modifier)]
+#![feature(marker_trait_attr)]
+#![feature(specialization)]
 #![recursion_limit = "256"]
 
-use rustc::arena::Arena;
 use rustc::dep_graph::DepGraph;
 use rustc::hir::map::definitions::{DefKey, DefPathData, Definitions};
 use rustc::{bug, span_bug};
@@ -85,6 +86,8 @@ macro_rules! arena_vec {
 
 const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
 
+rustc_hir::arena_types!(::arena::declare_arena, [], 'tcx);
+
 struct LoweringContext<'a, 'hir: 'a> {
     crate_root: Option<Symbol>,
 
diff --git a/src/librustc_hir/arena.rs b/src/librustc_hir/arena.rs
new file mode 100644 (file)
index 0000000..978565a
--- /dev/null
@@ -0,0 +1,49 @@
+/// This declares a list of types which can be allocated by `Arena`.
+///
+/// The `few` modifier will cause allocation to use the shared arena and recording the destructor.
+/// This is faster and more memory efficient if there's only a few allocations of the type.
+/// Leaving `few` out will cause the type to get its own dedicated `TypedArena` which is
+/// faster and more memory efficient if there is lots of allocations.
+///
+/// Specifying the `decode` modifier will add decode impls for &T and &[T] where T is the type
+/// listed. These impls will appear in the implement_ty_decoder! macro.
+#[macro_export]
+macro_rules! arena_types {
+    ($macro:path, $args:tt, $tcx:lifetime) => (
+        $macro!($args, [
+            // HIR types
+            [few] hir_krate: rustc_hir::Crate<$tcx>,
+            [] arm: rustc_hir::Arm<$tcx>,
+            [] attribute: rustc_ast::ast::Attribute,
+            [] block: rustc_hir::Block<$tcx>,
+            [] bare_fn_ty: rustc_hir::BareFnTy<$tcx>,
+            [few] global_asm: rustc_hir::GlobalAsm,
+            [] generic_arg: rustc_hir::GenericArg<$tcx>,
+            [] generic_args: rustc_hir::GenericArgs<$tcx>,
+            [] generic_bound: rustc_hir::GenericBound<$tcx>,
+            [] generic_param: rustc_hir::GenericParam<$tcx>,
+            [] expr: rustc_hir::Expr<$tcx>,
+            [] field: rustc_hir::Field<$tcx>,
+            [] field_pat: rustc_hir::FieldPat<$tcx>,
+            [] fn_decl: rustc_hir::FnDecl<$tcx>,
+            [] foreign_item: rustc_hir::ForeignItem<$tcx>,
+            [] impl_item_ref: rustc_hir::ImplItemRef<$tcx>,
+            [] inline_asm: rustc_hir::InlineAsm<$tcx>,
+            [] local: rustc_hir::Local<$tcx>,
+            [few] macro_def: rustc_hir::MacroDef<$tcx>,
+            [] param: rustc_hir::Param<$tcx>,
+            [] pat: rustc_hir::Pat<$tcx>,
+            [] path: rustc_hir::Path<$tcx>,
+            [] path_segment: rustc_hir::PathSegment<$tcx>,
+            [] poly_trait_ref: rustc_hir::PolyTraitRef<$tcx>,
+            [] qpath: rustc_hir::QPath<$tcx>,
+            [] stmt: rustc_hir::Stmt<$tcx>,
+            [] struct_field: rustc_hir::StructField<$tcx>,
+            [] trait_item_ref: rustc_hir::TraitItemRef,
+            [] ty: rustc_hir::Ty<$tcx>,
+            [] type_binding: rustc_hir::TypeBinding<$tcx>,
+            [] variant: rustc_hir::Variant<$tcx>,
+            [] where_predicate: rustc_hir::WherePredicate<$tcx>,
+        ], $tcx);
+    )
+}
index fa5c72b060dcfe59e886f987d98fb69647e47f8a..826d8df8374d9e73e92410802999d1f18cbe1745 100644 (file)
@@ -13,6 +13,7 @@
 #[macro_use]
 extern crate rustc_data_structures;
 
+mod arena;
 pub mod def;
 pub use rustc_span::def_id;
 mod hir;
index 8d9e287cdc9d69329166e5a6865fb0e0b26d728b..c331b1e3d1e5539c4c78a96ccd3ed8a2b42f25e7 100644 (file)
@@ -437,7 +437,7 @@ pub fn lower_to_hir<'res, 'tcx>(
     resolver: &'res mut Resolver<'_>,
     dep_graph: &'res DepGraph,
     krate: &'res ast::Crate,
-    arena: &'tcx Arena<'tcx>,
+    arena: &'tcx rustc_ast_lowering::Arena<'tcx>,
 ) -> Crate<'tcx> {
     // Lower AST to HIR.
     let hir_crate = rustc_ast_lowering::lower_crate(
index 3ca92216003d16976b78d44a5537aca33d109b16..b0eeb57173fa33532bde0e5cec707bee68d7b7ef 100644 (file)
@@ -68,6 +68,7 @@ pub struct Queries<'tcx> {
     gcx: Once<GlobalCtxt<'tcx>>,
 
     arena: WorkerLocal<Arena<'tcx>>,
+    hir_arena: WorkerLocal<rustc_ast_lowering::Arena<'tcx>>,
 
     dep_graph_future: Query<Option<DepGraphFuture>>,
     parse: Query<ast::Crate>,
@@ -87,6 +88,7 @@ pub fn new(compiler: &'tcx Compiler) -> Queries<'tcx> {
             compiler,
             gcx: Once::new(),
             arena: WorkerLocal::new(|_| Arena::default()),
+            hir_arena: WorkerLocal::new(|_| rustc_ast_lowering::Arena::default()),
             dep_graph_future: Default::default(),
             parse: Default::default(),
             crate_name: Default::default(),
@@ -218,10 +220,10 @@ pub fn lower_to_hir(&'tcx self) -> Result<&Query<(&'tcx Crate<'tcx>, Steal<Resol
                     resolver,
                     &*self.dep_graph()?.peek(),
                     &krate,
-                    &self.arena,
+                    &self.hir_arena,
                 ))
             })?;
-            let hir = self.arena.alloc(hir);
+            let hir = self.hir_arena.alloc(hir);
             Ok((hir, Steal::new(BoxedResolver::to_resolver_outputs(resolver))))
         })
     }