From d07ce65d56d527273a2a80862c8a69d0dbc88906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Tue, 20 Oct 2020 10:37:56 +0200 Subject: [PATCH 1/2] Resolve: Use dropless arena for types that don't need drop --- compiler/rustc_resolve/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index e7486db4debcc..170fece32f10b 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -19,7 +19,7 @@ pub use rustc_hir::def::{Namespace, PerNS}; use Determinacy::*; -use rustc_arena::TypedArena; +use rustc_arena::{DroplessArena, TypedArena}; use rustc_ast::node_id::NodeMap; use rustc_ast::unwrap_or; use rustc_ast::visit::{self, Visitor}; @@ -1035,12 +1035,10 @@ pub struct Resolver<'a> { pub struct ResolverArenas<'a> { modules: TypedArena>, local_modules: RefCell>>, - name_bindings: TypedArena>, imports: TypedArena>, name_resolutions: TypedArena>>, - macro_rules_bindings: TypedArena>, ast_paths: TypedArena, - pattern_spans: TypedArena, + dropless: DroplessArena, } impl<'a> ResolverArenas<'a> { @@ -1055,7 +1053,7 @@ impl<'a> ResolverArenas<'a> { self.local_modules.borrow() } fn alloc_name_binding(&'a self, name_binding: NameBinding<'a>) -> &'a NameBinding<'a> { - self.name_bindings.alloc(name_binding) + self.dropless.alloc(name_binding) } fn alloc_import(&'a self, import: Import<'a>) -> &'a Import<'_> { self.imports.alloc(import) @@ -1067,13 +1065,13 @@ impl<'a> ResolverArenas<'a> { &'a self, binding: MacroRulesBinding<'a>, ) -> &'a MacroRulesBinding<'a> { - self.macro_rules_bindings.alloc(binding) + self.dropless.alloc(binding) } fn alloc_ast_paths(&'a self, paths: &[ast::Path]) -> &'a [ast::Path] { self.ast_paths.alloc_from_iter(paths.iter().cloned()) } fn alloc_pattern_spans(&'a self, spans: impl Iterator) -> &'a [Span] { - self.pattern_spans.alloc_from_iter(spans) + self.dropless.alloc_from_iter(spans) } } From 9b453d695481f8898bf29eef25f3027c769e1a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Tue, 20 Oct 2020 11:05:00 +0200 Subject: [PATCH 2/2] Use DroplessArena for variance inference --- compiler/rustc_typeck/src/variance/mod.rs | 6 +++--- compiler/rustc_typeck/src/variance/terms.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_typeck/src/variance/mod.rs b/compiler/rustc_typeck/src/variance/mod.rs index a893f69c48ada..1565efbb022f4 100644 --- a/compiler/rustc_typeck/src/variance/mod.rs +++ b/compiler/rustc_typeck/src/variance/mod.rs @@ -4,7 +4,7 @@ //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/variance.html use hir::Node; -use rustc_arena::TypedArena; +use rustc_arena::DroplessArena; use rustc_hir as hir; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_middle::ty::query::Providers; @@ -32,8 +32,8 @@ pub fn provide(providers: &mut Providers) { fn crate_variances(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateVariancesMap<'_> { assert_eq!(crate_num, LOCAL_CRATE); - let mut arena = TypedArena::default(); - let terms_cx = terms::determine_parameters_to_be_inferred(tcx, &mut arena); + let arena = DroplessArena::default(); + let terms_cx = terms::determine_parameters_to_be_inferred(tcx, &arena); let constraints_cx = constraints::add_constraints_from_crate(terms_cx); solve::solve_constraints(constraints_cx) } diff --git a/compiler/rustc_typeck/src/variance/terms.rs b/compiler/rustc_typeck/src/variance/terms.rs index f61a783de694b..81c858c53cb8e 100644 --- a/compiler/rustc_typeck/src/variance/terms.rs +++ b/compiler/rustc_typeck/src/variance/terms.rs @@ -9,7 +9,7 @@ // `InferredIndex` is a newtype'd int representing the index of such // a variable. -use rustc_arena::TypedArena; +use rustc_arena::DroplessArena; use rustc_hir as hir; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::HirIdMap; @@ -47,7 +47,7 @@ impl<'a> fmt::Debug for VarianceTerm<'a> { pub struct TermsContext<'a, 'tcx> { pub tcx: TyCtxt<'tcx>, - pub arena: &'a TypedArena>, + pub arena: &'a DroplessArena, // For marker types, UnsafeCell, and other lang items where // variance is hardcoded, records the item-id and the hardcoded @@ -64,7 +64,7 @@ pub struct TermsContext<'a, 'tcx> { pub fn determine_parameters_to_be_inferred<'a, 'tcx>( tcx: TyCtxt<'tcx>, - arena: &'a mut TypedArena>, + arena: &'a DroplessArena, ) -> TermsContext<'a, 'tcx> { let mut terms_cx = TermsContext { tcx,