On 2/24/20 12:31 PM, H. S. Teoh wrote:
On Mon, Feb 24, 2020 at 10:41:16AM -0500, Steven Schveighoffer via 
Digitalmars-d-announce wrote:
[...]
I will also note that we did something very similar with
switch(string), where prior to this the compiler did all the "heavy
lifting" of generating the code to convert strings into integers. Now
it's done via a template which accepts all the strings as parameters.
I don't think it was a bad change, and I'm sure it increased compile
times and compiler memory usage.

No kidding, at one point it was making Phobos uncompilable except for
machines with huge gobs of RAM, because std.datetime had this gigantic
switch statement over, like, *every* locale name that exists in the
world, and it was causing a gigantic explosion of template bloat. I
think the solution that was eventually adopted was to replace that
switch with something else, which is not altogether a bad thing I
suppose, but still, it does put to question the practicality of having a
template generate code for a switch statement with >1000 string items.

The solution was to forward templates over a certain number of string elements to a single runtime function with an array created from the tuple list (which is a minimal wrapper) instead of a binary search via unrolled templates: https://github.com/dlang/druntime/blob/87bf88ba88d2926d7a470b5e126e0a5b1a1e266f/src/core/internal/switch_.d#L60-L73. It's unfortunate we even have to use CTFE to generate the immutable strings.

I wouldn't imagine a much different approach for this proposal as well -- convert to something useful at runtime and then call a runtime-only implementation.

As I said before, if we can make it so such "wrappers" are just forwarders, it would make the resulting code less bloated, and probably save on memory as well.

-Steve
  • DIP 1027---String Interpol... Mike Parker via Digitalmars-d-announce
    • Re: DIP 1027---String... Adam D. Ruppe via Digitalmars-d-announce
      • Re: DIP 1027---St... Adam D. Ruppe via Digitalmars-d-announce
      • Re: DIP 1027---St... Atila Neves via Digitalmars-d-announce
        • Re: DIP 1027-... Steven Schveighoffer via Digitalmars-d-announce
          • Re: DIP 1... Atila Neves via Digitalmars-d-announce
            • Re: ... Adam D. Ruppe via Digitalmars-d-announce
          • Re: DIP 1... H. S. Teoh via Digitalmars-d-announce
          • Re: DIP 1... Steven Schveighoffer via Digitalmars-d-announce
          • Re: DIP 1... Walter Bright via Digitalmars-d-announce
            • Re: ... Adam D. Ruppe via Digitalmars-d-announce
              • ... 12345swordy via Digitalmars-d-announce
              • ... Walter Bright via Digitalmars-d-announce
                • ... Adam D. Ruppe via Digitalmars-d-announce
                • ... aliak via Digitalmars-d-announce
                • ... Steven Schveighoffer via Digitalmars-d-announce
                • ... Adam D. Ruppe via Digitalmars-d-announce
            • Re: ... Steven Schveighoffer via Digitalmars-d-announce
              • ... Walter Bright via Digitalmars-d-announce

Reply via email to