[
https://issues.apache.org/jira/browse/GROOVY-11914?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King updated GROOVY-11914:
-------------------------------
Description:
I asked AI what features could be added to Groovy to give it vastly improved
reasoning capabilities of Groovy code. First up it suggested @Modifies
(GROOVY-11909) and the ModifiesChecker (GROOVY-11910). It said a close second
would be a PurityChecker type checking extension. This issue looks at that.
Some basic examples:
{code:groovy}
@TypeChecked(extensions = 'groovy.typecheckers.PurityChecker')
class MathUtils {
@Pure
int square(int x) { x * x } // OK
@Pure
long timestamp() { System.nanoTime() } // ERROR:
non-deterministic
@Pure
int logged(int x) { println("x=$x"); x * 2 } // ERROR: logging
}
{code}
----
*Allowing logging:*
{code:groovy}
@TypeChecked(extensions = 'groovy.typecheckers.PurityChecker(allows:
"LOGGING")')
class Service {
@Pure
int compute(int x) {
println("computing $x") // OK: logging allowed
return x * x
}
@Pure
long getTime() { System.nanoTime() } // ERROR: non-deterministic (not
allowed)
}
{code}
----
*Allowing logging and non-determinism:*
{code:groovy}
@TypeChecked(extensions = 'groovy.typecheckers.PurityChecker(allows:
"LOGGING|NONDETERMINISM")')
class Diagnostics {
@Pure
String snapshot(Map state) {
println("snapshot at ${System.nanoTime()}") // OK: both allowed
return state.toString()
}
}
{code}
was:I asked AI what features could be added to Groovy to give it vastly
improved reasoning capabilities of Groovy code. First up it suggested @Modifies
(GROOVY-11909) and the ModifiesChecker (GROOVY-11910). It said a close second
would be a PurityChecker type checking extension. This issue looks at that.
> Add PurityChecker type checking extension
> -----------------------------------------
>
> Key: GROOVY-11914
> URL: https://issues.apache.org/jira/browse/GROOVY-11914
> Project: Groovy
> Issue Type: New Feature
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
> I asked AI what features could be added to Groovy to give it vastly improved
> reasoning capabilities of Groovy code. First up it suggested @Modifies
> (GROOVY-11909) and the ModifiesChecker (GROOVY-11910). It said a close second
> would be a PurityChecker type checking extension. This issue looks at that.
> Some basic examples:
> {code:groovy}
> @TypeChecked(extensions = 'groovy.typecheckers.PurityChecker')
> class MathUtils {
> @Pure
> int square(int x) { x * x } // OK
> @Pure
> long timestamp() { System.nanoTime() } // ERROR:
> non-deterministic
> @Pure
> int logged(int x) { println("x=$x"); x * 2 } // ERROR: logging
> }
> {code}
> ----
> *Allowing logging:*
> {code:groovy}
> @TypeChecked(extensions = 'groovy.typecheckers.PurityChecker(allows:
> "LOGGING")')
> class Service {
> @Pure
> int compute(int x) {
> println("computing $x") // OK: logging allowed
> return x * x
> }
> @Pure
> long getTime() { System.nanoTime() } // ERROR: non-deterministic (not
> allowed)
> }
> {code}
> ----
> *Allowing logging and non-determinism:*
> {code:groovy}
> @TypeChecked(extensions = 'groovy.typecheckers.PurityChecker(allows:
> "LOGGING|NONDETERMINISM")')
> class Diagnostics {
> @Pure
> String snapshot(Map state) {
> println("snapshot at ${System.nanoTime()}") // OK: both allowed
> return state.toString()
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)