Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5e1ad0d

Browse files
committed
Remove Arcs in queries.
1 parent 3c0edc8 commit 5e1ad0d

File tree

9 files changed

+27
-31
lines changed

9 files changed

+27
-31
lines changed

src/librustc_codegen_llvm/context.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc_target::spec::{HasTargetSpec, Target};
2626
use std::cell::{Cell, RefCell};
2727
use std::ffi::CStr;
2828
use std::str;
29-
use std::sync::Arc;
3029

3130
/// There is one `CodegenCx` per compilation unit. Each one has its own LLVM
3231
/// `llvm::Context` so that several compilation units may be optimized in parallel.
@@ -39,7 +38,7 @@ pub struct CodegenCx<'ll, 'tcx> {
3938

4039
pub llmod: &'ll llvm::Module,
4140
pub llcx: &'ll llvm::Context,
42-
pub codegen_unit: Arc<CodegenUnit<'tcx>>,
41+
pub codegen_unit: &'tcx CodegenUnit<'tcx>,
4342

4443
/// Cache instances of monomorphic and polymorphic items
4544
pub instances: RefCell<FxHashMap<Instance<'tcx>, &'ll Value>>,
@@ -232,7 +231,7 @@ pub unsafe fn create_module(
232231
impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
233232
crate fn new(
234233
tcx: TyCtxt<'tcx>,
235-
codegen_unit: Arc<CodegenUnit<'tcx>>,
234+
codegen_unit: &'tcx CodegenUnit<'tcx>,
236235
llvm_module: &'ll crate::ModuleLlvm,
237236
) -> Self {
238237
// An interesting part of Windows which MSVC forces our hand on (and
@@ -402,8 +401,8 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
402401
self.check_overflow
403402
}
404403

405-
fn codegen_unit(&self) -> &Arc<CodegenUnit<'tcx>> {
406-
&self.codegen_unit
404+
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> {
405+
self.codegen_unit
407406
}
408407

409408
fn used_statics(&self) -> &RefCell<Vec<&'ll Value>> {

src/librustc_codegen_ssa/back/symbol_export.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::hash_map::Entry::*;
2-
use std::sync::Arc;
32

43
use rustc_ast::expand::allocator::ALLOCATOR_METHODS;
54
use rustc_data_structures::fingerprint::Fingerprint;
@@ -164,11 +163,11 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
164163
fn exported_symbols_provider_local(
165164
tcx: TyCtxt<'_>,
166165
cnum: CrateNum,
167-
) -> Arc<Vec<(ExportedSymbol<'_>, SymbolExportLevel)>> {
166+
) -> &'tcx [(ExportedSymbol<'_>, SymbolExportLevel)] {
168167
assert_eq!(cnum, LOCAL_CRATE);
169168

170169
if !tcx.sess.opts.output_types.should_codegen() {
171-
return Arc::new(vec![]);
170+
return &[];
172171
}
173172

174173
let mut symbols: Vec<_> = tcx
@@ -274,7 +273,7 @@ fn exported_symbols_provider_local(
274273
// Sort so we get a stable incr. comp. hash.
275274
symbols.sort_by_cached_key(|s| s.0.symbol_name_for_local_instance(tcx));
276275

277-
Arc::new(symbols)
276+
tcx.arena.alloc_from_iter(symbols)
278277
}
279278

280279
fn upstream_monomorphizations_provider(

src/librustc_codegen_ssa/base.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,14 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
533533
// Run the monomorphization collector and partition the collected items into
534534
// codegen units.
535535
let codegen_units = tcx.collect_and_partition_mono_items(LOCAL_CRATE).1;
536-
let codegen_units = (*codegen_units).clone();
537536

538537
// Force all codegen_unit queries so they are already either red or green
539538
// when compile_codegen_unit accesses them. We are not able to re-execute
540539
// the codegen_unit query from just the DepNode, so an unknown color would
541540
// lead to having to re-execute compile_codegen_unit, possibly
542541
// unnecessarily.
543542
if tcx.dep_graph.is_fully_enabled() {
544-
for cgu in &codegen_units {
543+
for cgu in codegen_units {
545544
tcx.codegen_unit(cgu.name());
546545
}
547546
}
@@ -603,7 +602,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
603602
// We sort the codegen units by size. This way we can schedule work for LLVM
604603
// a bit more efficiently.
605604
let codegen_units = {
606-
let mut codegen_units = codegen_units;
605+
let mut codegen_units = codegen_units.iter().collect::<Vec<_>>();
607606
codegen_units.sort_by_cached_key(|cgu| cmp::Reverse(cgu.size_estimate()));
608607
codegen_units
609608
};

src/librustc_codegen_ssa/traits/misc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_middle::mir::mono::CodegenUnit;
44
use rustc_middle::ty::{self, Instance, Ty};
55
use rustc_session::Session;
66
use std::cell::RefCell;
7-
use std::sync::Arc;
87

98
pub trait MiscMethods<'tcx>: BackendTypes {
109
fn vtables(
@@ -15,7 +14,7 @@ pub trait MiscMethods<'tcx>: BackendTypes {
1514
fn get_fn_addr(&self, instance: Instance<'tcx>) -> Self::Value;
1615
fn eh_personality(&self) -> Self::Value;
1716
fn sess(&self) -> &Session;
18-
fn codegen_unit(&self) -> &Arc<CodegenUnit<'tcx>>;
17+
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx>;
1918
fn used_statics(&self) -> &RefCell<Vec<Self::Value>>;
2019
fn set_frame_pointer_elimination(&self, llfn: Self::Function);
2120
fn apply_target_cpu_attr(&self, llfn: Self::Function);

src/librustc_metadata/rmeta/decoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,13 +1343,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13431343
fn exported_symbols(
13441344
&self,
13451345
tcx: TyCtxt<'tcx>,
1346-
) -> Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)> {
1346+
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
13471347
if self.root.is_proc_macro_crate() {
13481348
// If this crate is a custom derive crate, then we're not even going to
13491349
// link those in so we skip those crates.
1350-
vec![]
1350+
&[]
13511351
} else {
1352-
self.root.exported_symbols.decode((self, tcx)).collect()
1352+
tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx)))
13531353
}
13541354
}
13551355

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc_span::symbol::Symbol;
2626
use rustc_data_structures::sync::Lrc;
2727
use smallvec::SmallVec;
2828
use std::any::Any;
29-
use std::sync::Arc;
3029

3130
macro_rules! provide {
3231
(<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident,
@@ -239,7 +238,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
239238
// to block export of generics from dylibs, but we must fix
240239
// rust-lang/rust#65890 before we can do that robustly.
241240

242-
Arc::new(syms)
241+
syms
243242
}
244243
}
245244

src/librustc_middle/arena.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ macro_rules! arena_types {
117117
[few] inferred_outlives_crate: rustc_middle::ty::CratePredicatesMap<'tcx>,
118118
[] upvars: rustc_data_structures::fx::FxIndexMap<rustc_hir::HirId, rustc_hir::Upvar>,
119119
[] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation,
120+
[] codegen_unit: rustc_middle::mir::mono::CodegenUnit<$tcx>,
120121

121122
// Interned types
122123
[] tys: rustc_middle::ty::TyS<$tcx>,

src/librustc_middle/query/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,19 +1075,19 @@ rustc_queries! {
10751075
/// correspond to a publicly visible symbol in `cnum` machine code.
10761076
/// - The `exported_symbols` sets of different crates do not intersect.
10771077
query exported_symbols(_: CrateNum)
1078-
-> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>> {
1078+
-> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
10791079
desc { "exported_symbols" }
10801080
}
10811081
}
10821082

10831083
Codegen {
10841084
query collect_and_partition_mono_items(_: CrateNum)
1085-
-> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>) {
1085+
-> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
10861086
eval_always
10871087
desc { "collect_and_partition_mono_items" }
10881088
}
10891089
query is_codegened_item(_: DefId) -> bool {}
1090-
query codegen_unit(_: Symbol) -> Arc<CodegenUnit<'tcx>> {
1090+
query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> {
10911091
desc { "codegen_unit" }
10921092
}
10931093
query backend_optimization_level(_: CrateNum) -> OptLevel {

src/librustc_mir/monomorphize/partitioning.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
9595
use std::cmp;
9696
use std::collections::hash_map::Entry;
97-
use std::sync::Arc;
9897

9998
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
10099
use rustc_data_structures::sync;
@@ -883,7 +882,7 @@ where
883882
fn collect_and_partition_mono_items(
884883
tcx: TyCtxt<'_>,
885884
cnum: CrateNum,
886-
) -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'_>>>>) {
885+
) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'_>]) {
887886
assert_eq!(cnum, LOCAL_CRATE);
888887

889888
let collection_mode = match tcx.sess.opts.debugging_opts.print_mono_items {
@@ -921,10 +920,12 @@ fn collect_and_partition_mono_items(
921920
let (codegen_units, _) = tcx.sess.time("partition_and_assert_distinct_symbols", || {
922921
sync::join(
923922
|| {
924-
partition(tcx, items.iter().cloned(), tcx.sess.codegen_units(), &inlining_map)
925-
.into_iter()
926-
.map(Arc::new)
927-
.collect::<Vec<_>>()
923+
&*tcx.arena.alloc_from_iter(partition(
924+
tcx,
925+
items.iter().cloned(),
926+
tcx.sess.codegen_units(),
927+
&inlining_map,
928+
))
928929
},
929930
|| assert_symbols_are_distinct(tcx, items.iter()),
930931
)
@@ -942,7 +943,7 @@ fn collect_and_partition_mono_items(
942943
if tcx.sess.opts.debugging_opts.print_mono_items.is_some() {
943944
let mut item_to_cgus: FxHashMap<_, Vec<_>> = Default::default();
944945

945-
for cgu in &codegen_units {
946+
for cgu in codegen_units {
946947
for (&mono_item, &linkage) in cgu.items() {
947948
item_to_cgus.entry(mono_item).or_default().push((cgu.name(), linkage));
948949
}
@@ -990,7 +991,7 @@ fn collect_and_partition_mono_items(
990991
}
991992
}
992993

993-
(Arc::new(mono_items), Arc::new(codegen_units))
994+
(tcx.arena.alloc(mono_items), codegen_units)
994995
}
995996

996997
pub fn provide(providers: &mut Providers<'_>) {
@@ -1005,7 +1006,6 @@ pub fn provide(providers: &mut Providers<'_>) {
10051006
let (_, all) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
10061007
all.iter()
10071008
.find(|cgu| cgu.name() == name)
1008-
.cloned()
10091009
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))
10101010
};
10111011
}

0 commit comments

Comments
 (0)