When a codegen worker has a FatalError, propagate it instead of ICE'ing.
This commit is contained in:
parent
a916ac22b9
commit
0435c1b0a5
@ -903,7 +903,7 @@ pub enum Message<B: WriteBackendMethods> {
|
||||
worker_id: usize,
|
||||
},
|
||||
Done {
|
||||
result: Result<CompiledModule, ()>,
|
||||
result: Result<CompiledModule, Option<WorkerFatalError>>,
|
||||
worker_id: usize,
|
||||
},
|
||||
CodegenDone {
|
||||
@ -1476,9 +1476,12 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
||||
main_thread_worker_state = MainThreadWorkerState::Idle;
|
||||
}
|
||||
// If the thread failed that means it panicked, so we abort immediately.
|
||||
Message::Done { result: Err(()), worker_id: _ } => {
|
||||
Message::Done { result: Err(None), worker_id: _ } => {
|
||||
bug!("worker thread panicked");
|
||||
}
|
||||
Message::Done { result: Err(Some(WorkerFatalError)), worker_id: _ } => {
|
||||
return Err(());
|
||||
}
|
||||
Message::CodegenItem => bug!("the coordinator should not receive codegen requests"),
|
||||
}
|
||||
}
|
||||
@ -1527,6 +1530,10 @@ fn maybe_start_llvm_timer(config: &ModuleConfig, llvm_start_time: &mut Option<In
|
||||
|
||||
pub const CODEGEN_WORKER_ID: usize = ::std::usize::MAX;
|
||||
|
||||
/// `FatalError` is explicitly not `Send`.
|
||||
#[must_use]
|
||||
pub struct WorkerFatalError;
|
||||
|
||||
fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>) {
|
||||
let depth = time_depth();
|
||||
|
||||
@ -1537,23 +1544,26 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
|
||||
// we exit.
|
||||
struct Bomb<B: ExtraBackendMethods> {
|
||||
coordinator_send: Sender<Box<dyn Any + Send>>,
|
||||
result: Option<WorkItemResult<B>>,
|
||||
result: Option<Result<WorkItemResult<B>, FatalError>>,
|
||||
worker_id: usize,
|
||||
}
|
||||
impl<B: ExtraBackendMethods> Drop for Bomb<B> {
|
||||
fn drop(&mut self) {
|
||||
let worker_id = self.worker_id;
|
||||
let msg = match self.result.take() {
|
||||
Some(WorkItemResult::Compiled(m)) => {
|
||||
Some(Ok(WorkItemResult::Compiled(m))) => {
|
||||
Message::Done::<B> { result: Ok(m), worker_id }
|
||||
}
|
||||
Some(WorkItemResult::NeedsFatLTO(m)) => {
|
||||
Some(Ok(WorkItemResult::NeedsFatLTO(m))) => {
|
||||
Message::NeedsFatLTO::<B> { result: m, worker_id }
|
||||
}
|
||||
Some(WorkItemResult::NeedsThinLTO(name, thin_buffer)) => {
|
||||
Some(Ok(WorkItemResult::NeedsThinLTO(name, thin_buffer))) => {
|
||||
Message::NeedsThinLTO::<B> { name, thin_buffer, worker_id }
|
||||
}
|
||||
None => Message::Done::<B> { result: Err(()), worker_id },
|
||||
Some(Err(FatalError)) => {
|
||||
Message::Done::<B> { result: Err(Some(WorkerFatalError)), worker_id }
|
||||
}
|
||||
None => Message::Done::<B> { result: Err(None), worker_id },
|
||||
};
|
||||
drop(self.coordinator_send.send(Box::new(msg)));
|
||||
}
|
||||
@ -1573,7 +1583,7 @@ fn drop(&mut self) {
|
||||
// surface that there was an error in this worker.
|
||||
bomb.result = {
|
||||
let _prof_timer = cgcx.prof.generic_activity(work.profiling_event_id());
|
||||
execute_work_item(&cgcx, work).ok()
|
||||
Some(execute_work_item(&cgcx, work))
|
||||
};
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user