Bug 22397 – Out of memory during compilation

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-10-16T15:49:06Z
Last change time
2024-12-13T19:18:47Z
Assigned to
No Owner
Creator
Ray Kulhanek
Moved to GitHub: dmd#18060 →

Comments

Comment #0 by kulhanek.5 — 2021-10-16T15:49:06Z
# Linux error message --- ERROR: This is a compiler bug. Please report it via https://issues.dlang.org/enter_bug.cgi with, preferably, a reduced, reproducible example and the information below. DustMite (https://github.com/CyberShadow/DustMite/wiki) can help with the reduction. --- DMD v2.090.0 predefs DigitalMars Posix linux ELFv1 CRuntime_Glibc CppRuntime_Gcc LittleEndian D_Version2 all D_SIMD D_InlineAsm_X86_64 X86_64 D_LP64 D_PIC assert D_ModuleInfo D_Exceptions D_TypeInfo D_HardFloat binary dmd version v2.090.0 config /etc/dmd.conf DFLAGS -I/usr/include/dmd/phobos -I/usr/include/dmd/druntime/import -L-L/usr/lib/x86_64-linux-gnu -L--export-dynamic -fPIC --- core.exception.OutOfMemoryError@src/core/exception.d(647): Memory allocation failed ----------------Segmentation fault # Windows error message The same error appears in the Windows build (on Windows 10). predefs DigitalMars Windows CRuntime_DigitalMars CppRuntime_DigitalMars LittleEndian D_Version2 all D_InlineAsm D_InlineAsm_X86 X86 Win32 assert D_ModuleInfo D_Exceptions D_TypeInfo D_HardFloat version v2.089.1-dirty # Code import std.file, std.stdio, std.algorithm, std.array, std.path; void print(R)(R entries, uint depth) { entries .map!(a => a[depth..$]) .filter!(a => a.length > 1) .map!(a => a[1..$]) .print(depth + 1); } void main() { dirEntries(".", SpanMode.depth) .map!(a => a.name.pathSplitter.array) .print(0); }
Comment #1 by dlang-bugzilla — 2021-10-16T15:51:56Z
What behavior do you expect? "print" is instantiating itself recursively with a range type that is more complicated every iteration, so this program cannot be compiled.
Comment #2 by kulhanek.5 — 2021-10-16T15:55:03Z
Be sure to set ulimit -v to something reasonable when running the test code. It'll exhaust memory and freeze up in seconds if allowed to use unlimited swap.
Comment #3 by kulhanek.5 — 2021-10-16T15:59:22Z
Vladimir: I've no problem with it failing to compile. But the error message called it a compiler bug, so I reported it. Ideally, the behavior would be to fail to compile while indicating the error in any way other than exhausting memory. I needed to hard reboot the first time I ran it under Linux because I didn't manage to kill it before it started thrashing the swap.
Comment #4 by dlang-bugzilla — 2021-10-16T16:46:23Z
(In reply to Ray Kulhanek from comment #3) > Ideally, the behavior would be to fail to compile while indicating the error > in any way other than exhausting memory. The compiler generally cannot predict that a program will exhaust all memory. (Variation of halting problem)
Comment #5 by dlang-bugzilla — 2021-10-16T16:50:56Z
Maybe something like this to avoid saying that out-of-memory errors are compiler bugs: diff --git a/src/dmd/mars.d b/src/dmd/mars.d index 54c8298ea9..344ad207e2 100644 --- a/src/dmd/mars.d +++ b/src/dmd/mars.d @@ -1064,10 +1064,18 @@ else dmd_coverSetMerge(true); } - scope(failure) stderr.printInternalFailure; - - auto args = Runtime.cArgs(); - return tryMain(args.argc, cast(const(char)**)args.argv, global.params); + try + { + auto args = Runtime.cArgs(); + return tryMain(args.argc, cast(const(char)**)args.argv, global.params); + } + catch (OutOfMemoryError e) + throw e; + catch (Throwable e) + { + stderr.printInternalFailure; + throw e; + } } } // !NoMain
Comment #6 by robert.schadek — 2024-12-13T19:18:47Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18060 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB