@@ -685,7 +685,7 @@ fn produce_final_output_artifacts(
685
685
// These are used in linking steps and will be cleaned up afterward.
686
686
}
687
687
688
- pub enum WorkItem < B : WriteBackendMethods > {
688
+ pub ( crate ) enum WorkItem < B : WriteBackendMethods > {
689
689
/// Optimize a newly codegened, totally unoptimized module.
690
690
Optimize ( ModuleCodegen < B :: Module > ) ,
691
691
/// Copy the post-LTO artifacts from the incremental cache to the output
@@ -731,7 +731,7 @@ impl<B: WriteBackendMethods> WorkItem<B> {
731
731
}
732
732
}
733
733
734
- enum WorkItemResult < B : WriteBackendMethods > {
734
+ pub ( crate ) enum WorkItemResult < B : WriteBackendMethods > {
735
735
Compiled ( CompiledModule ) ,
736
736
NeedsLink ( ModuleCodegen < B :: Module > ) ,
737
737
NeedsFatLTO ( FatLTOInput < B > ) ,
@@ -923,23 +923,10 @@ fn finish_intra_module_work<B: ExtraBackendMethods>(
923
923
}
924
924
}
925
925
926
- pub enum Message < B : WriteBackendMethods > {
926
+ pub ( crate ) enum Message < B : WriteBackendMethods > {
927
927
Token ( io:: Result < Acquired > ) ,
928
- NeedsFatLTO {
929
- result : FatLTOInput < B > ,
930
- worker_id : usize ,
931
- } ,
932
- NeedsThinLTO {
933
- name : String ,
934
- thin_buffer : B :: ThinBuffer ,
935
- worker_id : usize ,
936
- } ,
937
- NeedsLink {
938
- module : ModuleCodegen < B :: Module > ,
939
- worker_id : usize ,
940
- } ,
941
- Done {
942
- result : Result < CompiledModule , Option < WorkerFatalError > > ,
928
+ WorkItem {
929
+ result : Result < WorkItemResult < B > , Option < WorkerFatalError > > ,
943
930
worker_id : usize ,
944
931
} ,
945
932
CodegenDone {
@@ -1481,50 +1468,54 @@ fn start_executing_work<B: ExtraBackendMethods>(
1481
1468
codegen_done = true ;
1482
1469
codegen_aborted = true ;
1483
1470
}
1484
- Message :: Done { result : Ok ( compiled_module) , worker_id } => {
1471
+
1472
+ Message :: WorkItem { result, worker_id } => {
1485
1473
free_worker ( worker_id) ;
1486
- match compiled_module. kind {
1487
- ModuleKind :: Regular => {
1488
- compiled_modules. push ( compiled_module) ;
1474
+
1475
+ match result {
1476
+ Ok ( WorkItemResult :: Compiled ( compiled_module) ) => {
1477
+ match compiled_module. kind {
1478
+ ModuleKind :: Regular => {
1479
+ compiled_modules. push ( compiled_module) ;
1480
+ }
1481
+ ModuleKind :: Allocator => {
1482
+ assert ! ( compiled_allocator_module. is_none( ) ) ;
1483
+ compiled_allocator_module = Some ( compiled_module) ;
1484
+ }
1485
+ ModuleKind :: Metadata => bug ! ( "Should be handled separately" ) ,
1486
+ }
1487
+ }
1488
+ Ok ( WorkItemResult :: NeedsLink ( module) ) => {
1489
+ needs_link. push ( module) ;
1490
+ }
1491
+ Ok ( WorkItemResult :: NeedsFatLTO ( fat_lto_input) ) => {
1492
+ assert ! ( !started_lto) ;
1493
+ needs_fat_lto. push ( fat_lto_input) ;
1494
+ }
1495
+ Ok ( WorkItemResult :: NeedsThinLTO ( name, thin_buffer) ) => {
1496
+ assert ! ( !started_lto) ;
1497
+ needs_thin_lto. push ( ( name, thin_buffer) ) ;
1489
1498
}
1490
- ModuleKind :: Allocator => {
1491
- assert ! ( compiled_allocator_module. is_none( ) ) ;
1492
- compiled_allocator_module = Some ( compiled_module) ;
1499
+ Err ( Some ( WorkerFatalError ) ) => {
1500
+ // Like `CodegenAborted`, wait for remaining work to finish.
1501
+ codegen_done = true ;
1502
+ codegen_aborted = true ;
1503
+ }
1504
+ Err ( None ) => {
1505
+ // If the thread failed that means it panicked, so
1506
+ // we abort immediately.
1507
+ bug ! ( "worker thread panicked" ) ;
1493
1508
}
1494
- ModuleKind :: Metadata => bug ! ( "Should be handled separately" ) ,
1495
1509
}
1496
1510
}
1497
- Message :: NeedsLink { module, worker_id } => {
1498
- free_worker ( worker_id) ;
1499
- needs_link. push ( module) ;
1500
- }
1501
- Message :: NeedsFatLTO { result, worker_id } => {
1502
- assert ! ( !started_lto) ;
1503
- free_worker ( worker_id) ;
1504
- needs_fat_lto. push ( result) ;
1505
- }
1506
- Message :: NeedsThinLTO { name, thin_buffer, worker_id } => {
1507
- assert ! ( !started_lto) ;
1508
- free_worker ( worker_id) ;
1509
- needs_thin_lto. push ( ( name, thin_buffer) ) ;
1510
- }
1511
+
1511
1512
Message :: AddImportOnlyModule { module_data, work_product } => {
1512
1513
assert ! ( !started_lto) ;
1513
1514
assert ! ( !codegen_done) ;
1514
1515
assert_eq ! ( main_thread_worker_state, MainThreadWorkerState :: Codegenning ) ;
1515
1516
lto_import_only_modules. push ( ( module_data, work_product) ) ;
1516
1517
main_thread_worker_state = MainThreadWorkerState :: Idle ;
1517
1518
}
1518
- // If the thread failed that means it panicked, so we abort immediately.
1519
- Message :: Done { result : Err ( None ) , worker_id : _ } => {
1520
- bug ! ( "worker thread panicked" ) ;
1521
- }
1522
- Message :: Done { result : Err ( Some ( WorkerFatalError ) ) , worker_id } => {
1523
- // Similar to CodegenAborted, wait for remaining work to finish.
1524
- free_worker ( worker_id) ;
1525
- codegen_done = true ;
1526
- codegen_aborted = true ;
1527
- }
1528
1519
}
1529
1520
}
1530
1521
@@ -1643,22 +1634,11 @@ fn spawn_work<B: ExtraBackendMethods>(cgcx: CodegenContext<B>, work: WorkItem<B>
1643
1634
fn drop ( & mut self ) {
1644
1635
let worker_id = self . worker_id ;
1645
1636
let msg = match self . result . take ( ) {
1646
- Some ( Ok ( WorkItemResult :: Compiled ( m) ) ) => {
1647
- Message :: Done :: < B > { result : Ok ( m) , worker_id }
1648
- }
1649
- Some ( Ok ( WorkItemResult :: NeedsLink ( m) ) ) => {
1650
- Message :: NeedsLink :: < B > { module : m, worker_id }
1651
- }
1652
- Some ( Ok ( WorkItemResult :: NeedsFatLTO ( m) ) ) => {
1653
- Message :: NeedsFatLTO :: < B > { result : m, worker_id }
1654
- }
1655
- Some ( Ok ( WorkItemResult :: NeedsThinLTO ( name, thin_buffer) ) ) => {
1656
- Message :: NeedsThinLTO :: < B > { name, thin_buffer, worker_id }
1657
- }
1637
+ Some ( Ok ( result) ) => Message :: WorkItem :: < B > { result : Ok ( result) , worker_id } ,
1658
1638
Some ( Err ( FatalError ) ) => {
1659
- Message :: Done :: < B > { result : Err ( Some ( WorkerFatalError ) ) , worker_id }
1639
+ Message :: WorkItem :: < B > { result : Err ( Some ( WorkerFatalError ) ) , worker_id }
1660
1640
}
1661
- None => Message :: Done :: < B > { result : Err ( None ) , worker_id } ,
1641
+ None => Message :: WorkItem :: < B > { result : Err ( None ) , worker_id } ,
1662
1642
} ;
1663
1643
drop ( self . coordinator_send . send ( Box :: new ( msg) ) ) ;
1664
1644
}
0 commit comments