diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2020-03-14 12:41:32 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2020-04-05 15:21:08 +0200 |
| commit | 5e1ad0d1e448a4ead87c52dd622e12a35c66a7f2 (patch) | |
| tree | 61c95e612da97fd6296d26de5475e779faa00770 | |
| parent | 3c0edc895ff4d3d82e93c9dc61bb4a8a24da5fad (diff) | |
| download | rust-5e1ad0d1e448a4ead87c52dd622e12a35c66a7f2.tar.gz rust-5e1ad0d1e448a4ead87c52dd622e12a35c66a7f2.zip | |
Remove Arcs in queries.
| -rw-r--r-- | src/librustc_codegen_llvm/context.rs | 9 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/back/symbol_export.rs | 7 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/base.rs | 5 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/traits/misc.rs | 3 | ||||
| -rw-r--r-- | src/librustc_metadata/rmeta/decoder.rs | 6 | ||||
| -rw-r--r-- | src/librustc_metadata/rmeta/decoder/cstore_impl.rs | 3 | ||||
| -rw-r--r-- | src/librustc_middle/arena.rs | 1 | ||||
| -rw-r--r-- | src/librustc_middle/query/mod.rs | 6 | ||||
| -rw-r--r-- | src/librustc_mir/monomorphize/partitioning.rs | 18 |
9 files changed, 27 insertions, 31 deletions
diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 99a825823c3..daa723495f6 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -26,7 +26,6 @@ use rustc_target::spec::{HasTargetSpec, Target}; use std::cell::{Cell, RefCell}; use std::ffi::CStr; use std::str; -use std::sync::Arc; /// There is one `CodegenCx` per compilation unit. Each one has its own LLVM /// `llvm::Context` so that several compilation units may be optimized in parallel. @@ -39,7 +38,7 @@ pub struct CodegenCx<'ll, 'tcx> { pub llmod: &'ll llvm::Module, pub llcx: &'ll llvm::Context, - pub codegen_unit: Arc<CodegenUnit<'tcx>>, + pub codegen_unit: &'tcx CodegenUnit<'tcx>, /// Cache instances of monomorphic and polymorphic items pub instances: RefCell<FxHashMap<Instance<'tcx>, &'ll Value>>, @@ -232,7 +231,7 @@ pub unsafe fn create_module( impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { crate fn new( tcx: TyCtxt<'tcx>, - codegen_unit: Arc<CodegenUnit<'tcx>>, + codegen_unit: &'tcx CodegenUnit<'tcx>, llvm_module: &'ll crate::ModuleLlvm, ) -> Self { // An interesting part of Windows which MSVC forces our hand on (and @@ -402,8 +401,8 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> { self.check_overflow } - fn codegen_unit(&self) -> &Arc<CodegenUnit<'tcx>> { - &self.codegen_unit + fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx> { + self.codegen_unit } fn used_statics(&self) -> &RefCell<Vec<&'ll Value>> { diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 39b70a5f2e7..cb39bf38209 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -1,5 +1,4 @@ use std::collections::hash_map::Entry::*; -use std::sync::Arc; use rustc_ast::expand::allocator::ALLOCATOR_METHODS; use rustc_data_structures::fingerprint::Fingerprint; @@ -164,11 +163,11 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b fn exported_symbols_provider_local( tcx: TyCtxt<'_>, cnum: CrateNum, -) -> Arc<Vec<(ExportedSymbol<'_>, SymbolExportLevel)>> { +) -> &'tcx [(ExportedSymbol<'_>, SymbolExportLevel)] { assert_eq!(cnum, LOCAL_CRATE); if !tcx.sess.opts.output_types.should_codegen() { - return Arc::new(vec![]); + return &[]; } let mut symbols: Vec<_> = tcx @@ -274,7 +273,7 @@ fn exported_symbols_provider_local( // Sort so we get a stable incr. comp. hash. symbols.sort_by_cached_key(|s| s.0.symbol_name_for_local_instance(tcx)); - Arc::new(symbols) + tcx.arena.alloc_from_iter(symbols) } fn upstream_monomorphizations_provider( diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index 02974151555..a7eb4f3ab01 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -533,7 +533,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>( // Run the monomorphization collector and partition the collected items into // codegen units. let codegen_units = tcx.collect_and_partition_mono_items(LOCAL_CRATE).1; - let codegen_units = (*codegen_units).clone(); // Force all codegen_unit queries so they are already either red or green // when compile_codegen_unit accesses them. We are not able to re-execute @@ -541,7 +540,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>( // lead to having to re-execute compile_codegen_unit, possibly // unnecessarily. if tcx.dep_graph.is_fully_enabled() { - for cgu in &codegen_units { + for cgu in codegen_units { tcx.codegen_unit(cgu.name()); } } @@ -603,7 +602,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>( // We sort the codegen units by size. This way we can schedule work for LLVM // a bit more efficiently. let codegen_units = { - let mut codegen_units = codegen_units; + let mut codegen_units = codegen_units.iter().collect::<Vec<_>>(); codegen_units.sort_by_cached_key(|cgu| cmp::Reverse(cgu.size_estimate())); codegen_units }; diff --git a/src/librustc_codegen_ssa/traits/misc.rs b/src/librustc_codegen_ssa/traits/misc.rs index beff9eae859..fc57a9a80b2 100644 --- a/src/librustc_codegen_ssa/traits/misc.rs +++ b/src/librustc_codegen_ssa/traits/misc.rs @@ -4,7 +4,6 @@ use rustc_middle::mir::mono::CodegenUnit; use rustc_middle::ty::{self, Instance, Ty}; use rustc_session::Session; use std::cell::RefCell; -use std::sync::Arc; pub trait MiscMethods<'tcx>: BackendTypes { fn vtables( @@ -15,7 +14,7 @@ pub trait MiscMethods<'tcx>: BackendTypes { fn get_fn_addr(&self, instance: Instance<'tcx>) -> Self::Value; fn eh_personality(&self) -> Self::Value; fn sess(&self) -> &Session; - fn codegen_unit(&self) -> &Arc<CodegenUnit<'tcx>>; + fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx>; fn used_statics(&self) -> &RefCell<Vec<Self::Value>>; fn set_frame_pointer_elimination(&self, llfn: Self::Function); fn apply_target_cpu_attr(&self, llfn: Self::Function); diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs index 0364493a48a..82b9b9693f3 100644 --- a/src/librustc_metadata/rmeta/decoder.rs +++ b/src/librustc_metadata/rmeta/decoder.rs @@ -1343,13 +1343,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { fn exported_symbols( &self, tcx: TyCtxt<'tcx>, - ) -> Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)> { + ) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] { if self.root.is_proc_macro_crate() { // If this crate is a custom derive crate, then we're not even going to // link those in so we skip those crates. - vec![] + &[] } else { - self.root.exported_symbols.decode((self, tcx)).collect() + tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx))) } } diff --git a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs index 5415c703039..1cbde23aceb 100644 --- a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs +++ b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs @@ -26,7 +26,6 @@ use rustc_span::symbol::Symbol; use rustc_data_structures::sync::Lrc; use smallvec::SmallVec; use std::any::Any; -use std::sync::Arc; macro_rules! provide { (<$lt:tt> $tcx:ident, $def_id:ident, $other:ident, $cdata:ident, @@ -239,7 +238,7 @@ provide! { <'tcx> tcx, def_id, other, cdata, // to block export of generics from dylibs, but we must fix // rust-lang/rust#65890 before we can do that robustly. - Arc::new(syms) + syms } } diff --git a/src/librustc_middle/arena.rs b/src/librustc_middle/arena.rs index 2d309230550..979621d9240 100644 --- a/src/librustc_middle/arena.rs +++ b/src/librustc_middle/arena.rs @@ -117,6 +117,7 @@ macro_rules! arena_types { [few] inferred_outlives_crate: rustc_middle::ty::CratePredicatesMap<'tcx>, [] upvars: rustc_data_structures::fx::FxIndexMap<rustc_hir::HirId, rustc_hir::Upvar>, [] object_safety_violations: rustc_middle::traits::ObjectSafetyViolation, + [] codegen_unit: rustc_middle::mir::mono::CodegenUnit<$tcx>, // Interned types [] tys: rustc_middle::ty::TyS<$tcx>, diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index dc3da9ec6ec..dc8834cf0ad 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -1075,19 +1075,19 @@ rustc_queries! { /// correspond to a publicly visible symbol in `cnum` machine code. /// - The `exported_symbols` sets of different crates do not intersect. query exported_symbols(_: CrateNum) - -> Arc<Vec<(ExportedSymbol<'tcx>, SymbolExportLevel)>> { + -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] { desc { "exported_symbols" } } } Codegen { query collect_and_partition_mono_items(_: CrateNum) - -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'tcx>>>>) { + -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) { eval_always desc { "collect_and_partition_mono_items" } } query is_codegened_item(_: DefId) -> bool {} - query codegen_unit(_: Symbol) -> Arc<CodegenUnit<'tcx>> { + query codegen_unit(_: Symbol) -> &'tcx CodegenUnit<'tcx> { desc { "codegen_unit" } } query backend_optimization_level(_: CrateNum) -> OptLevel { diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index 9068c0541a4..d842b8a5f38 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -94,7 +94,6 @@ use std::cmp; use std::collections::hash_map::Entry; -use std::sync::Arc; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync; @@ -883,7 +882,7 @@ where fn collect_and_partition_mono_items( tcx: TyCtxt<'_>, cnum: CrateNum, -) -> (Arc<DefIdSet>, Arc<Vec<Arc<CodegenUnit<'_>>>>) { +) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'_>]) { assert_eq!(cnum, LOCAL_CRATE); let collection_mode = match tcx.sess.opts.debugging_opts.print_mono_items { @@ -921,10 +920,12 @@ fn collect_and_partition_mono_items( let (codegen_units, _) = tcx.sess.time("partition_and_assert_distinct_symbols", || { sync::join( || { - partition(tcx, items.iter().cloned(), tcx.sess.codegen_units(), &inlining_map) - .into_iter() - .map(Arc::new) - .collect::<Vec<_>>() + &*tcx.arena.alloc_from_iter(partition( + tcx, + items.iter().cloned(), + tcx.sess.codegen_units(), + &inlining_map, + )) }, || assert_symbols_are_distinct(tcx, items.iter()), ) @@ -942,7 +943,7 @@ fn collect_and_partition_mono_items( if tcx.sess.opts.debugging_opts.print_mono_items.is_some() { let mut item_to_cgus: FxHashMap<_, Vec<_>> = Default::default(); - for cgu in &codegen_units { + for cgu in codegen_units { for (&mono_item, &linkage) in cgu.items() { item_to_cgus.entry(mono_item).or_default().push((cgu.name(), linkage)); } @@ -990,7 +991,7 @@ fn collect_and_partition_mono_items( } } - (Arc::new(mono_items), Arc::new(codegen_units)) + (tcx.arena.alloc(mono_items), codegen_units) } pub fn provide(providers: &mut Providers<'_>) { @@ -1005,7 +1006,6 @@ pub fn provide(providers: &mut Providers<'_>) { let (_, all) = tcx.collect_and_partition_mono_items(LOCAL_CRATE); all.iter() .find(|cgu| cgu.name() == name) - .cloned() .unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name)) }; } |
