Skip to content

Commit 6c435de

Browse files
authored
Support Kotlin 2.3.20 (#134)
1 parent 7f0b6ab commit 6c435de

File tree

9 files changed

+65
-15
lines changed

9 files changed

+65
-15
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ It’s **strongly recommended to use the exact same Kotlin version** as this lib
234234

235235
| Stability Analyzer | Kotlin |
236236
|--------------------|-------------|
237-
| 0.6.5+ | 2.3.0 |
237+
| 0.7.1+ | 2.3.20 |
238+
| 0.6.5~0.7.0 | 2.3.0 |
238239
| 0.4.0~0.6.4 | 2.2.21 |
239240

240241
### TraceRecomposition Annotation

docs/gradle-plugin/getting-started.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ The Compose Stability Analyzer compiler plugin is tightly coupled to the Kotlin
4545

4646
| Stability Analyzer | Kotlin |
4747
|--------------------|--------|
48-
| 0.6.5+ | 2.3.0 |
48+
| 0.7.1+ | 2.3.20 |
49+
| 0.6.5 ~ 0.7.0 | 2.3.0 |
4950
| 0.4.0 ~ 0.6.4 | 2.2.21 |
5051

5152
## What's Included

docs/version-map.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ It is **strongly recommended to use the exact same Kotlin version** as this libr
66

77
| Stability Analyzer | Kotlin |
88
|--------------------|--------|
9-
| 0.6.5+ | 2.3.0 |
9+
| 0.7.1+ | 2.3.20 |
10+
| 0.6.5 ~ 0.7.0 | 2.3.0 |
1011
| 0.4.0 ~ 0.6.4 | 2.2.21 |
1112

1213
!!! warning "Version mismatch"
@@ -26,6 +27,7 @@ The Compose Stability Analyzer works alongside the Compose compiler. Ensure your
2627

2728
| Kotlin | Compose Compiler |
2829
|--------|-----------------|
30+
| 2.3.20 | Bundled with Kotlin |
2931
| 2.3.0 | Bundled with Kotlin |
3032
| 2.2.21 | Bundled with Kotlin |
3133

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ kotlin.mpp.androidGradlePluginCompatibility.nowarn=true
5151

5252
# Maven publishing
5353
GROUP=com.github.skydoves
54-
VERSION_NAME=0.7.0
54+
VERSION_NAME=0.7.1-SNAPSHOT
5555

5656
POM_URL=https://github.com/skydoves/compose-stability-analyzer/
5757
POM_SCM_URL=https://github.com/skydoves/compose-stability-analyzer/

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
compiler = "1.5.15"
33
junit = "4.13.2"
4-
kotlin = "2.3.0"
4+
kotlin = "2.3.20"
55
dokka = "2.1.0"
66
jvmTarget = "17"
77
kotlinxCollectionsImmutable = "0.4.0"
@@ -13,7 +13,7 @@ androidGradlePlugin = "8.13.1"
1313
androidxActivity = "1.11.0"
1414
androidxComposeBom = "2025.12.00"
1515
jetbrains-compose = "1.9.3"
16-
compose-stability-analyzer = "0.6.2"
16+
compose-stability-analyzer = "0.7.1-SNAPSHOT"
1717
runtimeAnnotation = "1.9.0"
1818
spotless = "6.21.0"
1919
shadow = "8.1.1"

stability-compiler/src/main/kotlin/com/skydoves/compose/stability/compiler/ComposableStabilityChecker.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ package com.skydoves.compose.stability.compiler
1818
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
1919
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind
2020
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
21-
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirSimpleFunctionChecker
22-
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
21+
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirCallableDeclarationChecker
22+
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
23+
import org.jetbrains.kotlin.fir.declarations.FirFunction
2324
import org.jetbrains.kotlin.fir.declarations.getAnnotationByClassId
2425
import org.jetbrains.kotlin.name.ClassId
2526
import org.jetbrains.kotlin.name.FqName
@@ -29,16 +30,20 @@ import org.jetbrains.kotlin.name.Name
2930
* FIR checker for composable functions.
3031
* Currently unused - all stability analysis is performed in the IR phase.
3132
* This is kept as infrastructure for potential future FIR-phase checks.
33+
*
34+
* Note: Uses [FirCallableDeclarationChecker] instead of `FirSimpleFunctionChecker` because
35+
* `FirSimpleFunction` was renamed to `FirNamedFunction` in Kotlin 2.3.20, causing linkage failures.
3236
*/
33-
public object ComposableStabilityChecker : FirSimpleFunctionChecker(MppCheckerKind.Common) {
37+
public object ComposableStabilityChecker : FirCallableDeclarationChecker(MppCheckerKind.Common) {
3438

3539
private val COMPOSABLE_FQ_NAME = ClassId(
3640
FqName("androidx.compose.runtime"),
3741
Name.identifier("Composable"),
3842
)
3943

4044
context(ctx: CheckerContext, _: DiagnosticReporter)
41-
override fun check(declaration: FirSimpleFunction) {
45+
override fun check(declaration: FirCallableDeclaration) {
46+
if (declaration !is FirFunction) return
4247
if (declaration.symbol.getAnnotationByClassId(COMPOSABLE_FQ_NAME, ctx.session) == null) {
4348
return
4449
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Designed and developed by 2025 skydoves (Jaewoong Eum)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.skydoves.compose.stability.compiler.lower
17+
18+
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
19+
20+
/**
21+
* Compatibility wrapper for [IrDeclarationOrigin] constants.
22+
*
23+
* In Kotlin 2.3.20, the types of origin constants like [IrDeclarationOrigin.DEFINED] changed
24+
* from `IrDeclarationOriginImpl` to `IrDeclarationOrigin`, causing [NoSuchMethodError] when
25+
* compiled against an older Kotlin version. This object uses reflection-based lookups to
26+
* access these constants safely across Kotlin versions.
27+
*/
28+
internal object OriginCompat {
29+
30+
private fun getConstant(name: String): Lazy<IrDeclarationOrigin> = lazy {
31+
IrDeclarationOrigin.Companion::class.java
32+
.getDeclaredMethod("get$name")
33+
.invoke(IrDeclarationOrigin.Companion) as IrDeclarationOrigin
34+
}
35+
36+
val DEFINED: IrDeclarationOrigin by getConstant("DEFINED")
37+
val IR_EXTERNAL_DECLARATION_STUB: IrDeclarationOrigin by getConstant(
38+
"IR_EXTERNAL_DECLARATION_STUB",
39+
)
40+
val IR_EXTERNAL_JAVA_DECLARATION_STUB: IrDeclarationOrigin by getConstant(
41+
"IR_EXTERNAL_JAVA_DECLARATION_STUB",
42+
)
43+
}

stability-compiler/src/main/kotlin/com/skydoves/compose/stability/compiler/lower/RecompositionIrBuilder.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.ir.builders.irCall
2626
import org.jetbrains.kotlin.ir.builders.irGet
2727
import org.jetbrains.kotlin.ir.builders.irInt
2828
import org.jetbrains.kotlin.ir.builders.irString
29-
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
3029
import org.jetbrains.kotlin.ir.declarations.IrFunction
3130
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
3231
import org.jetbrains.kotlin.ir.declarations.IrVariable
@@ -199,7 +198,7 @@ public class RecompositionIrBuilder(
199198
parent = function,
200199
startOffset = UNDEFINED_OFFSET,
201200
endOffset = UNDEFINED_OFFSET,
202-
origin = IrDeclarationOrigin.DEFINED,
201+
origin = OriginCompat.DEFINED,
203202
name = Name.identifier("_tracker"),
204203
type = trackerClassSymbol!!.defaultType,
205204
isVar = false,

stability-compiler/src/main/kotlin/com/skydoves/compose/stability/compiler/lower/StabilityAnalyzerTransformer.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext
2121
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
2222
import org.jetbrains.kotlin.ir.IrStatement
2323
import org.jetbrains.kotlin.ir.declarations.IrClass
24-
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
2524
import org.jetbrains.kotlin.ir.declarations.IrFunction
2625
import org.jetbrains.kotlin.ir.expressions.IrConst
2726
import org.jetbrains.kotlin.ir.expressions.IrExpression
@@ -917,8 +916,8 @@ public class StabilityAnalyzerTransformer(
917916

918917
// Check 1: External library classes (from compiled JARs/AARs)
919918
val origin = clazz.origin
920-
if (origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB ||
921-
origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
919+
if (origin == OriginCompat.IR_EXTERNAL_DECLARATION_STUB ||
920+
origin == OriginCompat.IR_EXTERNAL_JAVA_DECLARATION_STUB
922921
) {
923922
return true
924923
}

0 commit comments

Comments
 (0)