Skip to content

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

Closed

Description

@tmiasko
#![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

Activity

  1. added
    C-bug
    on Aug 31, 2020
  2. tmiasko commented on Sep 1, 2020

    @tmiasko
    ContributorAuthor
    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.

  3. added a commit that references this issue on Sep 3, 2020
    cd68293
  4. added
    T-compiler
    A-mir-opt
    I-cycle
    on Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optC-bugI-cycleT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions