GROOVY-12117: replace super trait search with more complete helper stub#2678
GROOVY-12117: replace super trait search with more complete helper stub#2678eric-milles wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: 5f40130 | Previous: aa30a69 | Ratio |
|---|---|---|---|
org.apache.groovy.bench.AryBench.java ( {"n":"10"} ) |
0.006551610504040221 ms/op |
0.004037354064242993 ms/op |
1.62 |
This comment was automatically generated by workflow using github-action-benchmark.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2678 +/- ##
==================================================
- Coverage 68.6980% 68.6961% -0.0019%
+ Complexity 34121 34118 -3
==================================================
Files 1536 1536
Lines 128912 128933 +21
Branches 23368 23375 +7
==================================================
+ Hits 88560 88572 +12
- Misses 32522 32527 +5
- Partials 7830 7834 +4
🚀 New features to boost your workflow:
|
JMH summary — classic (commit
|
| Group | Speedup | Calibrated | n |
|---|---|---|---|
| bench | 1.037 × | 0.996 × | 78 |
| core | 1.024 × | 1.065 × | 77 |
| grails | 0.983 × | 1.034 × | 80 |
Runner calibration (this run vs baseline hardware): bench 1.04× (26 rulers) · core-ag 0.92× (3 rulers) · core-hz 1.01× (3 rulers) · grails-ad 0.91× (3 rulers) · grails-ez 0.98× (3 rulers)
Baseline: dev/bench/jmh/<part>/classic/data.js on gh-pages, trailing 90 days. Daily dashboard · Per-suite raw data
JMH summary — indy (commit
|
| Group | Speedup | Calibrated | n |
|---|---|---|---|
| bench | 0.979 × | 1.002 × | 78 |
| core | 3.666 × | 3.525 × | 77 |
| grails | 2.177 × | 2.058 × | 80 |
Runner calibration (this run vs baseline hardware): bench 0.98× (26 rulers) · core-ag 1.07× (3 rulers) · core-hz 1.00× (3 rulers) · grails-ad 1.06× (3 rulers) · grails-ez 1.06× (3 rulers)
Baseline: dev/bench/jmh/<part>/indy/data.js on gh-pages, trailing 90 days. Daily dashboard · Per-suite raw data
|
AI said the PR broke ordering, so I added an existing test to show that - and the PR breaks now - but the fix should be easy. AI read below: Thanks for this — replacing the super-trait search with a fuller helper stub is a nice simplification, and modelling the not-yet-lowered helper as a real stub (rather than the empty GROOVY-7909 one) is the right direction for the code-assist/inferencing goal. It also happens to fix a latent bug the old empty stub had: in One behavioural concern before this lands, though: as written, the stub drops the original method's annotations, which makes Why
The removed ReproducerThis is the sub-trait-first counterpart of the existing @Test
void testSuperTraitPublicStaticIsPolymorphicSubTraitFirst() {
GroovyAssert.assertScript '''
import groovy.transform.Virtual
trait Mid extends Base { static String greet() { hello() } } // sub-trait declared FIRST
trait Base { @Virtual static String hello() { 'base' } }
class C implements Mid {}
class D implements Mid { static String hello() { 'override' } }
assert C.greet() == 'base'
assert D.greet() == 'override'
'''
}
Suggested fixCopy the original method's annotations onto the stub method, mirroring var m = new MethodNode(method.getName(), mods, method.getReturnType(), helperParams, method.getExceptions(), null);
- m.addAnnotation(Traits.IMPLEMENTED_CLASSNODE);
+ // Mirror processMethod's annotation copy: findConcreteMethod dispatches on
+ // @Virtual, so a stub method missing it silently picks declarer-bound dispatch.
+ for (AnnotationNode annotation : method.getAnnotations()) {
+ if (!annotation.getClassNode().equals(ClassHelper.OVERRIDE_TYPE)) {
+ m.addAnnotation(annotation);
+ }
+ }
m.setGenericsTypes(method.getGenericsTypes());(Dropping the explicit With this change the full trait suite still passes ( Optional fidelity tweaks (not required to fix the bug)Since the stub now feeds code-assist/inferencing, a couple of small alignments with
|
6c85475 to
5f40130
Compare
|
✅ All tests passed ✅🏷️ Commit: 5f40130 Learn more about TestLens at testlens.app. |



In order to support some code assist or type inferencing for traits, I needed to fill out the trait helper stub a little more. This solution also works for GROOVY-12117 instead of the super trait method search. That is why I could not get the 12117 test case to trip locally.