-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Stack overflow in rustc when compiling generated function (7k+ lines) with debuginfo #93908
Copy link
Copy link
Open
Labels
A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)Area: Debugging information in compiled programs (DWARF, PDB, etc.)C-bugCategory: This is a bug.Category: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)Area: Debugging information in compiled programs (DWARF, PDB, etc.)C-bugCategory: This is a bug.Category: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I'm working on a project that heavily relies on generated code (e.g. derivatives obtained using symbolic differentiation) which I manually paste into my project. When I try to compile my crate with debuginfo (i.e.
cargo buildorcargo build --releasewithdebug=true) I get a stack overflow error fromrustc.I tried to reduce my code to a "minimal" example and uploaded a crate to reproduce this here: https://github.com/w1th0utnam3/stackoverflow_symbolic_code. The repository contains almost only the relevant function which can be found here: https://github.com/w1th0utnam3/stackoverflow_symbolic_code/blob/15d0da7cc578f85b5feac3f0a44c4be469fe282f/src/sympy_expressions.rs#L36.
The function has about 7000 lines of mostly basic arithmetic expressions. I removed any return values and added
#![allow(unused_variables)]as this didn't affect the outcome. I replaced some Vector/Matrix types with a dummy type to remove dependencies.By removing lines from the function e.g. using bisection you can find a point where the stack overflow disappears. The exact point seems to be depending on the environment so I don't provide specific values here.
Compiling with optimizations but without debuginfo (i.e. the standard
cargo build --release) works fine.Exemplary output on Windows:
A similar error appears on Linux. On Windows
rustfmtcrashes as well:I don't know how
rustfmtworks internally, so this might require separate investigation from therustccrash.Meta
Stack overflow happens on stable:
but also on nightly: