Skip to content

Commit 26abd2d

Browse files
travisMiehmbpoland
andauthored
Upgrade to Kotlin 1.9.21 (#1077)
* WIP - Support Kotlin 1.9.21 * Switch to ZacSweers/kotlin-compile-testing for 1.9.21 support * Automated fixes - formatting - regenerate API * Handle ClassGeneration extension phase * Remove unnecessary reference to com.github.tschuchortdev --------- Co-authored-by: Ben Poland <[email protected]>
1 parent d372ad2 commit 26abd2d

File tree

9 files changed

+145
-71
lines changed

9 files changed

+145
-71
lines changed

build.gradle.kts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ plugins {
1313
}
1414

1515
allprojects {
16-
repositories {
17-
mavenCentral()
18-
maven(url = "https://oss.sonatype.org/content/repositories/snapshots/")
19-
}
20-
2116
group = property("projects.group").toString()
2217
}
2318

gradle/projects.libs.versions.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ dokka = "1.8.10"
77
intellijOpenApi = "7.0.3"
88
javaAssist = "3.29.2-GA"
99
junit = "5.9.2"
10-
kotlin = "1.8.21"
11-
kotlinCompileTesting = "1.5.0"
10+
kotlin = "1.9.21"
11+
kotlinCompileTesting = "0.4.0"
1212
javaCompileTesting = "0.21.0"
1313
kotlinBinaryCompatibilityValidator = "0.13.0"
1414
detekt = "1.22.0"
15-
ksp = "1.8.21-1.0.11"
15+
ksp = "1.9.21-1.0.15"
1616

1717
[libraries]
1818
arrowCore = { module = "io.arrow-kt:arrow-core", version.ref = "arrow" }
@@ -26,17 +26,17 @@ junitEngine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref =
2626
junitPlatformLauncher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junit" }
2727
kotlin-annotationProcessingEmbeddable = { module = "org.jetbrains.kotlin:kotlin-annotation-processing-embeddable" }
2828
kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler" }
29-
kotlin-compilerEmbeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable" }
29+
kotlin-compilerEmbeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" }
3030
kotlin-stdlibCommon = { module = "org.jetbrains.kotlin:kotlin-stdlib-common", version.ref = "kotlin" }
3131
kotlin-stdlibJDK8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
3232
kotlin-stdlibJS = { module = "org.jetbrains.kotlin:kotlin-stdlib-js" }
3333
kotlin-scriptingCompilerEmbeddable = { module = "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable" }
34-
kotlin-scriptUtil = { module = "org.jetbrains.kotlin:kotlin-script-util" }
34+
kotlin-scriptUtil = { module = "org.jetbrains.kotlin:kotlin-script-util", version="1.8.22" }
3535
kotlin-gradlePluginX = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin" }
3636
kotlin-gradlePluginApi = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin-api" }
3737
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect" }
38-
kotlinCompileTesting = { module = "com.github.tschuchortdev:kotlin-compile-testing", version.ref = "kotlinCompileTesting" }
39-
kotlinCompileTestingKsp = { module = "com.github.tschuchortdev:kotlin-compile-testing-ksp", version.ref = "kotlinCompileTesting" }
38+
kotlinCompileTesting = { module = "dev.zacsweers.kctfork:core", version.ref = "kotlinCompileTesting" }
39+
kotlinCompileTestingKsp = { module = "dev.zacsweers.kctfork:ksp", version.ref = "kotlinCompileTesting" }
4040
javaCompileTesting = { module = "com.google.testing.compile:compile-testing", version.ref = "javaCompileTesting" }
4141
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
4242
ksp-lib = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }

libs/arrow-meta/api/arrow-meta.api

Lines changed: 46 additions & 39 deletions
Large diffs are not rendered by default.

libs/arrow-meta/src/main/kotlin/arrow/meta/internal/registry/InternalRegistry.kt

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import arrow.meta.phases.analysis.CollectAdditionalSources
1717
import arrow.meta.phases.analysis.ExtraImports
1818
import arrow.meta.phases.analysis.PreprocessedVirtualFileFactory
1919
import arrow.meta.phases.codegen.asm.ClassBuilder
20+
import arrow.meta.phases.codegen.asm.ClassGeneration
2021
import arrow.meta.phases.codegen.asm.Codegen
2122
import arrow.meta.phases.codegen.ir.IRGeneration
2223
import arrow.meta.phases.config.Config
@@ -29,13 +30,14 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult
2930
import org.jetbrains.kotlin.analyzer.ModuleInfo
3031
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
3132
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
33+
import org.jetbrains.kotlin.backend.jvm.extensions.ClassGenerator
34+
import org.jetbrains.kotlin.backend.jvm.extensions.ClassGeneratorExtension
3235
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
3336
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
3437
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
3538
import org.jetbrains.kotlin.codegen.ClassBuilderFactory
3639
import org.jetbrains.kotlin.codegen.ImplementationBodyCodegen
3740
import org.jetbrains.kotlin.codegen.StackValue
38-
import org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension
3941
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
4042
import org.jetbrains.kotlin.com.intellij.mock.MockProject
4143
import org.jetbrains.kotlin.com.intellij.openapi.project.Project
@@ -66,6 +68,7 @@ import org.jetbrains.kotlin.extensions.PreprocessedVirtualFileFactoryExtension
6668
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
6769
import org.jetbrains.kotlin.incremental.components.LookupLocation
6870
import org.jetbrains.kotlin.incremental.components.LookupTracker
71+
import org.jetbrains.kotlin.ir.declarations.IrClass
6972
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
7073
import org.jetbrains.kotlin.name.Name
7174
import org.jetbrains.kotlin.platform.TargetPlatform
@@ -179,6 +182,7 @@ interface InternalRegistry : ConfigSyntax {
179182
is AnalysisHandler -> registerAnalysisHandler(this, ctx)
180183
is ClassBuilder -> registerClassBuilder(this, ctx)
181184
is Codegen -> registerCodegen(this, ctx)
185+
is ClassGeneration -> registerClassGenerator(this, ctx)
182186
is DeclarationAttributeAlterer -> registerDeclarationAttributeAlterer(this, ctx)
183187
is PackageProvider -> packageFragmentProvider(this, ctx)
184188
is SyntheticResolver -> registerSyntheticResolver(this, ctx)
@@ -605,12 +609,29 @@ interface InternalRegistry : ConfigSyntax {
605609
}
606610
}
607611

