Skip to content

Commit e418d08

Browse files
committed
Remove worker id
It isn't used anywhere. Also inline free_worker into the only call site.
1 parent fdd2627 commit e418d08

File tree

1 file changed

+19
-56
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+19
-56
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ pub(crate) enum Message<B: WriteBackendMethods> {
10371037

10381038
/// The backend has finished processing a work item for a codegen unit.
10391039
/// Sent from a backend worker thread.
1040-
WorkItem { result: Result<WorkItemResult<B>, Option<WorkerFatalError>>, worker_id: usize },
1040+
WorkItem { result: Result<WorkItemResult<B>, Option<WorkerFatalError>> },
10411041

10421042
/// The frontend has finished generating something (backend IR or a
10431043
/// post-LTO artifact) for a codegen unit, and it should be passed to the
@@ -1355,18 +1355,6 @@ fn start_executing_work<B: ExtraBackendMethods>(
13551355
// necessary. There's already optimizations in place to avoid sending work
13561356
// back to the coordinator if LTO isn't requested.
13571357
return B::spawn_named_thread(cgcx.time_trace, "coordinator".to_string(), move || {
1358-
let mut worker_id_counter = 0;
1359-
let mut free_worker_ids = Vec::new();
1360-
let mut get_worker_id = |free_worker_ids: &mut Vec<usize>| {
1361-
if let Some(id) = free_worker_ids.pop() {
1362-
id
1363-
} else {
1364-
let id = worker_id_counter;
1365-
worker_id_counter += 1;
1366-
id
1367-
}
1368-
};
1369-
13701358
// This is where we collect codegen units that have gone all the way
13711359
// through codegen and LLVM.
13721360
let mut compiled_modules = vec![];
@@ -1447,12 +1435,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
14471435
let (item, _) =
14481436
work_items.pop().expect("queue empty - queue_full_enough() broken?");
14491437
main_thread_state = MainThreadState::Lending;
1450-
spawn_work(
1451-
&cgcx,
1452-
&mut llvm_start_time,
1453-
get_worker_id(&mut free_worker_ids),
1454-
item,
1455-
);
1438+
spawn_work(&cgcx, &mut llvm_start_time, item);
14561439
}
14571440
}
14581441
} else if codegen_state == Completed {
@@ -1521,12 +1504,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
15211504
MainThreadState::Idle => {
15221505
if let Some((item, _)) = work_items.pop() {
15231506
main_thread_state = MainThreadState::Lending;
1524-
spawn_work(
1525-
&cgcx,
1526-
&mut llvm_start_time,
1527-
get_worker_id(&mut free_worker_ids),
1528-
item,
1529-
);
1507+
spawn_work(&cgcx, &mut llvm_start_time, item);
15301508
} else {
15311509
// There is no unstarted work, so let the main thread
15321510
// take over for a running worker. Otherwise the
@@ -1562,34 +1540,14 @@ fn start_executing_work<B: ExtraBackendMethods>(
15621540
while running_with_own_token < tokens.len()
15631541
&& let Some((item, _)) = work_items.pop()
15641542
{
1565-
spawn_work(
1566-
&cgcx,
1567-
&mut llvm_start_time,
1568-
get_worker_id(&mut free_worker_ids),
1569-
item,
1570-
);
1543+
spawn_work(&cgcx, &mut llvm_start_time, item);
15711544
running_with_own_token += 1;
15721545
}
15731546
}
15741547

15751548
// Relinquish accidentally acquired extra tokens.
15761549
tokens.truncate(running_with_own_token);
15771550

1578-
// If a thread exits successfully then we drop a token associated
1579-
// with that worker and update our `running_with_own_token` count.
1580-
// We may later re-acquire a token to continue running more work.
1581-
// We may also not actually drop a token here if the worker was
1582-
// running with an "ephemeral token".
1583-
let mut free_worker = |worker_id| {
1584-
if main_thread_state == MainThreadState::Lending {
1585-
main_thread_state = MainThreadState::Idle;
1586-
} else {
1587-
running_with_own_token -= 1;
1588-
}
1589-
1590-
free_worker_ids.push(worker_id);
1591-
};
1592-
15931551
let msg = coordinator_receive.recv().unwrap();
15941552
match *msg.downcast::<Message<B>>().ok().unwrap() {
15951553
// Save the token locally and the next turn of the loop will use
@@ -1658,8 +1616,17 @@ fn start_executing_work<B: ExtraBackendMethods>(
16581616
codegen_state = Aborted;
16591617
}
16601618

1661-
Message::WorkItem { result, worker_id } => {
1662-
free_worker(worker_id);
1619+
Message::WorkItem { result } => {
1620+
// If a thread exits successfully then we drop a token associated
1621+
// with that worker and update our `running_with_own_token` count.
1622+
// We may later re-acquire a token to continue running more work.
1623+
// We may also not actually drop a token here if the worker was
1624+
// running with an "ephemeral token".
1625+
if main_thread_state == MainThreadState::Lending {
1626+
main_thread_state = MainThreadState::Idle;
1627+
} else {
1628+
running_with_own_token -= 1;
1629+
}
16631630

16641631
match result {
16651632
Ok(WorkItemResult::Finished(compiled_module)) => {
@@ -1805,7 +1772,6 @@ pub(crate) struct WorkerFatalError;
18051772
fn spawn_work<'a, B: ExtraBackendMethods>(
18061773
cgcx: &'a CodegenContext<B>,
18071774
llvm_start_time: &mut Option<VerboseTimingGuard<'a>>,
1808-
worker_id: usize,
18091775
work: WorkItem<B>,
18101776
) {
18111777
if cgcx.config(work.module_kind()).time_module && llvm_start_time.is_none() {
@@ -1820,24 +1786,21 @@ fn spawn_work<'a, B: ExtraBackendMethods>(
18201786
struct Bomb<B: ExtraBackendMethods> {
18211787
coordinator_send: Sender<Box<dyn Any + Send>>,
18221788
result: Option<Result<WorkItemResult<B>, FatalError>>,
1823-
worker_id: usize,
18241789
}
18251790
impl<B: ExtraBackendMethods> Drop for Bomb<B> {
18261791
fn drop(&mut self) {
1827-
let worker_id = self.worker_id;
18281792
let msg = match self.result.take() {
1829-
Some(Ok(result)) => Message::WorkItem::<B> { result: Ok(result), worker_id },
1793+
Some(Ok(result)) => Message::WorkItem::<B> { result: Ok(result) },
18301794
Some(Err(FatalError)) => {
1831-
Message::WorkItem::<B> { result: Err(Some(WorkerFatalError)), worker_id }
1795+
Message::WorkItem::<B> { result: Err(Some(WorkerFatalError)) }
18321796
}
1833-
None => Message::WorkItem::<B> { result: Err(None), worker_id },
1797+
None => Message::WorkItem::<B> { result: Err(None) },
18341798
};
18351799
drop(self.coordinator_send.send(Box::new(msg)));
18361800
}
18371801
}
18381802

1839-
let mut bomb =
1840-
Bomb::<B> { coordinator_send: cgcx.coordinator_send.clone(), result: None, worker_id };
1803+
let mut bomb = Bomb::<B> { coordinator_send: cgcx.coordinator_send.clone(), result: None };
18411804

18421805
// Execute the work itself, and if it finishes successfully then flag
18431806
// ourselves as a success as well.

0 commit comments

Comments
 (0)