Evaluate free constants and statics in definition order under the parallel front-end#157353
Open
xmakro wants to merge 1 commit into
Open
Evaluate free constants and statics in definition order under the parallel front-end#157353xmakro wants to merge 1 commit into
xmakro wants to merge 1 commit into
Conversation
001ad70 to
049476e
Compare
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
@petrochenkov please only look at PRs that are ready for review. Any draft PR is not in a reviewable state |
Contributor
petrochenkov
reviewed
Jun 3, 2026
| // depends on are cached, building a query stack whose depth depends on scheduling and | ||
| // can spuriously exceed the recursion limit. | ||
| if matches!(tcx.sess.threads(), Some(threads) if threads > 1) { | ||
| for item_def_id in tcx.hir_body_owners() { |
Contributor
There was a problem hiding this comment.
So the high level idea is to disable parallelization for a subset of the work below, because that subset causes more complex changes in test outputs than simple diagnostic reordering which can be easily normalized away.
…allel front-end Under the parallel front-end, free constant and static values are forced inside par_hir_body_owners, so worker threads pick up items in an arbitrary order. A const whose initializer refers to another const evaluates it as a nested, depth-limited query, so a thread that starts on a const before its dependencies are cached builds a query stack as deep as the uncached chain. A long enough chain can then spuriously exceed the recursion limit depending on scheduling (issue 146616). When more than one thread is in use, force these values sequentially in definition order before the parallel loop, matching the single-threaded order so each const's dependencies are already cached when it is evaluated. This only changes the order in which the existing set of free statics and free consts is forced; it does not change which items are evaluated, the recursion limit, or single-threaded output. maybe_check_static_with_link_section stays in the parallel loop so it still runs exactly once. Re-enable chained-constants-stackoverflow.rs under the parallel front-end.
049476e to
3e9f80f
Compare
Contributor
Author
|
I reverted the associated const change, so there shouldn't be any language observable change anymore. Now it is only the order change. Under the parallel front-end, free statics and free consts are forced in definition order before the parallel loop. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Under the parallel front-end,
tests/ui/consts/chained-constants-stackoverflow.rsintermittently fails with "queries overflow the depth limit" even though it is a valid program that compiles fine single-threaded. This is the depth-limit nondeterminism tracked in issue 146616.check_crateforces the value of every freestaticand non-generic freeconstinsidepar_hir_body_owners, so worker threads pick up items in an arbitrary order. A const whose initializer refers to another const evaluates it as a nested, depth-limited query, so when a thread starts on a const before its dependencies are cached the query stack grows as deep as the still-uncached chain. With a long enough chain (350 here) that depth depends on scheduling and can exceed the recursion limit, so the same crate compiles single-threaded but intermittently fails in parallel.When more than one thread is in use, this forces the values sequentially in definition order before the parallel loop, matching the single-threaded order so each const's dependencies are already cached when it is evaluated. It only changes the order in which the existing set of free statics and free consts is forced: which items get evaluated, the recursion limit, and single-threaded output are all unchanged. The genuine overflow tests each have a single evaluation entry point whose depth does not depend on scheduling, so they still overflow with identical output.
maybe_check_static_with_link_sectionstays in the parallel loop so it still runs exactly once. The previously ignored test is re-enabled.Verified with the rebuilt compiler: 0 overflows across 240 runs of
chained-constants-stackoverflow.rsat-Zthreads=8/16/32, the four genuine overflow tests (consts/recursive-block,query-system/query_depth,consts/recursive-const-in-impl,generic-const-items/recursive) still overflow deterministically, and the affected ui tests pass single-threaded.