DIP 1027---String Interpolation---Format Assessment

Steven Schveighoffer schveiguy at gmail.com
Mon Feb 24 18:15:54 UTC 2020

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: 
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 

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.


More information about the Digitalmars-d-announce mailing list