Skip to content
/ rust Public
forked from rust-lang/rust

Commit a08220b

Browse files
committed
Tweak structure of the message loop.
The main loop has a *very* complex condition, which includes two mentions of `codegen_state`. The body of the loop then immediately switches on the `codegen_state`. I find it easier to understand if it's a `loop` and we check for exit conditions after switching on `codegen_state`. We end up with a tiny bit of code duplication, but it's clear that (a) we never exit in the `Ongoing` case, (b) we exit in the `Completed` state only if several things are true (and there's interaction with LTO there), and (c) we exit in the `Aborted` state if a couple of things are true. Also, the exit conditions are all simple conjunctions.
1 parent 179bf19 commit a08220b

File tree

1 file changed

+20
-17
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+20
-17
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

+20-17
Original file line numberDiff line numberDiff line change
@@ -1313,16 +1313,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
13131313
// wait for all existing work to finish, so many of the conditions here
13141314
// only apply if codegen hasn't been aborted as they represent pending
13151315
// work to be done.
1316-
while codegen_state == Ongoing
1317-
|| running_with_own_token > 0
1318-
|| main_thread_state == MainThreadState::Lending
1319-
|| (codegen_state == Completed
1320-
&& !(work_items.is_empty()
1321-
&& needs_fat_lto.is_empty()
1322-
&& needs_thin_lto.is_empty()
1323-
&& lto_import_only_modules.is_empty()
1324-
&& main_thread_state == MainThreadState::Idle))
1325-
{
1316+
loop {
13261317
// While there are still CGUs to be codegened, the coordinator has
13271318
// to decide how to utilize the compiler processes implicit Token:
13281319
// For codegenning more CGU or for running them through LLVM.
@@ -1361,15 +1352,24 @@ fn start_executing_work<B: ExtraBackendMethods>(
13611352
}
13621353
}
13631354
} else if codegen_state == Completed {
1364-
// If we've finished everything related to normal codegen
1365-
// then it must be the case that we've got some LTO work to do.
1366-
// Perform the serial work here of figuring out what we're
1367-
// going to LTO and then push a bunch of work items onto our
1368-
// queue to do LTO
1369-
if work_items.is_empty()
1370-
&& running_with_own_token == 0
1355+
if running_with_own_token == 0
13711356
&& main_thread_state == MainThreadState::Idle
1357+
&& work_items.is_empty()
13721358
{
1359+
// All codegen work is done. Do we have LTO work to do?
1360+
if needs_fat_lto.is_empty()
1361+
&& needs_thin_lto.is_empty()
1362+
&& lto_import_only_modules.is_empty()
1363+
{
1364+
// Nothing more to do!
1365+
break;
1366+
}
1367+
1368+
// We have LTO work to do. Perform the serial work here of
1369+
// figuring out what we're going to LTO and then push a
1370+
// bunch of work items onto our queue to do LTO. This all
1371+
// happens on the coordinator thread but it's very quick so
1372+
// we don't worry about tokens.
13731373
assert!(!started_lto);
13741374
started_lto = true;
13751375

@@ -1427,6 +1427,9 @@ fn start_executing_work<B: ExtraBackendMethods>(
14271427
// Don't queue up any more work if codegen was aborted, we're
14281428
// just waiting for our existing children to finish.
14291429
assert!(codegen_state == Aborted);
1430+
if running_with_own_token == 0 && main_thread_state != MainThreadState::Lending {
1431+
break;
1432+
}
14301433
}
14311434

14321435
// Spin up what work we can, only doing this while we've got available

0 commit comments

Comments
 (0)