Skip to content
Permalink
Browse files

When a codegen worker has a FatalError, propagate it instead of ICE'ing.

  • Loading branch information
pnkfelix committed Dec 21, 2019
1 parent a916ac2 commit 0435c1b0a5fbc0cbaef8cb9f1711d3e30c944781
Showing with 18 additions and 8 deletions.
  1. +18 −8 src/librustc_codegen_ssa/back/write.rs
@@ -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 start_executing_work<B: ExtraBackendMethods>(

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 spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
// 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))
};
});
}

0 comments on commit 0435c1b

Please sign in to comment.
You can’t perform that action at this time.