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
fix Issue 20855 - stack overflow when compiling large file #12409
Conversation
Thanks for your pull request, @WalterBright! Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#12409" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the code is so trivial, I think it'd be better to just write a script generating it.
Also this doesn't really fix the issue, just adds a hard-coded limit which works on your system.
Yes, switching the test case to be generative is better; done. The fundamental problem here is the backend is recursive in nature. It's difficult to figure out just where to put the checks without engaging in whack-a-mole. The check I put in is conservative, it needs to go double that before it stack overflows. You're doing something wrong anyway with 10,000 statements in a function. I also put the check in the backend rather than the frontend, as other compilers have their own means of dealing with the problem. |
Isn't the issue that your doing something quadratic when traversing trees in the dmd backend? Why can't it be fixed to not be quadratic? (i.e: isn't this just issue 6401) |
Quadratic doesn't cause stack overflow. Recursive depth does. Trying different statement counts in the attached test clearly indicate a stack overflow in optelem(), and optelem() is recursive. There are many quadratic algorithms in the optimizer, which is why it is slow. |
Don't approve yet. I'm going to try out another idea. |
I completely changed the approach. Instead of connecting ExpStatements with OPcomma, it creates a new block for each ExpStatement. It resolves the stack overflow by changing the data structure from recursive to iterative. But it does not resolve the quadratic behavior in the optimizer. I cut the iterations in the test case from 100,000 to around 8,000 so it does not bog down the test suite. There are already separate bugzilla issues for the quadratic behavior, so I won't concern this PR with them. |
0ae3729
to
5004237
Compare
The test failures have something to do with -preview=fieldwise. Will investigate more tomorrow. |
This PR uncovered an unrelated optimizer bug. I disabled the problem code, and will fix the optimizer in a followup PR. |
Ubuntu test fails with:
|
Windows_VisualD_LDC x86-mscoff failed
I have no idea why this should fail only when built with LDC? |
buildkite AuburnSounds fails with:
Who is in charge of AuburnSounds? |
Guillaume Piolat @p0nce |
675b0d0
to
393960b
Compare
5fd940a
to
79912ec
Compare
version (MARS) | ||
// Switched to one block per Statement, do not undo it | ||
enum merge = false; | ||
else | ||
enum merge = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it's going to come back to haunt you down the road 🤷
Yay! |
Maybe related to these changes? |
This pull request introduced a regression: |
It's still regressed on master. Has been since 2.097. |
This PR introduced a regression https://issues.dlang.org/show_bug.cgi?id=23084 |
No description provided.