You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "paulk-asert (via GitHub)" <gi...@apache.org> on 2026/09/13 06:55:05 UTC

[PR] GROOVY-12405: jump-table dispatch for statically compiled switch stat… [groovy]

paulk-asert opened a new pull request, #2929:
URL: https://github.com/apache/groovy/pull/2929

   …ements
   
   A statically compiled switch expression already emits tableswitch or lookupswitch when the selector and labels are constants of a type javac would switch on. A switch statement never has, in any Groovy release, so the colon form compiles to a chain of isCase calls that is linear in the number of arms:
   
       @CompileStatic
       String m(int i) {
           String r = 'many'
           switch (i) {
               case 1: r = 'one'; break
               case 2: r = 'two'; break
               case 3: r = 'three'; break
           }
           r
       }
       // was: 3 x ScriptBytecodeAdapter.isCase, now: tableswitch
   
   javac emits a jump table for the statement form as readily as for the expression form, so this is Java alignment as much as an optimisation.
   
   The emitters are shared rather than copied: SwitchDispatchWriter now holds the arm grouping, the int and string dispatch and the arm layout that StaticTypesSwitchExpressionWriter used to own, and both writers drive it. Only what differs stays with each caller, which for a statement is that nothing is thrown when no arm matches.
   
   Statement semantics are preserved. Arms are laid out in source order, so one that does not jump falls into the next and then into the default, exactly as the sequential chain does. Labelled and unlabelled break, continue, return and throw are unaffected because they compile the same way in either layout. A null selector takes the default.
   
   The dispatch applies only where the type checker's inferred type and every label agree; anything else keeps the sequential chain, including repeated labels, which a jump table cannot express and which the type checker does not reject for a statement.


-- 
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-12405: jump-table dispatch for statically compiled switch stat… [groovy]

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

   ## [Codecov](https://app.codecov.io/gh/apache/groovy/pull/2929?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 `97.35450%` with `5 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 71.1993%. Comparing base ([`3eca1c9`](https://app.codecov.io/gh/apache/groovy/commit/3eca1c94b999d74d955407862a53d21bfbd9f7dd?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`f50b999`](https://app.codecov.io/gh/apache/groovy/commit/f50b999a78e1aeb3db870183e05a7bba632dd169?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 10 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2929?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...s/groovy/classgen/asm/sc/SwitchDispatchWriter.java](https://app.codecov.io/gh/apache/groovy/pull/2929?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2Fsc%2FSwitchDispatchWriter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9zYy9Td2l0Y2hEaXNwYXRjaFdyaXRlci5qYXZh) | 95.7627% | [1 Missing and 4 partials :warning: ](https://app.codecov.io/gh/apache/groovy/pull/2929?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/2929/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/2929?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #2929        +/-   ##
   ==================================================
   - Coverage     71.2065%   71.1993%   -0.0072%     
   - Complexity      37721      37753        +32     
   ==================================================
     Files            1584       1585         +1     
     Lines          136489     136587        +98     
     Branches        25358      25372        +14     
   ==================================================
   + Hits            97189      97249        +60     
   - Misses          30538      30553        +15     
   - Partials         8762       8785        +23     
   ```
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2929?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...vy/classgen/asm/sc/StaticTypesStatementWriter.java](https://app.codecov.io/gh/apache/groovy/pull/2929?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2Fsc%2FStaticTypesStatementWriter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9zYy9TdGF0aWNUeXBlc1N0YXRlbWVudFdyaXRlci5qYXZh) | `98.9247% <100.0000%> (+0.4995%)` | :arrow_up: |
   | [...sgen/asm/sc/StaticTypesSwitchExpressionWriter.java](https://app.codecov.io/gh/apache/groovy/pull/2929?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2Fsc%2FStaticTypesSwitchExpressionWriter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9zYy9TdGF0aWNUeXBlc1N3aXRjaEV4cHJlc3Npb25Xcml0ZXIuamF2YQ==) | `91.0891% <100.0000%> (-2.8503%)` | :arrow_down: |
   | [...s/groovy/classgen/asm/sc/SwitchDispatchWriter.java](https://app.codecov.io/gh/apache/groovy/pull/2929?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2Fsc%2FSwitchDispatchWriter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9zYy9Td2l0Y2hEaXNwYXRjaFdyaXRlci5qYXZh) | `95.7627% <95.7627%> (ø)` | |
   
   ... and [47 files with indirect coverage changes](https://app.codecov.io/gh/apache/groovy/pull/2929/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-12405: jump-table dispatch for statically compiled switch stat… [groovy]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2929:
URL: https://github.com/apache/groovy/pull/2929#issuecomment-5652085815

   ## ✅ All tests passed ✅
   
   🏷️ Commit: f50b999a78e1aeb3db870183e05a7bba632dd169
   ▶️ Tests:  118911 executed
   ⚪️ Checks: 32/32 completed
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
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-12405: jump-table dispatch for statically compiled switch stat… [groovy]

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


-- 
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-12405: jump-table dispatch for statically compiled switch stat… [groovy]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2929:
URL: https://github.com/apache/groovy/pull/2929#issuecomment-5652561303

   ## 🚨 All tests passed but jobs failed 🚨
   
   ### Failed Jobs without Test Failures
   
   ❌ [CodeQL / Analyze \(java, 21\)](https://github.com/apache/groovy/actions/runs/34748553363/job/103700823254?pr=2929)
   
   🏷️ Commit: f63a3160be2ea79cb7bdb1ac3befc894155c476e
   ▶️ Tests:  118911 executed
   ⚪️ Checks: 32/32 completed
   
   ---
   _Learn more about TestLens at [testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   


-- 
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