[Issue 21702] New: avoid quadratic template expansion in constraints of multiple search term versions of std.algorithm.searching.startsWith & endsWith

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 12 16:53:50 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21702

          Issue ID: 21702
           Summary: avoid quadratic template expansion in constraints of
                    multiple search term versions of
                    std.algorithm.searching.startsWith & endsWith
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: n8sh.secondary at hotmail.com

See DMD issue #21473 for an example of reasonable library usage that takes more
than 22 gigabytes of memory to compile (the process got killed before
finishing). There is other stuff going on too but fixing this problem is enough
to make the example compile.

The culprit is:

---
 uint endsWith(alias pred = "a == b", Range, Needles...)(Range doesThisEnd,
Needles withOneOfThese)
 if (isBidirectionalRange!Range && Needles.length > 1 &&
    is(typeof(.endsWith!pred(doesThisEnd, withOneOfThese[0])) : bool) &&
    is(typeof(.endsWith!pred(doesThisEnd, withOneOfThese[1 .. $])) : uint))
---

Because in certain situations this is causing the compiler to hang I think it
is reasonable to consider this a bug fix rather than an enhancement.

--


More information about the Digitalmars-d-bugs mailing list