Introduce TypingMode::Codegen to avoid layout cycles on coroutines#145477
Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
[EXPERIMENT] Introduce `TypingMode::Codegen` to avoid layout cycles
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (34dd67f): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking 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 @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.4%, secondary 4.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.9%, secondary 4.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.1%, secondary -1.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 469.562s -> 472.464s (0.62%) |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
[EXPERIMENT] Introduce `TypingMode::Codegen` to avoid layout cycles
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (4e9488c): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking 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 @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.7%, secondary 5.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 2.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary -1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 470.222s -> 472.094s (0.40%) |
This comment has been minimized.
This comment has been minimized.
|
☔ The latest upstream changes (presumably #145469) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
|
r=me (needs rebase) |
|
@rustbot label: +perf-regression-triaged |
|
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. |
|
@bors r=oli-obk |
This comment has been minimized.
This comment has been minimized.
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing b354133 (parent) -> 76dfce2 (this PR) Test differencesShow 12 test diffs12 doctest diffs were found. These are ignored, as they are noisy. Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard 76dfce2cb2d3f7b7f34d62e6ffe044f7e7d76948 --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (76dfce2): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Our benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.2%, secondary -1.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 1.9%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 511.076s -> 511.359s (0.06%) |
|
two thoughts, this feels related to the addition of the other one is that I am vaguely unhappy about adding new I don't think this PR is necessarily wrong, I would like this to have gone through a types MCP or at least nomination. |
| // We are in codegen. It's very likely this constant has been evaluated in PostAnalysis | ||
| // before. Try to reuse this evaluation, and only re-run if we hit a `TooGeneric` error. | ||
| ty::TypingMode::Codegen => { | ||
| let with_postanalysis = | ||
| ty::TypingEnv::new(typing_env.param_env, ty::TypingMode::PostAnalysis); | ||
| let with_postanalysis = f(with_postanalysis.as_query_input(value)); | ||
| match with_postanalysis { | ||
| Ok(_) | Err(ErrorHandled::Reported(..)) => return Some(with_postanalysis), | ||
| Err(ErrorHandled::TooGeneric(_)) => {} | ||
| } |
There was a problem hiding this comment.
I think the fact that this exists make me feel that this is not the right approach.
Perhaps we should just not use optimized_mir for coroutine layout computation? Coud we just run a fixed list of passes that does not require knowing layouts for coroutine layout computation?
Upstream rustc changes [1] `fully_monomophized` to `TypingMode::Codegen` instead of `TypingMode::post_analysis`. This causes many queries to run multiple times and cause issues because these modes do not compare equal. Switch everything to use `TypingEnv::codegen` to still have a single typing env shared by all analysis. Link: rust-lang/rust#145477 [1] Signed-off-by: Gary Guo <gary@garyguo.net>
View all comments
Computing layout of coroutines depends on their
optimized_mir. At the same time, MIR opts can require using layouts to work. For instance to evaluate constants. This leads to cycles and clumsy workarounds.This PR creates a new typing mode for layout computations:
TypingMode::PostAnalysisor earlier, returnLayourError::TooGeneric;TypingMode::Codegen, actually compute it.TypingMode::Codegenis meant be be used by codegen code, and analyses that require coroutine layout, like transmute check and coroutine recursion check.With this PR, we can remove all
is_coroutinechecks fromrustc_mir_transformand unlock simplifying coroutine MIR.Perf is not terrific. This PR causes recomputation of a few queries, and I had to insert workarounds.