"temporary" templates
FeepingCreature
feepingcreature at gmail.com
Wed Nov 27 08:45:55 UTC 2019
On Tuesday, 26 November 2019 at 18:59:26 UTC, Paul Backus wrote:
> On Tuesday, 26 November 2019 at 18:45:35 UTC, Adam D. Ruppe
> wrote:
>> On Tuesday, 26 November 2019 at 18:35:42 UTC, Stefan Koch
>> wrote:
>>> In _general_ it's not possible to categorize a template as
>>> being temporary or not.
>>> For language semantic reasons it is a requirement for every
>>> re-instantiated template to forward to exactly the same
>>> symbol as was generated during the first instantiation.
>>
>> What if it kept *just* the symbol, but discarded its innards
>> when under memory pressure, then could regenerate them if
>> evaluated again?
>
> This will cause compilation to become non-deterministic, since
> the result of template evaluation can depend on the order in
> which declarations are semantically analyzed:
>
...
Snapshot the lexical environment at the point of instantiation?
Could make namespaces linked list of arrays so you can
copy-on-write them for relatively cheap. Compilation is pure
enough that this should be sufficient.
Imo templates are mostly split into two halves: large templates
that are usually evaluated once with the same parameters, and
small templates that are evaluated repeatedly with the same
parameters. So a logic of "discard template contents beyond a
certain cutoff size" should already do it.
And of course, mixin templates don't need to save anything
because they're always reevaluated anyways.
More information about the Digitalmars-d
mailing list