www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22996] New: [ICE] Parsing at CTFE crash the compiler


          Issue ID: 22996
           Summary: [ICE] Parsing at CTFE crash the compiler
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: aliloko gmail.com

Created attachment 1844
  --> https://issues.dlang.org/attachment.cgi?id=1844&action=edit
Main source file

I lost an excellent potential contributor because he was not impressed with D,
after encountering bugs and regressions.

The following program he wanted to compile but exhausted memory.


import std.stdio;
import std.string;
import std.range;
import std.array;
import std.typecons;
import std.complex;

enum TEXT = import("shape-L8.txt");

enum Tuple!(double, Complex!double)[] DATA =

string transformLTSpiceToCode(string text)
    string result;
    result ~= "[";
    foreach (string line; text.lineSplitter.dropOne) {
        string[] fields = line.split!`a == ' ' || a == '\t' || a == ','`.array;
        result ~= "std.typecons.Tuple!(double, std.complex.Complex!double)(";
        result ~= fields[0];
        result ~= ",Complex!double(";
        result ~= fields[1];
        result ~= ",";
        result ~= fields[2];
        result ~= ")),\n";
    result ~= "]";
    return result;

void main(string[] args)


  To a seasoned D programmer, it is obvious why the program uses up all memory:
it uses tuples, std.complex, lazy ranges, arrays liberally at CTFE. It is of
course possible to make it work at CTFE with more pedestrian code.

  But a newfound D user will just dismiss the language without knowing he is
perhaps amongst the only to use such a costly CTFE program.
And then the compiler crashing is an ICE.

1. unzip the attached file and get shape-L8.txt

2. run the above program

DMD will crash after exhausting memory.
Better outcome with -lowmem, who caps memory usage at 100mb.

Apr 07 2022