[ 
https://issues.apache.org/jira/browse/GROOVY-12447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18126062#comment-18126062
 ] 

ASF GitHub Bot commented on GROOVY-12447:
-----------------------------------------

github-actions[bot] commented on PR #2975:
URL: https://github.com/apache/groovy/pull/2975#issuecomment-6109102175

   ### JMH summary — indy (commit `7c7926a`)
   
   Speedup vs trailing 90-day baseline on gh-pages. Higher = faster.
   `1.00` = in line with history. Per-benchmark ratio, geomean within group.
   Time-per-op units inverted so direction is consistent. The *calibrated*
   column divides out this runner's speed vs the baseline hardware, as
   measured by Groovy-independent pure-Java ruler benchmarks.
   
   | Group  | Speedup | Calibrated | n |
   |--------|---------|------------|---|
   | bench | 1.001 × | 1.052 × | 124 |
   | core | 2.465 × | 2.520 × | 108 |
   | grails | 2.322 × | 1.618 × | 80 |
   
   > ⚠️ **1 benchmark at least 1.5× slower than the 90-day baseline:**
   > - 
`org.apache.groovy.perf.grails.MetaclassVariationBench.perInstanceMetaclass` — 
1.72× slower (calibrated)
   
   > ⚠️ Runner speed differs ≥15% from the historical baseline hardware for: 
grails-ad, grails-ez. Raw speedups are not meaningful for those parts — use the 
calibrated column.
   
   <sub>Runner calibration (this run vs baseline hardware): bench 0.96× (27 
rulers) · core-ag 0.97× (3 rulers) · core-hz 1.00× (3 rulers) · grails-ad 1.48× 
(3 rulers) · grails-ez 1.39× (3 rulers)</sub>
   
   <sub>Baseline: <code>dev/bench/jmh/&lt;part&gt;/indy/data.js</code> on 
gh-pages, trailing 90 days. <a 
href="https://apache.github.io/groovy/dev/bench/jmh/summary.html";>Daily 
dashboard</a> · <a 
href="https://apache.github.io/groovy/dev/bench/jmh/";>Per-suite raw 
data</a></sub>
   
   <!

> STC: treat a complete native sealed type-case set as an exhaustive switch 
> expression
> ------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12447
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12447
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Daniel Sun
>            Priority: Major
>
> h2. Context
> GROOVY-12255 compiles switch expressions as first-class AST ([JEP 
> 361|https://openjdk.org/jeps/361]). Under {{@TypeChecked}} and 
> {{@CompileStatic}}, a switch expression is exhaustive when it has a 
> {{default}} arm, or when the selector is an enum and every constant is listed.
> Native sealed types (GROOVY-10148, GROOVY-10233, [JEP 
> 409|https://openjdk.org/jeps/409]) are a closed hierarchy when the target 
> bytecode is JDK 17+ and the sealed mode is native. Their permitted subclasses 
> are known at compile time, the same way enum constants are.
> Groovy already matches {{case Circle}} with {{isCase}} 
> ({{Class.isInstance}}). That type-case form is what this issue uses.
> h2. Problem
> STC rejects a switch expression that names every permitted subclass of a 
> native sealed selector:
> {code:groovy}
> sealed interface Shape permits Circle, Square {}
> final class Circle implements Shape {}
> final class Square implements Shape {}
> String name(Shape s) {
>     return switch (s) {
>         case Circle -> 'c'
>         case Square -> 's'
>     }
> }
> {code}
> The error is {{the switch expression does not cover all possible input 
> values}}. The same program is legal in Java with type patterns ([JEP 
> 441|https://openjdk.org/jeps/441]). Enums already receive this treatment in 
> Groovy.
> h2. Contract
> A switch expression with no {{default}} is exhaustive when the selector type 
> is native sealed and every remaining inhabitant is covered by a {{case Type}} 
> label.
> Inhabitants of the selector are its permitted subclasses, plus the selector 
> type itself when that type is a concrete class.
> A type-case label that names a member of the hierarchy removes remaining 
> inhabitants that are that type or a subtype of it. {{case Circle, Square}} is 
> two labels (the parser emits one {{CaseStatement}} per value). {{case Rect}} 
> covers nested {{Square}} and {{Triangle}}. {{case Square}} and {{case 
> Triangle}} leave {{Rect}} remaining.
> A label outside the hierarchy, including {{case Object}}, is ordinary 
> {{isCase}} and leaves the remaining set unchanged.
> Native sealed is detected as follows:
> * source: {{SealedASTTransformation.wouldBeNativeSealed}} (JDK 17+ target 
> bytecode and native mode), independent of transform order
> * class file: a non-empty permitted-subclass list (the 
> {{PermittedSubclasses}} attribute). Emulated sealed class files keep a 
> runtime {{@Sealed}} and leave that list empty.
> Duplicate permitted-subclass labels reuse the GROOVY-12289 / GROOVY-12406 
> check. The key is the pair (selector type, binary name), so {{case Circle}} 
> and {{case 'Circle'}} are distinct. That check already runs for switch 
> expressions and switch statements.
> ||Selector and labels||Today||This change||
> |native sealed interface, every permitted type|error|exhaustive|
> |one permitted type omitted|error|error|
> |emulated sealed, every permitted type|error|error|
> |concrete {{sealed class}}, subclasses only|error|error|
> |{{case Shape}} on a {{Shape}} selector|error|exhaustive|
> |{{case Object}} only|error|error|
> |{{case Circle}} and {{case Rect}} ({{Rect}} permits {{Square}}, 
> {{Triangle}})|error|exhaustive|
> |{{case Circle}}, {{case Square}}, {{case Triangle}} ({{Rect}} still 
> permitted)|error|error|
> |native sealed type from a class file, every permitted type|error|exhaustive|
> |switch statement, partial type cases|compiles|compiles|
> |enum, every constant (GROOVY-12255)|exhaustive|exhaustive|
> |duplicate {{case Circle}}|compiles|error: {{Duplicate case label: Circle}}|
> A concrete sealed class is itself an inhabitant:
> {code:groovy}
> sealed class Shape permits Circle, Square {}
> final class Circle extends Shape {}
> final class Square extends Shape {}
> String name(Shape s) {
>     return switch (s) {
>         case Circle -> 'c'
>         case Square -> 's'
>     }
> }
> {code}
> STC still reports {{the switch expression does not cover all possible input 
> values}}, because {{new Shape()}} is legal. {{case Shape}} covers the whole 
> hierarchy.
> Switch statements may be partial. Emulated sealed ({{@SealedOptions(mode = 
> SealedMode.EMULATE)}}) still needs a {{default}} arm. Dynamic Groovy still 
> throws {{IllegalStateException}} for an unmatched selector. Null stays 
> outside this check, matching enum exhaustiveness.
> h2. Touch points
> * {{org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor}} — 
> {{coversAllPermittedSubclasses}}, {{nativeSealedClosed}}, 
> {{permittedSubclassLabelKey}}
> * {{src/test/groovy/groovy/transform/stc/SwitchExpressionSTCTest.groovy}}
> h2. Scope
> This issue covers STC exhaustiveness of native sealed type-case labels, and 
> duplicate detection of those labels. GEP-19 pattern matching, flow typing of 
> the matched arm (GROOVY-12300), and bytecode dispatch for type cases are 
> separate work.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to