Skip to content

Commit

Permalink
Gross stdlib cleanup (part 2) (JetBrains#1924)
Browse files Browse the repository at this point in the history
  • Loading branch information
olonho authored Aug 24, 2018
1 parent 6d4218c commit 59eae5e
Show file tree
Hide file tree
Showing 60 changed files with 135 additions and 165 deletions.
4 changes: 2 additions & 2 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ 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).


### Q: How do I make a singleton object mutable?

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?
Expand Down
2 changes: 1 addition & 1 deletion IMMUTABILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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(
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/codegen/enum/isFrozen.kt
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/basic/worker_random.kt
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/atomic0.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package runtime.workers.atomic0

import kotlin.test.*

import kotlin.native.worker.*
import kotlin.native.concurrent.*

fun test1(workers: Array<Worker>) {
val atomic = AtomicInt(15)
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/enum_identity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/freeze0.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/freeze1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/freeze2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/freeze3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package runtime.workers.freeze3

import kotlin.test.*

import kotlin.native.worker.*
import kotlin.native.concurrent.*

object Immutable {
var x = 1
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/freeze4.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions backend.native/tests/runtime/workers/freeze5.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package runtime.workers.freeze5

import kotlin.test.*

object Keys {
internal val myMap: Map<String, List<String>> = mapOf(
"val1" to listOf("a1", "a2", "a3"),
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/freeze_stress.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/lazy0.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/lazy1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions backend.native/tests/runtime/workers/worker0.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions backend.native/tests/runtime/workers/worker1.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package runtime.workers.worker1

import kotlin.test.*

import kotlin.native.worker.*
import kotlin.native.concurrent.*

@Test fun runTest() {
val COUNT = 5
val workers = Array(COUNT, { _ -> startWorker()})

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 ->
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/worker2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/worker3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/worker4.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions backend.native/tests/runtime/workers/worker5.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/worker6.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions backend.native/tests/runtime/workers/worker7.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/worker8.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/runtime/workers/worker9.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand Down
3 changes: 1 addition & 2 deletions backend.native/tests/testing/annotations.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package kotlin.test.tests

import kotlin.test.*
import kotlin.native.test.*

import kotlin.native.internal.test.*

@Ignore
class IgnoredClass {
Expand Down
2 changes: 1 addition & 1 deletion backend.native/tests/testing/custom_main.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package kotlin.test.tests

import kotlin.test.*
import kotlin.native.test.*
import kotlin.native.internal.test.*

@Test
fun test() {
Expand Down
Loading

0 comments on commit 59eae5e

Please sign in to comment.