Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compiler crash when using Kotlin 2.0.20 #1830

Merged
merged 11 commits into from
Sep 16, 2024
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.2.0 (2024-09-13)
## 2.3.0-SNAPSHOT (YYYY-MM-DD)

### Breaking Changes
* None.
Expand All @@ -19,6 +19,7 @@
* [Sync] Client reset cycle detection now checks if the previous recovery attempt was made by the same core version, and if not attempts recovery again (Core issue [realm/realm-core#7944](https://github.com/realm/realm-core/pull/7944)).

### Fixed
* Via https://github.com/realm/realm-kotlin/pull/1826. Fix compiler crash caused by a change in Kotlin 2.0.20. (Issue [#1825](https://github.com/realm/realm-kotlin/issues/1825)). Thanks @KitsuneAlex.
* Comparing a numeric property with an argument list containing a string would throw. (Core issue [realm/realm-core#7714](https://github.com/realm/realm-core/issues/7714), since v2.0.0).
* After compacting, a file upgrade would be triggered. This could cause loss of data if schema mode is SoftResetFile (Core issue [realm/realm-core#7747](https://github.com/realm/realm-core/issues/7747), since v1.15.0).
* Encrypted files on Windows had a maximum size of 2GB even on x64 due to internal usage of `off_t`, which is a 32-bit type on 64-bit Windows (Core issue [realm/realm-core#7698](https://github.com/realm/realm-core/pull/7698)).
Expand Down Expand Up @@ -46,7 +47,7 @@
* File format: Generates Realms with file format v24 (reads and upgrades file format v10 or later).
* Realm Studio 15.0.0 or above is required to open Realms created by this version.
* This release is compatible with the following Kotlin releases:
* Kotlin 2.0.0 and above. Support for experimental K2-compilation with `kotlin.experimental.tryK2=true`.
* Kotlin 2.0.20 and above. Support for experimental K2-compilation with `kotlin.experimental.tryK2=true`.
* Ktor 2.1.2 and above.
* Coroutines 1.7.0 and above.
* AtomicFu 0.18.3 and above.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[![Gradle Plugin Portal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/io/realm/kotlin/io.realm.kotlin.gradle.plugin/maven-metadata.xml.svg?colorB=ff6b00&label=Gradle%20Plugin%20Portal)](https://plugins.gradle.org/plugin/io.realm.kotlin)
[![Maven Central](https://img.shields.io/maven-central/v/io.realm.kotlin/gradle-plugin?colorB=4dc427&label=Maven%20Central)](https://search.maven.org/artifact/io.realm.kotlin/gradle-plugin)
[![Kotlin](https://img.shields.io/badge/kotlin-2.0.0-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/kotlin-2.0.20-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![License](https://img.shields.io/badge/License-Apache-blue.svg)](https://github.com/realm/realm-kotlin/blob/master/LICENSE)


Expand Down Expand Up @@ -328,6 +328,7 @@ SDK supports. In the matrix below, you will find the minimum supported version f

| Realm Version | Requirements |
|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 2.3.0 | <ul><li>Kotlin 2.0.20+</li><li>AtomicFu 0.18.3+.</li><li>Ktor 2.1.2+.</li><li>Coroutines 1.7.0+.</li><li>Gradle 7.2 - 8.5</li><li>The new memory model only.</li></ul> |
| 2.0.0 | <ul><li>Kotlin 2.0.0+</li><li>AtomicFu 0.18.3+.</li><li>Ktor 2.1.2+.</li><li>Coroutines 1.7.0+.</li><li>Gradle 7.2 - 8.5</li><li>The new memory model only.</li></ul> |
| 1.16.0 | <ul><li>Kotlin 1.9.0+</li><li>AtomicFu 0.18.3+.</li><li>Ktor 2.1.2+.</li><li>Coroutines 1.7.0+.</li><li>Gradle 6.8.3 - 8.5</li><li>The new memory model only.</li></ul> |
| 1.15.0 | <ul><li>Kotlin 1.9.0+</li><li>AtomicFu 0.18.3+.</li><li>Ktor 2.1.2+.</li><li>Coroutines 1.7.0+.</li><li>Gradle 6.8.3 - 8.5</li><li>The new memory model only.</li></ul> |
Expand Down
12 changes: 6 additions & 6 deletions buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ val HOST_OS: OperatingSystem = findHostOs()

object Realm {
val ciBuild = (System.getenv("CI") != null)
const val version = "2.2.0"
const val version = "2.3.0-SNAPSHOT"
const val group = "io.realm.kotlin"
const val projectUrl = "https://realm.io"
const val pluginPortalId = "io.realm.kotlin"
Expand Down Expand Up @@ -123,15 +123,15 @@ object Versions {
const val junit = "4.13.2" // https://mvnrepository.com/artifact/junit/junit
const val kbson = "0.4.0" // https://github.com/mongodb/kbson
// When updating the Kotlin version, also remember to update /examples/min-android-sample/build.gradle.kts
const val kotlin = "2.0.0" // https://github.com/JetBrains/kotlin and https://kotlinlang.org/docs/releases.html#release-details
const val kotlin = "2.0.20" // https://github.com/JetBrains/kotlin and https://kotlinlang.org/docs/releases.html#release-details
const val kotlinJvmTarget = "1.8" // Which JVM bytecode version is kotlin compiled to.
const val latestKotlin = "2.0.0" // https://kotlinlang.org/docs/eap.html#build-details
const val kotlinCompileTesting = "0.5.0-alpha07" // https://github.com/zacsweers/kotlin-compile-testing
const val latestKotlin = "2.0.20" // https://kotlinlang.org/docs/eap.html#build-details
const val kotlinCompileTesting = "0.5.1" // https://github.com/zacsweers/kotlin-compile-testing
const val ktlint = "0.45.2" // https://github.com/pinterest/ktlint
const val ktor = "2.3.12" // https://github.com/ktorio/ktor
const val multidex = "2.0.1" // https://developer.android.com/jetpack/androidx/releases/multidex
const val nexusPublishPlugin = "1.1.0" // https://github.com/gradle-nexus/publish-plugin
const val okio = "3.2.0" // https://square.github.io/okio/#releases
const val nexusPublishPlugin = "1.3.0" // https://github.com/gradle-nexus/publish-plugin
const val okio = "3.9.0" // https://square.github.io/okio/#releases
const val relinker = "1.4.5" // https://github.com/KeepSafe/ReLinker
const val serialization = "1.7.1" // https://kotlinlang.org/docs/releases.html#release-details
const val shadowJar = "6.1.0" // https://mvnrepository.com/artifact/com.github.johnrengelman.shadow/com.github.johnrengelman.shadow.gradle.plugin?repo=gradle-plugins
Expand Down
2 changes: 1 addition & 1 deletion examples/min-android-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ buildscript {
}
dependencies {
classpath("com.android.tools.build:gradle:7.1.3")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20")
classpath("io.realm.kotlin:gradle-plugin:${rootProject.extra["realmVersion"]}")
}
}
Expand Down
9 changes: 8 additions & 1 deletion integration-tests/gradle/gradle72-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ buildscript {
it.substringAfter("\"").substringBefore("\"")
}

extra["kotlinVersion"] = file("${rootProject.rootDir.absolutePath}/../../../buildSrc/src/main/kotlin/Config.kt")
.readLines()
.first { it.contains("const val kotlin") }
.let {
it.substringAfter("\"").substringBefore("\"")
}

repositories {
maven(url = "file://${rootProject.rootDir.absolutePath}/../../../packages/build/m2-buildrepo")
gradlePluginPortal()
Expand All @@ -34,7 +41,7 @@ buildscript {
}
dependencies {
classpath("com.android.tools.build:gradle:7.1.3")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["kotlinVersion"]}")
classpath("io.realm.kotlin:gradle-plugin:${rootProject.extra["realmVersion"]}")
}
}
Expand Down
9 changes: 8 additions & 1 deletion integration-tests/gradle/gradle75-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ buildscript {
it.substringAfter("\"").substringBefore("\"")
}

extra["kotlinVersion"] = file("${rootProject.rootDir.absolutePath}/../../../buildSrc/src/main/kotlin/Config.kt")
.readLines()
.first { it.contains("const val kotlin") }
.let {
it.substringAfter("\"").substringBefore("\"")
}

repositories {
maven(url = "file://${rootProject.rootDir.absolutePath}/../../../packages/build/m2-buildrepo")
gradlePluginPortal()
Expand All @@ -34,7 +41,7 @@ buildscript {
}
dependencies {
classpath("com.android.tools.build:gradle:7.4.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["kotlinVersion"]}")
classpath("io.realm.kotlin:gradle-plugin:${rootProject.extra["realmVersion"]}")
}
}
Expand Down
9 changes: 8 additions & 1 deletion integration-tests/gradle/gradle8-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ buildscript {
it.substringAfter("\"").substringBefore("\"")
}

extra["kotlinVersion"] = file("${rootProject.rootDir.absolutePath}/../../../buildSrc/src/main/kotlin/Config.kt")
.readLines()
.first { it.contains("const val kotlin") }
.let {
it.substringAfter("\"").substringBefore("\"")
}

repositories {
maven(url = "file://${rootProject.rootDir.absolutePath}/../../../packages/build/m2-buildrepo")
gradlePluginPortal()
Expand All @@ -34,7 +41,7 @@ buildscript {
}
dependencies {
classpath("com.android.tools.build:gradle:8.1.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["kotlinVersion"]}")
classpath("io.realm.kotlin:gradle-plugin:${rootProject.extra["realmVersion"]}")
}
}
Expand Down
9 changes: 8 additions & 1 deletion integration-tests/gradle/gradle85-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ buildscript {
it.substringAfter("\"").substringBefore("\"")
}

extra["kotlinVersion"] = file("${rootProject.rootDir.absolutePath}/../../../buildSrc/src/main/kotlin/Config.kt")
.readLines()
.first { it.contains("const val kotlin") }
.let {
it.substringAfter("\"").substringBefore("\"")
}

repositories {
maven(url = "file://${rootProject.rootDir.absolutePath}/../../../packages/build/m2-buildrepo")
gradlePluginPortal()
Expand All @@ -34,7 +41,7 @@ buildscript {
}
dependencies {
classpath("com.android.tools.build:gradle:8.1.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["kotlinVersion"]}")
classpath("io.realm.kotlin:gradle-plugin:${rootProject.extra["realmVersion"]}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.IrTypeArgument
import org.jetbrains.kotlin.ir.types.getClass
import org.jetbrains.kotlin.ir.types.impl.IrAbstractSimpleType
import org.jetbrains.kotlin.ir.types.impl.IrTypeBase
import org.jetbrains.kotlin.ir.types.makeNullable
import org.jetbrains.kotlin.ir.types.typeWith
import org.jetbrains.kotlin.ir.util.classId
Expand Down Expand Up @@ -633,7 +632,7 @@ fun getCollectionElementType(backingFieldType: IrType): IrType? {
@Suppress("UNCHECKED_CAST")
val values: List<IrTypeArgument> = args.get(backingFieldType) as List<IrTypeArgument>
if (values.isNotEmpty()) {
return (values[0] as IrTypeBase).type
return (values[0] as IrType).type
}
}
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import org.jetbrains.kotlin.backend.common.CompilationException
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
import org.jetbrains.kotlin.backend.common.wrapWithCompilationException
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrFile
Expand Down Expand Up @@ -76,15 +75,25 @@ private class RealmModelLowering(private val pluginContext: IrPluginContext) : C
// Unfortunately we cannot access the IR element of e uniformly across 1.9 and 2.0 so
// leaving it as null. Hopefully the embedded cause will give the appropriate pointers
// to fix this.
throw e.wrapWithCompilationException("Internal error in realm lowering", it, null)
throw CompilationException(
"Internal error in realm lowering : ${this::class.qualifiedName}: ${e.message}",
it,
null,
cause = e
).apply {
stackTrace = e.stackTrace
}
} catch (e: KotlinExceptionWithAttachments) {
throw e
} catch (e: Throwable) {
throw e.wrapWithCompilationException(
"Internal error in file lowering",
throw CompilationException(
"Internal error in file lowering : ${this::class.qualifiedName}: ${e.message}",
it,
null
)
null,
cause = e
).apply {
stackTrace = e.stackTrace
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.jetbrains.kotlin.backend.common.DeclarationContainerLoweringPass
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
import org.jetbrains.kotlin.backend.common.wrapWithCompilationException
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclarationContainer
import org.jetbrains.kotlin.ir.declarations.IrFile
Expand Down Expand Up @@ -180,15 +179,25 @@ private class SyncLowering(private val pluginContext: IrPluginContext, private v
// Unfortunately we cannot access the IR element of e uniformly across 1.9 and 2.0 so
// leaving it as null. Hopefully the embedded cause will give the appropriate pointers
// to fix this.
throw e.wrapWithCompilationException("Internal error in realm lowering", it, null)
throw CompilationException(
"Internal error in realm lowering : ${this::class.qualifiedName}: ${e.message}",
it,
null,
cause = e
).apply {
stackTrace = e.stackTrace
}
} catch (e: KotlinExceptionWithAttachments) {
throw e
} catch (e: Throwable) {
throw e.wrapWithCompilationException(
"Internal error in file lowering",
throw CompilationException(
"Internal error in file lowering : ${this::class.qualifiedName}: ${e.message}",
it,
null
)
null,
cause = e
).apply {
stackTrace = e.stackTrace
}
}
}

Expand Down
Loading