[Dune-devel] Explicit template instantiation

Carsten Gräser graeser at mi.fu-berlin.de
Wed Feb 17 13:04:30 CET 2021


Am 16.02.21 um 23:53 schrieb Simon Praetorius:
>> Maybe this could be done in an opt-in fashion:
>>
>> * Do not use `extern template` in the header.
>> * Do some documented explicit instantiation in the library.
>> * Users may (but don't have to) prohibit implicit instantiation
>>   by using `extern template ...` in their application after
>>   including the header. For sure this can only be done for
>>   those well-documented instantiations contained in the lib.
>> * If the user does not use `extern template ...` she will
>>   get implicit instantiation as usual.
> 
> I don't know what is the best way to go. But I'm afraid that not
> writing the "extern termplate" in the headers would be more
> irritating than helping. We would just gain longer compile times for
> the libraries - not the opposite. And then the explicit instantiation
I don't understand this argument:

* If the template was implicitly instantiated in the library before,
   doing it explicitly now should not increase library build time.
* If the template was not implicitly instantiated in the library before,
   you must instantiate it explicitly now, which increases library build
   time. Otherwise you can't use it downstream. At some place you have
   to do the instantiation. The whole purpose of the proposal seems to
   be, to move this cost upward in the build hierarchy in order to prevent
   paying it multiple times downstream.

> (with prevented implicit instantiation) would mostly not be used. But
> it is something very positive for the user. I think just "well
> documentation" is not enough.
If there is some performance penalty, introducing this silently
is IMO a no-go. Hence I would prefer an opt-in approach.
An alternative to the fully manual approach I proposed before,
would be to provide a single header (per module) with all the
`extern template...` declarations for the instances contained
in the library. Then the user can opt-in by including this header.

Best,
Carsten




More information about the Dune-devel mailing list