diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 999c2237bd8..05b6272a354 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -8343,6 +8343,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/varSpilling"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @TestMetadata("fakeInlinerVariables.kt") + public void testFakeInlinerVariables() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt"); + } + @TestMetadata("kt19475.kt") public void testKt19475_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/kt19475.kt", "kotlin.coroutines"); diff --git a/compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt b/compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt new file mode 100644 index 00000000000..3309e1d8943 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt @@ -0,0 +1,149 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME +// WITH_COROUTINES +import kotlin.coroutines.* + +interface Scope + +fun doTest( + coroutineContext: CoroutineContext, + timeout: Long = 10000L, + action: suspend Scope.() -> T +): T = TODO() + +object Dispatcher : CoroutineContext { + override fun fold(initial: R, operation: (R, CoroutineContext.Element) -> R): R { + TODO() + } + + override fun get(key: CoroutineContext.Key): E? { + TODO() + } + + override fun minusKey(key: CoroutineContext.Key<*>): CoroutineContext { + TODO() + } + +} + +class Cache { + suspend fun getOrPutByString(str: String, put: suspend () -> Info): Info = TODO() + suspend fun getOrPutById(id: ID, put: suspend () -> Info): Info = TODO() + suspend fun removeById(id: ID, newValue: Info? = null) {} +} + +class Info(val str: String) + +typealias ID = String + +private val Info.id get() = "" + +inline fun expectAnyFailure(failureMessage: String? = null, action: () -> Unit) { + expectFailure(failureMessage) { + action() + } +} + +class LoggedErrors { + var disabled = false + + val disabledTypes = mutableSetOf() +} + +class AtomicReference(var value: T) { + fun get(): T = TODO() +} + +object Expector { + val currentErrors = AtomicReference(null) + + inline fun disable(action: () -> T) { + currentErrors.get()?.apply { + val oldValue = disabled + disabled = true + try { + action() + } finally { + disabled = oldValue + } + } ?: action() + } +} + +inline fun expectFailure( + failureMessage: String? = null, + noinline exceptionCheck: ((E) -> Unit)? = null, + action: () -> Unit +) { + var exceptionWasThrown = false + try { + Expector.disable { + action() + } + } catch (ex: Throwable) { + exceptionWasThrown = true + // Exception is expected. + assertTrue("'${ex::class}' was thrown.", ex is E) + exceptionCheck?.invoke(ex as E) + } + + if (!exceptionWasThrown) { + fail("No exception was thrown.${failureMessage?.let { " $it" } ?: ""}") + } +} + +fun assertEquals(expected: Any?, actual: Any?) {} +fun fail(message: String) { + error(message) +} + +fun assertTrue(message: String, value: Boolean) {} + +class Test { + private val i1 = Info("1") + private val i2 = Info("2") + fun test() { + doTest(Dispatcher) { + val cache = Cache() + + cache.getOrPutByString(i1.str) { i1 } + + assertEquals(i1, cache.getByString(i1.str.toLowerCase())) + assertEquals(i1, cache.getByString(i1.str.toUpperCase())) + assertEquals(i1, cache.getById(i1.id)) + expectAnyFailure { cache.getByString(i2.str.toLowerCase()) } + expectAnyFailure { cache.getByString(i2.str.toUpperCase()) } + expectAnyFailure { cache.getById(i2.id) } + + cache.removeById(i2.id) + + assertEquals(i1, cache.getByString(i1.str.toLowerCase())) + assertEquals(i1, cache.getByString(i1.str.toUpperCase())) + assertEquals(i1, cache.getById(i1.id)) + expectAnyFailure { cache.getByString(i2.str.toLowerCase()) } + expectAnyFailure { cache.getByString(i2.str.toUpperCase()) } + expectAnyFailure { cache.getById(i2.id) } + + cache.removeById(i1.id) + + expectAnyFailure { cache.getByString(i1.str.toLowerCase()) } + expectAnyFailure { cache.getByString(i1.str.toUpperCase()) } + expectAnyFailure { cache.getById(i1.id) } + expectAnyFailure { cache.getByString(i2.str.toLowerCase()) } + expectAnyFailure { cache.getByString(i2.str.toUpperCase()) } + expectAnyFailure { cache.getById(i2.id) } + } + } + + private suspend fun Cache.getByString(str: String) = + getOrPutByString(str) { error("Not found $str") } + + private suspend fun Cache.getById(id: ID) = + getOrPutById(id) { error("Not found $id") } +} + +fun box(): String { + // This is compiler sanity tests + Test() + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index f2611ad2bed..a973f033404 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -9553,6 +9553,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/varSpilling"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("fakeInlinerVariables.kt") + public void testFakeInlinerVariables() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt"); + } + @TestMetadata("kt19475.kt") public void testKt19475_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/kt19475.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 1587e7dc1c1..de930cff700 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -9553,6 +9553,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/varSpilling"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } + @TestMetadata("fakeInlinerVariables.kt") + public void testFakeInlinerVariables() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt"); + } + @TestMetadata("kt19475.kt") public void testKt19475_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/kt19475.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index e60bf68d696..2ae8369c362 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -8343,6 +8343,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/varSpilling"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); } + @TestMetadata("fakeInlinerVariables.kt") + public void testFakeInlinerVariables() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt"); + } + @TestMetadata("kt19475.kt") public void testKt19475_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/kt19475.kt", "kotlin.coroutines"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index 1c09ade0fdc..c7e95737e00 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -7068,6 +7068,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/varSpilling"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); } + @TestMetadata("fakeInlinerVariables.kt") + public void testFakeInlinerVariables() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt"); + } + @TestMetadata("kt19475.kt") public void testKt19475_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/kt19475.kt", "kotlin.coroutines"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index fffecd4ea31..8a90db2d98a 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -7078,6 +7078,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/varSpilling"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @TestMetadata("fakeInlinerVariables.kt") + public void testFakeInlinerVariables() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt"); + } + @TestMetadata("kt19475.kt") public void testKt19475_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/kt19475.kt", "kotlin.coroutines"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 078f32c8459..bd79b3f240d 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -7078,6 +7078,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/coroutines/varSpilling"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); } + @TestMetadata("fakeInlinerVariables.kt") + public void testFakeInlinerVariables() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt"); + } + @TestMetadata("kt19475.kt") public void testKt19475_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/varSpilling/kt19475.kt", "kotlin.coroutines");