Skip to content
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

regression: cycle in MIR opts #88972

Closed
Mark-Simulacrum opened this issue Sep 15, 2021 · 5 comments · Fixed by #88979
Closed

regression: cycle in MIR opts #88972

Mark-Simulacrum opened this issue Sep 15, 2021 · 5 comments · Fixed by #88979
Assignees
Labels
I-cycle Issue: A query cycle occurred while none was expected P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@Mark-Simulacrum
Copy link
Member

Found by 1.56 crater -- https://crater-reports.s3.amazonaws.com/beta-1.56-2/beta-2021-09-12/gh/jkarneges.rust-async-bench/log.txt

[INFO] [stdout] error[E0391]: cycle detected when optimizing MIR for `run::listen::{closure#0}`
[INFO] [stdout]    --> src/run.rs:167:28
[INFO] [stdout]     |
[INFO] [stdout] 167 |   ) -> Result<(), io::Error> {
[INFO] [stdout]     |  ____________________________^
[INFO] [stdout] 168 | |     let listener = AsyncFakeListener::new(reactor, stats);
[INFO] [stdout] 169 | |
[INFO] [stdout] 170 | |     for _ in 0..CONNS_MAX {
[INFO] [stdout] ...   |
[INFO] [stdout] 180 | |     Ok(())
[INFO] [stdout] 181 | | }
[INFO] [stdout]     | |_^
[INFO] [stdout]     |
[INFO] [stdout]     = note: ...which requires computing layout of `impl std::future::Future`...
[INFO] [stdout]     = note: ...which requires computing layout of `std::future::from_generator::GenFuture<[static generator@src/run.rs:213:3: 218:2]>`...
[INFO] [stdout]     = note: ...which requires computing layout of `[static generator@src/run.rs:213:3: 218:2]`...
[INFO] [stdout] note: ...which requires optimizing MIR for `run::do_async::{closure#0}`...
[INFO] [stdout]    --> src/run.rs:213:3
[INFO] [stdout]     |
[INFO] [stdout] 213 |   ) {
[INFO] [stdout]     |  ___^
[INFO] [stdout] 214 | |     match invoke {
[INFO] [stdout] 215 | |         AsyncInvoke::Listen => listen(spawn, ctx, reactor, stats).await.unwrap(),
[INFO] [stdout] 216 | |         AsyncInvoke::Connection(stream) => connection(stream).await.unwrap(),
[INFO] [stdout] 217 | |     }
[INFO] [stdout] 218 | | }
[INFO] [stdout]     | |_^
[INFO] [stdout]     = note: ...which requires computing layout of `impl std::future::Future`...
[INFO] [stdout]     = note: ...which requires computing layout of `std::future::from_generator::GenFuture<[static generator@src/run.rs:167:28: 181:2]>`...
[INFO] [stdout]     = note: ...which requires computing layout of `[static generator@src/run.rs:167:28: 181:2]`...
[INFO] [stdout]     = note: ...which again requires optimizing MIR for `run::listen::{closure#0}`, completing the cycle

cc @oli-obk

@Mark-Simulacrum Mark-Simulacrum added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Sep 15, 2021
@Mark-Simulacrum Mark-Simulacrum added this to the 1.56.0 milestone Sep 15, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 15, 2021
@oli-obk oli-obk self-assigned this Sep 15, 2021
@tmiasko
Copy link
Contributor

tmiasko commented Sep 15, 2021

diff --git a/compiler/rustc_mir_transform/src/remove_zsts.rs b/compiler/rustc_mir_transform/src/remove_zsts.rs
index 25e3c52132c..d93ffa38c69 100644
--- a/compiler/rustc_mir_transform/src/remove_zsts.rs
+++ b/compiler/rustc_mir_transform/src/remove_zsts.rs
@@ -9,6 +9,10 @@
 
 impl<'tcx> MirPass<'tcx> for RemoveZsts {
     fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
+        // Avoid query cycles (generators require optimized MIR for layout).
+        if tcx.type_of(body.source.def_id()).is_generator() {
+            return;
+        }
         let param_env = tcx.param_env(body.source.def_id());
         let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
         for block in basic_blocks.iter_mut() {

@tmiasko
Copy link
Contributor

tmiasko commented Sep 15, 2021

Fixed by #88979. Sorry for taking over, but since I started looking into it already.

Manishearth added a commit to Manishearth/rust that referenced this issue Sep 16, 2021
…s, r=oli-obk

Disable RemoveZsts in generators to avoid query cycles

Querying layout of a generator requires its optimized MIR. Thus
computing layout during MIR optimization of a generator might create a
query cycle. Disable RemoveZsts in generators to avoid the issue
(similar approach is used in ConstProp transform already).

Fixes rust-lang#88972.
@bors bors closed this as completed in 237bb5e Sep 16, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Sep 17, 2021

Still needs a backport

@oli-obk oli-obk reopened this Sep 17, 2021
@apiraino
Copy link
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Sep 22, 2021
ehuss pushed a commit to ehuss/rust that referenced this issue Oct 4, 2021
… r=oli-obk

Disable RemoveZsts in generators to avoid query cycles

Querying layout of a generator requires its optimized MIR. Thus
computing layout during MIR optimization of a generator might create a
query cycle. Disable RemoveZsts in generators to avoid the issue
(similar approach is used in ConstProp transform already).

Fixes rust-lang#88972.
@pnkfelix
Copy link
Member

fixed by #89527

@fmease fmease added the I-cycle Issue: A query cycle occurred while none was expected label Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-cycle Issue: A query cycle occurred while none was expected P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants