Skip to content

Commit 0b1521f

Browse files
committed
Auto merge of #64816 - Centril:rollup-gbeqot4, r=Centril
Rollup of 5 pull requests Successful merges: - #64221 ( Rust 2015: No longer downgrade NLL errors) - #64772 (Remove tx_to_llvm_workers from TyCtxt) - #64783 (Fix issue #64732) - #64787 (Fix ExitStatus on Fuchsia) - #64812 (Add test for E0543) Failed merges: r? @ghost
2 parents ddf4386 + 02a8505 commit 0b1521f

File tree

105 files changed

+367
-2003
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+367
-2003
lines changed

src/librustc/ty/context.rs

-11
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ use std::fmt;
6464
use std::mem;
6565
use std::ops::{Deref, Bound};
6666
use std::iter;
67-
use std::sync::mpsc;
6867
use std::sync::Arc;
6968
use rustc_target::spec::abi;
7069
use rustc_macros::HashStable;
@@ -1064,14 +1063,6 @@ pub struct GlobalCtxt<'tcx> {
10641063

10651064
layout_interner: ShardedHashMap<&'tcx LayoutDetails, ()>,
10661065

1067-
/// A general purpose channel to throw data out the back towards LLVM worker
1068-
/// threads.
1069-
///
1070-
/// This is intended to only get used during the codegen phase of the compiler
1071-
/// when satisfying the query for a particular codegen unit. Internally in
1072-
/// the query it'll send data along this channel to get processed later.
1073-
pub tx_to_llvm_workers: Lock<mpsc::Sender<Box<dyn Any + Send>>>,
1074-
10751066
output_filenames: Arc<OutputFilenames>,
10761067
}
10771068

