Rust-GCC / Rust-GCC/gccrs

Performance issue with recursive macro expansion

Open
#3,703 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

Summary

The compiler experiences significant performance degradation when handling deep recursive macro expansions, leading to timeouts.

Reproducer

I tried this code:

macro_rules! fooN {
    ($cur:ident $prev:ty) => {
        #[allow(dead_code)]
        enum $cur {
            Empty,
            First($prev),
            Second($prev),
            Third($prev),
            Fourth($prev),
        }
    }
}

fooN!(Foo0 ());
fooN!(Foo1 Foo0);
fooN!(Foo2 Foo1);
fooN!(Foo3 Foo2);
fooN!(Foo4 Foo3);
fooN!(Foo5 Foo4);
fooN!(Foo6 Foo5);
fooN!(Foo7 Foo6);
fooN!(Foo8 Foo7);
fooN!(Foo9 Foo8);
fooN!(Foo10 Foo9);
fooN!(Foo11 Foo10);
fooN!(Foo12 Foo11);
fooN!(Foo13 Foo12);
fooN!(Foo14 Foo13);
fooN!(Foo15 Foo14);
fooN!(Foo16 Foo15);
fooN!(Foo17 Foo16);
fooN!(Foo18 Foo17);
fooN!(Foo19 Foo18);
fooN!(Foo20 Foo19);
fooN!(Foo21 Foo20);
fooN!(Foo22 Foo21);
fooN!(Foo23 Foo22);
fooN!(Foo24 Foo23);
fooN!(Foo25 Foo24);
fooN!(Foo26 Foo25);
fooN!(Foo27 Foo26);

fn main() {
    let _foo = Foo27::Empty;
}
Does the code make use of any (1.49) nightly feature ?
  • Nightly
Godbolt link

https://godbolt.org/z/7zxxM6Wdf

Actual behavior

gccrs Fail to compile this code.

Expected behavior

gccrs should compile the code successfully.

GCC Version

14.0.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the supplied recursive macro reproducer with GCC 14.0.1 and compare the result with the linked Godbolt example. Trace the compiler path handling the deep macro expansion; done means gccrs compiles the example successfully without the reported timeout or performance degradation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.