From 10a1ea9091a91d85bc27dc32fa0a78e387170574 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 13 Nov 2020 11:19:11 +0100 Subject: [PATCH] Add kotlin.build.useIR property to compile project with JVM IR The change in Devirtualization.kt is needed to workaround JVM IR issue reported at KT-43286. (cherry picked from commit 4a945686bae98c147a641c0b41d3e8474f133ca2) --- .../backend/konan/optimizations/Devirtualization.kt | 2 +- kotlin-native/build.gradle | 9 +++++++++ kotlin-native/gradle.properties | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt index 3f67829cdf2..36f42b5e1eb 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/optimizations/Devirtualization.kt @@ -820,7 +820,7 @@ internal object Devirtualization { val value = fromId.toLong() or (toId.toLong() shl 32) // This is 64-bit extension of a hashing method from Knuth's "The Art of Computer Programming". // The magic constant is the closest prime to 2^64 * phi, where phi is the golden ratio. - val bucketIdx = ((value.toULong() * 11400714819323198393UL) % bagOfEdges.size.toUInt()).toInt() + val bucketIdx = ((value.toULong() * 11400714819323198393UL) % bagOfEdges.size.toULong()).toInt() val bucket = bagOfEdges[bucketIdx] ?: LongArrayList().also { bagOfEdges[bucketIdx] = it } for (x in bucket) if (x == value) return diff --git a/kotlin-native/build.gradle b/kotlin-native/build.gradle index 281800d9324..8cf97669123 100644 --- a/kotlin-native/build.gradle +++ b/kotlin-native/build.gradle @@ -131,6 +131,15 @@ allprojects { } } + if (findProperty("kotlin.build.useIR") == "true") { + tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { + kotlinOptions { + useIR = true + freeCompilerArgs += ["-Xir-binary-with-stable-abi"] + } + } + } + setupHostAndTarget() loadCommandLineProperties() loadLocalProperties() diff --git a/kotlin-native/gradle.properties b/kotlin-native/gradle.properties index deb6f429ee0..39e067f0e08 100644 --- a/kotlin-native/gradle.properties +++ b/kotlin-native/gradle.properties @@ -42,5 +42,8 @@ ktorVersion=1.2.1 shadowVersion=5.1.0 metadataVersion=0.0.1-dev-10 +# Uncomment to compile Kotlin/Native backend modules with JVM IR backend. +# kotlin.build.useIR=true + # Uncomment to enable composite build #kotlinProjectPath=