Scott Murphy Heiberg created GROOVY-12841:
---------------------------------------------

             Summary: Javadoc of CompilerConfiguration.CLOSURE_PACKING and 
@PackedClosures says the flag packs only @CompileStatic closures
                 Key: GROOVY-12841
                 URL: https://issues.apache.org/jira/browse/GROOVY-12841
             Project: Groovy
          Issue Type: Bug
          Components: Documentation
    Affects Versions: 6.0.1, 6.0.0
            Reporter: Scott Murphy Heiberg


CompilerConfiguration.CLOSURE_PACKING is documented as

{quote}
System-property name for the GEP-27 incubating option that automatically packs 
provably-safe @CompileStatic closures (hoisting their bodies to a shared 
adapter instead of a class).
{quote}

and the Javadoc of groovy.transform.PackedClosures says "Automatic packing of 
provably-safe @CompileStatic closures — without this annotation — is available 
behind the groovy.target.closure.pack flag".

With the property set, dynamically compiled closures are packed too when their 
body has no free name:

{code:groovy}
class Dyn {
    static void main(String[] args) {
        Closure c = { String s -> s.length() }
        println c.getClass().name
    }
}
{code}

{noformat}
$ java -Dgroovy.target.closure.pack=true -cp groovy-6.0.1.jar 
groovy.ui.GroovyMain Dyn.groovy
org.codehaus.groovy.runtime.PackedClosure$Fixed1
{noformat}

The behaviour is intended: ClosureWriter#isPackTriggered packs a dynamic 
closure that isSyntacticallyDelegateIndependent ("GROOVY-12151 dynamic 
syntactic path"), and 
ClosurePackCapabilityTest#dynamicDelegateIndependentClosuresAutoPackBySyntax 
asserts it. The documentation is what is out of date. The first sentence of the 
Javadoc of ClosureWriter#isPackTriggered ("the only trigger is the 
@PackedClosures trust assertion") and the class comment of 
ClosurePackCapabilityTest ("dynamic closures (no static resolution) are never 
auto-packed") say the same outdated thing.

Proposed fix (pull request to follow)

State both subsets in the two public Javadocs: under @CompileStatic, closures 
the type checker resolved without a delegate; under dynamic compilation, 
closures whose body has no free name (no implicit-this call and no name other 
than a parameter or local variable).




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to