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

Unittest compilation of std.string crash (Windows): too deep recursion #1297

Closed
JohanEngelen opened this issue Feb 16, 2016 · 16 comments
Closed

Comments

@JohanEngelen
Copy link
Member

On Windows, this stops compilation (-w!) without any diagnostic:
C:\projects\ninja-ldc\bin\ldc2.exe --output-o -c -IC:/projects/ldc/runtime/druntime/src -IC:/projects/ldc/runtime/druntime/src/gc C:/projects/ldc/runtime/phobos/std/string.d -ofC:/projects/ninja-ldc/runtime/std/string-unittest-debug.obj -w -d -link-debuglib -unittest -IC:/projects/ldc/runtime/phobos

@JohanEngelen
Copy link
Member Author

(Perhaps the bug is not directly related to -w)

@kinke
Copy link
Member

kinke commented Feb 16, 2016

On merge-2.069 only, right? I'll investigate once I'm home (in 6+ hours).

@JohanEngelen
Copy link
Member Author

yeah.
I thought I had isolated the issue, reduced it to a test case, and solved it by removing -w for now, but... somewhere I went wrong and the issue is still there.
Disabling the unittests up to line 1200 or so will fix compilation.

@JohanEngelen
Copy link
Member Author

Perhaps it is an out-of-memory issue? I am able to turn the crash on/off by duplicating/removing the asserts around line 1220.

@JohanEngelen
Copy link
Member Author

Nope, with a loop, I've been able to get LDC to allocate more than 10GB of memory, no problem.

@JohanEngelen
Copy link
Member Author

Looks like an infinite recursion of TemplateInstance.needsCodeGen()

@JohanEngelen
Copy link
Member Author

I think I have found the problem: TemplateInstance.needsCodeGen() is a recursive function. As it turns out, for some of the unittests of std.string (e.g. line 1222) the recursion depth is very very deep. The call from declarations.cpp, void visit(TemplateInstance *decl), reaches a recursion depth that is too much on Windows and the program simply exits.
I don't know how to solve this, other than rewriting needsCodeGen to something non-recursive; I think it can be turned into a loop.
What do you think?

@JohanEngelen JohanEngelen changed the title No diagnostic / silent failure on -w Unittest compilation of std.string crash (Windows): too deep recursion Feb 16, 2016
@JohanEngelen
Copy link
Member Author

(in one case, the depth is >10000)

@JohanEngelen
Copy link
Member Author

@9rnsr Do you think it is possible to rewrite TemplateInstance.needsCodeGen() into something non-recursive? Or at least a refactoring that reduces the depth of recursion?

@kinke
Copy link
Member

kinke commented Feb 16, 2016

Oh wow. That most likely also expains why we're apparently hitting a rare LLVM bug (#930) when compiling the std.string unittests with debug infos on Win64.
But as DMD seems unaffected by this stack limitation, is it something LDC specific?

@yebblies
Copy link

We do explicitly set the stack size for DMD on windows, since the default is too small. What is it set to in LDC?

@JohanEngelen
Copy link
Member Author

Thanks, found it: https://github.com/D-Programming-Language/dmd/blob/master/src/win32.mak#L285
I'll try that.
Is there a maximum nested template instantiation depth? (LDC has an experimental feature for setting that)

@kinke
Copy link
Member

kinke commented Feb 17, 2016

Apparently the default stack size used by MSVC is a single MB. Linux uses 8, and that's what DMD chose on Windows as well. Let's go with the same size.

@yebblies
Copy link

Yes, it has nested template instantiation limits but they are set up for the 8MB stack. We use 8MB for dmd because I looked up the linux default and went with that.

@JohanEngelen
Copy link
Member Author

Mac also uses 8MB as default.

@JohanEngelen
Copy link
Member Author

Fixed in merge-2.069 branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants