Skip to content

Commit c520cf2

Browse files
committed
Arena-allocate Crate during lowering.
1 parent e05cd15 commit c520cf2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ pub fn lower_crate<'a, 'hir>(
296296
resolver: &'a mut dyn ResolverAstLowering,
297297
nt_to_tokenstream: NtToTokenstream,
298298
arena: &'hir Arena<'hir>,
299-
) -> hir::Crate<'hir> {
299+
) -> &'hir hir::Crate<'hir> {
300300
let _prof_timer = sess.prof.verbose_generic_activity("hir_lowering");
301301

302302
LoweringContext {
@@ -403,7 +403,7 @@ enum AnonymousLifetimeMode {
403403
}
404404

405405
impl<'a, 'hir> LoweringContext<'a, 'hir> {
406-
fn lower_crate(mut self, c: &Crate) -> hir::Crate<'hir> {
406+
fn lower_crate(mut self, c: &Crate) -> &'hir hir::Crate<'hir> {
407407
/// Full-crate AST visitor that inserts into a fresh
408408
/// `LoweringContext` any information that may be
409409
/// needed from arbitrary locations in the crate,
@@ -530,7 +530,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
530530
}
531531
}
532532

533-
hir::Crate {
533+
let krate = hir::Crate {
534534
item: module,
535535
exported_macros: self.arena.alloc_from_iter(self.exported_macros),
536536
non_exported_macro_attrs: self.arena.alloc_from_iter(self.non_exported_macro_attrs),
@@ -545,7 +545,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
545545
proc_macros,
546546
trait_map,
547547
attrs: self.attrs,
548-
}
548+
};
549+
self.arena.alloc(krate)
549550
}
550551

551552
fn insert_item(&mut self, item: hir::Item<'hir>) -> hir::ItemId {

compiler/rustc_interface/src/passes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ pub fn lower_to_hir<'res, 'tcx>(
460460
resolver: &'res mut Resolver<'_>,
461461
krate: &'res ast::Crate,
462462
arena: &'tcx rustc_ast_lowering::Arena<'tcx>,
463-
) -> Crate<'tcx> {
463+
) -> &'tcx Crate<'tcx> {
464464
// Lower AST to HIR.
465465
let hir_crate = rustc_ast_lowering::lower_crate(
466466
sess,
@@ -796,7 +796,6 @@ pub fn create_global_ctxt<'tcx>(
796796
let krate = resolver
797797
.borrow_mut()
798798
.access(|resolver| lower_to_hir(sess, &lint_store, resolver, krate, hir_arena));
799-
let krate = &*hir_arena.alloc(krate);
800799
let resolver_outputs = BoxedResolver::to_resolver_outputs(resolver);
801800

802801
let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);

0 commit comments

Comments
 (0)