Thread overview
TypeTuple ABI mangling
Jul 26, 2014
Iain Buclaw
Jul 26, 2014
Iain Buclaw
Jul 26, 2014
Dicebot
Jul 27, 2014
H. S. Teoh
Jul 27, 2014
Iain Buclaw
Jul 27, 2014
Iain Buclaw
Jul 27, 2014
Iain Buclaw
Jul 27, 2014
Iain Buclaw
July 26, 2014
Hi,

TypeTuples have a special mangling convention in the compiler.

As per the docs (ref: http://dlang.org/abi.html)

TypeTuple:
    B Number Arguments


However after some cursory tests, it seems that the most obvious examples of, passing a tuple via parameters, returning a tuple, declaring a tuple variable, etc... all get lowered before mangling.

So at first glance, this mangling convention is redundant.

Unless of course someone can post an example which triggers mangling of TypeTuples...

Regards
Iain.
July 26, 2014
On Saturday, 26 July 2014 at 19:44:49 UTC, Iain Buclaw wrote:
> Hi,
>
> TypeTuples have a special mangling convention in the compiler.
>
> As per the docs (ref: http://dlang.org/abi.html)
>
> TypeTuple:
>     B Number Arguments
>
>
> However after some cursory tests, it seems that the most obvious examples of, passing a tuple via parameters, returning a tuple, declaring a tuple variable, etc... all get lowered before mangling.
>
> So at first glance, this mangling convention is redundant.
>
> Unless of course someone can post an example which triggers mangling of TypeTuples...
>

NB. This is purely for the purpose of demangling in binutils.
July 26, 2014
On Saturday, 26 July 2014 at 19:44:49 UTC, Iain Buclaw wrote:
> Hi,
>
> TypeTuples have a special mangling convention in the compiler.
>
> As per the docs (ref: http://dlang.org/abi.html)
>
> TypeTuple:
>     B Number Arguments

This is.. funny. Type tuples don't really have ABI, they don't even have .sizeof - any usage where expansion is meaningless results in compile-time error afaik. No idea what this may mean :O
July 27, 2014
On Sat, Jul 26, 2014 at 07:44:47PM +0000, Iain Buclaw via Digitalmars-d wrote:
> Hi,
> 
> TypeTuples have a special mangling convention in the compiler.
> 
> As per the docs (ref: http://dlang.org/abi.html)
> 
> TypeTuple:
>     B Number Arguments
> 
> 
> However after some cursory tests, it seems that the most obvious examples of, passing a tuple via parameters, returning a tuple, declaring a tuple variable, etc... all get lowered before mangling.
> 
> So at first glance, this mangling convention is redundant.
> 
> Unless of course someone can post an example which triggers mangling of TypeTuples...
[...]

Huh, interesting. I tried various wrapping/unwrapping tricks and passing things via alias parameters, but none of them triggered TypeTuple mangling. Either I missed something obvious, or perhaps this mangling is never actually emitted? Not sure.


T

-- 
It won't be covered in the book. The source code has to be useful for something, after all. -- Larry Wall
July 27, 2014
On 26 July 2014 21:06, H. S. Teoh via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> On Sat, Jul 26, 2014 at 07:44:47PM +0000, Iain Buclaw via Digitalmars-d wrote:
>> Hi,
>>
>> TypeTuples have a special mangling convention in the compiler.
>>
>> As per the docs (ref: http://dlang.org/abi.html)
>>
>> TypeTuple:
>>     B Number Arguments
>>
>>
>> However after some cursory tests, it seems that the most obvious examples of, passing a tuple via parameters, returning a tuple, declaring a tuple variable, etc... all get lowered before mangling.
>>
>> So at first glance, this mangling convention is redundant.
>>
>> Unless of course someone can post an example which triggers mangling of TypeTuples...
> [...]
>
> Huh, interesting. I tried various wrapping/unwrapping tricks and passing things via alias parameters, but none of them triggered TypeTuple mangling. Either I missed something obvious, or perhaps this mangling is never actually emitted? Not sure.
>

I've tried something similar using D1 too, and get the same results.

I'd be willing to do an experiment and remove TypeTuple mangling from the language by force and see what ICE's.
July 27, 2014
On 27 July 2014 00:20, Iain Buclaw <ibuclaw@gdcproject.org> wrote:
> On 26 July 2014 21:06, H. S. Teoh via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
>> On Sat, Jul 26, 2014 at 07:44:47PM +0000, Iain Buclaw via Digitalmars-d wrote:
>>> Hi,
>>>
>>> TypeTuples have a special mangling convention in the compiler.
>>>
>>> As per the docs (ref: http://dlang.org/abi.html)
>>>
>>> TypeTuple:
>>>     B Number Arguments
>>>
>>>
>>> However after some cursory tests, it seems that the most obvious examples of, passing a tuple via parameters, returning a tuple, declaring a tuple variable, etc... all get lowered before mangling.
>>>
>>> So at first glance, this mangling convention is redundant.
>>>
>>> Unless of course someone can post an example which triggers mangling of TypeTuples...
>> [...]
>>
>> Huh, interesting. I tried various wrapping/unwrapping tricks and passing things via alias parameters, but none of them triggered TypeTuple mangling. Either I missed something obvious, or perhaps this mangling is never actually emitted? Not sure.
>>
>
> I've tried something similar using D1 too, and get the same results.
>
> I'd be willing to do an experiment and remove TypeTuple mangling from the language by force and see what ICE's.

I changed Ttuple = 'B' to Ttuple = '@' and waited for assembly errors to happen.

Finally got them when compiling std.outbuffer unittests.

Reducing....
July 27, 2014
On 27 July 2014 08:14, Iain Buclaw <ibuclaw@gdcproject.org> wrote:
> On 27 July 2014 00:20, Iain Buclaw <ibuclaw@gdcproject.org> wrote:
>> On 26 July 2014 21:06, H. S. Teoh via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
>>> On Sat, Jul 26, 2014 at 07:44:47PM +0000, Iain Buclaw via Digitalmars-d wrote:
>>>> Hi,
>>>>
>>>> TypeTuples have a special mangling convention in the compiler.
>>>>
>>>> As per the docs (ref: http://dlang.org/abi.html)
>>>>
>>>> TypeTuple:
>>>>     B Number Arguments
>>>>
>>>>
>>>> However after some cursory tests, it seems that the most obvious examples of, passing a tuple via parameters, returning a tuple, declaring a tuple variable, etc... all get lowered before mangling.
>>>>
>>>> So at first glance, this mangling convention is redundant.
>>>>
>>>> Unless of course someone can post an example which triggers mangling of TypeTuples...
>>> [...]
>>>
>>> Huh, interesting. I tried various wrapping/unwrapping tricks and passing things via alias parameters, but none of them triggered TypeTuple mangling. Either I missed something obvious, or perhaps this mangling is never actually emitted? Not sure.
>>>
>>
>> I've tried something similar using D1 too, and get the same results.
>>
>> I'd be willing to do an experiment and remove TypeTuple mangling from the language by force and see what ICE's.
>
> I changed Ttuple = 'B' to Ttuple = '@' and waited for assembly errors to happen.
>
> Finally got them when compiling std.outbuffer unittests.
>
> Reducing....


Ah ha!  D-style native varargs use them!

void printf(...) { }
void main()
{
    printf;    // printf(_arguments_typeinfo);
}

Here, the _arguments_typeinfo is a TypeInfo_Tuple.

Regards
Iain.
July 27, 2014
On 27 July 2014 08:22, Iain Buclaw <ibuclaw@gdcproject.org> wrote:
> On 27 July 2014 08:14, Iain Buclaw <ibuclaw@gdcproject.org> wrote:
>> On 27 July 2014 00:20, Iain Buclaw <ibuclaw@gdcproject.org> wrote:
>>> On 26 July 2014 21:06, H. S. Teoh via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
>>>> On Sat, Jul 26, 2014 at 07:44:47PM +0000, Iain Buclaw via Digitalmars-d wrote:
>>>>> Hi,
>>>>>
>>>>> TypeTuples have a special mangling convention in the compiler.
>>>>>
>>>>> As per the docs (ref: http://dlang.org/abi.html)
>>>>>
>>>>> TypeTuple:
>>>>>     B Number Arguments
>>>>>
>>>>>
>>>>> However after some cursory tests, it seems that the most obvious examples of, passing a tuple via parameters, returning a tuple, declaring a tuple variable, etc... all get lowered before mangling.
>>>>>
>>>>> So at first glance, this mangling convention is redundant.
>>>>>
>>>>> Unless of course someone can post an example which triggers mangling of TypeTuples...
>>>> [...]
>>>>
>>>> Huh, interesting. I tried various wrapping/unwrapping tricks and passing things via alias parameters, but none of them triggered TypeTuple mangling. Either I missed something obvious, or perhaps this mangling is never actually emitted? Not sure.
>>>>
>>>
>>> I've tried something similar using D1 too, and get the same results.
>>>
>>> I'd be willing to do an experiment and remove TypeTuple mangling from the language by force and see what ICE's.
>>
>> I changed Ttuple = 'B' to Ttuple = '@' and waited for assembly errors to happen.
>>
>> Finally got them when compiling std.outbuffer unittests.
>>
>> Reducing....
>
>
> Ah ha!  D-style native varargs use them!
>
> void printf(...) { }
> void main()
> {
>     printf;    // printf(_arguments_typeinfo);
> }
>
> Here, the _arguments_typeinfo is a TypeInfo_Tuple.
>

Inspecting the resultant mangled identifier itself though, the tuple part will never get demangled.

_D15TypeInfo_B4iiii6__initZ

Meaning that I'm back at demangling tuple being pointless because it will never be reached.