Skip to content

Commit 757c290

Browse files
committed
Move Message::CodegenItem to a separate type.
`Message` is an enum with multiple variants, for messages sent to the coordinator thread. *Except* for `Message::CodegenItem`, which is entirely disjoint, being for messages sent from the coordinator thread to the main thread. This commit move `Message::CodegenItem` into a separate type, `CguMessage`, which makes the code much clearer.
1 parent 006a26c commit 757c290

File tree

1 file changed

+11
-10
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+11
-10
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -951,10 +951,13 @@ pub enum Message<B: WriteBackendMethods> {
951951
work_product: WorkProduct,
952952
},
953953
CodegenComplete,
954-
CodegenItem,
955954
CodegenAborted,
956955
}
957956

957+
/// A message sent from the coordinator thread to the main thread telling it to
958+
/// process another codegen unit.
959+
pub struct CguMessage;
960+
958961
type DiagnosticArgName<'source> = Cow<'source, str>;
959962

960963
struct Diagnostic {
@@ -976,7 +979,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
976979
tcx: TyCtxt<'_>,
977980
crate_info: &CrateInfo,
978981
shared_emitter: SharedEmitter,
979-
codegen_worker_send: Sender<Message<B>>,
982+
codegen_worker_send: Sender<CguMessage>,
980983
coordinator_receive: Receiver<Box<dyn Any + Send>>,
981984
total_cgus: usize,
982985
jobserver: Client,
@@ -1284,9 +1287,9 @@ fn start_executing_work<B: ExtraBackendMethods>(
12841287
let anticipated_running = running + additional_running + 1;
12851288

12861289
if !queue_full_enough(work_items.len(), anticipated_running) {
1287-
// The queue is not full enough, codegen more items:
1288-
if codegen_worker_send.send(Message::CodegenItem).is_err() {
1289-
panic!("Could not send Message::CodegenItem to main thread")
1290+
// The queue is not full enough, process more codegen units:
1291+
if codegen_worker_send.send(CguMessage).is_err() {
1292+
panic!("Could not send CguMessage to main thread")
12901293
}
12911294
main_thread_worker_state = MainThreadWorkerState::Codegenning;
12921295
} else {
@@ -1522,7 +1525,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
15221525
codegen_done = true;
15231526
codegen_aborted = true;
15241527
}
1525-
Message::CodegenItem => bug!("the coordinator should not receive codegen requests"),
15261528
}
15271529
}
15281530

@@ -1879,7 +1881,7 @@ pub struct OngoingCodegen<B: ExtraBackendMethods> {
18791881
pub metadata: EncodedMetadata,
18801882
pub metadata_module: Option<CompiledModule>,
18811883
pub crate_info: CrateInfo,
1882-
pub codegen_worker_receive: Receiver<Message<B>>,
1884+
pub codegen_worker_receive: Receiver<CguMessage>,
18831885
pub shared_emitter_main: SharedEmitterMain,
18841886
pub output_filenames: Arc<OutputFilenames>,
18851887
pub coordinator: Coordinator<B>,
@@ -1953,10 +1955,9 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
19531955

19541956
pub fn wait_for_signal_to_codegen_item(&self) {
19551957
match self.codegen_worker_receive.recv() {
1956-
Ok(Message::CodegenItem) => {
1957-
// Nothing to do
1958+
Ok(CguMessage) => {
1959+
// Ok to proceed.
19581960
}
1959-
Ok(_) => panic!("unexpected message"),
19601961
Err(_) => {
19611962
// One of the LLVM threads must have panicked, fall through so
19621963
// error handling can be reached.

0 commit comments

Comments
 (0)