612+
fun CompilerPluginRegistrar.ExtensionStorage.registerClassGenerator(
613+
phase: ClassGeneration,
614+
ctx: CompilerContext
615+
) {
616+
ClassGeneratorExtension.registerExtension(
617+
object : ClassGeneratorExtension {
618+
override fun generateClass(
619+
generator: ClassGenerator,
620+
declaration: IrClass?
621+
): ClassGenerator = phase.run { ctx.interceptClassGenerator(generator, declaration) }
622+
}
623+
)
624+
}
625+
608626
fun CompilerPluginRegistrar.ExtensionStorage.registerClassBuilder(
609627
phase: ClassBuilder,
610628
ctx: CompilerContext
611629
) {
612-
ClassBuilderInterceptorExtension.registerExtension(
613-
object : ClassBuilderInterceptorExtension {
630+
@Suppress("DEPRECATION_ERROR")
631+
org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension.registerExtension(
632+
object :
633+
@Suppress("DEPRECATION_ERROR")
634+
org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension {
614635
override fun interceptClassBuilderFactory(
615636
interceptedFactory: ClassBuilderFactory,
616637
bindingContext: BindingContext,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package arrow.meta.phases.codegen.asm
2+
3+
import arrow.meta.phases.CompilerContext
4+
import arrow.meta.phases.ExtensionPhase
5+
import org.jetbrains.kotlin.backend.jvm.extensions.ClassGenerator
6+
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
7+
import org.jetbrains.kotlin.ir.declarations.IrClass
8+
9+
/**
10+
* @see [ExtensionPhase]
11+
* @see [arrow.meta.dsl.codegen.asm.AsmSyntax]
12+
*/
13+
interface ClassGeneration : ExtensionPhase {
14+
@OptIn(ObsoleteDescriptorBasedAPI::class)
15+
fun CompilerContext.interceptClassGenerator(
16+
generator: ClassGenerator,
17+
declaration: IrClass?
18+
): ClassGenerator
19+
}

libs/arrow-meta/src/main/kotlin/arrow/meta/phases/codegen/ir/IrUtils.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ class IrUtils(
6767

6868
fun KotlinType.toIrType(): IrType = typeTranslator.translateType(this)
6969

70+
@OptIn(ObsoleteDescriptorBasedAPI::class)
7071
fun CallableDescriptor.irCall(): IrExpression =
7172
when (this) {
7273
is PropertyDescriptor -> {
73-
val irField = pluginContext.symbols.externalSymbolTable.referenceField(this)
74+
val irField =
75+
pluginContext.symbols.externalSymbolTable.descriptorExtension.referenceField(this)
7476
irField.owner.correspondingPropertySymbol?.owner?.getter?.symbol?.let {
7577
irSimpleFunctionSymbol ->
7678
IrCallImpl(
@@ -85,7 +87,8 @@ class IrUtils(
8587
?: TODO("Unsupported irCall for $this")
8688
}
8789
is ClassConstructorDescriptor -> {
88-
val irSymbol = pluginContext.symbols.externalSymbolTable.referenceConstructor(this)
90+
val irSymbol =
91+
pluginContext.symbols.externalSymbolTable.descriptorExtension.referenceConstructor(this)
8992
IrConstructorCallImpl(
9093
startOffset = UNDEFINED_OFFSET,
9194
endOffset = UNDEFINED_OFFSET,
@@ -108,7 +111,10 @@ class IrUtils(
108111
)
109112
}
110113
is FakeCallableDescriptorForObject -> {
111-
val irSymbol = pluginContext.symbols.externalSymbolTable.referenceClass(classDescriptor)
114+
val irSymbol =
115+
pluginContext.symbols.externalSymbolTable.descriptorExtension.referenceClass(
116+
classDescriptor
117+
)
112118
IrGetObjectValueImpl(
113119
startOffset = UNDEFINED_OFFSET,
114120
endOffset = UNDEFINED_OFFSET,
@@ -121,8 +127,10 @@ class IrUtils(
121127
}
122128
}
123129

130+
@OptIn(ObsoleteDescriptorBasedAPI::class)
124131
fun PropertyDescriptor.irGetterCall(): IrCall? {
125-
val irField = pluginContext.symbols.externalSymbolTable.referenceField(this)
132+
this.backingField
133+
val irField = pluginContext.symbols.externalSymbolTable.descriptorExtension.referenceField(this)
126134
return irField.owner.correspondingPropertySymbol?.owner?.getter?.symbol?.let {
127135
irSimpleFunctionSymbol ->
128136
IrCallImpl(

libs/meta-test/src/main/kotlin/arrow/meta/plugin/testing/Compilation.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package arrow.meta.plugin.testing
22

3+
import com.tschuchort.compiletesting.CompilationResult
34
import com.tschuchort.compiletesting.KotlinCompilation
4-
import com.tschuchort.compiletesting.KotlinCompilation.Result
55
import com.tschuchort.compiletesting.PluginOption
66
import com.tschuchort.compiletesting.SourceFile
77
import com.tschuchort.compiletesting.kspSourcesDir
@@ -14,7 +14,8 @@ import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
1414

1515
internal const val DEFAULT_FILENAME = "Source.kt"
1616

17-
internal fun compile(data: CompilationData): Result {
17+
@OptIn(ExperimentalCompilerApi::class)
18+
internal fun compile(data: CompilationData): CompilationResult {
1819
val compilation = createKotlinCompilation(data)
1920
if (data.symbolProcessors.isEmpty()) {
2021
return compilation.compile()
@@ -62,6 +63,7 @@ private fun createKotlinCompilation(data: CompilationData) =
6263
pluginOptions = data.pluginOptions.map { PluginOption(it.pluginId, it.key, it.value) }
6364
}
6465

66+
@OptIn(ExperimentalCompilerApi::class)
6567
private val KotlinCompilation.kspGeneratedSourceFiles: List<SourceFile>
6668
get() =
6769
kspSourcesDir

libs/meta-test/src/main/kotlin/arrow/meta/plugin/testing/CompilationAssertions.kt

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
@file:OptIn(ExperimentalCompilerApi::class)
2-
31
package arrow.meta.plugin.testing
42

3+
import com.tschuchort.compiletesting.CompilationResult
54
import com.tschuchort.compiletesting.KotlinCompilation.ExitCode
6-
import com.tschuchort.compiletesting.KotlinCompilation.Result
75
import java.io.File
86
import java.net.URLClassLoader
97
import java.nio.file.Files
@@ -24,8 +22,9 @@ private const val VARIABLE = "[^(]+"
2422
*
2523
* Running the compilation from the provided configuration and getting the results (status, classes,
2624
* and output messages) is possible thanks to
27-
* [Kotlin Compile Testing](https://github.com/tschuchortdev/kotlin-compile-testing), a library
28-
* developed by [Thilo Schuchort](https://github.com/tschuchortdev).
25+
* [Kotlin Compile Testing](https://github.com/ZacSweers/kotlin-compile-testing), a library
26+
* developed by [Thilo Schuchort](https://github.com/tschuchortdev), and forked by
27+
* [ZacSweers](https://github.com/ZacSweers).
2928
*
3029
* Main schema:
3130
* ```
@@ -61,6 +60,7 @@ private const val VARIABLE = "[^(]+"
6160
*/
6261
fun assertThis(compilerTest: CompilerTest): Unit = compilerTest.run(interpreter)
6362

63+
@OptIn(ExperimentalCompilerApi::class)
6464
private val interpreter: (CompilerTest) -> Unit = {
6565
tailrec fun List<Config>.compilationData(
6666
acc: CompilationData = CompilationData.empty
@@ -101,7 +101,7 @@ private val interpreter: (CompilerTest) -> Unit = {
101101
)
102102
}
103103

104-
fun runAssert(singleAssert: Assert.SingleAssert, compilationResult: Result): Unit =
104+
fun runAssert(singleAssert: Assert.SingleAssert, compilationResult: CompilationResult): Unit =
105105
when (singleAssert) {
106106
Assert.Empty -> println("Assertions not found")
107107
Assert.CompilationResult.Compiles -> assertCompiles(compilationResult)
@@ -128,32 +128,40 @@ private val interpreter: (CompilerTest) -> Unit = {
128128
}
129129
}
130130

131+
@OptIn(ExperimentalCompilerApi::class)
131132
private fun CompilationData.addDependencies(config: Config.AddDependencies) =
132133
copy(dependencies = dependencies + config.dependencies.map { it.mavenCoordinates })
133134

135+
@OptIn(ExperimentalCompilerApi::class)
134136
private fun CompilationData.addCompilerPlugins(config: Config.AddCompilerPlugins) =
135137
copy(
136138
compilerPlugins =
137139
compilerPlugins + config.plugins.flatMap { it.dependencies.map { it.mavenCoordinates } }
138140
)
139141

142+
@OptIn(ExperimentalCompilerApi::class)
140143
private fun CompilationData.addMetaPlugins(config: Config.AddMetaPlugins) =
141144
copy(metaPlugins = metaPlugins + config.plugins)
142145

146+
@OptIn(ExperimentalCompilerApi::class)
143147
private fun CompilationData.addArguments(config: Config.AddArguments) =
144148
copy(arguments = arguments + config.arguments)
145149

150+
@OptIn(ExperimentalCompilerApi::class)
146151
private fun CompilationData.addCommandLineProcessors(config: Config.AddCommandLineProcessors) =
147152
copy(commandLineProcessors = commandLineProcessors + config.commandLineProcessors)
148153

154+
@OptIn(ExperimentalCompilerApi::class)
149155
private fun CompilationData.addSymbolProcessors(config: Config.AddSymbolProcessors) =
150156
copy(symbolProcessors = symbolProcessors + config.symbolProcessors)
151157

158+
@OptIn(ExperimentalCompilerApi::class)
152159
private fun CompilationData.addPluginOptions(config: Config.AddPluginOptions) =
153160
copy(pluginOptions = pluginOptions + config.pluginOptions)
154161

162+
@OptIn(ExperimentalCompilerApi::class)
155163
private fun assertEvalsTo(
156-
compilationResult: Result,
164+
compilationResult: CompilationResult,
157165
source: Code.Source,
158166
output: Any?,
159167
onError: (Throwable) -> Any?
@@ -174,20 +182,24 @@ private fun assertEvalsTo(
174182
}
175183
}
176184

177-
private fun assertCompiles(compilationResult: Result) {
185+
@OptIn(ExperimentalCompilerApi::class)
186+
private fun assertCompiles(compilationResult: CompilationResult) {
178187
assertThat(compilationResult.exitCode).isEqualTo(ExitCode.OK)
179188
}
180189

181-
private fun assertCompilesWith(compilationResult: Result, check: (String) -> Boolean) {
190+
@OptIn(ExperimentalCompilerApi::class)
191+
private fun assertCompilesWith(compilationResult: CompilationResult, check: (String) -> Boolean) {
182192
assertThat(compilationResult.exitCode).isEqualTo(ExitCode.OK)
183193
assertThat(check(compilationResult.messages)).isTrue
184194
}
185195

186-
private fun assertFails(compilationResult: Result) {
196+
@OptIn(ExperimentalCompilerApi::class)
197+
private fun assertFails(compilationResult: CompilationResult) {
187198
assertThat(compilationResult.exitCode).isNotEqualTo(ExitCode.OK)
188199
}
189200

190-
private fun assertFailsWith(compilationResult: Result, check: (String) -> Boolean) {
201+
@OptIn(ExperimentalCompilerApi::class)
202+
private fun assertFailsWith(compilationResult: CompilationResult, check: (String) -> Boolean) {
191203
assertFails(compilationResult)
192204
assertThat(check(compilationResult.messages)).isTrue
193205
}

settings.gradle.kts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ dependencyResolutionManagement {
1515
kotlinVersion?.let { version("kotlin", it) }
1616
}
1717
}
18+
19+
repositories {
20+
mavenLocal {
21+
content {
22+
includeGroup("io.arrow-kt")
23+
}
24+
}
25+
mavenCentral()
26+
maven(url = "https://oss.sonatype.org/content/repositories/snapshots/")
27+
}
1828
}
1929

2030
rootProject.name = "arrow-meta-workspace"

0 commit comments

Comments
 (0)