Skip to content

polymorphic_recursion.rs takes longer to compile #120912

Description

@dianqk

Code

I tried this code:

// skip-filecheck
// Make sure that the MIR inliner does not loop indefinitely on polymorphic recursion.
// compile-flags: --crate-type lib

// Randomize `def_path_hash` by defining them under a module with different names
macro_rules! emit {
    ($($m:ident)*) => {$(
        pub mod $m {
            pub trait Tr { type Next: Tr; }

            pub fn hoge<const N: usize, T: Tr>() {
                inner::<N, T>();
            }

            #[inline(always)]
            fn inner<const N: usize, T: Tr>()
            {
                inner::<N, T::Next>();
                inner::<N, T::Next>();
            }
        }
    )*};
}

// Increase the chance of triggering the bug
emit!(m00 m01 m02 m03 m04 m05 m06 m07 m08 m09 m10 m11 m12 m13 m14 m15 m16 m17 m18 m19);

https://github.com/rust-lang/rust/blob/1.76.0/tests/mir-opt/inline/polymorphic_recursion.rs

I expected to see this happen: It compiles quickly.

Instead, this happened: It takes 10s to complete.

Version with regression

Bisected to #120584.

cc @compiler-errors

Activity

  1. added
    C-bugCategory: This is a bug.
    regression-untriagedUntriaged performance or correctness regression.
    on Feb 11, 2024
  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 11, 2024
  3. compiler-errors commented on Feb 11, 2024

    @compiler-errors
    Contributor

    @dianqk: Why did you title this "is broken"? It just takes longer to compile, or is it broken some other way?

    I'll look into the upcoming week.

  4. dianqk commented on Feb 11, 2024

    @dianqk
    MemberAuthor

    @dianqk: Why did you title this "is broken"? It just takes longer to compile, or is it broken some other way?

    I'll look into the upcoming week.

    Sorry, it just takes longer to compile.

  5. changed the title [-]`polymorphic_recursion.rs` is broken[/-] [+]`polymorphic_recursion.rs` takes longer to compile[/+] on Feb 11, 2024
  6. added
    I-compiletimeIssue: Problems and improvements with respect to compile times.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 11, 2024
  7. apiraino commented on Feb 12, 2024

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion).

    @rustbot label -I-prioritize +P-medium -regression-untriaged

  8. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    regression-untriagedUntriaged performance or correctness regression.
    on Feb 12, 2024
  9. added a commit that references this issue on Feb 13, 2024
    c1b1174
  10. Zalathar commented on Feb 13, 2024

    @Zalathar
    Member

    On my machine (Apple M2 Pro), this test currently takes about 30 seconds.

    But if I enable [rust] debug-assertions = true, the compiler appears to consume 100% CPU forever.

    I'm not sure whether it's actually stuck, or just taking an incredibly long time, but I've never seen it finish with debug assertions enabled.

  11. Zalathar commented on Feb 13, 2024

    @Zalathar
    Member

    If I apply #120942, the test finishes in about 45 seconds with debug assertions enabled, and about 3 seconds with them disabled.

  12. added a commit that references this issue on Feb 14, 2024
    37b6533
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

C-bugCategory: This is a bug.I-compiletimeIssue: Problems and improvements with respect to compile times.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions