[PL][tests] Keep PL test data under "testData/klib/" dir

This commit is contained in:
Dmitriy Dolovov
2023-08-15 14:38:02 +02:00
committed by Space Team
parent 9e3afe7a1f
commit 5c3e63e19a
186 changed files with 156 additions and 156 deletions
@@ -0,0 +1,99 @@
@file:Suppress("RedundantSuspendModifier", "NOTHING_TO_INLINE")
class Cache {
private val cache = mutableMapOf<String, String>()
fun load(key: String): String? = cache[key]
fun store(key: String, value: String) { cache[key] = value }
fun dumpToString(): String = cache.entries.sortedBy { it.key }.joinToString(",") { it.key + "=" + it.value }
}
class OperatorsToNonOperators(private val cache: Cache) {
operator fun get(key: String): String? = cache.load(key)
operator fun set(key: String, value: String) = cache.store(key, value)
operator fun invoke(): String = cache.dumpToString()
companion object {
operator fun Cache.get(key: String): String? = load(key)
operator fun Cache.set(key: String, value: String) = store(key, value)
operator fun Cache.invoke(): String = dumpToString()
}
}
class NonOperatorsToOperators(private val cache: Cache) {
fun get(key: String): String? = cache.load(key)
fun set(key: String, value: String) = cache.store(key, value)
fun invoke(): String = cache.dumpToString()
companion object {
fun Cache.get(key: String): String? = load(key)
fun Cache.set(key: String, value: String) = store(key, value)
fun Cache.invoke(): String = dumpToString()
}
}
data class Wrapper(private val value: Int) {
private operator fun plus(other: Wrapper): Wrapper = (value + other.value).wrap()
fun unwrap(): Int = value
fun memberNonInfixToInfix(other: Wrapper): Wrapper = this + other
infix fun memberInfixToNonInfix(other: Wrapper): Wrapper = this + other
companion object {
fun Wrapper.extensionNonInfixToInfix(other: Wrapper): Wrapper = this + other
infix fun Wrapper.extensionInfixToNonInfix(other: Wrapper): Wrapper = this + other
}
}
fun Int.wrap(): Wrapper = Wrapper(this)
object Functions {
fun nonTailrecToTailrec(n: Int, r: Int): Int = if (n <= 1) r else nonTailrecToTailrec(n - 1, n * r)
tailrec fun tailrecToNonTailrec(n: Int, r: Int): Int = if (n <= 1) r else tailrecToNonTailrec(n - 1, n * r)
@Suppress("RedundantSuspendModifier") suspend fun <R> wrapCoroutine(coroutine: suspend () -> R): R = coroutine.invoke()
suspend fun suspendToNonSuspendFunction(x: Int): Int = wrapCoroutine { -x }
fun nonSuspendToSuspendFunction(x: Int): Int = -x
inline fun inlineLambdaToNoinlineLambda(x: Int, lambda: (Int) -> String): String = "Functions.inlineLambdaToNoinlineLambda($x) { ${lambda(x * 2)} }"
inline fun inlineLambdaToCrossinlineLambda(x: Int, lambda: (Int) -> String): String = "Functions.inlineLambdaToCrossinlineLambda($x) { ${lambda(x * 2)} }"
fun removedFirstDefaultValue(a: Int = 42, b: Int): Int = a + b
fun removedVarargFirstDefaultValue(vararg a: Int = intArrayOf(1, 2, 3), b: Int): Int = a.sum() + b
fun removedLastDefaultValue(a: Int, b: Int = 42): Int = a + b
fun removedVarargLastDefaultValue(a: Int, vararg b: Int = intArrayOf(1, 2, 3)): Int = a + b.sum()
}
class RemovedFirstDefaultValueInConstructor(a: Int = 42, b: Int) {
val value = a + b
}
class RemovedLastDefaultValueInConstructor(a: Int, b: Int = 42) {
val value = a + b
}
interface Interface {
suspend fun suspendToNonSuspendFunction(x: Int): String
fun nonSuspendToSuspendFunction(x: Int): String
}
abstract class AbstractClass {
abstract suspend fun suspendToNonSuspendFunction(x: Int): String
abstract fun nonSuspendToSuspendFunction(x: Int): String
}
open class OpenClass {
open suspend fun suspendToNonSuspendFunction(x: Int): String = Functions.wrapCoroutine { "OpenClass.suspendToNonSuspendFunction($x)" }
open fun nonSuspendToSuspendFunction(x: Int): String = "OpenClass.nonSuspendToSuspendFunction($x)"
open suspend fun suspendToNonSuspendFunctionWithDelegation(x: Int): String = Functions.wrapCoroutine { "OpenClass.suspendToNonSuspendFunctionWithDelegation($x)" }
open fun nonSuspendToSuspendFunctionWithDelegation(x: Int): String = "OpenClass.nonSuspendToSuspendFunctionWithDelegation($x)"
open fun openNonInlineToInlineFunction(x: Int): String = "OpenClass.openNonInlineToInlineFunction($x)"
open fun openNonInlineToInlineFunctionWithDelegation(x: Int): String = "OpenClass.openNonInlineToInlineFunctionWithDelegation($x)"
//inline fun newInlineFunction1(x: Int): String = "OpenClass.newInlineFunction1($x)"
//inline fun newInlineFunction2(x: Int): String = "OpenClass.newInlineFunction2($x)"
//fun newNonInlineFunction(x: Int): String = "OpenClass.newNonInlineFunction($x)"
fun newInlineFunction1Caller(x: Int): String = TODO("Not implemented: OpenClass.newInlineFunction1Caller($x)")
fun newInlineFunction2Caller(x: Int): String = TODO("Not implemented: OpenClass.newInlineFunction2Caller($x)")
fun newNonInlineFunctionCaller(x: Int): String = TODO("Not implemented: OpenClass.newNonInlineFunctionCaller($x)")
}
@@ -0,0 +1,99 @@
@file:Suppress("RedundantSuspendModifier", "NOTHING_TO_INLINE")
class Cache {
private val cache = mutableMapOf<String, String>()
fun load(key: String): String? = cache[key]
fun store(key: String, value: String) { cache[key] = value }
fun dumpToString(): String = cache.entries.sortedBy { it.key }.joinToString(",") { it.key + "=" + it.value }
}
class OperatorsToNonOperators(private val cache: Cache) {
fun get(key: String): String? = cache.load(key)
fun set(key: String, value: String) = cache.store(key, value)
fun invoke(): String = cache.dumpToString()
companion object {
fun Cache.get(key: String): String? = load(key)
fun Cache.set(key: String, value: String) = store(key, value)
fun Cache.invoke(): String = dumpToString()
}
}
class NonOperatorsToOperators(private val cache: Cache) {
operator fun get(key: String): String? = cache.load(key)
operator fun set(key: String, value: String) = cache.store(key, value)
operator fun invoke(): String = cache.dumpToString()
companion object {
operator fun Cache.get(key: String): String? = load(key)
operator fun Cache.set(key: String, value: String) = store(key, value)
operator fun Cache.invoke(): String = dumpToString()
}
}
data class Wrapper(private val value: Int) {
private operator fun plus(other: Wrapper): Wrapper = (value + other.value).wrap()
fun unwrap(): Int = value
infix fun memberNonInfixToInfix(other: Wrapper): Wrapper = this + other
fun memberInfixToNonInfix(other: Wrapper): Wrapper = this + other
companion object {
infix fun Wrapper.extensionNonInfixToInfix(other: Wrapper): Wrapper = this + other
fun Wrapper.extensionInfixToNonInfix(other: Wrapper): Wrapper = this + other
}
}
fun Int.wrap(): Wrapper = Wrapper(this)
object Functions {
tailrec fun nonTailrecToTailrec(n: Int, r: Int): Int = if (n <= 1) r else nonTailrecToTailrec(n - 1, n * r)
fun tailrecToNonTailrec(n: Int, r: Int): Int = if (n <= 1) r else tailrecToNonTailrec(n - 1, n * r)
@Suppress("RedundantSuspendModifier") suspend fun <R> wrapCoroutine(coroutine: suspend () -> R): R = coroutine.invoke()
fun suspendToNonSuspendFunction(x: Int): Int = -x
suspend fun nonSuspendToSuspendFunction(x: Int): Int = wrapCoroutine { -x }
inline fun inlineLambdaToNoinlineLambda(x: Int, noinline lambda: (Int) -> String): String = "Functions.inlineLambdaToNoinlineLambda($x) { ${lambda(x * 2)} }"
inline fun inlineLambdaToCrossinlineLambda(x: Int, crossinline lambda: (Int) -> String): String = "Functions.inlineLambdaToCrossinlineLambda($x) { ${lambda(x * 2)} }"
fun removedFirstDefaultValue(a: Int /*= 42*/, b: Int): Int = a + b
fun removedVarargFirstDefaultValue(vararg a: Int /*= intArrayOf(1, 2, 3)*/, b: Int): Int = a.sum() + b
fun removedLastDefaultValue(a: Int, b: Int /*= 42*/): Int = a + b
fun removedVarargLastDefaultValue(a: Int, vararg b: Int /*= intArrayOf(1, 2, 3)*/): Int = a + b.sum()
}
class RemovedFirstDefaultValueInConstructor(a: Int /*= 42*/, b: Int) {
val value = a + b
}
class RemovedLastDefaultValueInConstructor(a: Int, b: Int /*= 42*/) {
val value = a + b
}
interface Interface {
fun suspendToNonSuspendFunction(x: Int): String
suspend fun nonSuspendToSuspendFunction(x: Int): String
}
abstract class AbstractClass {
abstract fun suspendToNonSuspendFunction(x: Int): String
abstract suspend fun nonSuspendToSuspendFunction(x: Int): String
}
open class OpenClass {
open fun suspendToNonSuspendFunction(x: Int): String = "OpenClassV2.suspendToNonSuspendFunction($x)"
open suspend fun nonSuspendToSuspendFunction(x: Int): String = Functions.wrapCoroutine { "OpenClassV2.nonSuspendToSuspendFunction($x)" }
open fun suspendToNonSuspendFunctionWithDelegation(x: Int): String = "OpenClassV2.suspendToNonSuspendFunctionWithDelegation($x)"
open suspend fun nonSuspendToSuspendFunctionWithDelegation(x: Int): String = Functions.wrapCoroutine { "OpenClassV2.nonSuspendToSuspendFunctionWithDelegation($x)" }
inline fun openNonInlineToInlineFunction(x: Int): String = "OpenClassV2.openNonInlineToInlineFunction($x)"
inline fun openNonInlineToInlineFunctionWithDelegation(x: Int): String = "OpenClassV2.openNonInlineToInlineFunctionWithDelegation($x)"
inline fun newInlineFunction1(x: Int): String = "OpenClassV2.newInlineFunction1($x)"
inline fun newInlineFunction2(x: Int): String = "OpenClassV2.newInlineFunction2($x)"
fun newNonInlineFunction(x: Int): String = "OpenClassV2.newNonInlineFunction($x)"
fun newInlineFunction1Caller(x: Int): String = newInlineFunction1(x)
fun newInlineFunction2Caller(x: Int): String = newInlineFunction2(x)
fun newNonInlineFunctionCaller(x: Int): String = newNonInlineFunction(x)
}
@@ -0,0 +1,6 @@
STEP 0:
dependencies: stdlib
STEP 1:
dependencies: stdlib
modifications:
U : l1.kt.1 -> l1.kt