Skip to content

Commit 4e1c3a6

Browse files
XilinJiaLouisCAD
authored andcommitted
kotlin 2.2.0 RC
(cherry picked from commit d9abc67498216e59a785e296dba186b8db0e234e)
1 parent 29ab0e0 commit 4e1c3a6

File tree

10 files changed

+167
-160
lines changed

10 files changed

+167
-160
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* gradle upped to 8.13
66
* fixed syntax errors in build.gradle.kts in cinterop related to kotlinOptions for Mac ans iOS
77
* fixed syntax errors in build.gradle.kts in cinterop related to KotlinCompile
8+
* various other dependencies updates suitable for Kotlin 2.2.0
89

910
## 3.2.7
1011

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Testing are performed on the dev versions. Maven artifacts can be published (tes
1010

1111
### Version compatibility
1212

13+
krdb 3.2.8 <==> Kotlin 2.2.0
14+
1315
krdb 3.2.6/7 <==> Kotlin 2.1.20
1416

1517
krdb 3.2.5 <==> Kotlin 2.1.10
@@ -49,8 +51,7 @@ with
4951
```apply plugin: "io.github.xilinjia.krdb" ```
5052

5153
* in all kotlin files, replace "io.realm.kotlin" with "io.github.xilinjia.krdb"
52-
* and of course, change your Kotlin to 2.1.x (refer to Version compatibility)
53-
54+
* and of course, change your Kotlin to 2.x.y (refer to Version compatibility)
5455

5556
### To use this with a local build
5657

buildSrc/src/main/kotlin/Config.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ object Versions {
111111
const val androidxTest = "1.6.1" // https://maven.google.com/web/index.html#androidx.test:rules
112112

113113
// Must be built with same (major.minor!?) kotlin version as 'kotlin' variable below, to be binary compatible with kotlin
114-
const val atomicfu = "0.27.0" // https://github.com/Kotlin/kotlinx.atomicfu
115-
const val atomicfuPlugin = "0.27.0" // https://github.com/Kotlin/kotlinx.atomicfu
114+
const val atomicfu = "0.29.0" // https://github.com/Kotlin/kotlinx.atomicfu
115+
const val atomicfuPlugin = "0.29.0" // https://github.com/Kotlin/kotlinx.atomicfu
116116
const val autoService = "1.0" // https://mvnrepository.com/artifact/com.google.auto.service/auto-service
117117
const val buildkonfig = "0.13.3" // https://github.com/yshrsmz/BuildKonfig
118118
const val coroutines = "1.10.1" // https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core
@@ -125,17 +125,18 @@ object Versions {
125125
const val junit = "4.13.2" // https://mvnrepository.com/artifact/junit/junit
126126
const val kbson = "0.4.0" // https://github.com/mongodb/kbson
127127
// When updating the Kotlin version, also remember to update /examples/min-android-sample/build.gradle.kts
128+
// these need to be compatible with Kotlin version: atomicfu, atomicfuPlugin, serialization, kotlinCompileTesting, ktlint
128129
const val kotlin = "2.2.0" // https://github.com/JetBrains/kotlin and https://kotlinlang.org/docs/releases.html#release-details
129130
const val latestKotlin = "2.2.0" // https://kotlinlang.org/docs/eap.html#build-details
130131
const val kotlinJvmTarget = "17" // Which JVM bytecode version is kotlin compiled to.
131-
const val kotlinCompileTesting = "0.7.0" // https://github.com/zacsweers/kotlin-compile-testing
132-
const val ktlint = "1.5.0" // https://github.com/pinterest/ktlint
132+
const val kotlinCompileTesting = "0.8.0" // https://github.com/zacsweers/kotlin-compile-testing
133+
const val ktlint = "1.7.0" // https://github.com/pinterest/ktlint
133134
const val ktor = "2.3.12" // https://github.com/ktorio/ktor
134135
const val multidex = "2.0.1" // https://developer.android.com/jetpack/androidx/releases/multidex
135136
const val nexusPublishPlugin = "1.3.0" // https://github.com/gradle-nexus/publish-plugin
136137
const val okio = "3.10.2" // https://square.github.io/okio/#releases
137138
const val relinker = "1.4.5" // https://github.com/KeepSafe/ReLinker
138-
const val serialization = "1.8.0" // https://kotlinlang.org/docs/releases.html#release-details
139+
const val serialization = "1.9.0" // https://kotlinlang.org/docs/releases.html#release-details
139140
const val shadowJar = "8.1.0" // https://mvnrepository.com/artifact/com.github.johnrengelman.shadow/com.github.johnrengelman.shadow.gradle.plugin?repo=gradle-plugins
140141
const val snakeYaml = "1.33" // https://github.com/snakeyaml/snakeyaml
141142
val sourceCompatibilityVersion = JavaVersion.VERSION_17 // Language level of any Java source code.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

packages/library-base/src/jvmMain/kotlin/io/github/xilinjia/krdb/internal/platform/SystemUtilsJvm.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public actual val DEVICE_MODEL: String = ""
2222
public actual fun appFilesDirectory(): String = System.getProperty("user.dir") ?: "."
2323

2424
public actual fun assetFileAsStream(assetFilename: String): InputStream {
25-
val classLoader = Realm.javaClass.classLoader
25+
// val classLoader = Realm.javaClass.classLoader
26+
val classLoader = Realm::class.java.classLoader
2627
val resource: URL = classLoader.getResource(assetFilename) ?: throw Exceptions.assetFileNotFound(assetFilename)
2728
return resource.openStream()
2829
}

packages/plugin-compiler/src/main/kotlin/io/github/xilinjia/krdb/compiler/AccessorModifierIrGeneration.kt

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import org.jetbrains.kotlin.ir.builders.irString
7777
import org.jetbrains.kotlin.ir.builders.irTemporary
7878
import org.jetbrains.kotlin.ir.declarations.IrClass
7979
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
80+
import org.jetbrains.kotlin.ir.declarations.IrParameterKind
8081
import org.jetbrains.kotlin.ir.declarations.IrProperty
8182
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
8283
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
@@ -97,10 +98,10 @@ import org.jetbrains.kotlin.ir.types.isDouble
9798
import org.jetbrains.kotlin.ir.types.isFloat
9899
import org.jetbrains.kotlin.ir.types.isInt
99100
import org.jetbrains.kotlin.ir.types.isLong
100-
import org.jetbrains.kotlin.ir.types.isNullable
101+
//import org.jetbrains.kotlin.ir.types.isNullable
101102
import org.jetbrains.kotlin.ir.types.isShort
102103
import org.jetbrains.kotlin.ir.types.isString
103-
import org.jetbrains.kotlin.ir.types.isSubtypeOfClass
104+
//import org.jetbrains.kotlin.ir.types.isSubtypeOfClass
104105
import org.jetbrains.kotlin.ir.types.makeNotNull
105106
import org.jetbrains.kotlin.ir.util.classId
106107
import org.jetbrains.kotlin.ir.util.defaultType
@@ -117,8 +118,8 @@ import org.jetbrains.kotlin.types.StarProjectionImpl
117118
import org.jetbrains.kotlin.types.isNullable
118119
import org.jetbrains.kotlin.types.typeUtil.supertypes
119120
import kotlin.collections.set
120-
//import org.jetbrains.kotlin.ir.util.isNullable
121-
//import org.jetbrains.kotlin.ir.util.isSubtypeOfClass
121+
import org.jetbrains.kotlin.ir.util.isNullable
122+
import org.jetbrains.kotlin.ir.util.isSubtypeOfClass
122123

123124
/**
124125
* Modifies the IR tree to transform getter/setter to call the C-Interop layer to retrieve read the managed values from the Realm
@@ -813,7 +814,7 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
813814
irCall(
814815
objectReferenceProperty.getter!!,
815816
).also {
816-
it.dispatchReceiver = irGet(receiver)
817+
it.arguments[0] = irGet(receiver)
817818
},
818819
nameHint = "objectReference",
819820
irType = objectReferenceType,
@@ -822,13 +823,13 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
822823
callee = getFunction,
823824
origin = null
824825
).also {
825-
it.dispatchReceiver = irGetObject(realmObjectHelper.symbol)
826+
it.arguments[0] = irGetObject(realmObjectHelper.symbol)
826827
}.apply {
827828
if (typeArguments.isNotEmpty()) {
828829
typeArguments[0] = type
829830
}
830-
arguments[0] = irGet(objectReferenceType, tmp.symbol)
831-
arguments[1] = irString(property.persistedName)
831+
arguments[1] = irGet(objectReferenceType, tmp.symbol)
832+
arguments[2] = irString(property.persistedName)
832833
}
833834
val storageValue = fromRealmValue?.let {
834835
irCall(callee = it).apply {
@@ -887,16 +888,17 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
887888
irCall(
888889
objectReferenceProperty.getter!!,
889890
).also {
890-
it.dispatchReceiver = irGet(receiver)
891+
it.arguments[0] = irGet(receiver)
891892
},
892893
nameHint = "objectReference",
893894
irType = objectReferenceType,
894895
)
896+
val params = parameters.filter { it.kind == IrParameterKind.Regular || it.kind == IrParameterKind.Context }
895897
val storageValue: IrDeclarationReference = fromPublic?.let {
896898
irCall(callee = it).apply {
897-
arguments[0] = irGet(parameters.first())
899+
arguments[0] = irGet(params.first())
898900
}
899-
} ?: irGet(parameters.first())
901+
} ?: irGet(params.first())
900902
val realmValue: IrDeclarationReference = toRealmValue?.let {
901903
irCall(callee = it).apply {
902904
if (typeArguments.isNotEmpty()) {
@@ -908,25 +910,24 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
908910
val cinteropCall = irCall(
909911
callee = setFunction,
910912
).also {
911-
it.dispatchReceiver = irGetObject(realmObjectHelper.symbol)
913+
it.arguments[0] = irGetObject(realmObjectHelper.symbol)
912914
}.apply {
913915
if (typeArguments.isNotEmpty()) {
914916
typeArguments[0] = type
915917
}
916-
arguments[0] = irGet(objectReferenceType, tmp.symbol)
917-
arguments[1] = irString(property.persistedName)
918-
arguments[2] = realmValue
918+
arguments[1] = irGet(objectReferenceType, tmp.symbol)
919+
arguments[2] = irString(property.persistedName)
920+
arguments[3] = realmValue
919921
}
920922

921923
+irIfNull(
922924
type = pluginContext.irBuiltIns.unitType,
923925
subject = irGet(objectReferenceType, tmp.symbol),
924926
// Unmanaged object, set the backing field
925-
thenPart =
926-
irSetField(
927+
thenPart = irSetField(
927928
irGet(receiver),
928929
backingField.symbol.owner,
929-
irGet(parameters.first()),
930+
irGet(params.first()),
930931
),
931932
// Managed object, return realm value
932933
elsePart = cinteropCall
@@ -1073,28 +1074,24 @@ class AccessorModifierIrGeneration(private val pluginContext: IrPluginContext) {
10731074

10741075
// Otherwise just return the matching core type present in the declaration
10751076
val genericPropertyType: PropertyType? = getPropertyTypeFromKotlinType(collectionGenericType)
1076-
return when (genericPropertyType) {
1077-
null -> {
1078-
logError(
1079-
"Unsupported type for ${collectionType.description}: '${collectionGenericType.getKotlinTypeFqNameCompat(true)
1080-
}'",
1081-
declaration.locationOf()
1082-
)
1083-
null
1084-
}
1085-
PropertyType.RLM_PROPERTY_TYPE_MIXED if !collectionGenericType.isNullable() -> {
1086-
logError(
1087-
"Unsupported type for ${collectionType.description}: Only '${collectionType.description}<RealmAny?>' is supported.",
1088-
declaration.locationOf()
1089-
)
1090-
return null
1091-
}
1092-
else -> {
1093-
CoreType(
1094-
propertyType = genericPropertyType,
1095-
nullable = collectionGenericType.isNullable()
1096-
)
1097-
}
1077+
return if (genericPropertyType == null) {
1078+
logError(
1079+
"Unsupported type for ${collectionType.description}: '${collectionGenericType.getKotlinTypeFqNameCompat(true)
1080+
}'",
1081+
declaration.locationOf()
1082+
)
1083+
null
1084+
} else if (genericPropertyType == PropertyType.RLM_PROPERTY_TYPE_MIXED && !collectionGenericType.isNullable()) {
1085+
logError(
1086+
"Unsupported type for ${collectionType.description}: Only '${collectionType.description}<RealmAny?>' is supported.",
1087+
declaration.locationOf()
1088+
)
1089+
return null
1090+
} else {
1091+
CoreType(
1092+
propertyType = genericPropertyType,
1093+
nullable = collectionGenericType.isNullable()
1094+
)
10981095
}
10991096
}
11001097

packages/plugin-compiler/src/main/kotlin/io/github/xilinjia/krdb/compiler/IrUtils.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ data class SchemaProperty(
425425
companion object {
426426
fun getPersistedName(declaration: IrProperty): String {
427427
@Suppress("UNCHECKED_CAST")
428-
return (declaration.getAnnotation(PERSISTED_NAME_ANNOTATION.asSingleFqName()).arguments[0] as? IrConstImpl)?.value?.toString() ?: ""
428+
return (declaration.getAnnotation(PERSISTED_NAME_ANNOTATION.asSingleFqName()).arguments[0] as IrConstImpl).value?.toString() ?: ""
429429
}
430430
}
431431
}
@@ -471,8 +471,8 @@ internal fun <T : IrExpression> buildSetOf(
471471
): IrExpression {
472472
val setOf = context.referenceFunctions(CallableId(FqName("kotlin.collections"), Name.identifier("setOf")))
473473
.first {
474-
val parameters = it.owner.parameters
475-
parameters.size == 1 && parameters.first().isVararg
474+
val params = it.owner.parameters.filter { p -> p.kind == IrParameterKind.Regular || p.kind == IrParameterKind.Context }
475+
params.size == 1 && params.first().isVararg
476476
}
477477
val setIrClass: IrClass = context.lookupClassOrThrow(ClassIds.KOTLIN_COLLECTIONS_SET)
478478
return buildOf(context, startOffset, endOffset, setOf, setIrClass, elementType, args)
@@ -487,8 +487,8 @@ internal fun <T : IrExpression> buildListOf(
487487
): IrExpression {
488488
val listOf = context.referenceFunctions(KOTLIN_COLLECTIONS_LISTOF)
489489
.first {
490-
val parameters = it.owner.parameters
491-
parameters.size == 1 && parameters.first().isVararg
490+
val params = it.owner.parameters.filter { p -> p.kind == IrParameterKind.Regular || p.kind == IrParameterKind.Context }
491+
params.size == 1 && params.first().isVararg
492492
}
493493
val listIrClass: IrClass = context.lookupClassOrThrow(ClassIds.KOTLIN_COLLECTIONS_LIST)
494494
return buildOf(context, startOffset, endOffset, listOf, listIrClass, elementType, args)
@@ -646,7 +646,7 @@ fun getCollectionElementType(backingFieldType: IrType): IrType? {
646646

647647
fun getBacklinksTargetType(backingField: IrField): IrType {
648648
(backingField.initializer!!.expression as IrCall).let { irCall ->
649-
val propertyReference = irCall.arguments[0] as IrPropertyReference
649+
val propertyReference = irCall.arguments[1] as IrPropertyReference
650650
val propertyType = (propertyReference.type as IrAbstractSimpleType)
651651
return propertyType.arguments[0] as IrType
652652
}
@@ -656,7 +656,7 @@ fun getBacklinksTargetPropertyType(declaration: IrProperty): IrType? {
656656
val backingField: IrField = declaration.backingField!!
657657

658658
(backingField.initializer!!.expression as IrCall).let { irCall ->
659-
val targetPropertyParameter = irCall.arguments[0]
659+
val targetPropertyParameter = irCall.arguments[1]
660660

661661
// Limit linkingObjects to accept only initialization parameters
662662
if (targetPropertyParameter is IrPropertyReference) {
@@ -674,7 +674,7 @@ fun getBacklinksTargetPropertyType(declaration: IrProperty): IrType? {
674674

675675
fun getLinkingObjectPropertyName(backingField: IrField): String {
676676
(backingField.initializer!!.expression as IrCall).let { irCall ->
677-
val propertyReference = irCall.arguments[0] as IrPropertyReference
677+
val propertyReference = irCall.arguments[1] as IrPropertyReference
678678
val targetProperty: IrProperty = propertyReference.symbol.owner
679679
return if (targetProperty.hasAnnotation(PERSISTED_NAME_ANNOTATION)) {
680680
SchemaProperty.getPersistedName(targetProperty)
@@ -690,7 +690,7 @@ fun getLinkingObjectPropertyName(backingField: IrField): String {
690690
fun getSchemaClassName(clazz: IrClass): String {
691691
return if (clazz.hasAnnotation(PERSISTED_NAME_ANNOTATION)) {
692692
@Suppress("UNCHECKED_CAST")
693-
return (clazz.getAnnotation(PERSISTED_NAME_ANNOTATION.asSingleFqName()).arguments[0] as? IrConstImpl)?.value?.toString() ?: ""
693+
return (clazz.getAnnotation(PERSISTED_NAME_ANNOTATION.asSingleFqName()).arguments[0] as IrConstImpl).value?.toString() ?: ""
694694
} else {
695695
clazz.name.identifier
696696
}

packages/plugin-compiler/src/main/kotlin/io/github/xilinjia/krdb/compiler/RealmModelDefaultMethodGeneration.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.ir.builders.irGet
77
import org.jetbrains.kotlin.ir.builders.irGetObject
88
import org.jetbrains.kotlin.ir.builders.irReturn
99
import org.jetbrains.kotlin.ir.declarations.IrClass
10+
import org.jetbrains.kotlin.ir.declarations.IrParameterKind
1011
import org.jetbrains.kotlin.ir.declarations.IrProperty
1112
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
1213
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
@@ -76,11 +77,11 @@ class RealmModelDefaultMethodGeneration(private val pluginContext: IrPluginConte
7677
type = pluginContext.irBuiltIns.booleanType,
7778
symbol = realmEquals.symbol,
7879
typeArgumentsCount = 0,
79-
// valueArgumentsCount = 2
8080
).apply {
81-
dispatchReceiver = irGetObject(realmObjectHelper.symbol)
82-
arguments[0] = irGet(function.dispatchReceiverParameter!!.type, function.dispatchReceiverParameter!!.symbol)
83-
arguments[1] = irGet(function.parameters[0].type, function.parameters[0].symbol)
81+
arguments[0] = irGetObject(realmObjectHelper.symbol)
82+
arguments[1] = irGet(function.dispatchReceiverParameter!!)
83+
val params = function.parameters.filter { it.kind == IrParameterKind.Regular || it.kind == IrParameterKind.Context }
84+
arguments[2] = irGet(params[0])
8485
}
8586
)
8687
}
@@ -96,10 +97,9 @@ class RealmModelDefaultMethodGeneration(private val pluginContext: IrPluginConte
9697
type = pluginContext.irBuiltIns.intType,
9798
symbol = realmHashCode.symbol,
9899
typeArgumentsCount = 0,
99-
// valueArgumentsCount = 1
100100
).apply {
101-
dispatchReceiver = irGetObject(realmObjectHelper.symbol)
102-
arguments[0] = irGet(function.dispatchReceiverParameter!!.type, function.dispatchReceiverParameter!!.symbol)
101+
arguments[0] = irGetObject(realmObjectHelper.symbol)
102+
arguments[1] = irGet(function.dispatchReceiverParameter!!)
103103
}
104104
)
105105
}
@@ -115,10 +115,9 @@ class RealmModelDefaultMethodGeneration(private val pluginContext: IrPluginConte
115115
type = pluginContext.irBuiltIns.stringType,
116116
symbol = realmToString.symbol,
117117
typeArgumentsCount = 0,
118-
// valueArgumentsCount = 1
119118
).apply {
120-
dispatchReceiver = irGetObject(realmObjectHelper.symbol)
121-
arguments[0] = irGet(function.dispatchReceiverParameter!!.type, function.dispatchReceiverParameter!!.symbol)
119+
arguments[0] = irGetObject(realmObjectHelper.symbol)
120+
arguments[1] = irGet(function.dispatchReceiverParameter!!)
122121
}
123122
)
124123
}

0 commit comments

Comments
 (0)