Skip to content

GROOVY-11878: Invariant loops spike#2400

Open
paulk-asert wants to merge 2 commits intoapache:masterfrom
paulk-asert:invariantLoopsSpike
Open

GROOVY-11878: Invariant loops spike#2400
paulk-asert wants to merge 2 commits intoapache:masterfrom
paulk-asert:invariantLoopsSpike

Conversation

@paulk-asert
Copy link
Contributor

@paulk-asert paulk-asert commented Mar 22, 2026

There are two commits:

  • The first commit contains the proposed grammar and AST plumbing changes. It includes changes to plumb the existing @Invariant annotation into loops within the groovy-contracts subproject. There isn't support for other annotations like @Ensures (see example GROOVY-11878) yet which languages like Dafny support. This could be considered for a subsequent PR.

  • The second commit contains a second @Parallel example AST transform (see example in GROOVY-11878). It isn't meant to be production quality or included in the merge of this PR, but is another useful check that the AST plumbing changes are working. In particular, the @Parallel transform doesn't attempt to do any state sharing (bar the loop variable) or protection, it's just a demo.

Future work:

  • At present no validation of target type is handled. For now, AST transforms using this feature should do whatever checks they deem appropriate on target type within the transform. We have additional work to do to be able to automatically do the checking. E.g. We could add enums/annotations so that we could do something like: @ExtendedTarget(ExtendedTargetType.LOOP) to an @interface definition. Then we could give appropriate error messages when the annotations were used incorrectly.

@codecov-commenter
Copy link

codecov-commenter commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 50.36496% with 68 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.6566%. Comparing base (b9c4135) to head (cdf0c51).

Files with missing lines Patch % Lines
...us/groovy/transform/ParallelASTTransformation.java 0.0000% 34 Missing ⚠️
...pache/groovy/contracts/LoopInvariantViolation.java 12.5000% 14 Missing ⚠️
.../contracts/ast/LoopInvariantASTTransformation.java 58.3333% 5 Missing and 5 partials ⚠️
.../apache/groovy/contracts/domain/LoopInvariant.java 0.0000% 5 Missing ⚠️
...pache/groovy/parser/antlr4/SemanticPredicates.java 82.3529% 0 Missing and 3 partials ⚠️
...n/java/org/codehaus/groovy/ast/AnnotationNode.java 0.0000% 1 Missing ⚠️
...aus/groovy/transform/ASTTransformationVisitor.java 83.3333% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #2400        +/-   ##
==================================================
- Coverage     66.6744%   66.6566%   -0.0178%     
- Complexity      29856      29887        +31     
==================================================
  Files            1382       1386         +4     
  Lines          116145     116278       +133     
  Branches        20481      20504        +23     
==================================================
+ Hits            77439      77507        +68     
- Misses          32361      32421        +60     
- Partials         6345       6350         +5     
Files with missing lines Coverage Δ
...haus/groovy/transform/ASTTestTransformation.groovy 85.5072% <100.0000%> (ø)
...va/org/apache/groovy/parser/antlr4/AstBuilder.java 86.5436% <100.0000%> (+0.0364%) ⬆️
...aus/groovy/ast/ClassCodeExpressionTransformer.java 100.0000% <100.0000%> (ø)
...g/codehaus/groovy/ast/ClassCodeVisitorSupport.java 100.0000% <100.0000%> (ø)
...n/java/org/codehaus/groovy/ast/stmt/Statement.java 100.0000% <100.0000%> (ø)
...va/org/codehaus/groovy/control/ResolveVisitor.java 89.6334% <100.0000%> (+0.0527%) ⬆️
...ansform/ASTTransformationCollectorCodeVisitor.java 91.1392% <100.0000%> (+0.2301%) ⬆️
...n/java/org/codehaus/groovy/ast/AnnotationNode.java 69.2308% <0.0000%> (-0.6721%) ⬇️
...aus/groovy/transform/ASTTransformationVisitor.java 81.8681% <83.3333%> (+0.0499%) ⬆️
...pache/groovy/parser/antlr4/SemanticPredicates.java 83.5294% <82.3529%> (-0.2941%) ⬇️
... and 4 more

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This comment was marked as outdated.

@paulk-asert paulk-asert force-pushed the invariantLoopsSpike branch from ab272e7 to 0428d2d Compare March 24, 2026 00:50
@paulk-asert paulk-asert force-pushed the invariantLoopsSpike branch from 0428d2d to cdf0c51 Compare March 24, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants