Skip to content

Commit 0f68ab0

Browse files
committed
separate out an arena for HIR
1 parent 4c28d68 commit 0f68ab0

File tree

11 files changed

+66
-41
lines changed

11 files changed

+66
-41
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,6 +3477,7 @@ dependencies = [
34773477
name = "rustc_ast_lowering"
34783478
version = "0.0.0"
34793479
dependencies = [
3480+
"arena",
34803481
"log",
34813482
"rustc",
34823483
"rustc_ast",

src/libarena/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,8 @@ macro_rules! declare_arena {
624624
}
625625

626626
$(
627-
impl ArenaAllocatable for $ty {}
627+
#[allow(unused_lifetimes)]
628+
impl<$tcx> ArenaAllocatable for $ty {}
628629
unsafe impl<$tcx> ArenaField<$tcx> for $ty {
629630
#[inline]
630631
fn arena<'a>(_arena: &'a Arena<$tcx>) -> Option<&'a $crate::TypedArena<Self>> {
@@ -653,7 +654,7 @@ macro_rules! declare_arena {
653654
self.dropless.alloc_slice(value)
654655
}
655656

656-
pub fn alloc_from_iter<T: ArenaAllocatable>(
657+
pub fn alloc_from_iter<'a, T: ArenaAllocatable>(
657658
&'a self,
658659
iter: impl ::std::iter::IntoIterator<Item = T>,
659660
) -> &'a mut [T] {

src/librustc/arena.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -120,40 +120,6 @@ macro_rules! arena_types {
120120
// Interned types
121121
[] tys: rustc::ty::TyS<$tcx>,
122122

123-
// HIR types
124-
[few] hir_krate: rustc_hir::Crate<$tcx>,
125-
[] arm: rustc_hir::Arm<$tcx>,
126-
[] attribute: rustc_ast::ast::Attribute,
127-
[] block: rustc_hir::Block<$tcx>,
128-
[] bare_fn_ty: rustc_hir::BareFnTy<$tcx>,
129-
[few] global_asm: rustc_hir::GlobalAsm,
130-
[] generic_arg: rustc_hir::GenericArg<$tcx>,
131-
[] generic_args: rustc_hir::GenericArgs<$tcx>,
132-
[] generic_bound: rustc_hir::GenericBound<$tcx>,
133-
[] generic_param: rustc_hir::GenericParam<$tcx>,
134-
[] expr: rustc_hir::Expr<$tcx>,
135-
[] field: rustc_hir::Field<$tcx>,
136-
[] field_pat: rustc_hir::FieldPat<$tcx>,
137-
[] fn_decl: rustc_hir::FnDecl<$tcx>,
138-
[] foreign_item: rustc_hir::ForeignItem<$tcx>,
139-
[] impl_item_ref: rustc_hir::ImplItemRef<$tcx>,
140-
[] inline_asm: rustc_hir::InlineAsm<$tcx>,
141-
[] local: rustc_hir::Local<$tcx>,
142-
[few] macro_def: rustc_hir::MacroDef<$tcx>,
143-
[] param: rustc_hir::Param<$tcx>,
144-
[] pat: rustc_hir::Pat<$tcx>,
145-
[] path: rustc_hir::Path<$tcx>,
146-
[] path_segment: rustc_hir::PathSegment<$tcx>,
147-
[] poly_trait_ref: rustc_hir::PolyTraitRef<$tcx>,
148-
[] qpath: rustc_hir::QPath<$tcx>,
149-
[] stmt: rustc_hir::Stmt<$tcx>,
150-
[] struct_field: rustc_hir::StructField<$tcx>,
151-
[] trait_item_ref: rustc_hir::TraitItemRef,
152-
[] ty: rustc_hir::Ty<$tcx>,
153-
[] type_binding: rustc_hir::TypeBinding<$tcx>,
154-
[] variant: rustc_hir::Variant<$tcx>,
155-
[] where_predicate: rustc_hir::WherePredicate<$tcx>,
156-
157123
// HIR query types
158124
[few] indexed_hir: rustc::hir::map::IndexedHir<$tcx>,
159125
[few] hir_definitions: rustc::hir::map::definitions::Definitions,

src/librustc/ty/codec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ macro_rules! implement_ty_decoder {
396396
// the caller to pick any lifetime for `'tcx`, including `'static`,
397397
// by using the unspecialized proxies to them.
398398

399+
rustc_hir::arena_types!(impl_arena_allocatable_decoders, [$DecoderName [$($typaram),*]], 'tcx);
399400
arena_types!(impl_arena_allocatable_decoders, [$DecoderName [$($typaram),*]], 'tcx);
400401

401402
impl<$($typaram),*> SpecializedDecoder<CrateNum>

src/librustc_ast_lowering/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ path = "lib.rs"
1010
doctest = false
1111

1212
[dependencies]
13+
arena = { path = "../libarena" }
1314
log = { version = "0.4", features = ["release_max_level_info", "std"] }
1415
rustc = { path = "../librustc" }
1516
rustc_ast_pretty = { path = "../librustc_ast_pretty" }

src/librustc_ast_lowering/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{AnonymousLifetimeMode, LoweringContext, ParamMode};
22
use super::{ImplTraitContext, ImplTraitPosition, ImplTraitTypeIdVisitor};
3+
use crate::Arena;
34

4-
use rustc::arena::Arena;
55
use rustc::bug;
66
use rustc_ast::ast::*;
77
use rustc_ast::attr;

src/librustc_ast_lowering/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
3333
#![feature(array_value_iter)]
3434
#![feature(crate_visibility_modifier)]
35+
#![feature(marker_trait_attr)]
36+
#![feature(specialization)]
3537
#![recursion_limit = "256"]
3638

37-
use rustc::arena::Arena;
3839
use rustc::dep_graph::DepGraph;
3940
use rustc::hir::map::definitions::{DefKey, DefPathData, Definitions};
4041
use rustc::{bug, span_bug};
@@ -85,6 +86,8 @@ mod path;
8586

8687
const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
8788

89+
rustc_hir::arena_types!(::arena::declare_arena, [], 'tcx);
90+
8891
struct LoweringContext<'a, 'hir: 'a> {
8992
crate_root: Option<Symbol>,
9093

src/librustc_hir/arena.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/// This declares a list of types which can be allocated by `Arena`.
2+
///
3+
/// The `few` modifier will cause allocation to use the shared arena and recording the destructor.
4+
/// This is faster and more memory efficient if there's only a few allocations of the type.
5+
/// Leaving `few` out will cause the type to get its own dedicated `TypedArena` which is
6+
/// faster and more memory efficient if there is lots of allocations.
7+
///
8+
/// Specifying the `decode` modifier will add decode impls for &T and &[T] where T is the type
9+
/// listed. These impls will appear in the implement_ty_decoder! macro.
10+
#[macro_export]
11+
macro_rules! arena_types {
12+
($macro:path, $args:tt, $tcx:lifetime) => (
13+
$macro!($args, [
14+
// HIR types
15+
[few] hir_krate: rustc_hir::Crate<$tcx>,
16+
[] arm: rustc_hir::Arm<$tcx>,
17+
[] attribute: rustc_ast::ast::Attribute,
18+
[] block: rustc_hir::Block<$tcx>,
19+
[] bare_fn_ty: rustc_hir::BareFnTy<$tcx>,
20+
[few] global_asm: rustc_hir::GlobalAsm,
21+
[] generic_arg: rustc_hir::GenericArg<$tcx>,
22+
[] generic_args: rustc_hir::GenericArgs<$tcx>,
23+
[] generic_bound: rustc_hir::GenericBound<$tcx>,
24+
[] generic_param: rustc_hir::GenericParam<$tcx>,
25+
[] expr: rustc_hir::Expr<$tcx>,
26+
[] field: rustc_hir::Field<$tcx>,
27+
[] field_pat: rustc_hir::FieldPat<$tcx>,
28+
[] fn_decl: rustc_hir::FnDecl<$tcx>,
29+
[] foreign_item: rustc_hir::ForeignItem<$tcx>,
30+
[] impl_item_ref: rustc_hir::ImplItemRef<$tcx>,
31+
[] inline_asm: rustc_hir::InlineAsm<$tcx>,
32+
[] local: rustc_hir::Local<$tcx>,
33+
[few] macro_def: rustc_hir::MacroDef<$tcx>,
34+
[] param: rustc_hir::Param<$tcx>,
35+
[] pat: rustc_hir::Pat<$tcx>,
36+
[] path: rustc_hir::Path<$tcx>,
37+
[] path_segment: rustc_hir::PathSegment<$tcx>,
38+
[] poly_trait_ref: rustc_hir::PolyTraitRef<$tcx>,
39+
[] qpath: rustc_hir::QPath<$tcx>,
40+
[] stmt: rustc_hir::Stmt<$tcx>,
41+
[] struct_field: rustc_hir::StructField<$tcx>,
42+
[] trait_item_ref: rustc_hir::TraitItemRef,
43+
[] ty: rustc_hir::Ty<$tcx>,
44+
[] type_binding: rustc_hir::TypeBinding<$tcx>,
45+
[] variant: rustc_hir::Variant<$tcx>,
46+
[] where_predicate: rustc_hir::WherePredicate<$tcx>,
47+
], $tcx);
48+
)
49+
}

src/librustc_hir/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#[macro_use]
1414
extern crate rustc_data_structures;
1515

16+
mod arena;
1617
pub mod def;
1718
pub use rustc_span::def_id;
1819
mod hir;

src/librustc_interface/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ pub fn lower_to_hir<'res, 'tcx>(
437437
resolver: &'res mut Resolver<'_>,
438438
dep_graph: &'res DepGraph,
439439
krate: &'res ast::Crate,
440-
arena: &'tcx Arena<'tcx>,
440+
arena: &'tcx rustc_ast_lowering::Arena<'tcx>,
441441
) -> Crate<'tcx> {
442442
// Lower AST to HIR.
443443
let hir_crate = rustc_ast_lowering::lower_crate(

0 commit comments

Comments
 (0)