From c520cf225310e0d1d3ebf513034255cee3f76e30 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 11 Jun 2021 18:55:14 +0200 Subject: [PATCH] Arena-allocate Crate during lowering. --- compiler/rustc_ast_lowering/src/lib.rs | 9 +++++---- compiler/rustc_interface/src/passes.rs | 3 +-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 9592c1d2fab..7a4e39376a8 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -296,7 +296,7 @@ pub fn lower_crate<'a, 'hir>( resolver: &'a mut dyn ResolverAstLowering, nt_to_tokenstream: NtToTokenstream, arena: &'hir Arena<'hir>, -) -> hir::Crate<'hir> { +) -> &'hir hir::Crate<'hir> { let _prof_timer = sess.prof.verbose_generic_activity("hir_lowering"); LoweringContext { @@ -403,7 +403,7 @@ enum AnonymousLifetimeMode { } impl<'a, 'hir> LoweringContext<'a, 'hir> { - fn lower_crate(mut self, c: &Crate) -> hir::Crate<'hir> { + fn lower_crate(mut self, c: &Crate) -> &'hir hir::Crate<'hir> { /// Full-crate AST visitor that inserts into a fresh /// `LoweringContext` any information that may be /// needed from arbitrary locations in the crate, @@ -530,7 +530,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - hir::Crate { + let krate = hir::Crate { item: module, exported_macros: self.arena.alloc_from_iter(self.exported_macros), non_exported_macro_attrs: self.arena.alloc_from_iter(self.non_exported_macro_attrs), @@ -545,7 +545,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { proc_macros, trait_map, attrs: self.attrs, - } + }; + self.arena.alloc(krate) } fn insert_item(&mut self, item: hir::Item<'hir>) -> hir::ItemId { diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index e08c8faaa52..f5a085250a6 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -460,7 +460,7 @@ pub fn lower_to_hir<'res, 'tcx>( resolver: &'res mut Resolver<'_>, krate: &'res ast::Crate, arena: &'tcx rustc_ast_lowering::Arena<'tcx>, -) -> Crate<'tcx> { +) -> &'tcx Crate<'tcx> { // Lower AST to HIR. let hir_crate = rustc_ast_lowering::lower_crate( sess, @@ -796,7 +796,6 @@ pub fn create_global_ctxt<'tcx>( let krate = resolver .borrow_mut() .access(|resolver| lower_to_hir(sess, &lint_store, resolver, krate, hir_arena)); - let krate = &*hir_arena.alloc(krate); let resolver_outputs = BoxedResolver::to_resolver_outputs(resolver); let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);