diff --git a/FAQ.md b/FAQ.md index 0d6cfaf51e5..e8464d4ea63 100644 --- a/FAQ.md +++ b/FAQ.md @@ -48,7 +48,7 @@ framework("MyCustomFramework") { ### Q: Why do I see `InvalidMutabilityException`? A: It likely happens, because you are trying to mutate a frozen object. Object could transfer to the -frozen state either explicitly, as objects reachable from objects on which `konan.worker.freeze` is called, +frozen state either explicitly, as objects reachable from objects on which `kotlin.native.concurrent.freeze` is called, or implicitly (i.e. reachable from `enum` or global singleton object - see next question). @@ -56,7 +56,7 @@ or implicitly (i.e. reachable from `enum` or global singleton object - see next A: Currently, singleton objects are immutable (i.e. frozen after creation), and it's generally considered a good practise to have global state immutable. If for some reasons you need mutable state inside such an -object, use `@konan.ThreadLocal` annotation on the object. Also `konan.worker.AtomicReference` class could be +object, use `@konan.ThreadLocal` annotation on the object. Also `kotlin.native.concurrent.AtomicReference` class could be used to store different pointers to frozen objects in a frozen object and atomically update those. ### Q: How can I compile my project against Kotlin/Native master? diff --git a/IMMUTABILITY.md b/IMMUTABILITY.md index c2080b3c958..4c36a2a946a 100644 --- a/IMMUTABILITY.md +++ b/IMMUTABILITY.md @@ -5,7 +5,7 @@ important invariant that object is either immutable or accessible from the single thread at the moment (`mutable XOR global`). Immutability is the runtime property in Kotlin/Native, and can be applied -to an arbitrary object subgraph using `konan.worker.freeze` function. +to an arbitrary object subgraph using `kotlin.native.concurrent.freeze` function. It makes all objects reachable from the given one immutable, and such a transition is a one way operation (object cannot be unfrozen later). Some naturally immutable objects, such as `kotlin.String`, `kotlin.Int` and diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt index 1d7f6a89a05..17552a0a0b6 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/InteropUtils.kt @@ -79,12 +79,12 @@ internal class InteropBuiltIns(builtIns: KonanBuiltIns, vararg konanPrimitives: val staticCFunction = packageScope.getContributedFunctions("staticCFunction").toSet() - val workerPackageScope = builtIns.builtInsModule.getPackage(FqName("kotlin.native.worker")).memberScope + val concurrentPackageScope = builtIns.builtInsModule.getPackage(FqName("kotlin.native.concurrent")).memberScope - val scheduleFunction = workerPackageScope.getContributedClass("Worker") + val scheduleFunction = concurrentPackageScope.getContributedClass("Worker") .unsubstitutedMemberScope.getContributedFunctions("schedule").single() - val scheduleImplFunction = workerPackageScope.getContributedFunctions("scheduleImpl").single() + val scheduleImplFunction = concurrentPackageScope.getContributedFunctions("scheduleImpl").single() val signExtend = packageScope.getContributedFunctions("signExtend").single() diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt index c37ea8f2c87..63a79f13057 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt @@ -297,10 +297,12 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val context.getInternalFunctions("valueOfForEnum").single()) val enumValues = symbolTable.referenceSimpleFunction( - builtInsPackage("kotlin").getContributedFunctions(Name.identifier("enumValues"), NoLookupLocation.FROM_BACKEND).single()) + builtInsPackage("kotlin").getContributedFunctions( + Name.identifier("enumValues"), NoLookupLocation.FROM_BACKEND).single()) val enumValueOf = symbolTable.referenceSimpleFunction( - builtInsPackage("kotlin").getContributedFunctions(Name.identifier("enumValueOf"), NoLookupLocation.FROM_BACKEND).single()) + builtInsPackage("kotlin").getContributedFunctions( + Name.identifier("enumValueOf"), NoLookupLocation.FROM_BACKEND).single()) val createUninitializedInstance = symbolTable.referenceSimpleFunction( context.getInternalFunctions("createUninitializedInstance").single()) @@ -309,14 +311,17 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val context.getInternalFunctions("initInstance").single()) val freeze = symbolTable.referenceSimpleFunction( - builtInsPackage("kotlin", "native", "worker").getContributedFunctions(Name.identifier("freeze"), NoLookupLocation.FROM_BACKEND).single()) + builtInsPackage("kotlin", "native", "concurrent").getContributedFunctions( + Name.identifier("freeze"), NoLookupLocation.FROM_BACKEND).single()) val println = symbolTable.referenceSimpleFunction( - builtInsPackage("kotlin", "io").getContributedFunctions(Name.identifier("println"), NoLookupLocation.FROM_BACKEND) + builtInsPackage("kotlin", "io").getContributedFunctions( + Name.identifier("println"), NoLookupLocation.FROM_BACKEND) .single { it.valueParameters.singleOrNull()?.type == builtIns.stringType }) val anyNToString = symbolTable.referenceSimpleFunction( - builtInsPackage("kotlin").getContributedFunctions(Name.identifier("toString"), NoLookupLocation.FROM_BACKEND) + builtInsPackage("kotlin").getContributedFunctions( + Name.identifier("toString"), NoLookupLocation.FROM_BACKEND) .single { it.extensionReceiverParameter?.type == builtIns.nullableAnyType}) val getContinuation = symbolTable.referenceSimpleFunction( @@ -350,10 +355,8 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val .filterNot { it.isExpect }.single().getter!! ) - // removed in Big Kotlin @c62e4b4fcf50e99800e6d5c3a220101b691e1d43 val refClass = symbolTable.referenceClass(context.getInternalClass("Ref")) - val kLocalDelegatedPropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedPropertyImpl) val kLocalDelegatedMutablePropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedMutablePropertyImpl) @@ -376,7 +379,7 @@ internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val symbolTable.referenceClass(context.getInternalClass(name)) private fun getKonanTestClass(className: String) = symbolTable.referenceClass( - builtInsPackage("kotlin", "native", "test").getContributedClassifier( + builtInsPackage("kotlin", "native", "internal", "test").getContributedClassifier( Name.identifier(className), NoLookupLocation.FROM_BACKEND ) as ClassDescriptor) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/EntryPoint.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/EntryPoint.kt index e2900a0ef90..1782f63a466 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/EntryPoint.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/EntryPoint.kt @@ -61,7 +61,7 @@ internal fun findMainEntryPoint(context: Context): FunctionDescriptor? { } private val defaultEntryName = "main" -private val testEntryName = "kotlin.native.test.main" +private val testEntryName = "kotlin.native.internal.test.main" private val defaultEntryPackage = FqName.ROOT diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt index eeca9958d81..aef139b4ffa 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt @@ -346,7 +346,7 @@ internal class TestProcessor (val context: KonanBackendContext) { } /** - * Builds a method in `[testSuite]` class with anem `[getterName]` + * Builds a method in `[testSuite]` class with name `[getterName]` * returning a new instance of class referenced by [classSymbol]. */ private inner class InstanceGetterBuilder(val classSymbol: IrClassSymbol, testSuite: IrClassSymbol, getterName: Name) diff --git a/backend.native/tests/codegen/enum/isFrozen.kt b/backend.native/tests/codegen/enum/isFrozen.kt index a2e6c3ec6a3..630423924d7 100644 --- a/backend.native/tests/codegen/enum/isFrozen.kt +++ b/backend.native/tests/codegen/enum/isFrozen.kt @@ -1,7 +1,7 @@ package codegen.enum.isFrozen import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* enum class Zzz(val zzz: String) { Z1("z1"), diff --git a/backend.native/tests/runtime/basic/worker_random.kt b/backend.native/tests/runtime/basic/worker_random.kt index ffdcb7608e4..6fb15a67ca5 100644 --- a/backend.native/tests/runtime/basic/worker_random.kt +++ b/backend.native/tests/runtime/basic/worker_random.kt @@ -1,6 +1,6 @@ package runtime.basic.worker_random -import kotlin.native.worker.* +import kotlin.native.concurrent.* import kotlin.collections.* import kotlin.random.* import kotlin.system.* diff --git a/backend.native/tests/runtime/workers/atomic0.kt b/backend.native/tests/runtime/workers/atomic0.kt index f9a3a345216..a81430ff891 100644 --- a/backend.native/tests/runtime/workers/atomic0.kt +++ b/backend.native/tests/runtime/workers/atomic0.kt @@ -2,7 +2,7 @@ package runtime.workers.atomic0 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* fun test1(workers: Array) { val atomic = AtomicInt(15) diff --git a/backend.native/tests/runtime/workers/enum_identity.kt b/backend.native/tests/runtime/workers/enum_identity.kt index be3bd1905b0..2cca9e54561 100644 --- a/backend.native/tests/runtime/workers/enum_identity.kt +++ b/backend.native/tests/runtime/workers/enum_identity.kt @@ -1,7 +1,7 @@ package runtime.workers.enum_identity import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* enum class A { A, B diff --git a/backend.native/tests/runtime/workers/freeze0.kt b/backend.native/tests/runtime/workers/freeze0.kt index 267faa03197..513ed2691da 100644 --- a/backend.native/tests/runtime/workers/freeze0.kt +++ b/backend.native/tests/runtime/workers/freeze0.kt @@ -18,7 +18,7 @@ package runtime.workers.freeze0 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* data class SharedDataMember(val double: Double) diff --git a/backend.native/tests/runtime/workers/freeze1.kt b/backend.native/tests/runtime/workers/freeze1.kt index 022373f5fe8..8ff0eda3198 100644 --- a/backend.native/tests/runtime/workers/freeze1.kt +++ b/backend.native/tests/runtime/workers/freeze1.kt @@ -18,7 +18,7 @@ package runtime.workers.freeze1 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* data class Node(var previous: Node?, var data: Int) diff --git a/backend.native/tests/runtime/workers/freeze2.kt b/backend.native/tests/runtime/workers/freeze2.kt index b3455a794eb..757c387ac85 100644 --- a/backend.native/tests/runtime/workers/freeze2.kt +++ b/backend.native/tests/runtime/workers/freeze2.kt @@ -18,7 +18,7 @@ package runtime.workers.freeze2 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* data class Data(var int: Int) diff --git a/backend.native/tests/runtime/workers/freeze3.kt b/backend.native/tests/runtime/workers/freeze3.kt index 62d8a1f7489..c752fe290bb 100644 --- a/backend.native/tests/runtime/workers/freeze3.kt +++ b/backend.native/tests/runtime/workers/freeze3.kt @@ -2,7 +2,7 @@ package runtime.workers.freeze3 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* object Immutable { var x = 1 diff --git a/backend.native/tests/runtime/workers/freeze4.kt b/backend.native/tests/runtime/workers/freeze4.kt index 4c36e29fcc4..b4be64033f2 100644 --- a/backend.native/tests/runtime/workers/freeze4.kt +++ b/backend.native/tests/runtime/workers/freeze4.kt @@ -2,7 +2,7 @@ package runtime.workers.freeze4 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* data class Data(val x: Int, val s: String, val next: Data? = null) diff --git a/backend.native/tests/runtime/workers/freeze5.kt b/backend.native/tests/runtime/workers/freeze5.kt index a55e8443a2e..8c155b0f57c 100644 --- a/backend.native/tests/runtime/workers/freeze5.kt +++ b/backend.native/tests/runtime/workers/freeze5.kt @@ -1,6 +1,7 @@ package runtime.workers.freeze5 import kotlin.test.* + object Keys { internal val myMap: Map> = mapOf( "val1" to listOf("a1", "a2", "a3"), diff --git a/backend.native/tests/runtime/workers/freeze_stress.kt b/backend.native/tests/runtime/workers/freeze_stress.kt index 9932bf2de92..04a1397b472 100644 --- a/backend.native/tests/runtime/workers/freeze_stress.kt +++ b/backend.native/tests/runtime/workers/freeze_stress.kt @@ -2,7 +2,7 @@ package runtime.workers.freeze_stress import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* class Random(private var seed: Int) { fun next(): Int { diff --git a/backend.native/tests/runtime/workers/lazy0.kt b/backend.native/tests/runtime/workers/lazy0.kt index 74296f734d8..444ce8621c4 100644 --- a/backend.native/tests/runtime/workers/lazy0.kt +++ b/backend.native/tests/runtime/workers/lazy0.kt @@ -2,7 +2,7 @@ package runtime.workers.lazy0 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* data class Data(val x: Int, val y: String) diff --git a/backend.native/tests/runtime/workers/lazy1.kt b/backend.native/tests/runtime/workers/lazy1.kt index f46c2824e09..1967359317b 100644 --- a/backend.native/tests/runtime/workers/lazy1.kt +++ b/backend.native/tests/runtime/workers/lazy1.kt @@ -2,7 +2,7 @@ package runtime.workers.lazy1 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* class Leak { val leak by lazy { this } diff --git a/backend.native/tests/runtime/workers/worker0.kt b/backend.native/tests/runtime/workers/worker0.kt index 4cd56af8be8..5a0c9f69260 100644 --- a/backend.native/tests/runtime/workers/worker0.kt +++ b/backend.native/tests/runtime/workers/worker0.kt @@ -2,11 +2,11 @@ package runtime.workers.worker0 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* @Test fun runTest() { val worker = startWorker() - val future = worker.schedule(TransferMode.CHECKED, { "Input".shallowCopy()}) { + val future = worker.schedule(TransferMode.CHECKED, { "Input" }) { input -> input + " processed" } future.consume { diff --git a/backend.native/tests/runtime/workers/worker1.kt b/backend.native/tests/runtime/workers/worker1.kt index 0e8a0493b15..acd36c8eb05 100644 --- a/backend.native/tests/runtime/workers/worker1.kt +++ b/backend.native/tests/runtime/workers/worker1.kt @@ -2,7 +2,7 @@ package runtime.workers.worker1 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* @Test fun runTest() { val COUNT = 5 @@ -10,7 +10,7 @@ import kotlin.native.worker.* for (attempt in 1 .. 3) { val futures = Array(workers.size, - { i -> workers[i].schedule(TransferMode.CHECKED, { "$attempt: Input $i".shallowCopy() }) + { i -> workers[i].schedule(TransferMode.CHECKED, { "$attempt: Input $i" }) { input -> input + " processed" } }) futures.forEachIndexed { index, future -> diff --git a/backend.native/tests/runtime/workers/worker2.kt b/backend.native/tests/runtime/workers/worker2.kt index b2b2c2cf719..ade57eaa8b8 100644 --- a/backend.native/tests/runtime/workers/worker2.kt +++ b/backend.native/tests/runtime/workers/worker2.kt @@ -2,7 +2,7 @@ package runtime.workers.worker2 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* data class WorkerArgument(val intParam: Int, val stringParam: String) data class WorkerResult(val intResult: Int, val stringResult: String) diff --git a/backend.native/tests/runtime/workers/worker3.kt b/backend.native/tests/runtime/workers/worker3.kt index 1dc6d69405b..007c1610bc3 100644 --- a/backend.native/tests/runtime/workers/worker3.kt +++ b/backend.native/tests/runtime/workers/worker3.kt @@ -2,7 +2,7 @@ package runtime.workers.worker3 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* data class DataParam(var int: Int) data class WorkerArgument(val intParam: Int, val dataParam: DataParam) diff --git a/backend.native/tests/runtime/workers/worker4.kt b/backend.native/tests/runtime/workers/worker4.kt index a87eb17252b..9a166b558d3 100644 --- a/backend.native/tests/runtime/workers/worker4.kt +++ b/backend.native/tests/runtime/workers/worker4.kt @@ -2,7 +2,7 @@ package runtime.workers.worker4 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* @Test fun runTest() { val worker = startWorker() diff --git a/backend.native/tests/runtime/workers/worker5.kt b/backend.native/tests/runtime/workers/worker5.kt index 1aeb2600136..c23db9755e4 100644 --- a/backend.native/tests/runtime/workers/worker5.kt +++ b/backend.native/tests/runtime/workers/worker5.kt @@ -2,11 +2,11 @@ package runtime.workers.worker5 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* @Test fun runTest() { val worker = startWorker() - val future = worker.schedule(TransferMode.CHECKED, { "zzz".shallowCopy() }) { + val future = worker.schedule(TransferMode.CHECKED, { "zzz" }) { input -> input.length } future.consume { diff --git a/backend.native/tests/runtime/workers/worker6.kt b/backend.native/tests/runtime/workers/worker6.kt index a00fd7b9d67..61a0c425d71 100644 --- a/backend.native/tests/runtime/workers/worker6.kt +++ b/backend.native/tests/runtime/workers/worker6.kt @@ -2,7 +2,7 @@ package runtime.workers.worker6 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* @Test fun runTest() { val worker = startWorker() diff --git a/backend.native/tests/runtime/workers/worker7.kt b/backend.native/tests/runtime/workers/worker7.kt index 1de1fe444ad..dc4bc0c1f67 100644 --- a/backend.native/tests/runtime/workers/worker7.kt +++ b/backend.native/tests/runtime/workers/worker7.kt @@ -2,11 +2,11 @@ package runtime.workers.worker7 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* @Test fun runTest() { val worker = startWorker() - val future = worker.schedule(TransferMode.CHECKED, { "Input".shallowCopy() }) { + val future = worker.schedule(TransferMode.CHECKED, { "Input" }) { input -> println(input) } future.consume { diff --git a/backend.native/tests/runtime/workers/worker8.kt b/backend.native/tests/runtime/workers/worker8.kt index 29a6ac5987f..064015e7152 100644 --- a/backend.native/tests/runtime/workers/worker8.kt +++ b/backend.native/tests/runtime/workers/worker8.kt @@ -2,7 +2,7 @@ package runtime.workers.worker8 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* data class SharedDataMember(val double: Double) diff --git a/backend.native/tests/runtime/workers/worker9.kt b/backend.native/tests/runtime/workers/worker9.kt index c9bd51d52a0..6743519cc05 100644 --- a/backend.native/tests/runtime/workers/worker9.kt +++ b/backend.native/tests/runtime/workers/worker9.kt @@ -2,7 +2,7 @@ package runtime.workers.worker9 import kotlin.test.* -import kotlin.native.worker.* +import kotlin.native.concurrent.* @Test fun runTest() { withLock { println("zzz") } diff --git a/backend.native/tests/testing/annotations.kt b/backend.native/tests/testing/annotations.kt index 5e4afc4260f..6b8809b466a 100644 --- a/backend.native/tests/testing/annotations.kt +++ b/backend.native/tests/testing/annotations.kt @@ -1,8 +1,7 @@ package kotlin.test.tests import kotlin.test.* -import kotlin.native.test.* - +import kotlin.native.internal.test.* @Ignore class IgnoredClass { diff --git a/backend.native/tests/testing/custom_main.kt b/backend.native/tests/testing/custom_main.kt index ef8a554d1d3..b4e1e067ad9 100644 --- a/backend.native/tests/testing/custom_main.kt +++ b/backend.native/tests/testing/custom_main.kt @@ -1,7 +1,7 @@ package kotlin.test.tests import kotlin.test.* -import kotlin.native.test.* +import kotlin.native.internal.test.* @Test fun test() { diff --git a/runtime/src/main/cpp/Worker.cpp b/runtime/src/main/cpp/Worker.cpp index 6dd364a1c92..c5a04ba15b6 100644 --- a/runtime/src/main/cpp/Worker.cpp +++ b/runtime/src/main/cpp/Worker.cpp @@ -415,25 +415,6 @@ KInt schedule(KInt id, KInt transferMode, KRef producer, KNativePtr jobFunction) return future->id(); } -OBJ_GETTER(shallowCopy, KConstRef object) { - if (object == nullptr) RETURN_OBJ(nullptr); - - const TypeInfo* typeInfo = object->type_info(); - bool isArray = typeInfo->instanceSize_ < 0; - KRef result = isArray ? - AllocArrayInstance(typeInfo, object->array()->count_, OBJ_RESULT) : - AllocInstance(typeInfo, OBJ_RESULT); - // TODO: what to do when object references exist. - if (isArray) { - RuntimeAssert(object->array()->count_ == 0 || typeInfo != theArrayTypeInfo, "Object array copy unimplemented"); - memcpy(result->array() + 1, object->array() + 1, ArrayDataSizeBytes(object->array())); - } else { - RuntimeAssert(typeInfo->objOffsetsCount_ == 0, "Object reference copy unimplemented"); - memcpy(result + 1, object + 1, typeInfo->instanceSize_); - } - return result; -} - KInt stateOfFuture(KInt id) { return theState()->stateOfFutureUnlocked(id); } @@ -477,11 +458,6 @@ KInt startWorker() { return -1; } -OBJ_GETTER(shallowCopy, KConstRef object) { - ThrowWorkerUnsupported(); - RETURN_OBJ(nullptr); -} - KInt stateOfFuture(KInt id) { ThrowWorkerUnsupported(); return 0; @@ -540,10 +516,6 @@ KInt Kotlin_Worker_scheduleInternal(KInt id, KInt transferMode, KRef producer, K return schedule(id, transferMode, producer, job); } -OBJ_GETTER(Kotlin_Worker_shallowCopyInternal, KConstRef object) { - RETURN_RESULT_OF(shallowCopy, object); -} - KInt Kotlin_Worker_stateOfFuture(KInt id) { return stateOfFuture(id); } diff --git a/runtime/src/main/kotlin/kotlin/BitSet.kt b/runtime/src/main/kotlin/kotlin/BitSet.kt index df4afb4832e..85fe144bc69 100644 --- a/runtime/src/main/kotlin/kotlin/BitSet.kt +++ b/runtime/src/main/kotlin/kotlin/BitSet.kt @@ -19,7 +19,8 @@ package kotlin /** * A vector of bits growing if necessary and allowing one to set/clear/read bits from it by a bit index. */ -class BitSet(size: Int = ELEMENT_SIZE) { +// TODO: make me internal! +public class BitSet(size: Int = ELEMENT_SIZE) { companion object { // Size of one element in the array used to store bits. diff --git a/runtime/src/main/kotlin/kotlin/Lazy.kt b/runtime/src/main/kotlin/kotlin/Lazy.kt index 20d662822fa..e8dc2e51dfe 100644 --- a/runtime/src/main/kotlin/kotlin/Lazy.kt +++ b/runtime/src/main/kotlin/kotlin/Lazy.kt @@ -16,8 +16,9 @@ package kotlin -import kotlin.reflect.KProperty +import kotlin.native.concurrent.FreezeAwareLazyImpl import kotlin.native.internal.FixmeConcurrency +import kotlin.reflect.KProperty /** * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer] @@ -28,7 +29,7 @@ import kotlin.native.internal.FixmeConcurrency * Note that the returned instance uses itself to synchronize on. Do not synchronize from external code on * the returned instance as it may cause accidental deadlock. Also this behavior can be changed in the future. */ -public actual fun lazy(initializer: () -> T): Lazy = kotlin.native.worker.FreezeAwareLazyImpl(initializer) +public actual fun lazy(initializer: () -> T): Lazy = FreezeAwareLazyImpl(initializer) /** * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer] diff --git a/runtime/src/main/kotlin/kotlin/Primitives.kt b/runtime/src/main/kotlin/kotlin/Primitives.kt index 0fadb25c5a5..134fff37d12 100644 --- a/runtime/src/main/kotlin/kotlin/Primitives.kt +++ b/runtime/src/main/kotlin/kotlin/Primitives.kt @@ -1182,7 +1182,8 @@ public final class Float private constructor(private val value: kotlin.native.in } @SymbolName("Kotlin_Float_bits") - external public fun bits(): Int + @PublishedApi + external internal fun bits(): Int } /** @@ -1398,10 +1399,11 @@ public final class Double private constructor(private val value: kotlin.native.i public override fun equals(other: Any?): Boolean = other is Double && this.equals(other) - public override fun toString() = NumberConverter.convert(this) + public override fun toString(): String = NumberConverter.convert(this) public override fun hashCode(): Int = bits().hashCode() @SymbolName("Kotlin_Double_bits") - external public fun bits(): Long + @PublishedApi + external internal fun bits(): Long } diff --git a/runtime/src/main/kotlin/kotlin/collections/HashMap.kt b/runtime/src/main/kotlin/kotlin/collections/HashMap.kt index 8154ab8db41..cd8982d4396 100644 --- a/runtime/src/main/kotlin/kotlin/collections/HashMap.kt +++ b/runtime/src/main/kotlin/kotlin/collections/HashMap.kt @@ -16,7 +16,7 @@ package kotlin.collections -import kotlin.native.worker.isFrozen +import kotlin.native.concurrent.isFrozen actual class HashMap private constructor( private var keysArray: Array, diff --git a/runtime/src/main/kotlin/kotlin/collections/IntUtil.kt b/runtime/src/main/kotlin/kotlin/collections/IntUtil.kt index bf83cd20092..69bb221a160 100644 --- a/runtime/src/main/kotlin/kotlin/collections/IntUtil.kt +++ b/runtime/src/main/kotlin/kotlin/collections/IntUtil.kt @@ -16,7 +16,7 @@ package kotlin.collections -fun Int.highestOneBit() : Int { +internal fun Int.highestOneBit() : Int { var index = 31 while (index >= 0) { @@ -29,7 +29,7 @@ fun Int.highestOneBit() : Int { return 0 } -fun Int.numberOfLeadingZeros() : Int { +internal fun Int.numberOfLeadingZeros() : Int { var index = 31 while (index >= 0) { diff --git a/runtime/src/main/kotlin/kotlin/jvm/JvmAnnotations.kt b/runtime/src/main/kotlin/kotlin/jvm/JvmAnnotations.kt index 28cba3390e4..7387d71f116 100644 --- a/runtime/src/main/kotlin/kotlin/jvm/JvmAnnotations.kt +++ b/runtime/src/main/kotlin/kotlin/jvm/JvmAnnotations.kt @@ -27,4 +27,4 @@ actual annotation class JvmMultifileClass actual annotation class JvmField @Target(AnnotationTarget.FIELD) -actual annotation class Volatile \ No newline at end of file +actual annotation class Volatile diff --git a/runtime/src/main/kotlin/kotlin/native/worker/Atomics.kt b/runtime/src/main/kotlin/kotlin/native/concurrent/Atomics.kt similarity index 99% rename from runtime/src/main/kotlin/kotlin/native/worker/Atomics.kt rename to runtime/src/main/kotlin/kotlin/native/concurrent/Atomics.kt index 3041edc9b7d..435c19fefde 100644 --- a/runtime/src/main/kotlin/kotlin/native/worker/Atomics.kt +++ b/runtime/src/main/kotlin/kotlin/native/concurrent/Atomics.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package kotlin.native.worker +package kotlin.native.concurrent import kotlin.native.internal.Frozen import kotlin.native.internal.NoReorderFields diff --git a/runtime/src/main/kotlin/kotlin/native/worker/Freezing.kt b/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt similarity index 98% rename from runtime/src/main/kotlin/kotlin/native/worker/Freezing.kt rename to runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt index 7012c011236..bffaa4f21a4 100644 --- a/runtime/src/main/kotlin/kotlin/native/worker/Freezing.kt +++ b/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package kotlin.native.worker +package kotlin.native.concurrent import kotlin.native.internal.ExportForCppRuntime diff --git a/runtime/src/main/kotlin/kotlin/native/worker/Future.kt b/runtime/src/main/kotlin/kotlin/native/concurrent/Future.kt similarity index 86% rename from runtime/src/main/kotlin/kotlin/native/worker/Future.kt rename to runtime/src/main/kotlin/kotlin/native/concurrent/Future.kt index 4ebd615fba9..cf29b3c5e3b 100644 --- a/runtime/src/main/kotlin/kotlin/native/worker/Future.kt +++ b/runtime/src/main/kotlin/kotlin/native/concurrent/Future.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package kotlin.native.worker +package kotlin.native.concurrent import kotlin.native.SymbolName import kotlin.native.internal.ExportForCppRuntime @@ -40,12 +40,11 @@ enum class FutureState(val value: Int) { /** * Class representing abstract computation, whose result may become available in the future. */ -// TODO: make me value class! -class Future internal constructor(val id: FutureId) { +public inline class Future(val id: FutureId) { /** * Blocks execution until the future is ready. */ - inline fun consume(code: (T) -> R) = + public inline fun consume(code: (T) -> R): R = when (state) { FutureState.SCHEDULED, FutureState.COMPUTED -> { val value = @Suppress("UNCHECKED_CAST", "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE") (consumeFuture(id) as T) @@ -57,21 +56,21 @@ class Future internal constructor(val id: FutureId) { throw IllegalStateException("Future is cancelled") } - fun result(): T = consume { it -> it } + public fun result(): T = consume { it -> it } - val state: FutureState + public val state: FutureState get() = FutureState.values()[stateOfFuture(id)] - override fun equals(other: Any?) = (other is Future<*>) && (id == other.id) + public override fun equals(other: Any?): Boolean = (other is Future<*>) && (id == other.id) - override fun hashCode() = id + public override fun hashCode(): Int = id } /** * Wait for availability of futures in the collection. Returns set with all futures which have * value available for the consumption. */ -fun Collection>.waitForMultipleFutures(millis: Int): Set> { +public fun Collection>.waitForMultipleFutures(millis: Int): Set> { val result = mutableSetOf>() while (true) { diff --git a/runtime/src/main/kotlin/kotlin/native/worker/Lazy.kt b/runtime/src/main/kotlin/kotlin/native/concurrent/Lazy.kt similarity index 94% rename from runtime/src/main/kotlin/kotlin/native/worker/Lazy.kt rename to runtime/src/main/kotlin/kotlin/native/concurrent/Lazy.kt index 0ff3b29e6fd..8bde37d8f23 100644 --- a/runtime/src/main/kotlin/kotlin/native/worker/Lazy.kt +++ b/runtime/src/main/kotlin/kotlin/native/concurrent/Lazy.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package kotlin.native.worker +package kotlin.native.concurrent import kotlin.native.internal.NoReorderFields @@ -65,7 +65,9 @@ internal class FreezeAwareLazyImpl(initializer: () -> T) : Lazy { } } - // Racy! + /** + * This operation on shared objects may return value which is no longer reflect the current state of lazy. + */ override fun isInitialized(): Boolean = (value_ !== UNINITIALIZED) && (value_ !== INITIALIZING) override fun toString(): String = if (isInitialized()) diff --git a/runtime/src/main/kotlin/kotlin/native/worker/Lock.kt b/runtime/src/main/kotlin/kotlin/native/concurrent/Lock.kt similarity index 98% rename from runtime/src/main/kotlin/kotlin/native/worker/Lock.kt rename to runtime/src/main/kotlin/kotlin/native/concurrent/Lock.kt index 60e9d7bff27..5cf72c9e527 100644 --- a/runtime/src/main/kotlin/kotlin/native/worker/Lock.kt +++ b/runtime/src/main/kotlin/kotlin/native/concurrent/Lock.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package kotlin.native.worker +package kotlin.native.concurrent import kotlin.native.internal.Frozen diff --git a/runtime/src/main/kotlin/kotlin/native/worker/ObjectTransfer.kt b/runtime/src/main/kotlin/kotlin/native/concurrent/ObjectTransfer.kt similarity index 84% rename from runtime/src/main/kotlin/kotlin/native/worker/ObjectTransfer.kt rename to runtime/src/main/kotlin/kotlin/native/concurrent/ObjectTransfer.kt index 38f6f877f26..65467c77ed9 100644 --- a/runtime/src/main/kotlin/kotlin/native/worker/ObjectTransfer.kt +++ b/runtime/src/main/kotlin/kotlin/native/concurrent/ObjectTransfer.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package kotlin.native.worker +package kotlin.native.concurrent import kotlinx.cinterop.* @@ -46,17 +46,6 @@ enum class TransferMode(val value: Int) { UNCHECKED(1) // USE UNCHECKED MODE ONLY IF ABSOLUTELY SURE WHAT YOU'RE DOING!!! } -/** - * Creates verbatim *shallow* copy of passed object, use carefully to create disjoint object graph. - */ -inline fun T.shallowCopy(): T = shallowCopyInternal(this) as T - -/** - * Creates verbatim *deep* copy of passed object's graph, use *VERY* carefully to create disjoint object graph. - * Note that this function could potentially duplicate a lot of objects. - */ -inline fun T.deepCopy(): T = TODO() - /** * Creates stable pointer to object, ensuring associated object subgraph is disjoint in specified mode * ([TransferMode.CHECKED] by default). @@ -75,11 +64,9 @@ inline fun attachObjectGraph(stable: COpaquePointer?): T = // Private APIs. @PublishedApi -@SymbolName("Kotlin_Worker_shallowCopyInternal") -external internal fun shallowCopyInternal(value: Any?): Any? -@PublishedApi @SymbolName("Kotlin_Worker_detachObjectGraphInternal") external internal fun detachObjectGraphInternal(mode: Int, producer: () -> Any?): COpaquePointer? + @PublishedApi @SymbolName("Kotlin_Worker_attachObjectGraphInternal") external internal fun attachObjectGraphInternal(stable: COpaquePointer?): Any? diff --git a/runtime/src/main/kotlin/kotlin/native/worker/Worker.kt b/runtime/src/main/kotlin/kotlin/native/concurrent/Worker.kt similarity index 90% rename from runtime/src/main/kotlin/kotlin/native/worker/Worker.kt rename to runtime/src/main/kotlin/kotlin/native/concurrent/Worker.kt index 885a6b93644..4dfee584049 100644 --- a/runtime/src/main/kotlin/kotlin/native/worker/Worker.kt +++ b/runtime/src/main/kotlin/kotlin/native/concurrent/Worker.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package kotlin.native.worker +package kotlin.native.concurrent import kotlin.native.SymbolName import kotlin.native.internal.ExportForCppRuntime @@ -42,12 +42,12 @@ typealias WorkerId = Int * Class representing worker. */ // TODO: make me value class! -class Worker(val id: WorkerId) { +public class Worker(val id: WorkerId) { /** * Requests termination of the worker. `processScheduledJobs` controls is we shall wait * until all scheduled jobs processed, or terminate immediately. */ - fun requestTermination(processScheduledJobs: Boolean = true) = + public fun requestTermination(processScheduledJobs: Boolean = true) = Future(requestTerminationInternal(id, processScheduledJobs)) /** @@ -61,7 +61,7 @@ class Worker(val id: WorkerId) { * the future, can use result of worker's computations. */ @Suppress("UNUSED_PARAMETER") - fun schedule(mode: TransferMode, producer: () -> T1, @VolatileLambda job: (T1) -> T2): Future = + public fun schedule(mode: TransferMode, producer: () -> T1, @VolatileLambda job: (T1) -> T2): Future = /** * This function is a magical operation, handled by lowering in the compiler, and replaced with call to * scheduleImpl(worker, mode, producer, job) @@ -69,9 +69,9 @@ class Worker(val id: WorkerId) { */ throw RuntimeException("Shall not be called directly") - override fun equals(other: Any?) = (other is Worker) && (id == other.id) + override public fun equals(other: Any?): Boolean = (other is Worker) && (id == other.id) - override fun hashCode() = id + override public fun hashCode(): Int = id } /** @@ -79,7 +79,7 @@ class Worker(val id: WorkerId) { * Typically new worker may be needed for computations offload to another core, for IO it may be * better to use non-blocking IO combined with more lightweight coroutines. */ -fun startWorker(): Worker = Worker(startInternal()) +public fun startWorker(): Worker = Worker(startInternal()) // Private APIs. @kotlin.native.internal.ExportForCompiler diff --git a/runtime/src/main/kotlin/kotlin/native/test/GTestLogger.kt b/runtime/src/main/kotlin/kotlin/native/internal/test/GTestLogger.kt similarity index 97% rename from runtime/src/main/kotlin/kotlin/native/test/GTestLogger.kt rename to runtime/src/main/kotlin/kotlin/native/internal/test/GTestLogger.kt index 5d4ad476611..74f8a014853 100644 --- a/runtime/src/main/kotlin/kotlin/native/test/GTestLogger.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/test/GTestLogger.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package kotlin.native.test +package kotlin.native.internal.test -class GTestLogger : TestLoggerWithStatistics() { +internal class GTestLogger : TestLoggerWithStatistics() { private val Collection.totalTestsNotIgnored: Int get() = asSequence().filter { !it.ignored }.sumBy { it.testCases.values.count { !it.ignored } } diff --git a/runtime/src/main/kotlin/kotlin/native/test/Launcher.kt b/runtime/src/main/kotlin/kotlin/native/internal/test/Launcher.kt similarity index 91% rename from runtime/src/main/kotlin/kotlin/native/test/Launcher.kt rename to runtime/src/main/kotlin/kotlin/native/internal/test/Launcher.kt index 5c5679b6ee9..1b12c15f874 100644 --- a/runtime/src/main/kotlin/kotlin/native/test/Launcher.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/test/Launcher.kt @@ -14,14 +14,14 @@ * limitations under the License. */ -package kotlin.native.test +package kotlin.native.internal.test import kotlin.system.exitProcess @ThreadLocal private val _generatedSuites = mutableListOf() -internal fun registerSuite(suite: TestSuite): Unit { +public fun registerSuite(suite: TestSuite): Unit { _generatedSuites.add(suite) } diff --git a/runtime/src/main/kotlin/kotlin/native/test/TeamCityLogger.kt b/runtime/src/main/kotlin/kotlin/native/internal/test/TeamCityLogger.kt similarity index 96% rename from runtime/src/main/kotlin/kotlin/native/test/TeamCityLogger.kt rename to runtime/src/main/kotlin/kotlin/native/internal/test/TeamCityLogger.kt index 0ab19abe710..28a6ba241db 100644 --- a/runtime/src/main/kotlin/kotlin/native/test/TeamCityLogger.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/test/TeamCityLogger.kt @@ -14,11 +14,11 @@ * limitations under the License. */ -package kotlin.native.test +package kotlin.native.internal.test import kotlin.text.StringBuilder -class TeamCityLogger : BaseTestLogger() { +internal class TeamCityLogger : BaseTestLogger() { private fun String.escapeForTC(): String = StringBuilder(length).apply { for(char in this@escapeForTC) { diff --git a/runtime/src/main/kotlin/kotlin/native/test/TestListener.kt b/runtime/src/main/kotlin/kotlin/native/internal/test/TestListener.kt similarity index 93% rename from runtime/src/main/kotlin/kotlin/native/test/TestListener.kt rename to runtime/src/main/kotlin/kotlin/native/internal/test/TestListener.kt index c2f2cb009d0..1e9981b445a 100644 --- a/runtime/src/main/kotlin/kotlin/native/test/TestListener.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/test/TestListener.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package kotlin.native.test +package kotlin.native.internal.test -interface TestListener { +internal interface TestListener { fun startTesting(runner: TestRunner) fun finishTesting(runner: TestRunner, timeMillis: Long) @@ -33,7 +33,7 @@ interface TestListener { fun ignore(testCase: TestCase) } -open class BaseTestListener: TestListener { +internal open class BaseTestListener: TestListener { override fun startTesting(runner: TestRunner) {} override fun finishTesting(runner: TestRunner, timeMillis: Long) {} override fun startIteration(runner: TestRunner, iteration: Int, suites: Collection) {} diff --git a/runtime/src/main/kotlin/kotlin/native/test/TestLogger.kt b/runtime/src/main/kotlin/kotlin/native/internal/test/TestLogger.kt similarity index 90% rename from runtime/src/main/kotlin/kotlin/native/test/TestLogger.kt rename to runtime/src/main/kotlin/kotlin/native/internal/test/TestLogger.kt index dc153a75444..be143cee93f 100644 --- a/runtime/src/main/kotlin/kotlin/native/test/TestLogger.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/test/TestLogger.kt @@ -14,14 +14,14 @@ * limitations under the License. */ -package kotlin.native.test +package kotlin.native.internal.test -interface TestLogger: TestListener { +internal interface TestLogger: TestListener { fun logTestList(runner: TestRunner, suites: Collection) fun log(message: String) } -open class BaseTestLogger: BaseTestListener(), TestLogger { +internal open class BaseTestLogger: BaseTestListener(), TestLogger { override fun log(message: String) = println(message) override fun logTestList(runner: TestRunner, suites: Collection) { suites.forEach { suite -> @@ -33,7 +33,7 @@ open class BaseTestLogger: BaseTestListener(), TestLogger { } } -open class TestLoggerWithStatistics: BaseTestLogger() { +internal open class TestLoggerWithStatistics: BaseTestLogger() { protected val statistics = MutableTestStatistics() @@ -46,13 +46,13 @@ open class TestLoggerWithStatistics: BaseTestLogger() { override fun ignore(testCase: TestCase) = statistics.registerIgnore() } -class SilentTestLogger: BaseTestLogger() { +internal class SilentTestLogger: BaseTestLogger() { override fun logTestList(runner: TestRunner, suites: Collection) {} override fun log(message: String) {} override fun fail(testCase: TestCase, e: Throwable, timeMillis: Long) = e.printStackTrace() } -class SimpleTestLogger: BaseTestLogger() { +internal class SimpleTestLogger: BaseTestLogger() { override fun startTesting(runner: TestRunner) = println("Starting testing") override fun finishTesting(runner: TestRunner, timeMillis: Long) = println("Testing finished") diff --git a/runtime/src/main/kotlin/kotlin/native/test/TestRunner.kt b/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt similarity index 98% rename from runtime/src/main/kotlin/kotlin/native/test/TestRunner.kt rename to runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt index e4f005f3b80..fdf679cd3f3 100644 --- a/runtime/src/main/kotlin/kotlin/native/test/TestRunner.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt @@ -14,14 +14,14 @@ * limitations under the License. */ -package kotlin.native.test +package kotlin.native.internal.test import kotlin.IllegalArgumentException import kotlin.system.getTimeMillis import kotlin.system.measureTimeMillis import kotlin.text.StringBuilder -class TestRunner(val suites: List, args: Array) { +internal class TestRunner(val suites: List, args: Array) { private val filters = mutableListOf<(TestCase) -> Boolean>() private val listeners = mutableSetOf() private var logger: TestLogger = GTestLogger() diff --git a/runtime/src/main/kotlin/kotlin/native/test/TestStatistics.kt b/runtime/src/main/kotlin/kotlin/native/internal/test/TestStatistics.kt similarity index 92% rename from runtime/src/main/kotlin/kotlin/native/test/TestStatistics.kt rename to runtime/src/main/kotlin/kotlin/native/internal/test/TestStatistics.kt index 4fad74c9f16..77f939d56d9 100644 --- a/runtime/src/main/kotlin/kotlin/native/test/TestStatistics.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/test/TestStatistics.kt @@ -14,9 +14,9 @@ * limitations under the License. */ -package kotlin.native.test +package kotlin.native.internal.test -interface TestStatistics { +internal interface TestStatistics { val total: Int val passed: Int val failed: Int @@ -28,7 +28,7 @@ interface TestStatistics { val hasFailedTests: Boolean } -class MutableTestStatistics: TestStatistics { +internal class MutableTestStatistics: TestStatistics { override var total: Int = 0; private set override var passed: Int = 0; private set diff --git a/runtime/src/main/kotlin/kotlin/native/test/TestSuite.kt b/runtime/src/main/kotlin/kotlin/native/internal/test/TestSuite.kt similarity index 94% rename from runtime/src/main/kotlin/kotlin/native/test/TestSuite.kt rename to runtime/src/main/kotlin/kotlin/native/internal/test/TestSuite.kt index 4dd11d3c437..f102f45900f 100644 --- a/runtime/src/main/kotlin/kotlin/native/test/TestSuite.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/test/TestSuite.kt @@ -14,13 +14,13 @@ * limitations under the License. */ -package kotlin.native.test +package kotlin.native.internal.test import kotlin.IllegalArgumentException import kotlin.system.getTimeMillis import kotlin.system.measureTimeMillis -interface TestCase { +public interface TestCase { val name: String val ignored: Boolean val suite: TestSuite @@ -30,7 +30,7 @@ interface TestCase { internal val TestCase.prettyName get() = "${suite.name}.$name" -interface TestSuite { +public interface TestSuite { val name: String val ignored: Boolean val testCases: Map @@ -40,14 +40,14 @@ interface TestSuite { fun doAfterClass() } -enum class TestFunctionKind { +public enum class TestFunctionKind { BEFORE_EACH, AFTER_EACH, BEFORE_CLASS, AFTER_CLASS } -abstract class AbstractTestSuite>(override val name: String, override val ignored: Boolean) +public abstract class AbstractTestSuite>(override val name: String, override val ignored: Boolean) : TestSuite { override fun toString(): String = name @@ -80,7 +80,7 @@ abstract class AbstractTestSuite>(override val name: String, o get() = testCases.size } -abstract class BaseClassSuite(name: String, ignored: Boolean) +public abstract class BaseClassSuite(name: String, ignored: Boolean) : AbstractTestSuite Unit>(name, ignored) { class TestCase(name: String, @@ -145,7 +145,7 @@ abstract class BaseClassSuite(name: String, ignored: Boolea private typealias TopLevelFun = () -> Unit -class TopLevelSuite(name: String): AbstractTestSuite(name, false) { +public class TopLevelSuite(name: String): AbstractTestSuite(name, false) { class TestCase(name: String, override val suite: TopLevelSuite, testFunction: TopLevelFun, ignored: Boolean) : BasicTestCase(name, suite, testFunction, ignored) { diff --git a/runtime/src/main/kotlin/kotlin/native/ref/Weak.kt b/runtime/src/main/kotlin/kotlin/native/ref/Weak.kt index c0e6eec3d06..042d5650154 100644 --- a/runtime/src/main/kotlin/kotlin/native/ref/Weak.kt +++ b/runtime/src/main/kotlin/kotlin/native/ref/Weak.kt @@ -21,7 +21,7 @@ package kotlin.native.ref * retrieve a strong reference to an object, or return null, if object was already destoyed by * the memory manager. */ -class WeakReference { +public class WeakReference { /** * Creates a weak reference object pointing to an object. Weak reference doesn't prevent * removing object, and is nullified once object is collected. @@ -42,9 +42,10 @@ class WeakReference { public fun clear() { pointer = null } + + /** + * Returns either reference to an object or null, if it was collected. + */ + public fun get(): T? = pointer?.get() as T? } -/** - * Returns either reference to an object or null, if it was collected. - */ -public inline fun WeakReference.get() = pointer?.get() as T? diff --git a/runtime/src/main/kotlin/kotlin/random/Random.kt b/runtime/src/main/kotlin/kotlin/random/Random.kt index 2520a6a6b92..171f2b83483 100644 --- a/runtime/src/main/kotlin/kotlin/random/Random.kt +++ b/runtime/src/main/kotlin/kotlin/random/Random.kt @@ -15,7 +15,7 @@ */ package kotlin.random -import kotlin.native.worker.AtomicLong +import kotlin.native.concurrent.AtomicLong import kotlin.system.getTimeNanos abstract class NativeRandom { diff --git a/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt b/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt index 64594df1ee5..298a49f9493 100644 --- a/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt +++ b/runtime/src/main/kotlin/kotlin/text/regex/AbstractCharClass.kt @@ -33,10 +33,9 @@ package kotlin.text.regex -import kotlin.native.worker.AtomicReference import kotlin.collections.associate -import kotlin.native.worker.freeze - +import kotlin.native.concurrent.AtomicReference +import kotlin.native.concurrent.freeze /** * Unicode category (i.e. Ll, Lu). diff --git a/samples/globalState/src/main/kotlin/Global.kt b/samples/globalState/src/main/kotlin/Global.kt index 2c7f48a9ff8..3e62443989c 100644 --- a/samples/globalState/src/main/kotlin/Global.kt +++ b/samples/globalState/src/main/kotlin/Global.kt @@ -15,9 +15,10 @@ */ import global.* + +import kotlin.native.concurrent.* import kotlinx.cinterop.* import platform.posix.* -import kotlin.native.worker.* inline fun Int.ensureUnixCallResult(op: String, predicate: (Int) -> Boolean = { x -> x == 0} ): Int { if (!predicate(this)) { @@ -49,7 +50,7 @@ fun main(args: Array) { sharedData.f = 0.5f sharedData.string = "Hello Kotlin!".cstr.getPointer(arena) // Here we create detached mutable object, which could be later reattached by another thread. - sharedData.kotlinObject = kotlin.native.worker.detachObjectGraph { + sharedData.kotlinObject = detachObjectGraph { SharedData("A string", 42, SharedDataMember(2.39)) } // Here we create shared frozen object reference, @@ -66,12 +67,12 @@ fun main(args: Array) { argC -> initRuntimeIfNeeded() dumpShared("thread2") - val kotlinObject = kotlin.native.worker.attachObjectGraph(sharedData.kotlinObject) - val arg = kotlin.native.worker.attachObjectGraph(argC) + val kotlinObject = attachObjectGraph(sharedData.kotlinObject) + val arg = attachObjectGraph(argC) println("thread arg is $arg Kotlin object is $kotlinObject frozen is $globalObject") // Workaround for compiler issue. null as COpaquePointer? - }, kotlin.native.worker.detachObjectGraph { SharedDataMember(3.14)} ).ensureUnixCallResult("pthread_create") + }, detachObjectGraph { SharedDataMember(3.14)} ).ensureUnixCallResult("pthread_create") pthread_join(thread.value, null).ensureUnixCallResult("pthread_join") } diff --git a/samples/objc/src/main/kotlin/Window.kt b/samples/objc/src/main/kotlin/Window.kt index fc19eb3d164..739aee5d6e0 100644 --- a/samples/objc/src/main/kotlin/Window.kt +++ b/samples/objc/src/main/kotlin/Window.kt @@ -1,3 +1,5 @@ +import kotlin.native.concurrent.attachObjectGraph +import kotlin.native.concurrent.detachObjectGraph import kotlinx.cinterop.* import platform.AppKit.* import platform.Foundation.* @@ -30,12 +32,12 @@ private class Controller : NSObject() { @ObjCAction fun onClick() { // Execute some async action on button click. - dispatch_async_f(asyncQueue, kotlin.native.worker.detachObjectGraph { + dispatch_async_f(asyncQueue, detachObjectGraph { Data(clock_gettime_nsec_np(CLOCK_REALTIME)) }, staticCFunction { it -> initRuntimeIfNeeded() - val data = kotlin.native.worker.attachObjectGraph(it) + val data = attachObjectGraph(it) println("in async: $data") }) } diff --git a/samples/videoplayer/src/main/kotlin/DecoderWorker.kt b/samples/videoplayer/src/main/kotlin/DecoderWorker.kt index 2b60db4afbd..2000444d369 100644 --- a/samples/videoplayer/src/main/kotlin/DecoderWorker.kt +++ b/samples/videoplayer/src/main/kotlin/DecoderWorker.kt @@ -15,8 +15,8 @@ */ import ffmpeg.* +import kotlin.native.concurrent.* import kotlinx.cinterop.* -import kotlin.native.worker.* import platform.posix.memcpy // This global variable only set to != null value in the decoding worker. @@ -329,7 +329,7 @@ class DecoderWorker : Disposable { // All the real state must be stored on the worker's side. private val worker: Worker - constructor() { worker = kotlin.native.worker.startWorker() } + constructor() { worker = startWorker() } constructor(id: WorkerId) { worker = Worker(id) } override fun dispose() { diff --git a/samples/workers/src/main/kotlin/Workers.kt b/samples/workers/src/main/kotlin/Workers.kt index 7121b8d03a7..a8d169da7e5 100644 --- a/samples/workers/src/main/kotlin/Workers.kt +++ b/samples/workers/src/main/kotlin/Workers.kt @@ -1,4 +1,4 @@ -import kotlin.native.worker.* +import kotlin.native.concurrent.* data class WorkerArgument(val intParam: Int, val stringParam: String) data class WorkerResult(val intResult: Int, val stringResult: String)