[cxx-abi-dev] Mangling C++0x Lambdas
David Vandevoorde
daveed at edg.com
Wed Dec 17 16:46:16 UTC 2008
On Dec 17, 2008, at 11:40 AM, Doug Gregor wrote:
> On Wed, Dec 17, 2008 at 8:28 AM, David Vandevoorde <daveed at edg.com>
> wrote:
>>
>> On Dec 17, 2008, at 11:17 AM, Doug Gregor wrote:
>>
>>> On Wed, Dec 17, 2008 at 8:00 AM, David Vandevoorde
>>> <daveed at edg.com> wrote:
>>>>
>>>> On Dec 17, 2008, at 10:39 AM, John Freeman wrote:
>>>>
>>>>> Doug Gregor wrote:
>>>>>>
>>>>>> We need something that encodes the context of the lambda
>>>>>> (function
>>>>>> "::foo" with no parameters) followed by, perhaps, a numbering
>>>>>> scheme
>>>>>> within that context. The context encoding needs to account for
>>>>>> (at
>>>>>> least) inline functions, classes, and namespaces.
>>>>>>
>>>>>
>>>>> This sounds like a problem that must have been encountered
>>>>> before. Is
>>>>> there already a solution for it? At least for the unnumbered
>>>>> portion?
>>>>
>>>>
>>>> Yes, see 5.1.6. We can reuse that general scheme for local
>>>> lambdas.
>>>> E.g.:
>>>>
>>>> <local-lambda-name> := Z <function encoding> E l
>>>> [<discriminator>]
>>>>
>>>> and maybe introduce something similar for local unnamed classes:
>>>>
>>>> <local-unnamed-class_name> := Z <function encoding> E u
>>>> [<discriminator>]
>>>>
>>>>
>>>> A tougher problem are namespace-scope lambdas (e.g., in
>>>> initializers or
>>>> default arguments).
>>>
>>> In an initializer, we could mangle the name of the entity being
>>> initialized (and then a counter, in case there are multiple
>>> lambdas in
>>> the initializer).
>>
>>
>> I'm not sure that we need to deal with the initializer case at all,
>> because
>> I _think_ that such a lambda would only be referenced internally.
>
> struct X {
> template <typename Lambda> X(Lambda);
> };
>
> X x = [](int x) -> int { return x; };
>
> We'll need to mangle X's constructor with the name of the lambda.
But that call and construct is internal to whatever TU x is defined
in, no?
(If x were itself a temploid instance, the constructor would have to
go in its comdat section, I suppose.)
>>> In a default argument, we could mangle it as if it's part of the
>>> entity where the default argument lives (in a function or template).
>>
>>
>> I believe it would require a different code from the entities local
>> to that
>> function/template, though (since the the two might not coexist in
>> the same
>> translation unit).
>
> Ah, right. So we need to have a separate mangling scheme and counter
> for the default arguments and for the entities local to that
> function/template.
Right.
>> I'm concerned that there might be other contexts where there isn't a
>> "top-level" entity to key off from. For example, explicit template
>> instantiations are such a context.
>
> Oh, yuck.
If that's how we feel, we must be on the right path ;-)
Daveed
More information about the cxx-abi-dev
mailing list