Support val initialization in non-inline function with EXACTLY_ONCE effect

by generating a box for the value.
 #KT-26126 Fixed
This commit is contained in:
Ilmir Usmanov
2018-12-26 21:31:46 +03:00
parent a52f430d8f
commit 8a01da6ec6
20 changed files with 278 additions and 73 deletions
@@ -0,0 +1,21 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +ReadDeserializedContracts
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// IGNORE_BACKEND: JVM_IR, NATIVE, JS_IR
import kotlin.contracts.*
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
public fun myrun(block: () -> Unit) {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
block()
}
fun box(): String {
val x: Long
myrun {
x = 1L
}
return if (x != 1L) "FAIL" else "OK"
}
@@ -0,0 +1,27 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +ReadDeserializedContracts
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// IGNORE_BACKEND: JVM_IR, NATIVE, JS_IR
// FILE: 1.kt
package test
import kotlin.contracts.*
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
public inline fun myrun(crossinline block: () -> Unit): Unit {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
val l = { block() }
l()
}
// FILE: 2.kt
import test.*
fun box(): String {
val x: Long
myrun {
x = 42L
}
return if (x != 42L) "FAIL" else "OK"
}
@@ -0,0 +1,27 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +ReadDeserializedContracts
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
// IGNORE_BACKEND: JVM_IR, NATIVE, JS_IR
// NO_CHECK_LAMBDA_INLINING
// FILE: 1.kt
package test
import kotlin.contracts.*
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
public inline fun myrun(noinline block: () -> Unit): Unit {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
block()
}
// FILE: 2.kt
import test.*
fun box(): String {
val x: Long
myrun {
x = 42L
}
return if (x != 42L) "FAIL" else "OK"
}
@@ -21,5 +21,5 @@ fun doIt(block: () -> Unit) {
block()
}
// 2 FCONST 0
// 1 LOCALVARIABLE c Lkotlin/jvm/internal/Ref$CharRef; L1 L10 0
// 0 ISTORE 0
// 1 LOCALVARIABLE c Lkotlin/jvm/internal/Ref\$CharRef; L1 L3 0