Skip to content

Commit 6b9fbf2

Browse files
committed
Auto merge of #78134 - bugadani:arena-nodrop, r=lcnr
Use `DroplessArena` where we know the type doesn't need drop This PR uses a single `DroplessArena` in resolve instead of three separate `TypedArena`s. `DroplessArena` checks that the type indeed doesn't need drop, so in case the types change, this will result in visible failures.
2 parents 8f0fa9d + 9b453d6 commit 6b9fbf2

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

compiler/rustc_resolve/src/lib.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use rustc_hir::def::{Namespace, PerNS};
1919

2020
use Determinacy::*;
2121

22-
use rustc_arena::TypedArena;
22+
use rustc_arena::{DroplessArena, TypedArena};
2323
use rustc_ast::node_id::NodeMap;
2424
use rustc_ast::unwrap_or;
2525
use rustc_ast::visit::{self, Visitor};
@@ -1035,12 +1035,10 @@ pub struct Resolver<'a> {
10351035
pub struct ResolverArenas<'a> {
10361036
modules: TypedArena<ModuleData<'a>>,
10371037
local_modules: RefCell<Vec<Module<'a>>>,
1038-
name_bindings: TypedArena<NameBinding<'a>>,
10391038
imports: TypedArena<Import<'a>>,
10401039
name_resolutions: TypedArena<RefCell<NameResolution<'a>>>,
1041-
macro_rules_bindings: TypedArena<MacroRulesBinding<'a>>,
10421040
ast_paths: TypedArena<ast::Path>,
1043-
pattern_spans: TypedArena<Span>,
1041+
dropless: DroplessArena,
10441042
}
10451043

10461044
impl<'a> ResolverArenas<'a> {
@@ -1055,7 +1053,7 @@ impl<'a> ResolverArenas<'a> {
10551053
self.local_modules.borrow()
10561054
}
10571055
fn alloc_name_binding(&'a self, name_binding: NameBinding<'a>) -> &'a NameBinding<'a> {
1058-
self.name_bindings.alloc(name_binding)
1056+
self.dropless.alloc(name_binding)
10591057
}
10601058
fn alloc_import(&'a self, import: Import<'a>) -> &'a Import<'_> {
10611059
self.imports.alloc(import)
@@ -1067,13 +1065,13 @@ impl<'a> ResolverArenas<'a> {
10671065
&'a self,
10681066
binding: MacroRulesBinding<'a>,
10691067
) -> &'a MacroRulesBinding<'a> {
1070-
self.macro_rules_bindings.alloc(binding)
1068+
self.dropless.alloc(binding)
10711069
}
10721070
fn alloc_ast_paths(&'a self, paths: &[ast::Path]) -> &'a [ast::Path] {
10731071
self.ast_paths.alloc_from_iter(paths.iter().cloned())
10741072
}
10751073
fn alloc_pattern_spans(&'a self, spans: impl Iterator<Item = Span>) -> &'a [Span] {
1076-
self.pattern_spans.alloc_from_iter(spans)
1074+
self.dropless.alloc_from_iter(spans)
10771075
}
10781076
}
10791077

compiler/rustc_typeck/src/variance/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/variance.html
55
66
use hir::Node;
7-
use rustc_arena::TypedArena;
7+
use rustc_arena::DroplessArena;
88
use rustc_hir as hir;
99
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
1010
use rustc_middle::ty::query::Providers;
@@ -32,8 +32,8 @@ pub fn provide(providers: &mut Providers) {
3232

3333
fn crate_variances(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateVariancesMap<'_> {
3434
assert_eq!(crate_num, LOCAL_CRATE);
35-
let mut arena = TypedArena::default();
36-
let terms_cx = terms::determine_parameters_to_be_inferred(tcx, &mut arena);
35+
let arena = DroplessArena::default();
36+
let terms_cx = terms::determine_parameters_to_be_inferred(tcx, &arena);
3737
let constraints_cx = constraints::add_constraints_from_crate(terms_cx);
3838
solve::solve_constraints(constraints_cx)
3939
}

compiler/rustc_typeck/src/variance/terms.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// `InferredIndex` is a newtype'd int representing the index of such
1010
// a variable.
1111

12-
use rustc_arena::TypedArena;
12+
use rustc_arena::DroplessArena;
1313
use rustc_hir as hir;
1414
use rustc_hir::itemlikevisit::ItemLikeVisitor;
1515
use rustc_hir::HirIdMap;
@@ -47,7 +47,7 @@ impl<'a> fmt::Debug for VarianceTerm<'a> {
4747

4848
pub struct TermsContext<'a, 'tcx> {
4949
pub tcx: TyCtxt<'tcx>,
50-
pub arena: &'a TypedArena<VarianceTerm<'a>>,
50+
pub arena: &'a DroplessArena,
5151

5252
// For marker types, UnsafeCell, and other lang items where
5353
// variance is hardcoded, records the item-id and the hardcoded
@@ -64,7 +64,7 @@ pub struct TermsContext<'a, 'tcx> {
6464

6565
pub fn determine_parameters_to_be_inferred<'a, 'tcx>(
6666
tcx: TyCtxt<'tcx>,
67-
arena: &'a mut TypedArena<VarianceTerm<'a>>,
67+
arena: &'a DroplessArena,
6868
) -> TermsContext<'a, 'tcx> {
6969
let mut terms_cx = TermsContext {
7070
tcx,

0 commit comments

Comments
 (0)