Skip to content

Commit

Permalink
Remove pre-IR backend support
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikaSD committed Jan 7, 2025
1 parent 943b392 commit edfcc46
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 66 deletions.
3 changes: 1 addition & 2 deletions kotlin-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin-api"
compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable"

// testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.5.0' does not support Kotlin 2
testImplementation 'dev.zacsweers.kctfork:core:0.6.0' // Fork of kotlin-compile-testing that supports Kotlin 2
testImplementation 'dev.zacsweers.kctfork:core:0.6.0'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.jetbrains.kotlin:kotlin-compiler-embeddable'
}
6 changes: 0 additions & 6 deletions kotlin-plugin/src/main/kotlin/me/shika/ComponentRegistrar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package me.shika

import me.shika.ObjectSerializationCommandLineProcessor.Companion.KEY_ENABLED
import me.shika.generation.ObjectSerializationIrGeneration
import me.shika.generation.ObjectSerializationJvmGeneration
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CompilerConfiguration
Expand All @@ -19,10 +17,6 @@ class ObjectSerializationCompilerPluginRegistrar : CompilerPluginRegistrar() {
return
}

ExpressionCodegenExtension.registerExtension(
ObjectSerializationJvmGeneration()
)

IrGenerationExtension.registerExtension(
ObjectSerializationIrGeneration()
)
Expand Down

This file was deleted.

14 changes: 0 additions & 14 deletions kotlin-plugin/src/main/kotlin/me/shika/generation/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import java.io.Serializable

fun ClassDescriptor.needSerializableFix() =
module.platform.has<JvmPlatform>()
&& DescriptorUtils.isObject(this)
&& isSerializable()
&& !hasReadMethod()

fun ClassDescriptor.hasReadMethod() =
unsubstitutedMemberScope.getContributedFunctions(SERIALIZABLE_READ, NoLookupLocation.FROM_BACKEND)
.any { it.name == SERIALIZABLE_READ && it.valueParameters.isEmpty() }

fun ClassDescriptor.isSerializable(): Boolean =
getSuperInterfaces().any { it.fqNameSafe == SERIALIZABLE_FQ_NAME || it.isSerializable() }
|| getSuperClassNotAny()?.isSerializable() == true

fun IrClass.needSerializableFix(): Boolean {
return isObject && isSerializable() && !hasReadMethod()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ import com.tschuchort.compiletesting.SourceFile
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters
import java.lang.reflect.Method

@OptIn(ExperimentalCompilerApi::class)
class ObjectSerializationFixTest {
@RunWith(Parameterized::class)
class ObjectSerializationFixTest(enableFir: Boolean) {
companion object {
@Parameters(name = "FIR: {1}")
@JvmStatic
fun data() = arrayOf(false, true)
}

private val compiler = KotlinCompilation().apply {
compilerPluginRegistrars = listOf(ObjectSerializationCompilerPluginRegistrar())
supportsK2 = true
languageVersion = if (enableFir) "1.9" else "2.0"
}

private val SERIALIZABLE_OBJECT = """
Expand Down

0 comments on commit edfcc46

Please sign in to comment.