Simplify Message
.
`Message` is an enum with multiple variants. Four of those variants map directly onto the four variants of `WorkItemResult`. This commit reduces those four `Message` variants to a single variant containing a `WorkItemResult`. This requires increasing `WorkItemResult`'s visibility to `pub(crate)` visibility, but `WorkItem` and `Message` can also have their visibility reduced to `pub(crate)`. This change avoids some boilerplate enum translation code, and makes `Message` easier to understand.
This commit is contained in:
parent
757c290fba
commit
88cd8f9324
1 changed files with 44 additions and 64 deletions
|
@ -685,7 +685,7 @@ fn produce_final_output_artifacts(
|
||||||
// These are used in linking steps and will be cleaned up afterward.
|
// These are used in linking steps and will be cleaned up afterward.
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum WorkItem<B: WriteBackendMethods> {
|
pub(crate) enum WorkItem<B: WriteBackendMethods> {
|
||||||
/// Optimize a newly codegened, totally unoptimized module.
|
/// Optimize a newly codegened, totally unoptimized module.
|
||||||
Optimize(ModuleCodegen<B::Module>),
|
Optimize(ModuleCodegen<B::Module>),
|
||||||
/// Copy the post-LTO artifacts from the incremental cache to the output
|
/// Copy the post-LTO artifacts from the incremental cache to the output
|
||||||
|
@ -731,7 +731,7 @@ impl<B: WriteBackendMethods> WorkItem<B> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum WorkItemResult<B: WriteBackendMethods> {
|
pub(crate) enum WorkItemResult<B: WriteBackendMethods> {
|
||||||
Compiled(CompiledModule),
|
Compiled(CompiledModule),
|
||||||
NeedsLink(ModuleCodegen<B::Module>),
|
NeedsLink(ModuleCodegen<B::Module>),
|
||||||
NeedsFatLTO(FatLTOInput<B>),
|
NeedsFatLTO(FatLTOInput<B>),
|
||||||
|
@ -923,23 +923,10 @@ fn finish_intra_module_work<B: ExtraBackendMethods>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Message<B: WriteBackendMethods> {
|
pub(crate) enum Message<B: WriteBackendMethods> {
|
||||||
Token(io::Result<Acquired>),
|
Token(io::Result<Acquired>),
|
||||||
NeedsFatLTO {
|
WorkItem {
|
||||||
result: FatLTOInput<B>,
|
result: Result<WorkItemResult<B>, Option<WorkerFatalError>>,
|
||||||
worker_id: usize,
|
|
||||||
},
|
|
||||||
NeedsThinLTO {
|
|
||||||
name: String,
|
|
||||||
thin_buffer: B::ThinBuffer,
|
|
||||||
worker_id: usize,
|
|
||||||
},
|
|
||||||
NeedsLink {
|
|
||||||
module: ModuleCodegen<B::Module>,
|
|
||||||
worker_id: usize,
|
|
||||||
},
|
|
||||||
Done {
|
|
||||||
result: Result<CompiledModule, Option<WorkerFatalError>>,
|
|
||||||
worker_id: usize,
|
worker_id: usize,
|
||||||
},
|
},
|
||||||
CodegenDone {
|
CodegenDone {
|
||||||
|
@ -1481,8 +1468,12 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
||||||
codegen_done = true;
|
codegen_done = true;
|
||||||
codegen_aborted = true;
|
codegen_aborted = true;
|
||||||
}
|
}
|
||||||
Message::Done { result: Ok(compiled_module), worker_id } => {
|
|
||||||
|
Message::WorkItem { result, worker_id } => {
|
||||||
free_worker(worker_id);
|
free_worker(worker_id);
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(WorkItemResult::Compiled(compiled_module)) => {
|
||||||
match compiled_module.kind {
|
match compiled_module.kind {
|
||||||
ModuleKind::Regular => {
|
ModuleKind::Regular => {
|
||||||
compiled_modules.push(compiled_module);
|
compiled_modules.push(compiled_module);
|
||||||
|
@ -1494,20 +1485,30 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
||||||
ModuleKind::Metadata => bug!("Should be handled separately"),
|
ModuleKind::Metadata => bug!("Should be handled separately"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::NeedsLink { module, worker_id } => {
|
Ok(WorkItemResult::NeedsLink(module)) => {
|
||||||
free_worker(worker_id);
|
|
||||||
needs_link.push(module);
|
needs_link.push(module);
|
||||||
}
|
}
|
||||||
Message::NeedsFatLTO { result, worker_id } => {
|
Ok(WorkItemResult::NeedsFatLTO(fat_lto_input)) => {
|
||||||
assert!(!started_lto);
|
assert!(!started_lto);
|
||||||
free_worker(worker_id);
|
needs_fat_lto.push(fat_lto_input);
|
||||||
needs_fat_lto.push(result);
|
|
||||||
}
|
}
|
||||||
Message::NeedsThinLTO { name, thin_buffer, worker_id } => {
|
Ok(WorkItemResult::NeedsThinLTO(name, thin_buffer)) => {
|
||||||
assert!(!started_lto);
|
assert!(!started_lto);
|
||||||
free_worker(worker_id);
|
|
||||||
needs_thin_lto.push((name, thin_buffer));
|
needs_thin_lto.push((name, thin_buffer));
|
||||||
}
|
}
|
||||||
|
Err(Some(WorkerFatalError)) => {
|
||||||
|
// Like `CodegenAborted`, wait for remaining work to finish.
|
||||||
|
codegen_done = true;
|
||||||
|
codegen_aborted = true;
|
||||||
|
}
|
||||||
|
Err(None) => {
|
||||||
|
// If the thread failed that means it panicked, so
|
||||||
|
// we abort immediately.
|
||||||
|
bug!("worker thread panicked");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Message::AddImportOnlyModule { module_data, work_product } => {
|
Message::AddImportOnlyModule { module_data, work_product } => {
|
||||||
assert!(!started_lto);
|
assert!(!started_lto);
|
||||||
assert!(!codegen_done);
|
assert!(!codegen_done);
|
||||||
|
@ -1515,16 +1516,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
||||||
lto_import_only_modules.push((module_data, work_product));
|
lto_import_only_modules.push((module_data, work_product));
|
||||||
main_thread_worker_state = MainThreadWorkerState::Idle;
|
main_thread_worker_state = MainThreadWorkerState::Idle;
|
||||||
}
|
}
|
||||||
// If the thread failed that means it panicked, so we abort immediately.
|
|
||||||
Message::Done { result: Err(None), worker_id: _ } => {
|
|
||||||
bug!("worker thread panicked");
|
|
||||||
}
|
|
||||||
Message::Done { result: Err(Some(WorkerFatalError)), worker_id } => {
|
|
||||||
// Similar to CodegenAborted, wait for remaining work to finish.
|
|
||||||
free_worker(worker_id);
|
|
||||||
codegen_done = true;
|
|
||||||
codegen_aborted = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1643,22 +1634,11 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let worker_id = self.worker_id;
|
let worker_id = self.worker_id;
|
||||||
let msg = match self.result.take() {
|
let msg = match self.result.take() {
|
||||||
Some(Ok(WorkItemResult::Compiled(m))) => {
|
Some(Ok(result)) => Message::WorkItem::<B> { result: Ok(result), worker_id },
|
||||||
Message::Done::<B> { result: Ok(m), worker_id }
|
|
||||||
}
|
|
||||||
Some(Ok(WorkItemResult::NeedsLink(m))) => {
|
|
||||||
Message::NeedsLink::<B> { module: m, worker_id }
|
|
||||||
}
|
|
||||||
Some(Ok(WorkItemResult::NeedsFatLTO(m))) => {
|
|
||||||
Message::NeedsFatLTO::<B> { result: m, worker_id }
|
|
||||||
}
|
|
||||||
Some(Ok(WorkItemResult::NeedsThinLTO(name, thin_buffer))) => {
|
|
||||||
Message::NeedsThinLTO::<B> { name, thin_buffer, worker_id }
|
|
||||||
}
|
|
||||||
Some(Err(FatalError)) => {
|
Some(Err(FatalError)) => {
|
||||||
Message::Done::<B> { result: Err(Some(WorkerFatalError)), worker_id }
|
Message::WorkItem::<B> { result: Err(Some(WorkerFatalError)), worker_id }
|
||||||
}
|
}
|
||||||
None => Message::Done::<B> { result: Err(None), worker_id },
|
None => Message::WorkItem::<B> { result: Err(None), worker_id },
|
||||||
};
|
};
|
||||||
drop(self.coordinator_send.send(Box::new(msg)));
|
drop(self.coordinator_send.send(Box::new(msg)));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue