On Friday, 25 March 2016 at 18:20:12 UTC, Steven Schveighoffer
wrote:
On 3/25/16 12:18 PM, H. S. Teoh via Digitalmars-d wrote:
On Fri, Mar 25, 2016 at 11:40:11AM -0400, Steven Schveighoffer
via Digitalmars-d wrote:
On 3/25/16 11:07 AM, Andrei Alexandrescu wrote:
On 3/25/16 10:07 AM, Steven Schveighoffer wrote:
We should actually be moving *away from* voldemort types:
https://forum.dlang.org/post/[email protected]
Has this bug been submitted? -- Andrei
I'm not sure it's a bug that can be fixed. It's caused by the
design
of the way template name mangling is included.
I can submit a general "enhancement", but I don't know what
it would
say? Make template mangling more efficient? :)
I suppose having a bug report with a demonstration of why we
should
change it is a good thing. I'll add that.
[...]
We've been talking about compressing template symbols a lot
recently,
but there's a very simple symbol size reduction that we can do
right
now: most of the templates in Phobos are eponymous templates,
and under
the current mangling scheme that means repetition of the
template name
and the eponymous member in the symbol. My guess is that most
of the 4k
symbol bloats come from eponymous templates. In theory, a
single
character (or something in that vicinity) ought to be enough
to indicate
an eponymous template. That should cut down symbol size
significantly
(I'm guessing about 30-40% reduction at a minimum, probably
more in
practice) without requiring a major overhaul of the mangling
scheme.
I don't think it's that simple. For example:
auto foo(T)(T t)
Needs to repeat T (whatever it happens to be) twice -- once for
the template foo, and once for the function parameter. If foo
returns an internally defined type that can be passed to foo:
x.foo.foo.foo.foo
Each nesting multiplies the size of the symbol by 2 (at least,
maybe even 3). So it's exponential growth. Even if you compress
it to one character, having a chain of, say, 16 calls brings
you to 65k characters for the symbol. We need to remove the
number of times the symbol is repeated, via some sort of
substitution.
Added the bug report. Take a look and see what you think.
https://issues.dlang.org/show_bug.cgi?id=15831
-Steve
These repetitions could be eliminated relatively easily (from a
user's perspective, anyway; things might be more difficult in the
actual implementation).
Two changes to the mangling:
1) `LName`s of length 0 (which currently cannot exist) mean to
repeat the previous `LName` of the current symbol.
2) N `Number` is added as a valid `Type`, meaning "Type Back
Reference". Basically, all instances of a
struct/class/interface/enum type in a symbol's mangling get
counted (starting from zero), and subsequent instances of that
type can be referred to by N0, N1, N2, etc.
So given:
```
module mod;
struct Foo;
Foo* func(Foo* a, Foo* b);
```
`func` currently mangles as:
_D3mod4funcFPS3mod3FooPS3mod3FooZPS3mod3Foo
It would instead be mangled as:
_D3mod4funcFPS3mod3FooPN0ZPN0
Nested templates declarations would get numbered depth first as
follows:
S7!(S2!(S0, S1), S6!(S3, S5!(S4)))
I have another idea for reducing the byte impact of template
string value parameters, but it is a bit more complicated and I
need to finish de-bugging and optimizing some code to make sure
it will work as well as I think. I'll post more on that soon, I
suspect.