You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "eric-milles (via GitHub)" <gi...@apache.org> on 2026/03/10 23:05:51 UTC

[PR] GROOVY-8699: SC: emit direct bytecode for simple list [groovy]

eric-milles opened a new pull request, #2395:
URL: https://github.com/apache/groovy/pull/2395

   Given a simple list expression like:
   ```groovy
   @CompileStatic test() {
    [5,6,7]
   }
   ```
   
   The class generator will produce a bytecode sequence like
   ```java
   list = new ArrayList(3); // list is top of operand stack
   list.add(5);
   list.add(6);
   list.add(7);
   ```
   
   There is a simpler implementation that can replace `NewListExpression`; I figured a new list followed by calls to `add` created the least extra stuff.  This replaces `ListExpression` with `new ArrayList(Arrays.asList(new Object[]{ /*list items*/ }))`:
   ```java
               var array = new ArrayExpression(ClassHelper.OBJECT_TYPE, le.getExpressions().stream().map(scTransformer::transform).toList());
   
               ClassNode java_util_Arrays = ClassHelper.make(java.util.Arrays.class);
               mn = java_util_Arrays.getDeclaredMethods("asList").get(0);
   
               var values = new MethodCallExpression(new ClassExpression(java_util_Arrays), "asList", array);
               values.setMethodTarget(mn);
   
               ClassNode java_util_ArrayList = ClassHelper.makeWithoutCaching(java.util.ArrayList.class);
               mn = java_util_ArrayList.getDeclaredConstructor(new Parameter[] {new Parameter(ClassHelper.COLLECTION_TYPE,"c")});
   
               var cce = new ConstructorCallExpression(java_util_ArrayList, values);
               cce.putNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET, mn);
               cce.setSourcePosition(le);
               return cce;
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-8699: SC: emit direct bytecode for simple list [groovy]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #2395:
URL: https://github.com/apache/groovy/pull/2395#issuecomment-4035683468

   ## [Codecov](https://app.codecov.io/gh/apache/groovy/pull/2395?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `94.11765%` with `2 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 66.7562%. Comparing base ([`a2a7da6`](https://app.codecov.io/gh/apache/groovy/commit/a2a7da6fc0780adae2e9d70fc7ebfc6a98ff2aa7?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`493c709`](https://app.codecov.io/gh/apache/groovy/commit/493c70912224b476391f790683ca56fe9227f305?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2395?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...rg/codehaus/groovy/classgen/AsmClassGenerator.java](https://app.codecov.io/gh/apache/groovy/pull/2395?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2FAsmClassGenerator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL0FzbUNsYXNzR2VuZXJhdG9yLmphdmE=) | 50.0000% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/groovy/pull/2395?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...orm/sc/transformers/ListExpressionTransformer.java](https://app.codecov.io/gh/apache/groovy/pull/2395?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Ftransform%2Fsc%2Ftransformers%2FListExpressionTransformer.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3RyYW5zZm9ybS9zYy90cmFuc2Zvcm1lcnMvTGlzdEV4cHJlc3Npb25UcmFuc2Zvcm1lci5qYXZh) | 96.7742% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/groovy/pull/2395?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/groovy/pull/2395/graphs/tree.svg?width=650&height=150&src=pr&token=1r45138NfQ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/groovy/pull/2395?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #2395        +/-   ##
   ==================================================
   + Coverage     66.7519%   66.7562%   +0.0043%     
   - Complexity      29867      29868         +1     
   ==================================================
     Files            1382       1382                
     Lines          116106     116130        +24     
     Branches        20472      20476         +4     
   ==================================================
   + Hits            77503      77524        +21     
   - Misses          32272      32273         +1     
   - Partials         6331       6333         +2     
   ```
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2395?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...in/java/org/codehaus/groovy/classgen/Verifier.java](https://app.codecov.io/gh/apache/groovy/pull/2395?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2FVerifier.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL1ZlcmlmaWVyLmphdmE=) | `89.4848% <100.0000%> (+0.0111%)` | :arrow_up: |
   | [...rg/codehaus/groovy/classgen/AsmClassGenerator.java](https://app.codecov.io/gh/apache/groovy/pull/2395?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2FAsmClassGenerator.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL0FzbUNsYXNzR2VuZXJhdG9yLmphdmE=) | `84.6494% <50.0000%> (ø)` | |
   | [...orm/sc/transformers/ListExpressionTransformer.java](https://app.codecov.io/gh/apache/groovy/pull/2395?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Ftransform%2Fsc%2Ftransformers%2FListExpressionTransformer.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3RyYW5zZm9ybS9zYy90cmFuc2Zvcm1lcnMvTGlzdEV4cHJlc3Npb25UcmFuc2Zvcm1lci5qYXZh) | `97.7778% <96.7742%> (-2.2222%)` | :arrow_down: |
   
   ... and [6 files with indirect coverage changes](https://app.codecov.io/gh/apache/groovy/pull/2395/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-8699: SC: emit direct bytecode for simple list [groovy]

Posted by "eric-milles (via GitHub)" <gi...@apache.org>.
eric-milles merged PR #2395:
URL: https://github.com/apache/groovy/pull/2395


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org