Skip to content

Fix parallel rustc not being reproducible due to unstable sorts of items #144722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

ywxt
Copy link
Contributor

@ywxt ywxt commented Jul 31, 2025

Currently, A tuple (DefId, SymbolName) is used to determine the order of items in the final binary. However DefId is expected as non-deterministic, which leads to some not reproducible issues under parallel compilation. (See #140425 (comment))

Theoretically, we don't need the sorting because the order of these items is already deterministic.

However, codegen tests reply on the same order of items between in binary and source.

So here we added a new option codegen-source-order to indicate whether sorting based on the order in source. For codegen tests, items are sorted according to the order in the source code, whereas in the normal path, no sorting is performed.

Specially, for codegen tests, in preparation for parallel compilation potentially being enabled by default in the future, we use Span replacing DefId to make the order deterministic.

This PR is purposed to fix #140425, but seemly works on #140413 too.

This behavior hasn't added into any test until we have a test suit for the parallel frontend. (See #143953)

Related discussion: Zulip #144576

Update #113349

r? @oli-obk
cc @lqd @cramertj @matthiaskrgr @Zoxc @SparrowLii @bjorn3 @cjgillot @joshtriplett

@rustbot
Copy link
Collaborator

rustbot commented Jul 31, 2025

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 31, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 31, 2025

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@rust-log-analyzer

This comment has been minimized.

@ywxt
Copy link
Contributor Author

ywxt commented Jul 31, 2025

I don't think the changes of diagnostic orders are expected.😅

@ywxt ywxt force-pushed the parallel-reproducibile branch from b7e0813 to a03edc6 Compare August 1, 2025 01:24
@rust-log-analyzer

This comment has been minimized.

MonoItem::Static(def_id) => def_id.as_local().map(Idx::index),
MonoItem::GlobalAsm(item_id) => Some(item_id.owner_id.def_id.index()),
},
local_item_query(item, |def_id| tcx.def_span(def_id)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we try to use def_ident_span or find_ancestor_not_from_extern_macro to avoid having to shuffle tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your advice. I'll try it. :)

Copy link
Contributor Author

@ywxt ywxt Aug 4, 2025

Choose a reason for hiding this comment

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

def_ident_span failed on tests/assembly-llvm/emit-intel-att-syntax.rs about naked and global asm.

find_ancestor_not_from_macro works here.

@ywxt ywxt force-pushed the parallel-reproducibile branch from a03edc6 to d6294cc Compare August 4, 2025 03:19
@rust-log-analyzer

This comment has been minimized.

@ywxt
Copy link
Contributor Author

ywxt commented Aug 4, 2025

If we don't sort items again, it would broke existing tests.

How about (def_span().find_ancestor_not_form_macro(), SymbolName) to replace (DefId, SymbolName) instead of using a new option?

Edit: querying span makes a significant regression for perf.

@ywxt ywxt force-pushed the parallel-reproducibile branch from a9ba3d9 to 989e39f Compare August 5, 2025 01:27
@rust-log-analyzer

This comment has been minimized.

@ywxt ywxt force-pushed the parallel-reproducibile branch from 989e39f to 9e4f296 Compare August 6, 2025 01:54
@SparrowLii
Copy link
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Aug 6, 2025

⌛ Trying commit 8a02371 with merge 77b6bc0

To cancel the try build, run the command @bors try cancel.

rust-bors bot added a commit that referenced this pull request Aug 6, 2025
Fix parallel rustc not being reproducible due to unstable sorts of items
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 6, 2025
@rust-bors
Copy link

rust-bors bot commented Aug 6, 2025

☀️ Try build successful (CI)
Build commit: 77b6bc0 (77b6bc0c5f1162a75f7502ef975c859ece90ef4e, parent: ec7c02612527d185c379900b613311bc1dcbf7dc)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (77b6bc0): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@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)
0.3% [0.1%, 0.5%] 2
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
-0.2% [-0.3%, -0.2%] 8
Improvements ✅
(secondary)
-0.6% [-1.6%, -0.0%] 16
All ❌✅ (primary) -0.1% [-0.3%, 0.5%] 10

Max RSS (memory usage)

Results (primary -2.4%, secondary 2.1%)

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

mean range count
Regressions ❌
(primary)
2.7% [2.7%, 2.7%] 1
Regressions ❌
(secondary)
2.1% [1.6%, 2.6%] 2
Improvements ✅
(primary)
-3.2% [-6.2%, -1.5%] 6
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.4% [-6.2%, 2.7%] 7

Cycles

Results (primary 3.4%, secondary 3.5%)

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

mean range count
Regressions ❌
(primary)
3.4% [1.7%, 6.8%] 17
Regressions ❌
(secondary)
3.5% [1.8%, 5.0%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.4% [1.7%, 6.8%] 17

Binary size

Results (primary 0.0%, secondary 0.1%)

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

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.1%] 11
Regressions ❌
(secondary)
0.2% [0.0%, 0.9%] 47
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 17
Improvements ✅
(secondary)
-0.0% [-0.1%, -0.0%] 8
All ❌✅ (primary) 0.0% [-0.0%, 0.1%] 28

Bootstrap: 467.149s -> 473.005s (1.25%)
Artifact size: 377.42 MiB -> 377.35 MiB (-0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiletest Area: The compiletest test runner A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-testsuite Area: The testsuite used to check the correctness of rustc perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

parallel rustc: async closures not reproducible
7 participants