Thread overview
[Issue 21473] DMD enters infinite loop
Dec 11, 2020
Boris Carvajal
Mar 12, 2021
Nathan S.
Apr 24, 2021
Imperatorn
Mar 25, 2022
RazvanN
December 11, 2020
https://issues.dlang.org/show_bug.cgi?id=21473

Boris Carvajal <boris2.9@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |boris2.9@gmail.com

--- Comment #1 from Boris Carvajal <boris2.9@gmail.com> ---
There are two issues here, the first is in phobos that somewhere in the pipeline generates a ridiculous amount of template instances.

Second is the recursive nature of 'TemplateInstance::needsCodegen()' that overflows the stack when there are too many instances of a particular template, this is the same bug as issue 18026 and the only way to fix it is to refactor 'needsCodegen' function. You can reproduce it with this simple piece of code:

---------------
struct S() {}

static foreach (i; 0..180000)
{
    mixin("S!() s", i, ";");
}
---------------

The number of iterations can vary, for example using a non-optimized DMD build I only need '90000' to crash. (my stack size is 8MB)

--
March 12, 2021
https://issues.dlang.org/show_bug.cgi?id=21473

Nathan S. <n8sh.secondary@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |n8sh.secondary@hotmail.com
         Depends on|                            |21702

--- Comment #2 from Nathan S. <n8sh.secondary@hotmail.com> ---
https://github.com/dlang/phobos/pull/7847 solves the problem of Phobos performing a crazy amount of template expansion for this code.


Referenced Issues:

https://issues.dlang.org/show_bug.cgi?id=21702
[Issue 21702] avoid quadratic template expansion in constraints of multiple
search term versions of std.algorithm.searching.startsWith & endsWith
--
March 13, 2021
https://issues.dlang.org/show_bug.cgi?id=21473
Issue 21473 depends on issue 21702, which changed state.

Issue 21702 Summary: avoid quadratic template expansion in constraints of multiple search term versions of std.algorithm.searching.startsWith & endsWith
https://issues.dlang.org/show_bug.cgi?id=21702

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--
April 24, 2021
https://issues.dlang.org/show_bug.cgi?id=21473

Imperatorn <johan_forsberg_86@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johan_forsberg_86@hotmail.c
                   |                            |om

--- Comment #3 from Imperatorn <johan_forsberg_86@hotmail.com> ---
Does https://github.com/dlang/phobos/pull/7847 solve this issue? If so, update the status.

--
March 25, 2022
https://issues.dlang.org/show_bug.cgi?id=21473

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |WORKSFORME

--- Comment #4 from RazvanN <razvan.nitu1305@gmail.com> ---
I can't reproduce this with the latest version of the compiler. Closing as WORKSFORME. Please reopen if I am missing something.

--