freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Dekany (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (FREEMARKER-60) Document interaction between lazy import and #global
Date Fri, 30 Jun 2017 16:55:00 GMT

    [ https://issues.apache.org/jira/browse/FREEMARKER-60?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16070390#comment-16070390
] 

Daniel Dekany edited comment on FREEMARKER-60 at 6/30/17 4:54 PM:
------------------------------------------------------------------

Since the imported template is not executed at all until something accesses a namespace member
(in fact, might not even loaded until that), it's not a special case. We can add some notices
about that, but I think it's not a surprising behavior.

As of disqualifying templates based on what they do, the main problem there is that nothing
can be told about the content of an imported template until it was actually loaded (or get
from the cache), so if laziness depends on template content, then all lazy imports has to
be loaded (even if not executed), which is of course makes laziness less useful. Even if you
have the {{Template}}, it can't be reliably detected if something will create global variables,
partly because of {{#include}} and {{?interpret}}, which are only resolved during execution.
Also it's not entirely sure that not creating global variables is a problem before the imported
namespace is used. Also imports can do other things with side effects, like create HTTP request
attributes, call into other imports that might have a global effect, etc. So I think only
explicit disqualification could work, where you specify in the {{Configuration}} that if the
template's lookup name (not even the source name) matches certain pattern then it can't be
lazy imported.




was (Author: ddekany):
Since the imported template is not executed at all until something accesses a namespace member,
it's not a special case. We can add some notices about that, but I think it's not a surprising
behavior.

As of disqualifying templates based on what they do, the main problem there is that nothing
can be told about the content of an imported template until it was actually loaded (or get
from the cache), so if laziness depends on template content, then all lazy imports has to
be loaded (even if not executed), which is of course makes laziness less useful. Even if you
have the {{Template}}, it can't be reliably detected if something will create global variables,
partly because of {{#include}} and {{?interpret}}, which are only resolved during execution.
Also it's not entirely sure that not creating global variables is a problem before the imported
namespace is used. Also imports can do other things with side effects, like create HTTP request
attributes, call into other imports that might have a global effect, etc. So I think only
explicit disqualification could work, where you specify in the {{Configuration}} the templates
lookup name (not even the source name) matches certain pattern can't be lazy imported.



> Document interaction between lazy import and #global
> ----------------------------------------------------
>
>                 Key: FREEMARKER-60
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-60
>             Project: Apache Freemarker
>          Issue Type: Improvement
>          Components: documentation
>    Affects Versions: 2.3.26-incubating
>            Reporter: Jasper Rosenberg
>            Priority: Trivial
>
> If I am understanding what is going on correctly, it appears that when you turn on lazy
imports, #global variables defined in that file will not be defined unless something else
first accesses the imported file's namespace.  This is a bit of a weird case so it might just
be worth documenting.
> Alternatively, you could say that if you have #global variables defined in a file it
disqualifies it from being lazily imported.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message