[atomicfu-JVM] Preparation for commonization of JVM and K/N transformers

The following updates in the JVM/IR plugin were made:
* Lots of refactoring with preparation for K/N support: commonization of transformations.
* Improved error handling (checks for visibility constraints, appending message about usage constraints in case of an error).
* Explicit requirements for the visibility of atomic properties: to prevent leaking they should be private/internal or be members of private/internal classes.
* Fixed visibility of generated properties: volatile properties are always private and atomic updaters have the same visibility as the original atomic property.
* Volatile fields are generated from scratch and original atomic properties are removed.
* Delegated properties support is fixed (only declaration in the same scope is allowed).
* Non-inline atomic extensions are forbidden.
* For top-level atomics: only one wrapper class per file (with corresponding visibility) is generated.
* Bug fixes.

The corresponding tickets: 
https://github.com/Kotlin/kotlinx-atomicfu/issues/322
KT-60528



Merge-request: KT-MR-10579
Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
This commit is contained in:
mvicsokolova
2023-07-20 13:59:23 +00:00
committed by Space Team
parent 6ca95dc338
commit 5c5367d377
92 changed files with 3480 additions and 2575 deletions
@@ -0,0 +1,34 @@
import kotlinx.atomicfu.locks.*
import kotlin.test.*
//class ReentrantLockTest {
// private val lock = reentrantLock()
// private var state = 0
//
// fun testLockField() {
// lock.withLock {
// state = 1
// }
// assertEquals(1, state)
// }
//}
class ReentrantLockFieldTest {
private val lock = reentrantLock()
private var state = 0
fun testLock() {
lock.withLock {
state = 1
}
assertEquals(1, state)
assertTrue(lock.tryLock())
lock.unlock()
}
}
fun box(): String {
val testClass = ReentrantLockFieldTest()
testClass.testLock()
return "OK"
}
@@ -0,0 +1,14 @@
@kotlin.Metadata
public final class ReentrantLockFieldTest {
// source: 'ReentrantLockTest.kt'
private final @org.jetbrains.annotations.NotNull field lock: java.util.concurrent.locks.ReentrantLock
private field state: int
public method <init>(): void
public final method testLock(): void
}
@kotlin.Metadata
public final class ReentrantLockTestKt {
// source: 'ReentrantLockTest.kt'
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
}
@@ -0,0 +1,21 @@
import kotlinx.atomicfu.locks.*
import kotlin.test.*
class SynchronizedObjectTest : SynchronizedObject() {
fun testSync() {
val result = synchronized(this) { bar() }
assertEquals("OK", result)
}
private fun bar(): String =
synchronized(this) {
"OK"
}
}
fun box(): String {
val testClass = SynchronizedObjectTest()
testClass.testSync()
return "OK"
}
@@ -0,0 +1,13 @@
@kotlin.Metadata
public final class SynchronizedObjectTest {
// source: 'SynchronizedObjectTest.kt'
public method <init>(): void
private final method bar(): java.lang.String
public final method testSync(): void
}
@kotlin.Metadata
public final class SynchronizedObjectTestKt {
// source: 'SynchronizedObjectTest.kt'
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
}