@@ -902,7 +902,7 @@ pub enum Message<B: WriteBackendMethods> {
902902 worker_id : usize ,
903903 } ,
904904 Done {
905- result : Result < CompiledModule , ( ) > ,
905+ result : Result < CompiledModule , Option < WorkerFatalError > > ,
906906 worker_id : usize ,
907907 } ,
908908 CodegenDone {
@@ -1474,9 +1474,12 @@ fn start_executing_work<B: ExtraBackendMethods>(
14741474 main_thread_worker_state = MainThreadWorkerState :: Idle ;
14751475 }
14761476 // If the thread failed that means it panicked, so we abort immediately.
1477- Message :: Done { result : Err ( ( ) ) , worker_id : _ } => {
1477+ Message :: Done { result : Err ( None ) , worker_id : _ } => {
14781478 bug ! ( "worker thread panicked" ) ;
14791479 }
1480+ Message :: Done { result : Err ( Some ( WorkerFatalError ) ) , worker_id : _ } => {
1481+ return Err ( ( ) ) ;
1482+ }
14801483 Message :: CodegenItem => bug ! ( "the coordinator should not receive codegen requests" ) ,
14811484 }
14821485 }
@@ -1520,29 +1523,36 @@ fn start_executing_work<B: ExtraBackendMethods>(
15201523
15211524pub const CODEGEN_WORKER_ID : usize = :: std:: usize:: MAX ;
15221525
1526+ /// `FatalError` is explicitly not `Send`.
1527+ #[ must_use]
1528+ pub struct WorkerFatalError ;
1529+
15231530fn spawn_work < B : ExtraBackendMethods > ( cgcx : CodegenContext < B > , work : WorkItem < B > ) {
15241531 thread:: spawn ( move || {
15251532 // Set up a destructor which will fire off a message that we're done as
15261533 // we exit.
15271534 struct Bomb < B : ExtraBackendMethods > {
15281535 coordinator_send : Sender < Box < dyn Any + Send > > ,
1529- result : Option < WorkItemResult < B > > ,
1536+ result : Option < Result < WorkItemResult < B > , FatalError > > ,
15301537 worker_id : usize ,
15311538 }
15321539 impl < B : ExtraBackendMethods > Drop for Bomb < B > {
15331540 fn drop ( & mut self ) {
15341541 let worker_id = self . worker_id ;
15351542 let msg = match self . result . take ( ) {
1536- Some ( WorkItemResult :: Compiled ( m) ) => {
1543+ Some ( Ok ( WorkItemResult :: Compiled ( m) ) ) => {
15371544 Message :: Done :: < B > { result : Ok ( m) , worker_id }
15381545 }
1539- Some ( WorkItemResult :: NeedsFatLTO ( m) ) => {
1546+ Some ( Ok ( WorkItemResult :: NeedsFatLTO ( m) ) ) => {
15401547 Message :: NeedsFatLTO :: < B > { result : m, worker_id }
15411548 }
1542- Some ( WorkItemResult :: NeedsThinLTO ( name, thin_buffer) ) => {
1549+ Some ( Ok ( WorkItemResult :: NeedsThinLTO ( name, thin_buffer) ) ) => {
15431550 Message :: NeedsThinLTO :: < B > { name, thin_buffer, worker_id }
15441551 }
1545- None => Message :: Done :: < B > { result : Err ( ( ) ) , worker_id } ,
1552+ Some ( Err ( FatalError ) ) => {
1553+ Message :: Done :: < B > { result : Err ( Some ( WorkerFatalError ) ) , worker_id }
1554+ }
1555+ None => Message :: Done :: < B > { result : Err ( None ) , worker_id } ,
15461556 } ;
15471557 drop ( self . coordinator_send . send ( Box :: new ( msg) ) ) ;
15481558 }
@@ -1562,7 +1572,7 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
15621572 // surface that there was an error in this worker.
15631573 bomb. result = {
15641574 let _prof_timer = cgcx. prof . generic_activity ( work. profiling_event_id ( ) ) ;
1565- execute_work_item ( & cgcx, work) . ok ( )
1575+ Some ( execute_work_item ( & cgcx, work) )
15661576 } ;
15671577 } ) ;
15681578}
0 commit comments