Skip to content

Commit

Permalink
Move Message::CodegenItem to a separate type.
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
nnethercote committed Jun 21, 2023
1 parent 006a26c commit 757c290
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,10 +951,13 @@ pub enum Message<B: WriteBackendMethods> {
work_product: WorkProduct,
},
CodegenComplete,
CodegenItem,
CodegenAborted,
}

/// A message sent from the coordinator thread to the main thread telling it to
/// process another codegen unit.
pub struct CguMessage;

type DiagnosticArgName<'source> = Cow<'source, str>;

struct Diagnostic {
Expand All @@ -976,7 +979,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
tcx: TyCtxt<'_>,
crate_info: &CrateInfo,
shared_emitter: SharedEmitter,
codegen_worker_send: Sender<Message<B>>,
codegen_worker_send: Sender<CguMessage>,
coordinator_receive: Receiver<Box<dyn Any + Send>>,
total_cgus: usize,
jobserver: Client,
Expand Down Expand Up @@ -1284,9 +1287,9 @@ fn start_executing_work<B: ExtraBackendMethods>(
let anticipated_running = running + additional_running + 1;

if !queue_full_enough(work_items.len(), anticipated_running) {
// The queue is not full enough, codegen more items:
if codegen_worker_send.send(Message::CodegenItem).is_err() {
panic!("Could not send Message::CodegenItem to main thread")
// The queue is not full enough, process more codegen units:
if codegen_worker_send.send(CguMessage).is_err() {
panic!("Could not send CguMessage to main thread")
}
main_thread_worker_state = MainThreadWorkerState::Codegenning;
} else {
Expand Down Expand Up @@ -1522,7 +1525,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
codegen_done = true;
codegen_aborted = true;
}
Message::CodegenItem => bug!("the coordinator should not receive codegen requests"),
}
}

Expand Down Expand Up @@ -1879,7 +1881,7 @@ pub struct OngoingCodegen<B: ExtraBackendMethods> {
pub metadata: EncodedMetadata,
pub metadata_module: Option<CompiledModule>,
pub crate_info: CrateInfo,
pub codegen_worker_receive: Receiver<Message<B>>,
pub codegen_worker_receive: Receiver<CguMessage>,
pub shared_emitter_main: SharedEmitterMain,
pub output_filenames: Arc<OutputFilenames>,
pub coordinator: Coordinator<B>,
Expand Down Expand Up @@ -1953,10 +1955,9 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {

pub fn wait_for_signal_to_codegen_item(&self) {
match self.codegen_worker_receive.recv() {
Ok(Message::CodegenItem) => {
// Nothing to do
Ok(CguMessage) => {
// Ok to proceed.
}
Ok(_) => panic!("unexpected message"),
Err(_) => {
// One of the LLVM threads must have panicked, fall through so
// error handling can be reached.
Expand Down

0 comments on commit 757c290

Please sign in to comment.