@@ -903,7 +903,7 @@ pub enum Message<B: WriteBackendMethods> {
903903 worker_id : usize ,
904904 } ,
905905 Done {
906- result : Result < CompiledModule , ( ) > ,
906+ result : Result < CompiledModule , Option < WorkerFatalError > > ,
907907 worker_id : usize ,
908908 } ,
909909 CodegenDone {
@@ -1476,9 +1476,12 @@ fn start_executing_work<B: ExtraBackendMethods>(
14761476 main_thread_worker_state = MainThreadWorkerState :: Idle ;
14771477 }
14781478 // If the thread failed that means it panicked, so we abort immediately.
1479- Message :: Done { result : Err ( ( ) ) , worker_id : _ } => {
1479+ Message :: Done { result : Err ( None ) , worker_id : _ } => {
14801480 bug ! ( "worker thread panicked" ) ;
14811481 }
1482+ Message :: Done { result : Err ( Some ( WorkerFatalError ) ) , worker_id : _ } => {
1483+ return Err ( ( ) ) ;
1484+ }
14821485 Message :: CodegenItem => bug ! ( "the coordinator should not receive codegen requests" ) ,
14831486 }
14841487 }
@@ -1527,6 +1530,10 @@ fn start_executing_work<B: ExtraBackendMethods>(
15271530
15281531pub const CODEGEN_WORKER_ID : usize = :: std:: usize:: MAX ;
15291532
1533+ /// `FatalError` is explicitly not `Send`.
1534+ #[ must_use]
1535+ pub struct WorkerFatalError ;
1536+
15301537fn spawn_work < B : ExtraBackendMethods > ( cgcx : CodegenContext < B > , work : WorkItem < B > ) {
15311538 let depth = time_depth ( ) ;
15321539
@@ -1537,23 +1544,26 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
15371544 // we exit.
15381545 struct Bomb < B : ExtraBackendMethods > {
15391546 coordinator_send : Sender < Box < dyn Any + Send > > ,
1540- result : Option < WorkItemResult < B > > ,
1547+ result : Option < Result < WorkItemResult < B > , FatalError > > ,
15411548 worker_id : usize ,
15421549 }
15431550 impl < B : ExtraBackendMethods > Drop for Bomb < B > {
15441551 fn drop ( & mut self ) {
15451552 let worker_id = self . worker_id ;
15461553 let msg = match self . result . take ( ) {
1547- Some ( WorkItemResult :: Compiled ( m) ) => {
1554+ Some ( Ok ( WorkItemResult :: Compiled ( m) ) ) => {
15481555 Message :: Done :: < B > { result : Ok ( m) , worker_id }
15491556 }
1550- Some ( WorkItemResult :: NeedsFatLTO ( m) ) => {
1557+ Some ( Ok ( WorkItemResult :: NeedsFatLTO ( m) ) ) => {
15511558 Message :: NeedsFatLTO :: < B > { result : m, worker_id }
15521559 }
1553- Some ( WorkItemResult :: NeedsThinLTO ( name, thin_buffer) ) => {
1560+ Some ( Ok ( WorkItemResult :: NeedsThinLTO ( name, thin_buffer) ) ) => {
15541561 Message :: NeedsThinLTO :: < B > { name, thin_buffer, worker_id }
15551562 }
1556- None => Message :: Done :: < B > { result : Err ( ( ) ) , worker_id } ,
1563+ Some ( Err ( FatalError ) ) => {
1564+ Message :: Done :: < B > { result : Err ( Some ( WorkerFatalError ) ) , worker_id }
1565+ }
1566+ None => Message :: Done :: < B > { result : Err ( None ) , worker_id } ,
15571567 } ;
15581568 drop ( self . coordinator_send . send ( Box :: new ( msg) ) ) ;
15591569 }
@@ -1573,7 +1583,7 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
15731583 // surface that there was an error in this worker.
15741584 bomb. result = {
15751585 let _prof_timer = cgcx. prof . generic_activity ( work. profiling_event_id ( ) ) ;
1576- execute_work_item ( & cgcx, work) . ok ( )
1586+ Some ( execute_work_item ( & cgcx, work) )
15771587 } ;
15781588 } ) ;
15791589}
0 commit comments