Skip to content

Split LTO out into a new CodegenBackend method with separate incr comp cache - #166608

Open
bjorn3 wants to merge 9 commits into
rust-lang:mainfrom
bjorn3:lto_refactors24
Open

bjorn3 wants to merge 9 commits into
rust-lang:mainfrom
bjorn3:lto_refactors24

Conversation

@bjorn3

@bjorn3 bjorn3 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

View all comments

To allow moving it into the -Zlink-only step in the next PR.

Part of rust-lang/compiler-team#908

@rustbot

rustbot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 26, 2026
@bjorn3

bjorn3 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

The last commit is a squashed version of ab696d1...6352cfe in case you are curious how exactly I got there.

@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

@rust-log-analyzer

This comment has been minimized.

@petrochenkov

petrochenkov commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Some questions, in case I won't finish reviewing today:

  • Is there two IncrCompSessions or just one IncrCompSession with two directories for main and lto?
  • Does this PR do some new incremental caching/tracking that may affect performance? (Some of the related FIXMEs were removed.)
  • Some files previously lived in in_incr_comp_dir_sess, but are now moved to temp_path_ext_for_cgu, they are moved because they are not actually incremental files and are just temporaries, right?

@bjorn3

bjorn3 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Does this PR do some new incremental caching/tracking that may affect performance? (Some of the related FIXMEs were removed.)

It will create a new incr comp session for both fat and thin lto, but it is currently only used for thin lto. This new incr comp session stores a work product index and the actual work products. The only extra work is creating that new incr comp session dir and writing an extra work product index file. The actual work products are just moved to a different location.

Some files previously lived in in_incr_comp_dir_sess, but are now moved to temp_path_ext_for_cgu, they are moved because they are not actually incremental files and are just temporaries, right?

Previously we hardlinked some files directly from the old incr comp dir to the new one. Now we instead hardlink to a temporary path and later hardlink to the new path. This is important because these files are cached in the main incr comp cache, but we need access to them after the main incr comp cache is finalized and thus the files can be deleted by a concurrent rustc instance.

@bjorn3

bjorn3 commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Can't reproduce the CI failure with ./x.py test tests/coverage --stage 2.

@rust-bors

This comment has been minimized.

Comment thread compiler/rustc_interface/src/queries.rs Resolved
Comment thread compiler/rustc_interface/src/queries.rs Resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 27, 2026
This ensures GC happens each time a new session directory is created,
even if future prepare_session_directory call may forget it. This should
not result in any behavior change, even in the presence of corrupted
incr comp cache dirs given that the load_dep_graph result is only
checked after GCing.
This is more consistent with the non-LTO cache copying.
This requires using a separate incr comp session for ThinLTO. Also avoid
directly copying between incr comp session dirs.
To make sure they run for non-LTO builds too
@rustbot

rustbot commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@bjorn3

bjorn3 commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Can't reproduce the CI failure with ./x.py test tests/coverage --stage 2.

Managed to reproduce it by removing the test output dir. Pushed a quick fix for most of the issue. Couple of codegen-llvm tests that still fail that I need to investigate.

// Generate a session directory of the form:
//
// {incr-comp-dir}/{crate-name-and-disambiguator}/s-{timestamp}-{random}-working
// {incr-comp-dir}/{crate-name}-{disambiguator}-{prefix}/s-{timestamp}-{random}-{suffix}-working

@petrochenkov petrochenkov Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// {incr-comp-dir}/{crate-name}-{disambiguator}-{prefix}/s-{timestamp}-{random}-{suffix}-working
// {incr-comp-dir}/{crate-name}-{disambiguator}-{suffix}/s-{timestamp}-{random}-{suffix}-working

View changes since the review

@petrochenkov

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 27, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Nov 27, 2026
Split LTO out into a new CodegenBackend method with separate incr comp cache
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
------------------------------------------

error: verification with 'FileCheck' failed
status: exit status: 2
command: LD_LIBRARY_PATH=":" "/checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/diverging-function-call-debuginfo/diverging-function-call-debuginfo.ll" "/checkout/tests/codegen-llvm/diverging-function-call-debuginfo.rs" "--check-prefix=CHECK" "--allow-unused-prefixes" "--dump-input-context" "100"
stdout: none
--- stderr -------------------------------
Could not open input file '/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/diverging-function-call-debuginfo/diverging-function-call-debuginfo.ll': No such file or directory
------------------------------------------

