Bug 14561 – Large enums cannot be parsed due to too many recursive template expansions

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-05-09T16:15:00Z
Last change time
2016-12-23T21:26:08Z
Assigned to
nobody
Creator
Philip.Daniels1971

Attachments

IDFilenameSummaryContent-TypeSize
1520color.dLarge Colors enumtext/plain25311

Comments

Comment #0 by Philip.Daniels1971 — 2015-05-09T16:15:08Z
Created attachment 1520 Large Colors enum I have defined a large enum to hold X11 named color values (see attachment). The enum contains more than 500 elements. Trying to convert a string to an enum value with auto c = to!Colors("AliceBlue"); fails to compile, giving: Error: template instance std.traits.EnumMembers!(Colors).WithIdentifier!"OliveDrab3" recursive expansion To reproduce: dmd -unitttest color.d Further Info There is an existing pull request which adds a command line option to workaround this problem which may be relevant, though I am not sure where the "recursive" elements comes in. https://github.com/D-Programming-Language/dmd/pull/3708 I think this bug demonstrates a valid use case.
Comment #1 by yebblies — 2015-05-09T16:30:27Z
I've hit this same issue, and considered posting about it on that pull request. But I'm pretty sure the real problem here is that EnumMembers instantiates with the list[1..$] pattern when it has other options.
Comment #2 by simen.kjaras — 2015-05-10T14:09:17Z
(In reply to yebblies from comment #1) > I've hit this same issue, and considered posting about it on that pull > request. But I'm pretty sure the real problem here is that EnumMembers > instantiates with the list[1..$] pattern when it has other options. EnumMembers is one problem, and is easily solved with divide-and-conquer, as used in staticMap, allSatisfy and a few other functions in std.typetuple. The problem is NoDuplicates. EraseAll (called by NoDuplicates) can also be divided and conquered, but I see no way to make NoDuplicates anything other than O(N). It could test for the first ten elements instead of just the first one, thus effectively increasing the max list size by a factor of 10, but then people will come asking why we don't support enums of 5000+ elements.
Comment #3 by simen.kjaras — 2015-05-11T20:29:07Z
Implemented changes discussed here, in pull 3275: https://github.com/D-Programming-Language/phobos/pull/3275
Comment #4 by andrei — 2016-12-23T21:26:08Z
Could compile quickly with the current dmd.