name = "rustc_ast_lowering"
version = "0.0.0"
dependencies = [
+ "arena",
"log",
"rustc",
"rustc_ast",
}
$(
- 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>> {
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] {
// 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,
// 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>
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" }
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;
#![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};
const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
+rustc_hir::arena_types!(::arena::declare_arena, [], 'tcx);
+
struct LoweringContext<'a, 'hir: 'a> {
crate_root: Option<Symbol>,
--- /dev/null
+/// 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);
+ )
+}
#[macro_use]
extern crate rustc_data_structures;
+mod arena;
pub mod def;
pub use rustc_span::def_id;
mod hir;
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(
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>,
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(),
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))))
})
}