Skip to content

Commit

Permalink
Add support for Kotlin 2.1.0-RC.
Browse files Browse the repository at this point in the history
  • Loading branch information
TadeasKriz committed Nov 14, 2024
1 parent b96044d commit db90ffd
Show file tree
Hide file tree
Showing 43 changed files with 249 additions and 20 deletions.
30 changes: 30 additions & 0 deletions SKIE/.run/Tests_Libraries_Selected Library.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tests/Libraries/Selected Library" type="GradleRunConfiguration" factoryName="Gradle" folderName="Latest">
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="libraryTest" value="" />
<entry key="onlyIndices" value="226" />
</map>
</option>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$/acceptance-tests" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="libraries:kgp_latestTest" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tests/Types/All" type="GradleRunConfiguration" factoryName="Gradle" folderName="Latest">
<ExternalSystemSettings>
<option name="env">
<map>
<entry key="DISABLE_PARALLEL_TESTS" value="true" />
</map>
</option>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
Expand All @@ -21,4 +26,4 @@
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
</component>
2 changes: 1 addition & 1 deletion SKIE/acceptance-tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import co.touchlab.skie.buildsetup.plugins.MultiCompileTarget
import co.touchlab.skie.gradle.KotlinToolingVersion
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

plugins {
Expand All @@ -14,7 +15,8 @@ multiCompileRuntime {
if (target.platformType == KotlinPlatformType.jvm) {
"build/libs/configuration-annotations-${kotlinVersion}-${target.name.lowercase()}-${version}.jar"
} else {
"build/classes/kotlin/${target.name}/main/klib/configuration-annotations-${kotlinVersion}.klib"
val includeKlibExtension = true // kotlinVersion < MultiCompileTarget.kotlin_2_1_0
"build/classes/kotlin/${target.name}/main/klib/configuration-annotations-${kotlinVersion}" + if (includeKlibExtension) ".klib" else ""
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions SKIE/common/configuration/annotations/impl/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
org.gradle.jvmargs=-Xmx1g -XX:MaxMetaspaceSize=500m -XX:+UseParallelGC

kotlin.internal.compiler.arguments.log.level=info

kotlin.internal.klibs.non-packed=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@file:Suppress("invisible_reference", "invisible_member")

package co.touchlab.skie.shim

import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportMapper
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.backend.konan.objcexport.getClassIfCategory
import org.jetbrains.kotlin.backend.konan.objcexport.isObjCProperty
import org.jetbrains.kotlin.backend.konan.objcexport.isTopLevel

actual object ObjCExportMapperShim {
actual fun isSpecialMapped(
mapper: ObjCExportMapper,
descriptor: ClassDescriptor
): Boolean = mapper.isSpecialMapped(descriptor)

actual fun isTopLevel(
mapper: ObjCExportMapper,
descriptor: CallableMemberDescriptor
): Boolean = mapper.isTopLevel(descriptor)

actual fun getClassIfCategory(
mapper: ObjCExportMapper,
descriptor: CallableMemberDescriptor
): ClassDescriptor? = mapper.getClassIfCategory(descriptor)

actual fun isObjCProperty(
mapper: ObjCExportMapper,
property: PropertyDescriptor
): Boolean = mapper.isObjCProperty(property)

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package co.touchlab.skie.kir.irbuilder.impl.symboltable

import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrConstructor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource

actual class DummyIrConstructor actual constructor(override val symbol: IrConstructorSymbol) : IrConstructor() {

actual override var isPrimary: Boolean by unsupported()
override val startOffset: Int by unsupported()
override val endOffset: Int by unsupported()
override val factory: IrFactory by unsupported()
override var origin: IrDeclarationOrigin by unsupported()
override var name: Name by unsupported()
override var visibility: DescriptorVisibility by unsupported()
override var body: IrBody? by unsupported()
override var contextReceiverParametersCount: Int by unsupported()

@ObsoleteDescriptorBasedAPI
override val descriptor: ClassConstructorDescriptor by unsupported()
override var dispatchReceiverParameter: IrValueParameter? by unsupported()
override var extensionReceiverParameter: IrValueParameter? by unsupported()
actual override var isExpect: Boolean by unsupported()
actual override var isInline: Boolean by unsupported()
override var returnType: IrType by unsupported()
override val containerSource: DeserializedContainerSource? by unsupported()
override var metadata: MetadataSource? by unsupported()
override var annotations: List<IrConstructorCall> by unsupported()
actual override var isExternal: Boolean by unsupported()
override var typeParameters: List<IrTypeParameter> by unsupported()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package co.touchlab.skie.kir.irbuilder.impl.symboltable

import org.jetbrains.kotlin.descriptors.DescriptorVisibility
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrAttributeContainer
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource

actual class DummyIrSimpleFunction actual constructor(
override val symbol: IrSimpleFunctionSymbol,
) : IrSimpleFunction() {

override var startOffset: Int by unsupported()
override var endOffset: Int by unsupported()
override var attributeOwnerId: IrAttributeContainer by unsupported()
override val factory: IrFactory by unsupported()
override var origin: IrDeclarationOrigin by unsupported()
override var originalBeforeInline: IrAttributeContainer? by unsupported()
override var name: Name by unsupported()
override var visibility: DescriptorVisibility by unsupported()
override var body: IrBody? by unsupported()
override var contextReceiverParametersCount: Int by unsupported()

@ObsoleteDescriptorBasedAPI
override val descriptor: FunctionDescriptor by unsupported()
override var dispatchReceiverParameter: IrValueParameter? by unsupported()
override var extensionReceiverParameter: IrValueParameter? by unsupported()
override var isExpect: Boolean by unsupported()
override var isInline: Boolean by unsupported()
override var returnType: IrType by unsupported()
override val containerSource: DeserializedContainerSource? by unsupported()
override var metadata: MetadataSource? by unsupported()
override var annotations: List<IrConstructorCall> by unsupported()
override var overriddenSymbols: List<IrSimpleFunctionSymbol> by unsupported()
override var modality: Modality by unsupported()
override var isExternal: Boolean by unsupported()
override var correspondingPropertySymbol: IrPropertySymbol? by unsupported()
override var isFakeOverride: Boolean by unsupported()
override var isInfix: Boolean by unsupported()
override var isOperator: Boolean by unsupported()
override var isSuspend: Boolean by unsupported()
override var isTailrec: Boolean by unsupported()
override var typeParameters: List<IrTypeParameter> by unsupported()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@file:Suppress("invisible_reference", "invisible_member")

package co.touchlab.skie.shim

import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportMapper
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.backend.konan.objcexport.isSpecialMapped
import org.jetbrains.kotlin.backend.konan.objcexport.getClassIfCategory
import org.jetbrains.kotlin.backend.konan.objcexport.isObjCProperty
import org.jetbrains.kotlin.backend.konan.objcexport.isTopLevel

actual object ObjCExportMapperShim {
actual fun isSpecialMapped(
mapper: ObjCExportMapper,
descriptor: ClassDescriptor
): Boolean = isSpecialMapped(descriptor)

actual fun isTopLevel(
mapper: ObjCExportMapper,
descriptor: CallableMemberDescriptor
): Boolean = isTopLevel(descriptor)

actual fun getClassIfCategory(
mapper: ObjCExportMapper,
descriptor: CallableMemberDescriptor
): ClassDescriptor? = getClassIfCategory(descriptor)

actual fun isObjCProperty(
mapper: ObjCExportMapper,
property: PropertyDescriptor
): Boolean = isObjCProperty(property)

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
package co.touchlab.skie.kir.descriptor.cache

import co.touchlab.skie.shim.isObjCObjectType
import co.touchlab.skie.shim.ObjCExportMapperShim
import org.jetbrains.kotlin.backend.konan.FrontendServices
import org.jetbrains.kotlin.backend.konan.KonanConfig
import org.jetbrains.kotlin.backend.konan.KonanFqNames
import org.jetbrains.kotlin.backend.konan.objcexport.MethodBridge
import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportMapper
import org.jetbrains.kotlin.backend.konan.objcexport.getBaseMethods
import org.jetbrains.kotlin.backend.konan.objcexport.getBaseProperties
import org.jetbrains.kotlin.backend.konan.objcexport.getClassIfCategory
import org.jetbrains.kotlin.backend.konan.objcexport.getDeprecation
import org.jetbrains.kotlin.backend.konan.objcexport.isBaseMethod
import org.jetbrains.kotlin.backend.konan.objcexport.isBaseProperty
import org.jetbrains.kotlin.backend.konan.objcexport.isObjCProperty
import org.jetbrains.kotlin.backend.konan.objcexport.isTopLevel
import org.jetbrains.kotlin.backend.konan.objcexport.shouldBeExposed
import org.jetbrains.kotlin.backend.konan.objcexport.shouldBeVisible
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
Expand Down Expand Up @@ -65,17 +63,17 @@ class CachedObjCExportMapper internal constructor(
fun shouldBeExposed(descriptor: ClassDescriptor): Boolean =
shouldBeExposedClassCache.getOrPut(descriptor) {
// shouldBeExposed cannot be called directly starting from Kotlin 2.0.0 because it is internal and the other overload is public
kotlinMapper.shouldBeVisible(descriptor) && !kotlinMapper.isSpecialMapped(descriptor) && !descriptor.defaultType.isObjCObjectType()
kotlinMapper.shouldBeVisible(descriptor) && !ObjCExportMapperShim.isSpecialMapped(kotlinMapper, descriptor) && !descriptor.defaultType.isObjCObjectType()
}

fun isTopLevel(descriptor: CallableMemberDescriptor): Boolean =
isTopLevelCache.getOrPut(descriptor) {
kotlinMapper.isTopLevel(descriptor)
ObjCExportMapperShim.isTopLevel(kotlinMapper, descriptor)
}

fun getClassIfCategory(descriptor: CallableMemberDescriptor): ClassDescriptor? =
getClassIfCategoryCache.getOrPut(descriptor) {
kotlinMapper.getClassIfCategory(descriptor)
ObjCExportMapperShim.getClassIfCategory(kotlinMapper, descriptor)
}

fun isBaseMethod(functionDescriptor: FunctionDescriptor): Boolean =
Expand All @@ -90,7 +88,7 @@ class CachedObjCExportMapper internal constructor(

fun isObjCProperty(property: PropertyDescriptor): Boolean =
isObjCPropertyCache.getOrPut(property) {
kotlinMapper.isObjCProperty(property)
ObjCExportMapperShim.isObjCProperty(kotlinMapper, property)
}

fun getBaseMethods(descriptor: FunctionDescriptor): List<FunctionDescriptor> =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package co.touchlab.skie.shim

import org.jetbrains.kotlin.backend.konan.objcexport.ObjCExportMapper
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor

expect object ObjCExportMapperShim {
fun isSpecialMapped(mapper: ObjCExportMapper, descriptor: ClassDescriptor): Boolean

fun isTopLevel(mapper: ObjCExportMapper, descriptor: CallableMemberDescriptor): Boolean

fun getClassIfCategory(mapper: ObjCExportMapper, descriptor: CallableMemberDescriptor): ClassDescriptor?

fun isObjCProperty(mapper: ObjCExportMapper, property: PropertyDescriptor): Boolean
}
2 changes: 2 additions & 0 deletions SKIE/runtime/kotlin/impl/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
org.gradle.jvmargs=-Xmx1g -XX:MaxMetaspaceSize=500m -XX:+UseParallelGC

kotlin.internal.klibs.non-packed=false
4 changes: 3 additions & 1 deletion SKIE/runtime/kotlin/runtime-kotlin.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import co.touchlab.skie.buildsetup.plugins.MultiCompileTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

plugins {
id("skie.base")
Expand All @@ -9,7 +10,8 @@ multiCompileRuntime {
isPublishable = true
targets.set(MultiCompileTarget.allDarwin)
klibPath = { kotlinVersion, target ->
"build/classes/kotlin/${target.name}/main/klib/runtime-kotlin-${kotlinVersion}.klib"
val includeKlibExtension = true // kotlinVersion < MultiCompileTarget.kotlin_2_1_0
"build/classes/kotlin/${target.name}/main/klib/runtime-kotlin-${kotlinVersion}" + if (includeKlibExtension) ".klib" else ""
}
dependencies = { _ ->
"implementation(libs.kotlinx.coroutines.core)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ interface KotlinCompilerVersion : Named {
}

class DisambiguationRule @Inject constructor(
private val currentKotlinVersion: String,
currentKotlinVersion: String,
) : AttributeDisambiguationRule<KotlinCompilerVersion> {
private val currentKotlinVersion = KotlinToolingVersion(currentKotlinVersion)

override fun execute(details: MultipleCandidatesDetails<KotlinCompilerVersion>) {
val correctCandidate = details.candidateValues.lastOrNull {
it.name == currentKotlinVersion
KotlinToolingVersion(it.name) < currentKotlinVersion
}

if (correctCandidate != null) {
details.closestMatch(correctCandidate)
} else {
// This should've already been caught by SKIE Plugin Loader, but we'll let the user know just in case.
log.error("Could not find a Kotlin compiler version matching the current Kotlin version ($currentKotlinVersion)!")
log.error("Could not find a Kotlin compiler version matching the current Kotlin version ($currentKotlinVersion)! Candidates: ${details.candidateValues.joinToString { it.name }}")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.gradle.language.jvm.tasks.ProcessResources

abstract class DevAcceptanceTestsFramework : Plugin<Project> {

override fun apply(target: Project): Unit = with(target) {
override fun apply(project: Project): Unit = with(project) {
apply<SkieBase>()
apply<MultiDimensionTargetPlugin>()
apply<OptInExperimentalCompilerApi>()
Expand Down Expand Up @@ -60,7 +60,7 @@ abstract class DevAcceptanceTestsFramework : Plugin<Project> {
}
}

extensions.configure<BuildConfigExtension> {
project.extensions.configure<BuildConfigExtension> {
sourceSets.named(target.name + "Main").configure {
generator(ExpectActualBuildConfigGenerator(isActualImplementation = true, internalVisibility = false))
className.set("BuildConfig")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class MultiCompileTarget(
val kotlin_1_9_0 = KotlinToolingVersion("1.9.0")
val kotlin_1_9_20 = KotlinToolingVersion("1.9.20")
val kotlin_2_0_0 = KotlinToolingVersion("2.0.0")
val kotlin_2_1_0 = KotlinToolingVersion("2.1.0")

val jvm = MultiCompileTarget(
name = "jvm",
Expand Down
Loading

0 comments on commit db90ffd

Please sign in to comment.