72def186a3
The change is needed for the parallel resolution (^KT-55750), so we can resolve the declaration under a lock that is specific to this declaration. Previously, if LL FIR was resolving some FirClass, LL FIR resolved all its children too, and it had no control over what parts of the FIR tree were modified. The same applied to the designation path, sometimes the classes on the designation path might be unexpectedly (and without lock) modified. This commit introduces LLFirResolveTarget, which specifies which exact declarations should be resolved during the lazy resolution of the declaration. All elements outside the declarations specified for resolve in LLFirResolveTarget, should not be modified. The logic of lazy transformers is the following: - Go to target declaration collecting all scopes from the file and containing classes - Resolve only declarations that are specified by the LLFirResolveTarget, performing the resolve under a separate lock for each declaration ^KT-56543 ^KT-57619 Fixed
50 lines
1.6 KiB
Kotlin
Vendored
50 lines
1.6 KiB
Kotlin
Vendored
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
|
|
|
import kotlin.reflect.KProperty
|
|
import kotlin.properties.ReadWriteProperty
|
|
|
|
class CleanupTestExample {
|
|
val cleanUpBlocks: MutableList<Pair<Any, (Any) -> Unit>> = mutableListOf()
|
|
|
|
class CleaningDelegate<T : Any?>(
|
|
initialValue: T? = null,
|
|
val cleanupBlocks: MutableList<Pair<Any, (Any) -> Unit>>,
|
|
val block: (T) -> Unit
|
|
) : ReadWriteProperty<Any?, T> {
|
|
private var value: T? = initialValue
|
|
|
|
init {
|
|
addCleanupBlock(initialValue)
|
|
}
|
|
|
|
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
|
return value ?: throw IllegalStateException("Property ${property.name} should be initialized before get.")
|
|
}
|
|
|
|
@Suppress("UNCHECKED_CAST")
|
|
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
|
addCleanupBlock(value)
|
|
this.value = value
|
|
}
|
|
|
|
fun addCleanupBlock(value: T?) {
|
|
if (value != null) {
|
|
@Suppress("UNCHECKED_CAST")
|
|
cleanupBlocks.add((<!DEBUG_INFO_SMARTCAST!>value<!> to block) as Pair<Any, (Any) -> Unit>)
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
data class TestHolder(val num: Int)
|
|
|
|
fun <T : Any?> cleanup(initialValue: T? = null, block: (T) -> Unit) = CleaningDelegate(initialValue, cleanUpBlocks, block)
|
|
|
|
fun testWithCleanup() {
|
|
val testHolder = TestHolder(1)
|
|
|
|
var thing: TestHolder by CleaningDelegate(testHolder, cleanupBlocks = cleanUpBlocks, block = { println("cleaning up $it") })
|
|
var thing2: TestHolder by cleanup(testHolder) { println("cleaning up $it") }
|
|
}
|
|
}
|