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

rustc hangs on a recursive function marked with #[inline] #100476

Closed
yvt opened this issue Aug 13, 2022 · 1 comment · Fixed by #100522
Closed

rustc hangs on a recursive function marked with #[inline] #100476

yvt opened this issue Aug 13, 2022 · 1 comment · Fixed by #100522
Assignees
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. P-medium Medium 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.

Comments

@yvt
Copy link
Contributor

yvt commented Aug 13, 2022

I tried this code with -Copt-level=3 --crate-type=lib (Playground, Godbolt; minimized and modified from r3_core's failing code):

#![feature(decl_macro)]

macro emit($($m:ident)*) {$(
    // Randomize `def_path_hash` by defining them under a module with
    // different names
    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>();
        }
    }
)*}

// 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
);

I expected to see this happen: Successful compilation

Instead, this happened: Compiler hangup

Meta

rustc --version --verbose:

rustc 1.64.0-nightly (f8588549c 2022-07-18)
binary: rustc
commit-hash: f8588549c3c3d45c32b404210cada01e2a45def3
commit-date: 2022-07-18
host: aarch64-apple-darwin
release: 1.64.0-nightly
LLVM version: 14.0.6
Backtrace

Captured by a backtrace command in GDB: gdb.txt

@yvt yvt added the C-bug Category: This is a bug. label Aug 13, 2022
@yvt yvt changed the title Compiler hangs when compiling a recursive function rustc hangs when compiling a recursive function Aug 13, 2022
@yvt yvt changed the title rustc hangs when compiling a recursive function rustc hangs on a recursive function Aug 13, 2022
yvt added a commit to r3-os/r3 that referenced this issue Aug 13, 2022
Implements a work-around for infinite recursion in the MIR inliner
([rust-lang/rust#100476][1]).

Since they are only called at compile time, this change will not cause
a runtime performance or code size regression.

[1]: rust-lang/rust#100476
@yvt yvt changed the title rustc hangs on a recursive function rustc hangs on a recursive function marked with #[inline] Aug 13, 2022
@tmiasko tmiasko 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. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. A-mir-opt Area: MIR optimizations labels Aug 14, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 14, 2022
@cjgillot cjgillot self-assigned this Aug 14, 2022
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 17, 2022
@bors bors closed this as completed in d83abe8 Aug 19, 2022
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-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. P-medium Medium 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.

5 participants