Skip to content

Cycle detected when optimizing MIR #146998

Closed

Description

@FlixCoder

Code

I tried this code:
https://github.com/FlixCoder/fhir-sdk

cargo build -p fhir-model --release

(Probably the same as creating a crate with dependency fhir-model from crates.io).

The example crate is huge and difficult to navigate, so I tried to reproduce with a minimal example with the same cycle:

#[derive(Debug, PartialEq)]
pub struct Bundle(pub Box<BundleInner>);

#[derive(Debug, PartialEq)]
pub struct BundleInner {
	pub issues: Option<Resource>,
	pub entry: Vec<Option<BundleEntry>>,
}

#[derive(Debug, PartialEq)]
pub struct BundleEntry {
	pub resource: Option<Resource>,
}

#[derive(Debug, PartialEq)]
pub enum Resource {
	Bundle(Bundle),
}

However, this successfully compiles.. So I don't really know how to proceed from here, I am open to suggestions what we could try to find a better small example.

I expected to see this happen: Code compiles with opt-level > 1

Instead, this happened: Compilation error on opt-level > 1

(See FlixCoder/fhir-sdk#56 )

Version it worked on

It most recently worked on: 1.89

Version with regression

Rust 1.90 does not and rustc 1.92.0-nightly (975e6c8 2025-09-23) also does not work.

rustc --version --verbose:

rustc 1.92.0-nightly (975e6c8fe 2025-09-23)
binary: rustc
commit-hash: 975e6c8fec280816d24fbde6b8dfe19620f2efe6
commit-date: 2025-09-23
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.1

Backtrace

Backtrace

No crash, no backtrace.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Sep 24, 2025
  2. added
    I-cycleIssue: A query cycle occurred while none was expected
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    and removed
    regression-untriagedUntriaged performance or correctness regression.
    on Sep 24, 2025
  3. FlixCoder commented on Sep 24, 2025

    @FlixCoder
    Author

    Since I have found it in other issues of this kind, I have run cargo bisect-rustc:

    cargo bisect-rustc --start=2025-05-25 -- build -p fhir-model --release

    It found the following:

    ********************************************************************************
    Regression in nightly-2025-06-29
    ********************************************************************************
    
    looking for regression commit between 2025-06-28 and 2025-06-29
    fetching (via remote github) commits from max(bdaba05a953eb5abeba0011cdda2560d157aed2e, 2025-06-26) to 11ad40bb839ca16f74784b4ab72596ad85587298
    ending github query because we found starting sha: bdaba05a953eb5abeba0011cdda2560d157aed2e
    get_commits_between returning commits, len: 5
      commit[0] 2025-06-27: Auto merge of #143064 - flip1995:clippy-subtree-update, r=GuillaumeGomez
      commit[1] 2025-06-27: Auto merge of #143116 - matthiaskrgr:rollup-zy9ez06, r=matthiaskrgr
      commit[2] 2025-06-28: Auto merge of #141759 - 1c3t3a:discriminants-query, r=saethlin
      commit[3] 2025-06-28: Auto merge of #142317 - compiler-errors:perf-fold, r=lcnr
      commit[4] 2025-06-28: Auto merge of #142625 - cjgillot:inline-nocycle, r=oli-obk
    validated commits found, specifying toolchains
    
    ********************************************************************************
    Regression in 11ad40bb839ca16f74784b4ab72596ad85587298
    ********************************************************************************
    
    Attempting to search unrolled perf builds
    ERROR: couldn't find perf build comment
    
    searched nightlies: from nightly-2025-05-25 to nightly-2025-09-24
    regressed nightly: nightly-2025-06-29
    searched commit range: https://github.com/rust-lang/rust/compare/bdaba05a953eb5abeba0011cdda2560d157aed2e...11ad40bb839ca16f74784b4ab72596ad85587298
    regressed commit: https://github.com/rust-lang/rust/commit/11ad40bb839ca16f74784b4ab72596ad85587298
    
    <details>
    <summary>bisected with <a href='https://github.com/rust-lang/cargo-bisect-rustc'>cargo-bisect-rustc</a> v0.6.10</summary>
    
    
    Host triple: x86_64-unknown-linux-gnu
    
  4. Jules-Bertholet commented on Sep 24, 2025

    @Jules-Bertholet
    Contributor
  5. self-assigned this
    on Sep 26, 2025
  6. lqd commented on Sep 26, 2025

    @lqd
    Member

    We may need help reducing this 29MB source code 😓

  7. FlixCoder commented on Sep 27, 2025

    @FlixCoder
    Author
  8. cyrgani commented on Sep 27, 2025

    @cyrgani
  9. 1 remaining item

  10. added
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    and removed
    E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
    on Sep 28, 2025
  11. cyrgani commented on Sep 28, 2025

    @cyrgani
    Contributor

    Another reduction with expanded derives and simplified output: (requires two library crates foo and x, foo depends on x)

    // crate x
    pub trait Compare {
        fn eq(self);
    }
    
    pub fn wrap<A: Compare>(a: A) {
        Compare::eq(a);
    }
    // crate foo
    use x::{Compare, wrap};
    
    pub struct BundleInner;
    
    impl Compare for BundleInner {
        fn eq(self) {
            lots_of_calls();
            wrap(Resource::ExtensionValue);
        }
    }
    
    pub enum Resource {
        Bundle,
        ExtensionValue,
    }
    
    impl Compare for Resource {
        fn eq(self) {
            match self {
                Self::Bundle => wrap(BundleInner),
                Self::ExtensionValue => lots_of_calls(),
            }
        }
    }
    
    macro_rules! units {
        ($($n: ident)*) => {
            $(
                struct $n;
    
                impl Compare for $n {
                    fn eq(self) {  }
                }
    
                wrap($n);
            )*
        };
    }
    
    fn lots_of_calls() {
        units! {
            O1 O2 O3 O4 O5 O6 O7 O8 O9 O10 O11 O12 O13 O14 O15 O16 O17 O18 O19 O20
            O21 O22 O23 O24 O25 O26 O27 O28 O29 O30 O31 O32 O33 O34 O35 O36 O37 O38 O39 O40
            O41 O42 O43 O44 O45 O46 O47 O48 O49 O50 O51 O52 O53 O54 O55 O56 O57 O58 O59 O60
            O61 O62 O63 O64 O65
        }
    }
  12. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-mir-optArea: MIR optimizations
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 29, 2025
  13. apiraino commented on Oct 29, 2025

    @apiraino
    Contributor

    Assigning priority (discussion on Zulip).

    @rustbot label -I-prioritize +P-medium

  14. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 29, 2025
  15. self-assigned this
    on Dec 31, 2025
  16. added a commit that references this issue on Dec 31, 2025
  17. cyrgani commented on Jan 22, 2026

    @cyrgani
    Contributor

    Fixed by #147361.

  18. saethlin commented on Jan 22, 2026

    @saethlin
    Member

    I am not 100% sure that PR fixed the original issue. Don't hesitate to file a new issue if you run into the problem again.

  19. FlixCoder commented on Jan 24, 2026

    @FlixCoder
    Author

    Just tried the current nightly and it succeeds compiling, thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.I-cycleIssue: A query cycle occurred while none was expectedP-mediumMedium priorityS-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions