From 3517fe899e200a2904cd0a931a7afa4b9f6fd35b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 21 Jul 2023 09:32:57 +1000 Subject: Remove `CodegenContext::worker`. `CodegenContext` is immutable except for the `worker` field - we clone `CodegenContext` in multiple places, changing the `worker` field each time. It's simpler to move the `worker` field out of `CodegenContext`. --- compiler/rustc_codegen_ssa/src/back/write.rs | 36 ++++++++++------------------ 1 file changed, 12 insertions(+), 24 deletions(-) (limited to 'compiler/rustc_codegen_ssa/src') diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 246be71f26c..ef10b5c21d5 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -349,8 +349,6 @@ pub struct CodegenContext { /// Directory into which should the LLVM optimization remarks be written. /// If `None`, they will be written to stderr. pub remark_dir: Option, - /// Worker thread number - pub worker: usize, /// The incremental compilation session directory, or None if we are not /// compiling incrementally pub incr_comp_session_dir: Option, @@ -1104,7 +1102,6 @@ fn start_executing_work( exported_symbols, remark: sess.opts.cg.remark.clone(), remark_dir, - worker: 0, incr_comp_session_dir: sess.incr_comp_session_dir_opt().map(|r| r.clone()), cgu_reuse_tracker: sess.cgu_reuse_tracker.clone(), coordinator_send, @@ -1355,17 +1352,13 @@ fn start_executing_work( // LLVM work too. let (item, _) = work_items.pop().expect("queue empty - queue_full_enough() broken?"); - let cgcx = CodegenContext { - worker: get_worker_id(&mut free_worker_ids), - ..cgcx.clone() - }; maybe_start_llvm_timer( prof, cgcx.config(item.module_kind()), &mut llvm_start_time, ); main_thread_state = MainThreadState::Lending; - spawn_work(cgcx, item); + spawn_work(&cgcx, get_worker_id(&mut free_worker_ids), item); } } } else if codegen_state == Completed { @@ -1404,17 +1397,13 @@ fn start_executing_work( match main_thread_state { MainThreadState::Idle => { if let Some((item, _)) = work_items.pop() { - let cgcx = CodegenContext { - worker: get_worker_id(&mut free_worker_ids), - ..cgcx.clone() - }; maybe_start_llvm_timer( prof, cgcx.config(item.module_kind()), &mut llvm_start_time, ); main_thread_state = MainThreadState::Lending; - spawn_work(cgcx, item); + spawn_work(&cgcx, get_worker_id(&mut free_worker_ids), item); } else { // There is no unstarted work, so let the main thread // take over for a running worker. Otherwise the @@ -1450,11 +1439,7 @@ fn start_executing_work( let (item, _) = work_items.pop().unwrap(); maybe_start_llvm_timer(prof, cgcx.config(item.module_kind()), &mut llvm_start_time); - - let cgcx = - CodegenContext { worker: get_worker_id(&mut free_worker_ids), ..cgcx.clone() }; - - spawn_work(cgcx, item); + spawn_work(&cgcx, get_worker_id(&mut free_worker_ids), item); running_with_own_token += 1; } @@ -1700,7 +1685,13 @@ fn start_executing_work( #[must_use] pub struct WorkerFatalError; -fn spawn_work(cgcx: CodegenContext, work: WorkItem) { +fn spawn_work( + cgcx: &CodegenContext, + worker_id: usize, + work: WorkItem, +) { + let cgcx = cgcx.clone(); + B::spawn_named_thread(cgcx.time_trace, work.short_description(), move || { // Set up a destructor which will fire off a message that we're done as // we exit. @@ -1723,11 +1714,8 @@ fn spawn_work(cgcx: CodegenContext, work: WorkItem } } - let mut bomb = Bomb:: { - coordinator_send: cgcx.coordinator_send.clone(), - result: None, - worker_id: cgcx.worker, - }; + let mut bomb = + Bomb:: { coordinator_send: cgcx.coordinator_send.clone(), result: None, worker_id }; // Execute the work itself, and if it finishes successfully then flag // ourselves as a success as well. -- cgit 1.4.1-3-g733a5