<p dir="ltr"><br>
On Sep 19, 2015 11:31 PM, "Richard Smith" <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br>
><br>
> On Sat, Sep 19, 2015 at 8:33 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
>><br>
>> On Sat, Sep 19, 2015 at 8:15 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br>
>>><br>
>>> On Sat, Sep 19, 2015 at 6:15 PM, David Blaikie via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br>
>>>><br>
>>>> I was just thinking through the possible advice of encouraging users to use explicit template instantiation declarations/definitions to reduce object size.<br>
>>>><br>
>>>> It seems this may hurt performance in non-LTO builds by causing what were inlinable functions to no longer be available for inlining.<br>
>>>><br>
>>>> Should we consider emitting available_externally definitions of such entities (possibly under specific/higher optimization levels)?<br>
>>><br>
>>><br>
>>> We should, and we already do: <a href="http://goo.gl/V8G5kU">http://goo.gl/V8G5kU</a><br>
>>><br>
>>> Do you have a case where we fail to do so? It's possible there's a bug in this determination.<br>
>><br>
>><br>
>> Sorry, yes, should've included my test case, which boiled down to:<br>
>><br>
>> template <typename T> void f() {}<br>
>> extern template void f<int>(); <br>
>> void g() { f<int>(); } <br>
>><br>
>> The difference being the absence of the "inline" keyword on f's definition. I wonder if that's the right tradeoff (I can understand using the inline keyword to hint the inliner a little more strongly - but this seems like a much stronger dependence on the keyword than I'd expect). Perhaps it is.<br>
><br>
><br>
> The C++ standard doesn't permit us to instantiate f<int> in this case; per [temp.explicit]/10,<br>
><br>
> "Except for inline functions, declarations with types deduced from their initializer or return value (7.1.6.4), const variables of literal types, variables of reference types, and class template specializations, explicit instantiation declarations have the effect of suppressing the implicit instantiation of the entity to which they refer."<br>
><br>
> So whether or not this is the right tradeoff, it's not our call to make. We emit function definitions available_externally in (more or less) all the cases that C++ lets us do so.</p>
<p dir="ltr">Ah, ok - that simplifies things at least. Thanks for the explanation, examples, etc.</p>
<p dir="ltr">(I wonder about as-if opportunities, but can chat about that over lunch or something, as I'm sure there aren't any and I'll just need to wrap my head around why)</p>