Thread overview
[Issue 7926] stack overflow on recursive string mixin
Apr 17, 2014
Kenji Hara
Apr 17, 2014
Ivan Kazmenko
Apr 17, 2014
Artem Borisovskiy
April 17, 2014
https://issues.dlang.org/show_bug.cgi?id=7926

Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID
                 OS|Linux                       |All

--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> ---
I don't think this is a bug. The infinite recursive expansion is the intended behavior of the code. We can write arbitrary code in this kind.

// mutual recursion version
enum string a = "mixin(b);";
enum string b = "mixin(a);";
mixin(a);


// infinite code bloating version
string a(string num = "1")
{
    string inc(string num)
    {
        return (num.length == 0 ? "1" :
                num[$-1] == '9' ? inc(num[0..$-1]) ~ "0" :
                num[0..$-1] ~ cast(char)(num[$-1] + 1));
    }
    return `enum a`~num~` = a("`~inc(num)~`"); `~
           `/*pragma(msg, a`~num~`);*/` ~
           `mixin(a`~num~`);`;
}
mixin(a);

--
April 17, 2014
https://issues.dlang.org/show_bug.cgi?id=7926

Ivan Kazmenko <gassa@mail.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gassa@mail.ru

--- Comment #3 from Ivan Kazmenko <gassa@mail.ru> ---
Still, the diagnostics can be better than just "Error: out of memory".  At least showing a [reasonably-sized tail of] what consumed all that memory.

On the other hand, it is tricky to log when you already have no memory, and adding logging information for such cases will probably increase the memory footprint in the general case, too.

--
April 17, 2014
https://issues.dlang.org/show_bug.cgi?id=7926

--- Comment #4 from Artem Borisovskiy <kolos80@bk.ru> ---
(In reply to Ivan Kazmenko from comment #3)
> Still, the diagnostics can be better than just "Error: out of memory".  At least showing a [reasonably-sized tail of] what consumed all that memory.
That's right. "Segmentation fault" gives no clue on what's went bad, and it happens at compile time, so it's pretty hard to find the source of the problem. You might know your own sources well, but digging into the compiler sources is not an option for most, even experienced, developers.

--