diff options
| author | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2025-07-04 07:52:30 +0000 |
|---|---|---|
| committer | bjorn3 <17426603+bjorn3@users.noreply.github.com> | 2025-07-21 07:58:44 +0000 |
| commit | 2ad7930b40bd5cb0e103cb5c7145f4b335dd4520 (patch) | |
| tree | e7e16f000d4ffc4bb39c1beb6d9f16167bf1c165 /compiler/rustc_codegen_ssa/src/back/write.rs | |
| parent | 112799e63772988d874287979b5b4cc8b27668ab (diff) | |
| download | rust-2ad7930b40bd5cb0e103cb5c7145f4b335dd4520.tar.gz rust-2ad7930b40bd5cb0e103cb5c7145f4b335dd4520.zip | |
Remove worker id
It isn't used anywhere. Also inline free_worker into the only call site.
Diffstat (limited to 'compiler/rustc_codegen_ssa/src/back/write.rs')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/write.rs | 75 |
1 files changed, 19 insertions, 56 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 50e799a1687..8c3d1711519 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -1037,7 +1037,7 @@ pub(crate) enum Message<B: WriteBackendMethods> { /// The backend has finished processing a work item for a codegen unit. /// Sent from a backend worker thread. - WorkItem { result: Result<WorkItemResult<B>, Option<WorkerFatalError>>, worker_id: usize }, + WorkItem { result: Result<WorkItemResult<B>, Option<WorkerFatalError>> }, /// The frontend has finished generating something (backend IR or a /// post-LTO artifact) for a codegen unit, and it should be passed to the @@ -1355,18 +1355,6 @@ fn start_executing_work<B: ExtraBackendMethods>( // necessary. There's already optimizations in place to avoid sending work // back to the coordinator if LTO isn't requested. return B::spawn_named_thread(cgcx.time_trace, "coordinator".to_string(), move || { - let mut worker_id_counter = 0; - let mut free_worker_ids = Vec::new(); - let mut get_worker_id = |free_worker_ids: &mut Vec<usize>| { - if let Some(id) = free_worker_ids.pop() { - id - } else { - let id = worker_id_counter; - worker_id_counter += 1; - id - } - }; - // This is where we collect codegen units that have gone all the way // through codegen and LLVM. let mut compiled_modules = vec![]; @@ -1447,12 +1435,7 @@ fn start_executing_work<B: ExtraBackendMethods>( let (item, _) = work_items.pop().expect("queue empty - queue_full_enough() broken?"); main_thread_state = MainThreadState::Lending; - spawn_work( - &cgcx, - &mut llvm_start_time, - get_worker_id(&mut free_worker_ids), - item, - ); + spawn_work(&cgcx, &mut llvm_start_time, item); } } } else if codegen_state == Completed { @@ -1521,12 +1504,7 @@ fn start_executing_work<B: ExtraBackendMethods>( MainThreadState::Idle => { if let Some((item, _)) = work_items.pop() { main_thread_state = MainThreadState::Lending; - spawn_work( - &cgcx, - &mut llvm_start_time, - get_worker_id(&mut free_worker_ids), - item, - ); + spawn_work(&cgcx, &mut llvm_start_time, item); } else { // There is no unstarted work, so let the main thread // take over for a running worker. Otherwise the @@ -1562,12 +1540,7 @@ fn start_executing_work<B: ExtraBackendMethods>( while running_with_own_token < tokens.len() && let Some((item, _)) = work_items.pop() { - spawn_work( - &cgcx, - &mut llvm_start_time, - get_worker_id(&mut free_worker_ids), - item, - ); + spawn_work(&cgcx, &mut llvm_start_time, item); running_with_own_token += 1; } } @@ -1575,21 +1548,6 @@ fn start_executing_work<B: ExtraBackendMethods>( // Relinquish accidentally acquired extra tokens. tokens.truncate(running_with_own_token); - // If a thread exits successfully then we drop a token associated - // with that worker and update our `running_with_own_token` count. - // We may later re-acquire a token to continue running more work. - // We may also not actually drop a token here if the worker was - // running with an "ephemeral token". - let mut free_worker = |worker_id| { - if main_thread_state == MainThreadState::Lending { - main_thread_state = MainThreadState::Idle; - } else { - running_with_own_token -= 1; - } - - free_worker_ids.push(worker_id); - }; - let msg = coordinator_receive.recv().unwrap(); match *msg.downcast::<Message<B>>().ok().unwrap() { // Save the token locally and the next turn of the loop will use @@ -1658,8 +1616,17 @@ fn start_executing_work<B: ExtraBackendMethods>( codegen_state = Aborted; } - Message::WorkItem { result, worker_id } => { - free_worker(worker_id); + Message::WorkItem { result } => { + // If a thread exits successfully then we drop a token associated + // with that worker and update our `running_with_own_token` count. + // We may later re-acquire a token to continue running more work. + // We may also not actually drop a token here if the worker was + // running with an "ephemeral token". + if main_thread_state == MainThreadState::Lending { + main_thread_state = MainThreadState::Idle; + } else { + running_with_own_token -= 1; + } match result { Ok(WorkItemResult::Finished(compiled_module)) => { @@ -1805,7 +1772,6 @@ pub(crate) struct WorkerFatalError; fn spawn_work<'a, B: ExtraBackendMethods>( cgcx: &'a CodegenContext<B>, llvm_start_time: &mut Option<VerboseTimingGuard<'a>>, - worker_id: usize, work: WorkItem<B>, ) { if cgcx.config(work.module_kind()).time_module && llvm_start_time.is_none() { @@ -1820,24 +1786,21 @@ fn spawn_work<'a, B: ExtraBackendMethods>( struct Bomb<B: ExtraBackendMethods> { coordinator_send: Sender<Box<dyn Any + Send>>, 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(Ok(result)) => Message::WorkItem::<B> { result: Ok(result), worker_id }, + Some(Ok(result)) => Message::WorkItem::<B> { result: Ok(result) }, Some(Err(FatalError)) => { - Message::WorkItem::<B> { result: Err(Some(WorkerFatalError)), worker_id } + Message::WorkItem::<B> { result: Err(Some(WorkerFatalError)) } } - None => Message::WorkItem::<B> { result: Err(None), worker_id }, + None => Message::WorkItem::<B> { result: Err(None) }, }; drop(self.coordinator_send.send(Box::new(msg))); } } - let mut bomb = - Bomb::<B> { coordinator_send: cgcx.coordinator_send.clone(), result: None, worker_id }; + let mut bomb = Bomb::<B> { coordinator_send: cgcx.coordinator_send.clone(), result: None }; // Execute the work itself, and if it finishes successfully then flag // ourselves as a success as well. |