@@ -1184,7 +1175,6 @@ impl<'tcx> TyCtxt<'tcx> {
11841175
hir: hir_map::Map<'tcx>,
11851176
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
11861177
crate_name: &str,
1187-
tx: mpsc::Sender<Box<dyn Any + Send>>,
11881178
output_filenames: &OutputFilenames,
11891179
) -> GlobalCtxt<'tcx> {
11901180
let data_layout = TargetDataLayout::parse(&s.target.target).unwrap_or_else(|err| {
@@ -1291,7 +1281,6 @@ impl<'tcx> TyCtxt<'tcx> {
12911281
stability_interner: Default::default(),
12921282
allocation_interner: Default::default(),
12931283
alloc_map: Lock::new(interpret::AllocMap::new()),
1294-
tx_to_llvm_workers: Lock::new(tx),
12951284
output_filenames: Arc::new(output_filenames.clone()),
12961285
}
12971286
}

src/librustc_codegen_llvm/base.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ pub fn iter_globals(llmod: &'ll llvm::Module) -> ValueIter<'ll> {
103103
}
104104
}
105105

106-
pub fn compile_codegen_unit(tcx: TyCtxt<'tcx>, cgu_name: InternedString) {
106+
pub fn compile_codegen_unit(
107+
tcx: TyCtxt<'tcx>,
108+
cgu_name: InternedString,
109+
tx_to_llvm_workers: &std::sync::mpsc::Sender<Box<dyn std::any::Any + Send>>,
110+
) {
107111
let start_time = Instant::now();
108112

109113
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
@@ -121,7 +125,7 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'tcx>, cgu_name: InternedString) {
121125
let cost = time_to_codegen.as_secs() * 1_000_000_000 +
122126
time_to_codegen.subsec_nanos() as u64;
123127

124-
submit_codegened_module_to_llvm(&LlvmCodegenBackend(()), tcx, module, cost);
128+
submit_codegened_module_to_llvm(&LlvmCodegenBackend(()), tx_to_llvm_workers, module, cost);
125129

126130
fn module_codegen(
127131
tcx: TyCtxt<'_>,

src/librustc_codegen_llvm/lib.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use syntax::ext::allocator::AllocatorKind;
5252
use syntax_pos::symbol::InternedString;
5353
pub use llvm_util::target_features;
5454
use std::any::Any;
55-
use std::sync::{mpsc, Arc};
55+
use std::sync::Arc;
5656
use std::ffi::CStr;
5757

5858
use rustc::dep_graph::DepGraph;
@@ -122,8 +122,12 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
122122
) {
123123
unsafe { allocator::codegen(tcx, mods, kind) }
124124
}
125-
fn compile_codegen_unit(&self, tcx: TyCtxt<'_>, cgu_name: InternedString) {
126-
base::compile_codegen_unit(tcx, cgu_name);
125+
fn compile_codegen_unit(
126+
&self, tcx: TyCtxt<'_>,
127+
cgu_name: InternedString,
128+
tx: &std::sync::mpsc::Sender<Box<dyn Any + Send>>,
129+
) {
130+
base::compile_codegen_unit(tcx, cgu_name, tx);
127131
}
128132
fn target_machine_factory(
129133
&self,
@@ -284,10 +288,9 @@ impl CodegenBackend for LlvmCodegenBackend {
284288
tcx: TyCtxt<'tcx>,
285289
metadata: EncodedMetadata,
286290
need_metadata_module: bool,
287-
rx: mpsc::Receiver<Box<dyn Any + Send>>,
288291
) -> Box<dyn Any> {
289292
box rustc_codegen_ssa::base::codegen_crate(
290-
LlvmCodegenBackend(()), tcx, metadata, need_metadata_module, rx)
293+
LlvmCodegenBackend(()), tcx, metadata, need_metadata_module)
291294
}
292295

293296
fn join_codegen_and_link(

src/librustc_codegen_ssa/back/write.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
376376
backend: B,
377377
tcx: TyCtxt<'_>,
378378
metadata: EncodedMetadata,
379-
coordinator_receive: Receiver<Box<dyn Any + Send>>,
380379
total_cgus: usize,
381380
) -> OngoingCodegen<B> {
381+
let (coordinator_send, coordinator_receive) = channel();
382382
let sess = tcx.sess;
383383
let crate_name = tcx.crate_name(LOCAL_CRATE);
384384
let crate_hash = tcx.crate_hash(LOCAL_CRATE);
@@ -500,7 +500,8 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
500500
sess.jobserver.clone(),
501501
Arc::new(modules_config),
502502
Arc::new(metadata_config),
503-
Arc::new(allocator_config));
503+
Arc::new(allocator_config),
504+
coordinator_send.clone());
504505

505506
OngoingCodegen {
506507
backend,
@@ -511,7 +512,7 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
511512
linker_info,
512513
crate_info,
513514

514-
coordinator_send: tcx.tx_to_llvm_workers.lock().clone(),
515+
coordinator_send,
515516
codegen_worker_receive,
516517
shared_emitter_main,
517518
future: coordinator_thread,
@@ -1005,8 +1006,9 @@ fn start_executing_work<B: ExtraBackendMethods>(
10051006
modules_config: Arc<ModuleConfig>,
10061007
metadata_config: Arc<ModuleConfig>,
10071008
allocator_config: Arc<ModuleConfig>,
1009+
tx_to_llvm_workers: Sender<Box<dyn Any + Send>>,
10081010
) -> thread::JoinHandle<Result<CompiledModules, ()>> {
1009-
let coordinator_send = tcx.tx_to_llvm_workers.lock().clone();
1011+
let coordinator_send = tx_to_llvm_workers;
10101012
let sess = tcx.sess;
10111013

10121014
// Compute the set of symbols we need to retain when doing LTO (if we need to)
@@ -1857,7 +1859,7 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
18571859

18581860
// These are generally cheap and won't throw off scheduling.
18591861
let cost = 0;
1860-
submit_codegened_module_to_llvm(&self.backend, tcx, module, cost);
1862+
submit_codegened_module_to_llvm(&self.backend, &self.coordinator_send, module, cost);
18611863
}
18621864

18631865
pub fn codegen_finished(&self, tcx: TyCtxt<'_>) {
@@ -1899,24 +1901,24 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
18991901

19001902
pub fn submit_codegened_module_to_llvm<B: ExtraBackendMethods>(
19011903
_backend: &B,
1902-
tcx: TyCtxt<'_>,
1904+
tx_to_llvm_workers: &Sender<Box<dyn Any + Send>>,
19031905
module: ModuleCodegen<B::Module>,
19041906
cost: u64,
19051907
) {
19061908
let llvm_work_item = WorkItem::Optimize(module);
1907-
drop(tcx.tx_to_llvm_workers.lock().send(Box::new(Message::CodegenDone::<B> {
1909+
drop(tx_to_llvm_workers.send(Box::new(Message::CodegenDone::<B> {
19081910
llvm_work_item,
19091911
cost,
19101912
})));
19111913
}
19121914

19131915
pub fn submit_post_lto_module_to_llvm<B: ExtraBackendMethods>(
19141916
_backend: &B,
1915-
tcx: TyCtxt<'_>,
1917+
tx_to_llvm_workers: &Sender<Box<dyn Any + Send>>,
19161918
module: CachedModuleCodegen,
19171919
) {
19181920
let llvm_work_item = WorkItem::CopyPostLtoArtifacts(module);
1919-
drop(tcx.tx_to_llvm_workers.lock().send(Box::new(Message::CodegenDone::<B> {
1921+
drop(tx_to_llvm_workers.send(Box::new(Message::CodegenDone::<B> {
19201922
llvm_work_item,
19211923
cost: 0,
19221924
})));
@@ -1925,6 +1927,7 @@ pub fn submit_post_lto_module_to_llvm<B: ExtraBackendMethods>(
19251927
pub fn submit_pre_lto_module_to_llvm<B: ExtraBackendMethods>(
19261928
_backend: &B,
19271929
tcx: TyCtxt<'_>,
1930+
tx_to_llvm_workers: &Sender<Box<dyn Any + Send>>,
19281931
module: CachedModuleCodegen,
19291932
) {
19301933
let filename = pre_lto_bitcode_filename(&module.name);
@@ -1939,7 +1942,7 @@ pub fn submit_pre_lto_module_to_llvm<B: ExtraBackendMethods>(
19391942
})
19401943
};
19411944
// Schedule the module to be loaded
1942-
drop(tcx.tx_to_llvm_workers.lock().send(Box::new(Message::AddImportOnlyModule::<B> {
1945+
drop(tx_to_llvm_workers.send(Box::new(Message::AddImportOnlyModule::<B> {
19431946
module_data: SerializedModule::FromUncompressedFile(mmap),
19441947
work_product: module.source,
19451948
})));

src/librustc_codegen_ssa/base.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ use crate::mir;
4343

4444
use crate::traits::*;
4545

46-
use std::any::Any;
4746
use std::cmp;
4847
use std::ops::{Deref, DerefMut};
4948
use std::time::{Instant, Duration};
50-
use std::sync::mpsc;
5149
use syntax_pos::Span;
5250
use syntax::attr;
5351
use rustc::hir;
@@ -482,19 +480,13 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
482480
tcx: TyCtxt<'tcx>,
483481
metadata: EncodedMetadata,
484482
need_metadata_module: bool,
485-
rx: mpsc::Receiver<Box<dyn Any + Send>>,
486483
) -> OngoingCodegen<B> {
487484
check_for_rustc_errors_attr(tcx);
488485

489486
// Skip crate items and just output metadata in -Z no-codegen mode.
490487
if tcx.sess.opts.debugging_opts.no_codegen ||
491488
!tcx.sess.opts.output_types.should_codegen() {
492-
let ongoing_codegen = start_async_codegen(
493-
backend,
494-
tcx,
495-
metadata,
496-
rx,
497-
1);
489+
let ongoing_codegen = start_async_codegen(backend, tcx, metadata, 1);
498490

499491
ongoing_codegen.codegen_finished(tcx);
500492

@@ -523,12 +515,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
523515
}
524516
}
525517

526-
let ongoing_codegen = start_async_codegen(
527-
backend.clone(),
528-
tcx,
529-
metadata,
530-
rx,
531-
codegen_units.len());
518+
let ongoing_codegen = start_async_codegen(backend.clone(), tcx, metadata, codegen_units.len());
532519
let ongoing_codegen = AbortCodegenOnDrop::<B>(Some(ongoing_codegen));
533520

534521
// Codegen an allocator shim, if necessary.
@@ -614,20 +601,22 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
614601
CguReuse::No => {
615602
tcx.sess.profiler(|p| p.start_activity(format!("codegen {}", cgu.name())));
616603
let start_time = Instant::now();
617-
backend.compile_codegen_unit(tcx, *cgu.name());
604+
backend.compile_codegen_unit(tcx, *cgu.name(), &ongoing_codegen.coordinator_send);
618605
total_codegen_time += start_time.elapsed();
619606
tcx.sess.profiler(|p| p.end_activity(format!("codegen {}", cgu.name())));
620607
false
621608
}
622609
CguReuse::PreLto => {
623-
submit_pre_lto_module_to_llvm(&backend, tcx, CachedModuleCodegen {
610+
submit_pre_lto_module_to_llvm(&backend, tcx, &ongoing_codegen.coordinator_send,
611+
CachedModuleCodegen {
624612
name: cgu.name().to_string(),
625613
source: cgu.work_product(tcx),
626614
});
627615
true
628616
}
629617
CguReuse::PostLto => {
630-
submit_post_lto_module_to_llvm(&backend, tcx, CachedModuleCodegen {
618+
submit_post_lto_module_to_llvm(&backend, &ongoing_codegen.coordinator_send,
619+
CachedModuleCodegen {
631620
name: cgu.name().to_string(),
632621
source: cgu.work_product(tcx),
633622
});

src/librustc_codegen_ssa/traits/backend.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc::session::{Session, config};
88
use rustc::ty::TyCtxt;
99
use rustc_codegen_utils::codegen_backend::CodegenBackend;
1010
use std::sync::Arc;
11+
use std::sync::mpsc;
1112
use syntax::ext::allocator::AllocatorKind;
1213
use syntax_pos::symbol::InternedString;
1314

@@ -44,7 +45,12 @@ pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Se
4445
mods: &mut Self::Module,
4546
kind: AllocatorKind,
4647
);
47-
fn compile_codegen_unit(&self, tcx: TyCtxt<'_>, cgu_name: InternedString);
48+
fn compile_codegen_unit(
49+
&self,
50+
tcx: TyCtxt<'_>,
51+
cgu_name: InternedString,
52+
tx_to_llvm_workers: &mpsc::Sender<Box<dyn std::any::Any + Send>>,
53+
);
4854
// If find_features is true this won't access `sess.crate_types` by assuming
4955
// that `is_pie_binary` is false. When we discover LLVM target features
5056
// `sess.crate_types` is uninitialized so we cannot access it.

src/librustc_codegen_utils/codegen_backend.rs

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
88

99
use std::any::Any;
10-
use std::sync::mpsc;
1110

1211
use syntax::symbol::Symbol;
1312
use rustc::session::Session;
@@ -36,7 +35,6 @@ pub trait CodegenBackend {
3635
tcx: TyCtxt<'tcx>,
3736
metadata: EncodedMetadata,
3837
need_metadata_module: bool,
39-
rx: mpsc::Receiver<Box<dyn Any + Send>>,
4038
) -> Box<dyn Any>;
4139

4240
/// This is called on the returned `Box<dyn Any>` from `codegen_backend`

src/librustc_interface/passes.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ use std::fs;
5454
use std::io::{self, Write};
5555
use std::iter;
5656
use std::path::PathBuf;
57-
use std::sync::mpsc;
5857
use std::cell::RefCell;
5958
use std::rc::Rc;
6059

@@ -816,7 +815,6 @@ pub fn create_global_ctxt(
816815
defs: hir::map::Definitions,
817816
resolutions: Resolutions,
818817
outputs: OutputFilenames,
819-
tx: mpsc::Sender<Box<dyn Any + Send>>,
820818
crate_name: &str,
821819
) -> BoxedGlobalCtxt {
822820
let sess = compiler.session().clone();
@@ -858,7 +856,6 @@ pub fn create_global_ctxt(
858856
hir_map,
859857
query_result_on_disk_cache,
860858
&crate_name,
861-
tx,
862859
&outputs
863860
);
864861

@@ -1068,7 +1065,6 @@ fn encode_and_write_metadata(
10681065
pub fn start_codegen<'tcx>(
10691066
codegen_backend: &dyn CodegenBackend,
10701067
tcx: TyCtxt<'tcx>,
1071-
rx: mpsc::Receiver<Box<dyn Any + Send>>,
10721068
outputs: &OutputFilenames,
10731069
) -> Box<dyn Any> {
10741070
if log_enabled!(::log::Level::Info) {
@@ -1082,7 +1078,7 @@ pub fn start_codegen<'tcx>(
10821078

10831079
tcx.sess.profiler(|p| p.start_activity("codegen crate"));
10841080
let codegen = time(tcx.sess, "codegen", move || {
1085-
codegen_backend.codegen_crate(tcx, metadata, need_metadata_module, rx)
1081+
codegen_backend.codegen_crate(tcx, metadata, need_metadata_module)
10861082
});
10871083
tcx.sess.profiler(|p| p.end_activity("codegen crate"));
10881084

0 commit comments

Comments
 (0)