Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Number:

GEP-10

Title:

Static compilation

Version:

3

Type:

Feature

Status:

Draft

Leader:

Cédric Champeau

Created:

2011-11-23

Last modification:

2012-0206-21

Abstract: Static compilation

...

The alternative implementation is not to rely on inferred types, but rather behave exactly like Java does. The main advantage of this is that the user doesn't have 3 distinct method dispatch modes to understand, like in the previous solution (Java, dynamic Groovy, inferred static Groovy). The major drawback is that the semantics of static Groovy are not close to the ones of dynamic Groovy. For this reason, this is not the preferred experimental implementation. If you think this version should be preferred, do not hesitate to send an email to the mailing list so that we can discuss. You can even fork the current implementation to provide your own.

Development branch

...

Testing

Static compilation is now part of the Groovy 2.0.0 -beta-3, the experimental compiler branch will be merged into master.

Testing

Alternatively, using Groovy 2.0.0-beta-2, you can download the attached jar and add it to your classpath to activate the @CompileStatic annotation. Note that you must use groovy.jar (not groovy-all.jar) and the additional jar with the annotation must be first in the classpath, because it overwrites classes from standard Groovy. Currently, the experimental compiler only supports annotations at the method level.

@CompileStatic

Static compilation is for the moment only supported at the method level (do not try to add it to a class) and supports direct method calls as long as you do not:

  • use methods from DefaultGroovyMethods
  • use "indirect" methods like list << obj where the AST representation is not a method call but a binary expression

For example, you release. You can download the latest Groovy 2 releases and test it.

@CompileStatic

You can try the following snippet :

Code Block
@groovy.transform.CompileStatic
int fib(int i) {
    i < 2 ? 1 : fib(i - 2) + fib(i - 1)
}

...