Standalone AA implementation ready for review (Was: Re: Replacing AA's in druntime)

Steven Schveighoffer schveiguy at yahoo.com
Thu Mar 15 12:47:19 PDT 2012


On Thu, 15 Mar 2012 14:11:11 -0400, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> On 3/15/12 12:39 PM, Steven Schveighoffer wrote:
>> On Thu, 15 Mar 2012 13:24:24 -0400, Andrei Alexandrescu
>> <SeeWebsiteForEmail at erdani.org> wrote:
>>> Template function takes over, does whatever is necessary, such as
>>> possibly conversion to varargs.
>>
>> Right, but with a template:
>>
>> [1:1]
>> [1:1, 2:2]
>>
>> become two separate template instantiations, but with something that
>> just takes two arrays, it's only one template, no matter how many
>> elements you are initializing with.
>
> I guess I should ask this then: why is instantiating a template function  
> a problem?

1. non-inlined functions (dmd doesn't inline by default) result in extra  
calls.
2. I think even if it's inlined, dmd generates a function and sticks it in  
the object file, which will never be called. (bloat).  I'm not sure if  
anything else is put into the binary, or if the function is optimized out  
on linking.

> Off the top of my head it changes the order of evaluation in the general  
> case (or complicates code generation if left-to-right preservation is  
> needed). Also the constructor needs to be @trusted because references to  
> static arrays can't escape in safe code. All workable matters, but  
> generally I prefer migrating cleverness from code generation into  
> library code.

All good points.  One thing to be sure, given the fact that this is one  
hook implemented in one location, it should be easy to fix later if we use  
a bad approach.

Perhaps the best way to address my concerns are to fix how unused  
templates are included in the binary.  I could also be wrong about that.

-Steve


More information about the Digitalmars-d mailing list