[dmd-internals] Type mangling for deduced attributes

kenji hara k.hara.pg at gmail.com
Thu Nov 17 02:09:47 PST 2011


Withdraw a previous statement, I still argue that is better to apply
result of inference into mangleof.
First of all, the pure/safe/nothrow inference runs against only
function literals and template functions.For function literal, its
type determines in the place its written.For template function, its
type determines in its instantiation.Both of cases can always see
their function bodies. Then the problem that Don said never comes.
And second, see following description of an issue that I found.
alias typeof({}) D;static if (is(typeof({}) X == delegate)) alias X
F;pragma(msg, F.mangleof);	// (1)pragma(msg, D.mangleof);	// (2)
In dmd2.057head, #1 prints "FZv", and #2 prints "DFNaNbNfZv"It is
definitely inconsistent.(From this fact, I was convinced that
separating inference result from the type is much difficult.)
Do you think it should do? If we select the conservative strategy,
that Don and Walter agree, D.mangleof should return "DFZv".But, the
decision will break existing codes, like std.exception.enforce.
T enforce(T, Dg : void delegate())(T, scope Dg dg){ ... }
Now this template function supports pure/safe/nothrow attributes that
depends on the Dg type.But the conservative decision will make the
deduction result of Dg in the following calling,
enforce(condtion, { ; })
as which the type of delegate literal is 'void delegate()' because the
type inference does not apply into type.And we'll never use enforce in
pure/nothrow/safe function with delegate literal argument.
As the end of second, F.mangleof should return "FNaNbNfZv", and
D.mangleof should return "DFNaNbNfZv".
>From the above description, I think that applying the inference result
into "mangleof" property (and the type) is the best way.
Kenji Hara

2011/11/17 Don Clugston <dclugston at googlemail.com>:
> On 17 November 2011 09:03, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
>> On Thursday, November 17, 2011 07:51:24 Rainer Schuetze wrote:
>>> On 16.11.2011 15:35, Steve Schveighoffer wrote:
>>> > Take this argument with a grain of salt, I have very little internal
>>> > dmd knowledge.  But...
>>> >
>>> > Isn't deduction of pure/nothrow/safe restricted to templates?  Don't
>>> > templates *require* availability of source?
>>> >
>>> > Just saying...
>>> >
>>> > -Steve
>>>
>>> I think it would be an unexpected restricton to limit pure/nothrow/safe
>>> inference to templates. But if it is not, using di files instead of d
>>> files will break code because inference very much depends on whether the
>>> di-file generation emitted the code or not. Adding inferred attributes
>>> to  the function declarations could help but it currently changes the
>>> name mangling, breaking it again.
>>
>> It's _already_ restricted to templates and delegates. You _need_ it for
>> templates, since whether they can be pure, nothrow, or @safe depends on their
>> arguments, and the only way to do that without inference is to duplicate the
>> template a bunch of times with each possible combination of pur,e nothrow, and
>> @safe. Normal functions, however, do _not_ need the inference. Whether they
>> can be pure, nothrow, or @safe doesn't change unless you change according to
>> their arguments.
>>
>> In any case, I don't quite understand how this is an issue, since as Steve
>> says, templates _require_ that their source be available.
>
> Inference doesn't apply only to templates. It applies also to
> delegate/function literals, and to function pointers.
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals
>


More information about the dmd-internals mailing list