On 5/19/16 9:45 AM, Andrei Alexandrescu wrote:
On 05/19/2016 08:38 AM, Steven Schveighoffer wrote:
Yep. chain uses voldemort type, map does not.

We definitely need to fix Voldemort types. Walter and I bounced a few
ideas during DConf.

1. Do the cleartext/compress/hash troika everywhere (currently we do it
on Windows). That should help in several places.

2. For Voldemort types, simply generate a GUID-style random string of
e.g. 64 bytes. Currently the name of the type is composed out of its
full scope, with some exponentially-increasing repetition of substrings.
That would compress well, but it's just a lot of work to produce and
then compress the name. A random string is cheap to produce and adequate
for Voldemort types (you don't care for their name anyway...
Voldemort... get it?).

I very much advocate slapping a 64-long random string for all Voldermort
returns and calling it a day. I bet Liran's code will get a lot quicker
to build and smaller to boot.

This may be crazy, but I solved this problem by simply moving the struct outside the function. What about a lowering that does this for you?

Example:

auto foo(T)(T t) if (someConstraints)
{
   static struct Result
   {
      T t;
   }
   return Result(t);
}

Changes to:

private struct foo_Result(T) if (someConstraints)
{
   T t;
}

auto foo(T)(T t) if (someConstraints)
{
   alias Result = foo_Result!T // inserted by compiler
   return Result(t);
}

Or even better:

template(T) foo if (someConstraints)
{
   struct Result
   {
      T t;
   }

   auto foo(T t)
   {
      return Result(t);
   }
}

What this does is lower the number of times the template parameters (and function arguments) appears in the type name to 1. This gets rid of the exponential nature of the symbol name.

This doesn't work for voldemorts with closures, but maybe it can somehow be reconstructed so the context is included in the generated struct.

-Steve

Reply via email to