https://issues.dlang.org/show_bug.cgi?id=15831

--- Comment #1 from Anon 
<3g5o3v+4kzxpixqyfgsicckylm60badawevzw9upy4e1qrrcmdizcxk734n0...@spam4.me> ---
As I posted on the newsgroup, I would suggest the following 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.

Given:

```
module mod;
struct Foo;
Foo* func(Foo* a, Foo* b);
```

`func` currently mangles as:
_D3mod4funcFPS3mod3FooPS3mod3FooZPS3mod3Foo

It would instead mangle as:
_D3mod4funcFPS3mod3FooPN0ZPN0

Nested template declarations would get numbered depth first as follows:

S7!(S2!(S0, S1), S6!(S3, S5!(S4)))

This, on its own, won't eliminate the recursive expansion bloat, but (based on
manual experiments I've now done), takes foo's mangled name length almost
linear with respect to the number of recursions:

Recursive calls to s() before x.foo :  1 |  2 |   3 |   4 |   5
Current mangle length of foo (bytes): 39 | 90 | 192 | 397 | 807 
Same, with proposed mangling changes: 38 | 64 |  90 | 116 | 148

As I said on the newsgroup, I have another idea relating to template string
value mangling, but that is only tangentially related to this bug (in that both
reducing mangle bloat). I'll post that separately once it is ready.

--

Reply via email to