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

cycle detected when optimizing MIR with mir-opt-level=2 #76181

Closed
tmiasko opened this issue Aug 31, 2020 · 1 comment · Fixed by #76245
Closed

cycle detected when optimizing MIR with mir-opt-level=2 #76181

tmiasko opened this issue Aug 31, 2020 · 1 comment · Fixed by #76245
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. I-cycle Issue: A query cycle occurred while none was expected T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tmiasko
Copy link
Contributor

tmiasko commented Aug 31, 2020

#![crate_type = "lib"]

#[derive(Clone, Debug)]
pub struct S {}

impl S {
    pub async fn g(mut c: Self) {
        Self::h(&mut c);
    }

    pub fn h(c: &mut Self) {
        let _ = S::g(c.clone());
    }
}
$ rustc --edition=2018  -Zmir-opt-level=2 a.rs
error[E0391]: cycle detected when optimizing MIR for `<impl at a.rs:6:1: 14:2>::g::{{closure}}#0`
  --> a.rs:7:33
   |
7  |       pub async fn g(mut c: Self) {
   |  _________________________________^
8  | |         Self::h(&mut c);
9  | |     }
   | |_____^
   |
note: ...which requires optimizing MIR for `<impl at a.rs:6:1: 14:2>::h`...
  --> a.rs:11:5
   |
11 |     pub fn h(c: &mut Self) {
   |     ^^^^^^^^^^^^^^^^^^^^^^
   = note: ...which requires computing layout of `std::future::from_generator::GenFuture<[static generator@a.rs:7:33: 9:6 __arg0:S {}]>`...
   = note: ...which requires computing layout of `[static generator@a.rs:7:33: 9:6 __arg0:S {}]`...
   = note: ...which again requires optimizing MIR for `<impl at a.rs:6:1: 14:2>::g::{{closure}}#0`, completing the cycle
@tmiasko tmiasko added the C-bug Category: This is a bug. label Aug 31, 2020
@tmiasko
Copy link
Contributor Author

tmiasko commented Sep 1, 2020

  1. Attempt is made to inline h into g::{{closure}}#0 which requires computing optimized MIR for h.
  2. Optimized MIR for h executes ConstProp, which computes layout for locals, one of which is a generator.
  3. Computing layout of this generator involves computing optimized MIR for g::{{closure}}#0 completing the cycle.

The issue might be addressed at some point by changes in #68828.

@bors bors closed this as completed in cd68293 Sep 3, 2020
@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-mir-opt Area: MIR optimizations I-cycle Issue: A query cycle occurred while none was expected labels Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. I-cycle Issue: A query cycle occurred while none was expected 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.

2 participants