From d2e311048078c7d2f6279277f2c9f2a31c7bb0a7 Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Wed, 24 Nov 2021 03:48:43 +0700 Subject: [PATCH] Update gradle-tools, do Kotlin 1.6.0 migrations --- benchmarks/build.gradle.kts | 8 +++---- build.gradle.kts | 8 +++---- buildSrc/build.gradle.kts | 6 +++--- examples/build.gradle.kts | 8 +++---- kmath-ast/build.gradle.kts | 2 +- .../random/CMRandomGeneratorWrapper.kt | 3 --- kmath-core/build.gradle.kts | 21 +++++++------------ .../space/kscience/kmath/misc/annotations.kt | 6 +++--- .../kmath/operations/BufferAlgebra.kt | 5 ----- .../kmath/operations/DoubleBufferField.kt | 1 - .../kmath/operations/DoubleBufferOps.kt | 2 -- kmath-coroutines/build.gradle.kts | 6 +++--- kmath-jafama/build.gradle.kts | 2 +- kmath-jupyter/build.gradle.kts | 4 ++-- kmath-optimization/build.gradle.kts | 4 ++++ kmath-tensors/build.gradle.kts | 6 +++++- .../kmath/tensors/core/DoubleTensorAlgebra.kt | 1 - settings.gradle.kts | 9 +------- 18 files changed, 42 insertions(+), 60 deletions(-) diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index 130cc84a3..ea9934a52 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -48,7 +48,7 @@ kotlin { implementation(project(":kmath-nd4j")) implementation(project(":kmath-kotlingrad")) implementation(project(":kmath-viktor")) - implementation(projects.kmathMultik) + implementation(project(":kmath-multik")) implementation("org.nd4j:nd4j-native:1.0.0-M1") // uncomment if your system supports AVX2 // val os = System.getProperty("os.name") @@ -134,9 +134,9 @@ afterEvaluate { kotlin.sourceSets.all { with(languageSettings) { - useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") - useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes") - useExperimentalAnnotation("space.kscience.kmath.misc.UnstableKMathAPI") + optIn("kotlin.contracts.ExperimentalContracts") + optIn("kotlin.ExperimentalUnsignedTypes") + optIn("space.kscience.kmath.misc.UnstableKMathAPI") } } diff --git a/build.gradle.kts b/build.gradle.kts index c2347f7be..919356c0f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,7 +39,7 @@ subprojects { localDirectory.set(kotlinDir) remoteUrl.set( - URL("https://github.com/mipt-npm/${rootProject.name}/tree/master/${this@subprojects.name}/$kotlinDirPath") + URL("https://github.com/mipt-npm/kmath/tree/master/${this@subprojects.name}/$kotlinDirPath") ) } @@ -64,9 +64,9 @@ subprojects { readme.readmeTemplate = file("docs/templates/README-TEMPLATE.md") ksciencePublish { - vcs("https://github.com/mipt-npm/kmath") - space(publish = true) - sonatype(publish = true) + github("kmath", publish = false) + space() + sonatype() } apiValidation.nonPublicMarkers.add("space.kscience.kmath.misc.UnstableKMathAPI") diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 36a1ffd9e..072309332 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,6 +1,6 @@ plugins { `kotlin-dsl` - kotlin("plugin.serialization") version "1.4.31" + kotlin("plugin.serialization") version "1.5.21" } repositories { @@ -10,8 +10,8 @@ repositories { } dependencies { - api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0") - api("ru.mipt.npm:gradle-tools:0.10.2") + api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.2") + api("ru.mipt.npm:gradle-tools:0.10.7") api("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:0.3.1") } diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 05e562143..990b564e1 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -32,7 +32,7 @@ dependencies { //jafama implementation(project(":kmath-jafama")) //multik - implementation(projects.kmathMultik) + implementation(project(":kmath-multik")) implementation("org.nd4j:nd4j-native:1.0.0-beta7") @@ -57,9 +57,9 @@ dependencies { kotlin.sourceSets.all { with(languageSettings) { - useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") - useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes") - useExperimentalAnnotation("space.kscience.kmath.misc.UnstableKMathAPI") + optIn("kotlin.contracts.ExperimentalContracts") + optIn("kotlin.ExperimentalUnsignedTypes") + optIn("space.kscience.kmath.misc.UnstableKMathAPI") } } diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts index 331d8c614..15b1d0900 100644 --- a/kmath-ast/build.gradle.kts +++ b/kmath-ast/build.gradle.kts @@ -20,7 +20,7 @@ kotlin.js { kotlin.sourceSets { filter { it.name.contains("test", true) } .map(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::languageSettings) - .forEach { it.useExperimentalAnnotation("space.kscience.kmath.misc.UnstableKMathAPI") } + .forEach { it.optIn("space.kscience.kmath.misc.UnstableKMathAPI") } commonMain { dependencies { diff --git a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt index 6aeebb68c..194be6002 100644 --- a/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt +++ b/kmath-commons/src/main/kotlin/space/kscience/kmath/commons/random/CMRandomGeneratorWrapper.kt @@ -38,10 +38,7 @@ public class CMRandomGeneratorWrapper( override fun nextInt(): Int = generator.nextInt() override fun nextInt(n: Int): Int = generator.nextInt(n) - - @PerformancePitfall override fun nextGaussian(): Double = runBlocking { GaussianSampler(0.0, 1.0).next(generator) } - override fun nextDouble(): Double = generator.nextDouble() override fun nextLong(): Long = generator.nextLong() } diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index 143e576f7..490868a0b 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -5,21 +5,14 @@ plugins { // id("com.xcporter.metaview") version "0.0.5" } -kotlin { - jvm { - compilations.all { - kotlinOptions { - freeCompilerArgs = - freeCompilerArgs + "-Xjvm-default=all" + "-Xopt-in=kotlin.RequiresOptIn" + "-Xlambdas=indy" - } - } - } +kotlin.sourceSets { + filter { it.name.contains("test", true) } + .map(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::languageSettings) + .forEach { it.optIn("space.kscience.kmath.misc.PerformancePitfall") } - sourceSets { - commonMain { - dependencies { - api(project(":kmath-memory")) - } + commonMain { + dependencies { + api(project(":kmath-memory")) } } } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/annotations.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/annotations.kt index 73ecd6492..7c612b6a9 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/annotations.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/misc/annotations.kt @@ -12,7 +12,7 @@ package space.kscience.kmath.misc * in some way that may break some code. */ @MustBeDocumented -@Retention(value = AnnotationRetention.SOURCE) +@Retention(value = AnnotationRetention.BINARY) @RequiresOptIn("This API is unstable and could change in future", RequiresOptIn.Level.WARNING) public annotation class UnstableKMathAPI @@ -21,10 +21,10 @@ public annotation class UnstableKMathAPI * slow-down in some cases. Refer to the documentation and benchmark it to be sure. */ @MustBeDocumented -@Retention(value = AnnotationRetention.SOURCE) +@Retention(value = AnnotationRetention.BINARY) @RequiresOptIn( "Refer to the documentation to use this API in performance-critical code", - RequiresOptIn.Level.WARNING + RequiresOptIn.Level.WARNING, ) public annotation class PerformancePitfall( val message: String = "Potential performance problem" diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt index 634a115c7..653552044 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/BufferAlgebra.kt @@ -35,13 +35,11 @@ public interface BufferAlgebra> : Algebra> { public fun Buffer.zip(other: Buffer, block: A.(left: T, right: T) -> T): Buffer = zipInline(this, other, block) - @UnstableKMathAPI override fun unaryOperationFunction(operation: String): (arg: Buffer) -> Buffer { val operationFunction = elementAlgebra.unaryOperationFunction(operation) return { arg -> bufferFactory(arg.size) { operationFunction(arg[it]) } } } - @UnstableKMathAPI override fun binaryOperationFunction(operation: String): (left: Buffer, right: Buffer) -> Buffer { val operationFunction = elementAlgebra.binaryOperationFunction(operation) return { left, right -> @@ -141,11 +139,9 @@ public open class BufferRingOps>( override fun multiply(left: Buffer, right: Buffer): Buffer = zipInline(left, right) { l, r -> l * r } override fun Buffer.unaryMinus(): Buffer = map { -it } - @UnstableKMathAPI override fun unaryOperationFunction(operation: String): (arg: Buffer) -> Buffer = super.unaryOperationFunction(operation) - @UnstableKMathAPI override fun binaryOperationFunction(operation: String): (left: Buffer, right: Buffer) -> Buffer = super.binaryOperationFunction(operation) } @@ -165,7 +161,6 @@ public open class BufferFieldOps>( override fun scale(a: Buffer, value: Double): Buffer = a.map { scale(it, value) } override fun Buffer.unaryMinus(): Buffer = map { -it } - @UnstableKMathAPI override fun binaryOperationFunction(operation: String): (left: Buffer, right: Buffer) -> Buffer = super.binaryOperationFunction(operation) } diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/DoubleBufferField.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/DoubleBufferField.kt index 8ec3c3aea..f2f7326aa 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/DoubleBufferField.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/DoubleBufferField.kt @@ -40,7 +40,6 @@ public class DoubleBufferField(public val size: Int) : ExtendedField) -> Buffer = super.unaryOperationFunction(operation) diff --git a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/DoubleBufferOps.kt b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/DoubleBufferOps.kt index a5e1c42e2..0ee591acc 100644 --- a/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/DoubleBufferOps.kt +++ b/kmath-core/src/commonMain/kotlin/space/kscience/kmath/operations/DoubleBufferOps.kt @@ -26,11 +26,9 @@ public abstract class DoubleBufferOps : BufferAlgebra, Exte override fun Buffer.map(block: DoubleField.(Double) -> Double): DoubleBuffer = mapInline { DoubleField.block(it) } - @UnstableKMathAPI override fun unaryOperationFunction(operation: String): (arg: Buffer) -> Buffer = super.unaryOperationFunction(operation) - @UnstableKMathAPI override fun binaryOperationFunction(operation: String): (left: Buffer, right: Buffer) -> Buffer = super.binaryOperationFunction(operation) diff --git a/kmath-coroutines/build.gradle.kts b/kmath-coroutines/build.gradle.kts index 317691ae5..aa30c412b 100644 --- a/kmath-coroutines/build.gradle.kts +++ b/kmath-coroutines/build.gradle.kts @@ -7,9 +7,9 @@ plugins { kotlin.sourceSets { all { with(languageSettings) { - useExperimentalAnnotation("kotlinx.coroutines.InternalCoroutinesApi") - useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi") - useExperimentalAnnotation("kotlinx.coroutines.FlowPreview") + optIn("kotlinx.coroutines.InternalCoroutinesApi") + optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") + optIn("kotlinx.coroutines.FlowPreview") } } diff --git a/kmath-jafama/build.gradle.kts b/kmath-jafama/build.gradle.kts index 9cf328d0b..925a2bc60 100644 --- a/kmath-jafama/build.gradle.kts +++ b/kmath-jafama/build.gradle.kts @@ -23,5 +23,5 @@ readme { } kotlin.sourceSets.all { - languageSettings.useExperimentalAnnotation("space.kscience.kmath.misc.UnstableKMathAPI") + languageSettings.optIn("space.kscience.kmath.misc.UnstableKMathAPI") } diff --git a/kmath-jupyter/build.gradle.kts b/kmath-jupyter/build.gradle.kts index 5bd08c485..ca1a5485f 100644 --- a/kmath-jupyter/build.gradle.kts +++ b/kmath-jupyter/build.gradle.kts @@ -9,7 +9,7 @@ dependencies { api(project(":kmath-for-real")) } -kscience{ +kscience { useHtml() } @@ -18,7 +18,7 @@ readme { } kotlin.sourceSets.all { - languageSettings.useExperimentalAnnotation("space.kscience.kmath.misc.UnstableKMathAPI") + languageSettings.optIn("space.kscience.kmath.misc.UnstableKMathAPI") } tasks.processJupyterApiResources { diff --git a/kmath-optimization/build.gradle.kts b/kmath-optimization/build.gradle.kts index 68b82ad65..b920b9267 100644 --- a/kmath-optimization/build.gradle.kts +++ b/kmath-optimization/build.gradle.kts @@ -8,6 +8,10 @@ kscience { } kotlin.sourceSets { + all { + languageSettings.optIn("space.kscience.kmath.misc.UnstableKMathAPI") + } + commonMain { dependencies { api(project(":kmath-coroutines")) diff --git a/kmath-tensors/build.gradle.kts b/kmath-tensors/build.gradle.kts index d084878ea..66316d21d 100644 --- a/kmath-tensors/build.gradle.kts +++ b/kmath-tensors/build.gradle.kts @@ -6,9 +6,13 @@ plugins { kotlin.sourceSets { all { - languageSettings.useExperimentalAnnotation("space.kscience.kmath.misc.UnstableKMathAPI") + languageSettings.optIn("space.kscience.kmath.misc.UnstableKMathAPI") } + filter { it.name.contains("test", true) } + .map(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::languageSettings) + .forEach { it.optIn("space.kscience.kmath.misc.PerformancePitfall") } + commonMain { dependencies { api(project(":kmath-core")) diff --git a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt index ae1a053af..dc3ec43e9 100644 --- a/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt +++ b/kmath-tensors/src/commonMain/kotlin/space/kscience/kmath/tensors/core/DoubleTensorAlgebra.kt @@ -384,7 +384,6 @@ public open class DoubleTensorAlgebra : override fun Tensor.viewAs(other: StructureND): DoubleTensor = tensor.view(other.shape) - @PerformancePitfall override infix fun StructureND.dot(other: StructureND): DoubleTensor { if (tensor.shape.size == 1 && other.shape.size == 1) { return DoubleTensor(intArrayOf(1), doubleArrayOf(tensor.times(other).tensor.mutableBuffer.array().sum())) diff --git a/settings.gradle.kts b/settings.gradle.kts index e73381bf2..343e937e1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,14 +5,10 @@ pluginManagement { gradlePluginPortal() } - val kotlinVersion = "1.6.0-RC" - val toolsVersion = "0.10.5" + val kotlinVersion = "1.6.0" plugins { id("org.jetbrains.kotlinx.benchmark") version "0.3.1" - id("ru.mipt.npm.gradle.project") version toolsVersion - id("ru.mipt.npm.gradle.jvm") version toolsVersion - id("ru.mipt.npm.gradle.mpp") version toolsVersion kotlin("multiplatform") version kotlinVersion kotlin("plugin.allopen") version kotlinVersion } @@ -20,9 +16,6 @@ pluginManagement { rootProject.name = "kmath" -enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") -enableFeaturePreview("VERSION_CATALOGS") - include( ":kmath-memory", ":kmath-complex", -- 2.34.1