---
------------------------------------------

error: verification with 'FileCheck' failed
status: exit status: 2
command: LD_LIBRARY_PATH=":" "/checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/lto-removes-invokes/lto-removes-invokes.ll" "/checkout/tests/codegen-llvm/lto-removes-invokes.rs" "--check-prefix=CHECK" "--allow-unused-prefixes" "--dump-input-context" "100"
stdout: none
--- stderr -------------------------------
Could not open input file '/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/lto-removes-invokes/lto-removes-invokes.ll': No such file or directory
------------------------------------------

---- [codegen] tests/codegen-llvm/lto-removes-invokes.rs stdout end ----
---- [codegen] tests/codegen-llvm/pgo-counter-bias.rs stdout ----
------FileCheck stdout------------------------------

------FileCheck stderr------------------------------
Could not open input file '/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/pgo-counter-bias/pgo-counter-bias.ll': No such file or directory

------------------------------------------

error: verification with 'FileCheck' failed
status: exit status: 2
command: LD_LIBRARY_PATH=":" "/checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/pgo-counter-bias/pgo-counter-bias.ll" "/checkout/tests/codegen-llvm/pgo-counter-bias.rs" "--check-prefix=CHECK" "--allow-unused-prefixes" "--dump-input-context" "100"
stdout: none
--- stderr -------------------------------
Could not open input file '/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/pgo-counter-bias/pgo-counter-bias.ll': No such file or directory
------------------------------------------

---- [codegen] tests/codegen-llvm/pgo-counter-bias.rs stdout end ----
---- [codegen] tests/codegen-llvm/vfe-annotate-supertrait.rs stdout ----
------FileCheck stdout------------------------------

------FileCheck stderr------------------------------
Could not open input file '/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/vfe-annotate-supertrait/vfe-annotate-supertrait.ll': No such file or directory

------------------------------------------

error: verification with 'FileCheck' failed
status: exit status: 2
command: LD_LIBRARY_PATH=":" "/checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/vfe-annotate-supertrait/vfe-annotate-supertrait.ll" "/checkout/tests/codegen-llvm/vfe-annotate-supertrait.rs" "--check-prefix=CHECK" "--allow-unused-prefixes" "--dump-input-context" "100"
stdout: none
--- stderr -------------------------------
Could not open input file '/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/vfe-annotate-supertrait/vfe-annotate-supertrait.ll': No such file or directory
------------------------------------------

---- [codegen] tests/codegen-llvm/vfe-annotate-supertrait.rs stdout end ----
---- [codegen] tests/codegen-llvm/vfe-upcast.rs stdout ----
------FileCheck stdout------------------------------
---
------------------------------------------

error: verification with 'FileCheck' failed
status: exit status: 2
command: LD_LIBRARY_PATH=":" "/checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/vfe-upcast/vfe-upcast.ll" "/checkout/tests/codegen-llvm/vfe-upcast.rs" "--check-prefix=CHECK" "--allow-unused-prefixes" "--dump-input-context" "100"
stdout: none
--- stderr -------------------------------
Could not open input file '/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen-llvm/vfe-upcast/vfe-upcast.ll': No such file or directory
------------------------------------------

@rust-bors

rust-bors Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: a3081a9 (a3081a92710847b7939bfecfa77b601efbf37b7d)
Base parent: b8794ab (b8794ab3b96cbe1cd0698ecec35b7ffcedc9e995)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (a3081a9): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=iffy rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
1.4% [1.4%, 1.4%] 1
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
-0.2% [-0.2%, -0.2%] 1
Improvements ✅
(secondary)
-0.6% [-0.6%, -0.6%] 1
All ❌✅ (primary) 0.6% [-0.2%, 1.4%] 2

Max RSS (memory usage)

Results (primary -4.5%, secondary -0.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.9% [2.9%, 2.9%] 1
Regressions ❌
(secondary)
1.0% [0.4%, 2.3%] 5
Improvements ✅
(primary)
-7.0% [-12.1%, -3.9%] 3
Improvements ✅
(secondary)
-3.1% [-5.8%, -0.5%] 2
All ❌✅ (primary) -4.5% [-12.1%, 2.9%] 4

Cycles

Results (secondary -0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.2% [1.6%, 2.8%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.5% [-2.7%, -0.8%] 3
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 461.156s -> 460.481s (-0.15%)
Artifact size: 405.64 MiB -> 405.70 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Nov 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants