diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index 9f842024d..f5a4d5831 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -56,6 +56,12 @@ benchmark { } } +kotlin.sourceSets.all { + with(languageSettings) { + useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") + useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes") + } +} tasks.withType { kotlinOptions { diff --git a/examples/src/benchmarks/kotlin/scientifik/kmath/utils/utils.kt b/examples/src/benchmarks/kotlin/scientifik/kmath/utils/utils.kt index 305f21d4f..3b0d56291 100644 --- a/examples/src/benchmarks/kotlin/scientifik/kmath/utils/utils.kt +++ b/examples/src/benchmarks/kotlin/scientifik/kmath/utils/utils.kt @@ -1,11 +1,9 @@ package scientifik.kmath.utils -import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.system.measureTimeMillis -@OptIn(ExperimentalContracts::class) internal inline fun measureAndPrint(title: String, block: () -> Unit) { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } val time = measureTimeMillis(block) diff --git a/examples/src/main/kotlin/scientifik/kmath/structures/NDField.kt b/examples/src/main/kotlin/scientifik/kmath/structures/NDField.kt index 1ce74b2a3..1bc0ed7c8 100644 --- a/examples/src/main/kotlin/scientifik/kmath/structures/NDField.kt +++ b/examples/src/main/kotlin/scientifik/kmath/structures/NDField.kt @@ -8,7 +8,6 @@ import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.system.measureTimeMillis -@OptIn(ExperimentalContracts::class) internal inline fun measureAndPrint(title: String, block: () -> Unit) { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } val time = measureTimeMillis(block) diff --git a/examples/src/main/kotlin/scientifik/kmath/structures/typeSafeDimensions.kt b/examples/src/main/kotlin/scientifik/kmath/structures/typeSafeDimensions.kt index e627cecaa..5d323823a 100644 --- a/examples/src/main/kotlin/scientifik/kmath/structures/typeSafeDimensions.kt +++ b/examples/src/main/kotlin/scientifik/kmath/structures/typeSafeDimensions.kt @@ -16,7 +16,6 @@ fun DMatrixContext.simple() { object D5 : Dimension { - @OptIn(ExperimentalUnsignedTypes::class) override val dim: UInt = 5u } diff --git a/kmath-ast/build.gradle.kts b/kmath-ast/build.gradle.kts index d13a7712d..86b10bdc7 100644 --- a/kmath-ast/build.gradle.kts +++ b/kmath-ast/build.gradle.kts @@ -1,11 +1,8 @@ plugins { id("scientifik.mpp") } kotlin.sourceSets { -// all { -// languageSettings.apply{ -// enableLanguageFeature("NewInference") -// } -// } + all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") } + commonMain { dependencies { api(project(":kmath-core")) diff --git a/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MstExpression.kt b/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MstExpression.kt index 635dc940d..3cee33956 100644 --- a/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MstExpression.kt +++ b/kmath-ast/src/commonMain/kotlin/scientifik/kmath/ast/MstExpression.kt @@ -41,7 +41,6 @@ inline fun , E : Algebra> A.mst( /** * Builds [MstExpression] over [Space]. */ -@OptIn(ExperimentalContracts::class) inline fun Space.mstInSpace(block: MstSpace.() -> MST): MstExpression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return MstExpression(this, MstSpace.block()) @@ -50,7 +49,6 @@ inline fun Space.mstInSpace(block: MstSpace.() -> MST): Mst /** * Builds [MstExpression] over [Ring]. */ -@OptIn(ExperimentalContracts::class) inline fun Ring.mstInRing(block: MstRing.() -> MST): MstExpression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return MstExpression(this, MstRing.block()) @@ -59,7 +57,6 @@ inline fun Ring.mstInRing(block: MstRing.() -> MST): MstExp /** * Builds [MstExpression] over [Field]. */ -@OptIn(ExperimentalContracts::class) inline fun Field.mstInField(block: MstField.() -> MST): MstExpression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return MstExpression(this, MstField.block()) @@ -68,7 +65,6 @@ inline fun Field.mstInField(block: MstField.() -> MST): Mst /** * Builds [MstExpression] over [ExtendedField]. */ -@OptIn(ExperimentalContracts::class) inline fun Field.mstInExtendedField(block: MstExtendedField.() -> MST): MstExpression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return MstExpression(this, MstExtendedField.block()) @@ -77,7 +73,6 @@ inline fun Field.mstInExtendedField(block: MstExtendedField /** * Builds [MstExpression] over [FunctionalExpressionSpace]. */ -@OptIn(ExperimentalContracts::class) inline fun > FunctionalExpressionSpace.mstInSpace(block: MstSpace.() -> MST): MstExpression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return algebra.mstInSpace(block) @@ -86,8 +81,6 @@ inline fun > FunctionalExpressionSpace.mstIn /** * Builds [MstExpression] over [FunctionalExpressionRing]. */ - -@OptIn(ExperimentalContracts::class) inline fun > FunctionalExpressionRing.mstInRing(block: MstRing.() -> MST): MstExpression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return algebra.mstInRing(block) @@ -96,7 +89,6 @@ inline fun > FunctionalExpressionRing.mstInRi /** * Builds [MstExpression] over [FunctionalExpressionField]. */ -@OptIn(ExperimentalContracts::class) inline fun > FunctionalExpressionField.mstInField(block: MstField.() -> MST): MstExpression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return algebra.mstInField(block) @@ -105,7 +97,6 @@ inline fun > FunctionalExpressionField.mstIn /** * Builds [MstExpression] over [FunctionalExpressionExtendedField]. */ -@OptIn(ExperimentalContracts::class) inline fun > FunctionalExpressionExtendedField.mstInExtendedField(block: MstExtendedField.() -> MST): MstExpression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return algebra.mstInExtendedField(block) diff --git a/kmath-ast/src/jvmMain/kotlin/scientifik/kmath/asm/internal/codegenUtils.kt b/kmath-ast/src/jvmMain/kotlin/scientifik/kmath/asm/internal/codegenUtils.kt index 97bfba7f2..6f51fe855 100644 --- a/kmath-ast/src/jvmMain/kotlin/scientifik/kmath/asm/internal/codegenUtils.kt +++ b/kmath-ast/src/jvmMain/kotlin/scientifik/kmath/asm/internal/codegenUtils.kt @@ -29,7 +29,6 @@ internal val KClass<*>.asm: Type /** * Returns singleton array with this value if the [predicate] is true, returns empty array otherwise. */ -@OptIn(ExperimentalContracts::class) internal inline fun T.wrapToArrayIf(predicate: (T) -> Boolean): Array { contract { callsInPlace(predicate, InvocationKind.EXACTLY_ONCE) } return if (predicate(this)) arrayOf(this) else emptyArray() @@ -43,7 +42,6 @@ private fun MethodVisitor.instructionAdapter(): InstructionAdapter = Instruction /** * Creates an [InstructionAdapter] from this [MethodVisitor] and applies [block] to it. */ -@OptIn(ExperimentalContracts::class) internal inline fun MethodVisitor.instructionAdapter(block: InstructionAdapter.() -> Unit): InstructionAdapter { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return instructionAdapter().apply(block) @@ -72,14 +70,12 @@ internal tailrec fun buildName(mst: MST, collision: Int = 0): String { return buildName(mst, collision + 1) } -@OptIn(ExperimentalContracts::class) @Suppress("FunctionName") internal inline fun ClassWriter(flags: Int, block: ClassWriter.() -> Unit): ClassWriter { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return ClassWriter(flags).apply(block) } -@OptIn(ExperimentalContracts::class) internal inline fun ClassWriter.visitField( access: Int, name: String, @@ -167,7 +163,6 @@ private fun AsmBuilder.tryInvokeSpecific( /** * Builds specialized algebra call with option to fallback to generic algebra operation accepting String. */ -@OptIn(ExperimentalContracts::class) internal inline fun AsmBuilder.buildAlgebraOperationCall( context: Algebra, name: String, diff --git a/kmath-commons/build.gradle.kts b/kmath-commons/build.gradle.kts index 5ce1b935a..63c832b7c 100644 --- a/kmath-commons/build.gradle.kts +++ b/kmath-commons/build.gradle.kts @@ -1,7 +1,4 @@ -plugins { - id("scientifik.jvm") -} - +plugins { id("scientifik.jvm") } description = "Commons math binding for kmath" dependencies { @@ -10,4 +7,6 @@ dependencies { api(project(":kmath-prob")) api(project(":kmath-functions")) api("org.apache.commons:commons-math3:3.6.1") -} \ No newline at end of file +} + +kotlin.sourceSets.all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") } diff --git a/kmath-commons/src/test/kotlin/scientifik/kmath/commons/expressions/AutoDiffTest.kt b/kmath-commons/src/test/kotlin/scientifik/kmath/commons/expressions/AutoDiffTest.kt index ae4bb755a..bbdcff2fc 100644 --- a/kmath-commons/src/test/kotlin/scientifik/kmath/commons/expressions/AutoDiffTest.kt +++ b/kmath-commons/src/test/kotlin/scientifik/kmath/commons/expressions/AutoDiffTest.kt @@ -1,13 +1,11 @@ package scientifik.kmath.commons.expressions import scientifik.kmath.expressions.invoke -import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.test.Test import kotlin.test.assertEquals -@OptIn(ExperimentalContracts::class) inline fun diff(order: Int, vararg parameters: Pair, block: DerivativeStructureField.() -> R): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return DerivativeStructureField(order, mapOf(*parameters)).run(block) diff --git a/kmath-core/build.gradle.kts b/kmath-core/build.gradle.kts index bea0fbf42..7f9922de4 100644 --- a/kmath-core/build.gradle.kts +++ b/kmath-core/build.gradle.kts @@ -1,7 +1,6 @@ plugins { id("scientifik.mpp") } kotlin.sourceSets { - commonMain { - dependencies { api(project(":kmath-memory")) } - } + all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") } + commonMain { dependencies { api(project(":kmath-memory")) } } } diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/expressions/Builders.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/expressions/Builders.kt index 3bbc86ce5..8d0b82a89 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/expressions/Builders.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/expressions/Builders.kt @@ -11,7 +11,6 @@ import kotlin.contracts.contract /** * Creates a functional expression with this [Space]. */ -@OptIn(ExperimentalContracts::class) inline fun Space.spaceExpression(block: FunctionalExpressionSpace>.() -> Expression): Expression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return FunctionalExpressionSpace(this).block() @@ -20,7 +19,6 @@ inline fun Space.spaceExpression(block: FunctionalExpressionSpace Ring.ringExpression(block: FunctionalExpressionRing>.() -> Expression): Expression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return FunctionalExpressionRing(this).block() @@ -29,7 +27,6 @@ inline fun Ring.ringExpression(block: FunctionalExpressionRing /** * Creates a functional expression with this [Field]. */ -@OptIn(ExperimentalContracts::class) inline fun Field.fieldExpression(block: FunctionalExpressionField>.() -> Expression): Expression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return FunctionalExpressionField(this).block() @@ -38,7 +35,6 @@ inline fun Field.fieldExpression(block: FunctionalExpressionField ExtendedField.extendedFieldExpression(block: FunctionalExpressionExtendedField>.() -> Expression): Expression { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return FunctionalExpressionExtendedField(this).block() diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/linear/FeaturedMatrix.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/linear/FeaturedMatrix.kt index 39256f4ac..9b60bf719 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/linear/FeaturedMatrix.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/linear/FeaturedMatrix.kt @@ -28,7 +28,6 @@ interface FeaturedMatrix : Matrix { companion object } -@OptIn(ExperimentalContracts::class) inline fun Structure2D.Companion.real(rows: Int, columns: Int, initializer: (Int, Int) -> Double): Matrix { contract { callsInPlace(initializer) } return MatrixContext.real.produce(rows, columns, initializer) diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/misc/AutoDiff.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/misc/AutoDiff.kt index 1609f063a..be222783e 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/misc/AutoDiff.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/misc/AutoDiff.kt @@ -55,7 +55,6 @@ class DerivationResult( * assertEquals(9.0, x.d) // dy/dx * ``` */ -@OptIn(ExperimentalContracts::class) inline fun > F.deriv(body: AutoDiffField.() -> Variable): DerivationResult { contract { callsInPlace(body, InvocationKind.EXACTLY_ONCE) } diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/misc/cumulative.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/misc/cumulative.kt index dc7a4bf1f..e11adc135 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/misc/cumulative.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/misc/cumulative.kt @@ -13,7 +13,6 @@ import kotlin.jvm.JvmName * @param R the type of resulting iterable. * @param initial lazy evaluated. */ -@OptIn(ExperimentalContracts::class) inline fun Iterator.cumulative(initial: R, crossinline operation: (R, T) -> R): Iterator { contract { callsInPlace(operation) } diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt index d0c4989d8..0eed7132e 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/BigInt.kt @@ -10,7 +10,6 @@ import kotlin.math.max import kotlin.math.min import kotlin.math.sign - typealias Magnitude = UIntArray typealias TBase = ULong @@ -487,13 +486,11 @@ fun String.parseBigInteger(): BigInt? { return res * sign } -@OptIn(ExperimentalContracts::class) inline fun Buffer.Companion.bigInt(size: Int, initializer: (Int) -> BigInt): Buffer { contract { callsInPlace(initializer) } return boxing(size, initializer) } -@OptIn(ExperimentalContracts::class) inline fun MutableBuffer.Companion.bigInt(size: Int, initializer: (Int) -> BigInt): MutableBuffer { contract { callsInPlace(initializer) } return boxing(size, initializer) diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt index e80e6983a..dcfd97d1a 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt @@ -198,13 +198,11 @@ data class Complex(val re: Double, val im: Double) : FieldElement Complex): Buffer { contract { callsInPlace(init) } return MemoryBuffer.create(Complex, size, init) } -@OptIn(ExperimentalContracts::class) inline fun MutableBuffer.Companion.complex(size: Int, crossinline init: (Int) -> Complex): Buffer { contract { callsInPlace(init) } return MemoryBuffer.create(Complex, size, init) diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Buffers.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Buffers.kt index e065f4990..4afaa63ab 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Buffers.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/Buffers.kt @@ -167,7 +167,6 @@ fun List.asBuffer(): ListBuffer = ListBuffer(this) * The function [init] is called for each array element sequentially starting from the first one. * It should return the value for an array element given its index. */ -@OptIn(ExperimentalContracts::class) inline fun ListBuffer(size: Int, init: (Int) -> T): ListBuffer { contract { callsInPlace(init) } return List(size, init).asBuffer() diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ComplexNDField.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ComplexNDField.kt index a4855ca7c..2c6e3a5c7 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ComplexNDField.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ComplexNDField.kt @@ -112,7 +112,6 @@ inline fun ComplexNDElement.mapIndexed(crossinline transform: ComplexField.(inde /** * Map one [ComplexNDElement] using function without indices. */ -@OptIn(ExperimentalContracts::class) inline fun ComplexNDElement.map(crossinline transform: ComplexField.(Complex) -> Complex): ComplexNDElement { contract { callsInPlace(transform) } val buffer = Buffer.complex(strides.linearSize) { offset -> ComplexField.transform(buffer[offset]) } @@ -153,7 +152,6 @@ fun NDElement.Companion.complex(vararg shape: Int, initializer: ComplexField.(In /** * Produce a context for n-dimensional operations inside this real field */ -@OptIn(ExperimentalContracts::class) inline fun ComplexField.nd(vararg shape: Int, action: ComplexNDField.() -> R): R { contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) } return NDField.complex(*shape).action() diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/FlaggedBuffer.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/FlaggedBuffer.kt index b78ac0beb..9c32aa31b 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/FlaggedBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/FlaggedBuffer.kt @@ -66,7 +66,6 @@ class FlaggedRealBuffer(val values: DoubleArray, val flags: ByteArray) : Flagged }.iterator() } -@OptIn(ExperimentalContracts::class) inline fun FlaggedRealBuffer.forEachValid(block: (Double) -> Unit) { contract { callsInPlace(block) } diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/FloatBuffer.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/FloatBuffer.kt index 24822056b..9e974c644 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/FloatBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/FloatBuffer.kt @@ -30,7 +30,6 @@ inline class FloatBuffer(val array: FloatArray) : MutableBuffer { * The function [init] is called for each array element sequentially starting from the first one. * It should return the value for an buffer element given its index. */ -@OptIn(ExperimentalContracts::class) inline fun FloatBuffer(size: Int, init: (Int) -> Float): FloatBuffer { contract { callsInPlace(init) } return FloatBuffer(FloatArray(size) { init(it) }) diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/IntBuffer.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/IntBuffer.kt index 229b62b48..95651c547 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/IntBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/IntBuffer.kt @@ -31,7 +31,6 @@ inline class IntBuffer(val array: IntArray) : MutableBuffer { * The function [init] is called for each array element sequentially starting from the first one. * It should return the value for an buffer element given its index. */ -@OptIn(ExperimentalContracts::class) inline fun IntBuffer(size: Int, init: (Int) -> Int): IntBuffer { contract { callsInPlace(init) } return IntBuffer(IntArray(size) { init(it) }) diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/LongBuffer.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/LongBuffer.kt index cfedb5f35..a44109f8a 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/LongBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/LongBuffer.kt @@ -31,7 +31,6 @@ inline class LongBuffer(val array: LongArray) : MutableBuffer { * The function [init] is called for each array element sequentially starting from the first one. * It should return the value for an buffer element given its index. */ -@OptIn(ExperimentalContracts::class) inline fun LongBuffer(size: Int, init: (Int) -> Long): LongBuffer { contract { callsInPlace(init) } return LongBuffer(LongArray(size) { init(it) }) diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDStructure.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDStructure.kt index a16caab68..f4eb93b9e 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDStructure.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/NDStructure.kt @@ -140,7 +140,6 @@ interface MutableNDStructure : NDStructure { operator fun set(index: IntArray, value: T) } -@OptIn(ExperimentalContracts::class) inline fun MutableNDStructure.mapInPlace(action: (IntArray, T) -> T) { contract { callsInPlace(action) } elements().forEach { (index, oldValue) -> this[index] = action(index, oldValue) } diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/RealBuffer.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/RealBuffer.kt index f897134db..cba8e9689 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/RealBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/RealBuffer.kt @@ -30,7 +30,6 @@ inline class RealBuffer(val array: DoubleArray) : MutableBuffer { * The function [init] is called for each array element sequentially starting from the first one. * It should return the value for an buffer element given its index. */ -@OptIn(ExperimentalContracts::class) inline fun RealBuffer(size: Int, init: (Int) -> Double): RealBuffer { contract { callsInPlace(init) } return RealBuffer(DoubleArray(size) { init(it) }) diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ShortBuffer.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ShortBuffer.kt index 08d4a4376..9aa674177 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ShortBuffer.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/structures/ShortBuffer.kt @@ -30,7 +30,6 @@ inline class ShortBuffer(val array: ShortArray) : MutableBuffer { * The function [init] is called for each array element sequentially starting from the first one. * It should return the value for an buffer element given its index. */ -@OptIn(ExperimentalContracts::class) inline fun ShortBuffer(size: Int, init: (Int) -> Short): ShortBuffer { contract { callsInPlace(init) } return ShortBuffer(ShortArray(size) { init(it) }) diff --git a/kmath-coroutines/build.gradle.kts b/kmath-coroutines/build.gradle.kts index 373d9b8ac..4469a9ef6 100644 --- a/kmath-coroutines/build.gradle.kts +++ b/kmath-coroutines/build.gradle.kts @@ -4,20 +4,27 @@ plugins { } kotlin.sourceSets { + all { + with(languageSettings) { + useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") + useExperimentalAnnotation("kotlinx.coroutines.InternalCoroutinesApi") + useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi") + useExperimentalAnnotation("kotlinx.coroutines.FlowPreview") + } + } + commonMain { dependencies { api(project(":kmath-core")) api("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:${Scientifik.coroutinesVersion}") } } + jvmMain { - dependencies { - api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Scientifik.coroutinesVersion}") - } + dependencies { api("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Scientifik.coroutinesVersion}") } } + jsMain { - dependencies { - api("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${Scientifik.coroutinesVersion}") - } + dependencies { api("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:${Scientifik.coroutinesVersion}") } } } diff --git a/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/Chain.kt b/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/Chain.kt index aac4f2534..f0ffd13cd 100644 --- a/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/Chain.kt +++ b/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/Chain.kt @@ -16,9 +16,9 @@ package scientifik.kmath.chains -import kotlinx.coroutines.InternalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.FlowCollector +import kotlinx.coroutines.flow.flow import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock @@ -37,14 +37,8 @@ interface Chain : Flow { */ fun fork(): Chain - @OptIn(InternalCoroutinesApi::class) - override suspend fun collect(collector: FlowCollector) { - kotlinx.coroutines.flow.flow { - while (true) { - emit(next()) - } - }.collect(collector) - } + override suspend fun collect(collector: FlowCollector): Unit = + flow { while (true) emit(next()) }.collect(collector) companion object } diff --git a/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/flowExtra.kt b/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/flowExtra.kt index 6624722ce..5db660c39 100644 --- a/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/flowExtra.kt +++ b/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/chains/flowExtra.kt @@ -9,7 +9,6 @@ import scientifik.kmath.operations.Space import scientifik.kmath.operations.SpaceOperations import scientifik.kmath.operations.invoke - @ExperimentalCoroutinesApi fun Flow.cumulativeSum(space: SpaceOperations): Flow = space { scanReduce { sum: T, element: T -> sum + element } diff --git a/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/coroutines/coroutinesExtra.kt b/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/coroutines/coroutinesExtra.kt index 8ee6c52ad..692f89589 100644 --- a/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/coroutines/coroutinesExtra.kt +++ b/kmath-coroutines/src/commonMain/kotlin/scientifik/kmath/coroutines/coroutinesExtra.kt @@ -3,7 +3,6 @@ package scientifik.kmath.coroutines import kotlinx.coroutines.* import kotlinx.coroutines.channels.produce import kotlinx.coroutines.flow.* -import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract val Dispatchers.Math: CoroutineDispatcher @@ -25,15 +24,11 @@ internal class LazyDeferred(val dispatcher: CoroutineDispatcher, val block: s } class AsyncFlow internal constructor(internal val deferredFlow: Flow>) : Flow { - @InternalCoroutinesApi override suspend fun collect(collector: FlowCollector) { - deferredFlow.collect { - collector.emit((it.await())) - } + deferredFlow.collect { collector.emit((it.await())) } } } -@FlowPreview fun Flow.async( dispatcher: CoroutineDispatcher = Dispatchers.Default, block: suspend CoroutineScope.(T) -> R @@ -44,7 +39,6 @@ fun Flow.async( return AsyncFlow(flow) } -@FlowPreview fun AsyncFlow.map(action: (T) -> R): AsyncFlow = AsyncFlow(deferredFlow.map { input -> //TODO add function composition @@ -54,10 +48,9 @@ fun AsyncFlow.map(action: (T) -> R): AsyncFlow = } }) -@ExperimentalCoroutinesApi -@FlowPreview suspend fun AsyncFlow.collect(concurrency: Int, collector: FlowCollector) { require(concurrency >= 1) { "Buffer size should be more than 1, but was $concurrency" } + coroutineScope { //Starting up to N deferred coroutines ahead of time val channel = produce(capacity = concurrency - 1) { @@ -83,9 +76,6 @@ suspend fun AsyncFlow.collect(concurrency: Int, collector: FlowCollector< } } -@OptIn(ExperimentalContracts::class) -@ExperimentalCoroutinesApi -@FlowPreview suspend inline fun AsyncFlow.collect(concurrency: Int, crossinline action: suspend (value: T) -> Unit) { contract { callsInPlace(action) } @@ -94,9 +84,6 @@ suspend inline fun AsyncFlow.collect(concurrency: Int, crossinline action }) } -@OptIn(ExperimentalContracts::class) -@ExperimentalCoroutinesApi -@FlowPreview inline fun Flow.mapParallel( dispatcher: CoroutineDispatcher = Dispatchers.Default, crossinline transform: suspend (T) -> R diff --git a/kmath-for-real/build.gradle.kts b/kmath-for-real/build.gradle.kts index a8a8975bc..46d2682f7 100644 --- a/kmath-for-real/build.gradle.kts +++ b/kmath-for-real/build.gradle.kts @@ -1,11 +1,6 @@ -plugins { - id("scientifik.mpp") -} +plugins { id("scientifik.mpp") } kotlin.sourceSets { - commonMain { - dependencies { - api(project(":kmath-core")) - } - } -} \ No newline at end of file + all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") } + commonMain { dependencies { api(project(":kmath-core")) } } +} diff --git a/kmath-for-real/src/commonMain/kotlin/scientifik/kmath/real/realMatrix.kt b/kmath-for-real/src/commonMain/kotlin/scientifik/kmath/real/realMatrix.kt index 5ccba90a9..3752fc3ca 100644 --- a/kmath-for-real/src/commonMain/kotlin/scientifik/kmath/real/realMatrix.kt +++ b/kmath-for-real/src/commonMain/kotlin/scientifik/kmath/real/realMatrix.kt @@ -120,7 +120,6 @@ operator fun Matrix.minus(other: Matrix): RealMatrix = * Operations on columns */ -@OptIn(ExperimentalContracts::class) inline fun Matrix.appendColumn(crossinline mapper: (Buffer) -> Double): Matrix { contract { callsInPlace(mapper) } diff --git a/kmath-functions/build.gradle.kts b/kmath-functions/build.gradle.kts index 4c158a32e..46d2682f7 100644 --- a/kmath-functions/build.gradle.kts +++ b/kmath-functions/build.gradle.kts @@ -1,11 +1,6 @@ -plugins { - id("scientifik.mpp") -} +plugins { id("scientifik.mpp") } kotlin.sourceSets { - commonMain { - dependencies { - api(project(":kmath-core")) - } - } + all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") } + commonMain { dependencies { api(project(":kmath-core")) } } } diff --git a/kmath-functions/src/commonMain/kotlin/scientifik/kmath/functions/Polynomial.kt b/kmath-functions/src/commonMain/kotlin/scientifik/kmath/functions/Polynomial.kt index 46b1d7c90..c4470ad27 100644 --- a/kmath-functions/src/commonMain/kotlin/scientifik/kmath/functions/Polynomial.kt +++ b/kmath-functions/src/commonMain/kotlin/scientifik/kmath/functions/Polynomial.kt @@ -71,7 +71,6 @@ class PolynomialSpace>(val ring: C) : Space> operator fun Polynomial.invoke(arg: T): T = value(ring, arg) } -@OptIn(ExperimentalContracts::class) inline fun , R> C.polynomial(block: PolynomialSpace.() -> R): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } return PolynomialSpace(this).block() diff --git a/kmath-memory/build.gradle.kts b/kmath-memory/build.gradle.kts index 1f34a4f17..44a5ae24d 100644 --- a/kmath-memory/build.gradle.kts +++ b/kmath-memory/build.gradle.kts @@ -1,3 +1,2 @@ -plugins { - id("scientifik.mpp") -} +plugins { id("scientifik.mpp") } +kotlin.sourceSets.all { languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts") } diff --git a/kmath-memory/src/commonMain/kotlin/scientifik/memory/Memory.kt b/kmath-memory/src/commonMain/kotlin/scientifik/memory/Memory.kt index 9e6ca9bde..daae0c3d2 100644 --- a/kmath-memory/src/commonMain/kotlin/scientifik/memory/Memory.kt +++ b/kmath-memory/src/commonMain/kotlin/scientifik/memory/Memory.kt @@ -1,6 +1,5 @@ package scientifik.memory -import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract @@ -84,7 +83,6 @@ interface MemoryReader { /** * Uses the memory for read then releases the reader. */ -@OptIn(ExperimentalContracts::class) inline fun Memory.read(block: MemoryReader.() -> Unit) { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } reader().apply(block).release() @@ -138,7 +136,6 @@ interface MemoryWriter { /** * Uses the memory for write then releases the writer. */ -@OptIn(ExperimentalContracts::class) inline fun Memory.write(block: MemoryWriter.() -> Unit) { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } writer().apply(block).release() diff --git a/kmath-memory/src/jvmMain/kotlin/scientifik/memory/ByteBufferMemory.kt b/kmath-memory/src/jvmMain/kotlin/scientifik/memory/ByteBufferMemory.kt index 73ad7deec..f4967bf5c 100644 --- a/kmath-memory/src/jvmMain/kotlin/scientifik/memory/ByteBufferMemory.kt +++ b/kmath-memory/src/jvmMain/kotlin/scientifik/memory/ByteBufferMemory.kt @@ -117,7 +117,6 @@ fun ByteBuffer.asMemory(startOffset: Int = 0, size: Int = limit()): Memory = /** * Uses direct memory-mapped buffer from file to read something and close it afterwards. */ -@OptIn(ExperimentalContracts::class) @Throws(IOException::class) inline fun Path.readAsMemory(position: Long = 0, size: Long = Files.size(this), block: Memory.() -> R): R { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }