diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index f7a1ac97ae0..1784d6e0a55 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -8105,11 +8105,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class Resume extends AbstractLightAnalysisModeTest { - @TestMetadata("boxTypeParameterOfSuperType.kt") - public void ignoreBoxTypeParameterOfSuperType() throws Exception { - runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resume/boxTypeParameterOfSuperType.kt"); - } - private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } @@ -8128,6 +8123,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resume/boxReturnValueOfSuspendLambda.kt"); } + @TestMetadata("boxTypeParameterOfSuperType.kt") + public void testBoxTypeParameterOfSuperType() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resume/boxTypeParameterOfSuperType.kt"); + } + @TestMetadata("boxUnboxInsideCoroutine.kt") public void testBoxUnboxInsideCoroutine() throws Exception { runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resume/boxUnboxInsideCoroutine.kt"); @@ -8338,11 +8338,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class ResumeWithException extends AbstractLightAnalysisModeTest { - @TestMetadata("boxTypeParameterOfSuperType.kt") - public void ignoreBoxTypeParameterOfSuperType() throws Exception { - runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resumeWithException/boxTypeParameterOfSuperType.kt"); - } - private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } @@ -8361,6 +8356,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resumeWithException/boxReturnValueOfSuspendLambda.kt"); } + @TestMetadata("boxTypeParameterOfSuperType.kt") + public void testBoxTypeParameterOfSuperType() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resumeWithException/boxTypeParameterOfSuperType.kt"); + } + @TestMetadata("boxUnboxInsideCoroutine.kt") public void testBoxUnboxInsideCoroutine() throws Exception { runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resumeWithException/boxUnboxInsideCoroutine.kt"); @@ -14188,6 +14188,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/kt44867.kt"); } + @TestMetadata("safeAsOfTypeParameterWithInlineClassBound.kt") + public void ignoreSafeAsOfTypeParameterWithInlineClassBound() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt"); + } + @TestMetadata("simpleSecondaryConstructor.kt") public void ignoreSimpleSecondaryConstructor() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/simpleSecondaryConstructor.kt"); @@ -14941,11 +14946,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/resultRunCatchingOrElse.kt"); } - @TestMetadata("safeAsOfTypeParameterWithInlineClassBound.kt") - public void testSafeAsOfTypeParameterWithInlineClassBound() throws Exception { - runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt"); - } - @TestMetadata("secondaryConstructorWithVararg.kt") public void testSecondaryConstructorWithVararg() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/secondaryConstructorWithVararg.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt index 4465da5e1c3..7f99df4035f 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt @@ -101,17 +101,13 @@ abstract class BasicBoxTest( fun doTest(filePath: String) { - doTestWithIgnoringByFailFile(filePath, coroutinesPackage = "") + doTestWithIgnoringByFailFile(filePath) } - fun doTestWithCoroutinesPackageReplacement(filePath: String, coroutinesPackage: String) { - doTestWithIgnoringByFailFile(filePath, coroutinesPackage) - } - - fun doTestWithIgnoringByFailFile(filePath: String, coroutinesPackage: String) { + fun doTestWithIgnoringByFailFile(filePath: String) { val failFile = File("$filePath.fail") try { - doTest(filePath, "OK", MainCallParameters.noCall(), coroutinesPackage) + doTest(filePath, "OK", MainCallParameters.noCall()) } catch (e: Throwable) { if (failFile.exists()) { KotlinTestUtils.assertEqualsToFile(failFile, e.message ?: "") @@ -121,7 +117,7 @@ abstract class BasicBoxTest( } } - open fun doTest(filePath: String, expectedResult: String, mainCallParameters: MainCallParameters, coroutinesPackage: String = "") { + open fun doTest(filePath: String, expectedResult: String, mainCallParameters: MainCallParameters) { val file = File(filePath) logger.logFile("Test file", file) @@ -130,9 +126,6 @@ abstract class BasicBoxTest( val dceOutputDir = getOutputDir(file, testGroupOutputDirForMinification) val pirOutputDir = getOutputDir(file, testGroupOutputDirForPir) var fileContent = KtTestUtil.doLoadFile(file) - if (coroutinesPackage.isNotEmpty()) { - fileContent = fileContent.replace("COROUTINES_PACKAGE", coroutinesPackage) - } val needsFullIrRuntime = KJS_WITH_FULL_RUNTIME.matcher(fileContent).find() || WITH_RUNTIME.matcher(fileContent).find() || WITH_STDLIB.matcher(fileContent).find() @@ -157,7 +150,7 @@ abstract class BasicBoxTest( val propertyLazyInitialization = PROPERTY_LAZY_INITIALIZATION.matcher(fileContent).find() - TestFileFactoryImpl(coroutinesPackage).use { testFactory -> + TestFileFactoryImpl().use { testFactory -> val inputFiles = TestFiles.createTestFiles( file.name, fileContent, @@ -957,7 +950,7 @@ abstract class BasicBoxTest( TestCase.assertEquals(expectedResult, result) } - private inner class TestFileFactoryImpl(val coroutinesPackage: String) : TestFiles.TestFileFactory, Closeable { + private inner class TestFileFactoryImpl() : TestFiles.TestFileFactory, Closeable { var testPackage: String? = null val tmpDir = KtTestUtil.tmpDir("js-tests") val defaultModule = TestModule(TEST_MODULE, emptyList(), emptyList()) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt index 3d72e268468..45e419a8185 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt @@ -65,10 +65,10 @@ abstract class BasicIrBoxTest( private val cachedDependencies = mutableMapOf>() - override fun doTest(filePath: String, expectedResult: String, mainCallParameters: MainCallParameters, coroutinesPackage: String) { + override fun doTest(filePath: String, expectedResult: String, mainCallParameters: MainCallParameters) { compilationCache.clear() cachedDependencies.clear() - super.doTest(filePath, expectedResult, mainCallParameters, coroutinesPackage) + super.doTest(filePath, expectedResult, mainCallParameters) } override val testChecker get() = if (runTestInNashorn) NashornIrJsTestChecker() else V8IrJsTestChecker diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt index 005d3017b63..ab668095e6b 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/TestDirectives.kt @@ -11,7 +11,6 @@ import java.nio.file.Path import java.nio.file.Paths import java.util.regex.Matcher import java.util.regex.Pattern -import java.io.File private const val MODULE_DELIMITER = ",\\s*" // These patterns are copies from @@ -34,8 +33,7 @@ fun buildCompileList(source: Path, outputDirectory: String): List { val srcText = srcFile.readText().replace(Regex("(.*?)")) { match -> match.groupValues[1] } if (srcText.contains("// WITH_COROUTINES")) { - result.add(TestFile("helpers.kt", "$outputDirectory/helpers.kt", - createTextForHelpers(true), TestModule.support)) + result.add(TestFile("helpers.kt", "$outputDirectory/helpers.kt", createTextForHelpers(), TestModule.support)) } val matcher = FILE_OR_MODULE_PATTERN.matcher(srcText) diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/coroutineTestUtil.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/coroutineTestUtil.kt index 00ef38be4d4..93fda9e6e46 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/coroutineTestUtil.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/coroutineTestUtil.kt @@ -7,138 +7,74 @@ package org.jetbrains.kotlin // This is almost a full copy of kotlin/compiler/tests-common/tests/org/jetbrains/kotlin/coroutineTestUtil.kt // TODO: get it automatically as a dependency -fun createTextForHelpers(isReleaseCoroutines: Boolean): String { - val coroutinesPackage = "kotlin.coroutines" +fun createTextForHelpers(): String = """ +package helpers +import kotlin.coroutines.* - val emptyContinuationBody = - if (isReleaseCoroutines) - """ - |override fun resumeWith(result: Result) { - | result.getOrThrow() - |} - """.trimMargin() - else - """ - |override fun resume(data: Any?) {} - |override fun resumeWithException(exception: Throwable) { throw exception } - """.trimMargin() - - val handleResultContinuationBody = - if (isReleaseCoroutines) - """ - |override fun resumeWith(result: Result) { - | x(result.getOrThrow()) - |} - """.trimMargin() - else - """ - |override fun resumeWithException(exception: Throwable) { - | throw exception - |} - | - |override fun resume(data: T) = x(data) - """.trimMargin() - - val handleExceptionContinuationBody = - if (isReleaseCoroutines) - """ - |override fun resumeWith(result: Result) { - | result.exceptionOrNull()?.let(x) - |} - """.trimMargin() - else - """ - |override fun resumeWithException(exception: Throwable) { - | x(exception) - |} - | - |override fun resume(data: Any?) {} - """.trimMargin() - - val continuationAdapterBody = - if (isReleaseCoroutines) - """ - |override fun resumeWith(result: Result) { - | if (result.isSuccess) { - | resume(result.getOrThrow()) - | } else { - | resumeWithException(result.exceptionOrNull()!!) - | } - |} - | - |abstract fun resumeWithException(exception: Throwable) - |abstract fun resume(value: T) - """.trimMargin() - else - "" - - return """ - |package helpers - |import $coroutinesPackage.* - | - |fun handleResultContinuation(x: (T) -> Unit): Continuation = object: Continuation { - | override val context = EmptyCoroutineContext - | $handleResultContinuationBody - |} - | - | - |fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation = object: Continuation { - | override val context = EmptyCoroutineContext - | $handleExceptionContinuationBody - |} - | - |open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { - | companion object : EmptyContinuation() - | $emptyContinuationBody - |} - | - |abstract class ContinuationAdapter : Continuation { - | override val context: CoroutineContext = EmptyCoroutineContext - | $continuationAdapterBody - |} - |class StateMachineCheckerClass { - | private var counter = 0 - | var finished = false - | - | var proceed: () -> Unit = {} - | - | fun reset() { - | counter = 0 - | finished = false - | proceed = {} - | } - | - | suspend fun suspendHere() = suspendCoroutine { c -> - | counter++ - | proceed = { c.resume(Unit) } - | } - | - | fun check(numberOfSuspensions: Int, checkFinished: Boolean = true) { - | for (i in 1..numberOfSuspensions) { - | if (counter != i) error("Wrong state-machine generated: suspendHere called should be called exactly once in one state. Expected " + i + ", got " + counter) - | proceed() - | } - | if (counter != numberOfSuspensions) - | error("Wrong state-machine generated: suspendHere called should be called exactly once in one state. Expected " + numberOfSuspensions + ", got " + counter) - | if (finished) error("Wrong state-machine generated: it is finished early") - | proceed() - | if (checkFinished && !finished) error("Wrong state-machine generated: it is not finished yet") - | } - |} - |val StateMachineChecker = StateMachineCheckerClass() - |object CheckStateMachineContinuation: ContinuationAdapter() { - | override val context: CoroutineContext - | get() = EmptyCoroutineContext - | - | override fun resume(value: Unit) { - | StateMachineChecker.proceed = { - | StateMachineChecker.finished = true - | } - | } - | - | override fun resumeWithException(exception: Throwable) { - | throw exception - | } - |} - """.trimMargin() +fun handleResultContinuation(x: (T) -> Unit): Continuation = object: Continuation { + override val context = EmptyCoroutineContext + + override fun resumeWith(result: Result) { + x(result.getOrThrow()) + } } + + +fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation = object: Continuation { + override val context = EmptyCoroutineContext + + override fun resumeWith(result: Result) { + result.exceptionOrNull()?.let(x) + } +} + +open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { + companion object : EmptyContinuation() + + override fun resumeWith(result: Result) { + result.getOrThrow() + } +} + +class StateMachineCheckerClass { + private var counter = 0 + var finished = false + + var proceed: () -> Unit = {} + + fun reset() { + counter = 0 + finished = false + proceed = {} + } + + suspend fun suspendHere() = suspendCoroutine { c -> + counter++ + proceed = { c.resume(Unit) } + } + + fun check(numberOfSuspensions: Int, checkFinished: Boolean = true) { + for (i in 1..numberOfSuspensions) { + if (counter != i) error("Wrong state-machine generated: suspendHere called should be called exactly once in one state. Expected " + i + ", got " + counter) + proceed() + } + if (counter != numberOfSuspensions) + error("Wrong state-machine generated: suspendHere called should be called exactly once in one state. Expected " + numberOfSuspensions + ", got " + counter) + if (finished) error("Wrong state-machine generated: it is finished early") + proceed() + if (checkFinished && !finished) error("Wrong state-machine generated: it is not finished yet") + } +} +val StateMachineChecker = StateMachineCheckerClass() +object CheckStateMachineContinuation: Continuation() { + override val context: CoroutineContext + get() = EmptyCoroutineContext + + override fun resumeWith(result: Result) { + result.getOrThrow() + StateMachineChecker.proceed = { + StateMachineChecker.finished = true + } + } +} +"""