From 2e43fa7cd09c01022dede45cdf18c830a1b4b4dc Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Mon, 19 Jun 2023 14:10:09 +0200 Subject: [PATCH] [PL][tests] Adapt tests for K/N to the conditions when static cache is used w/o lazy IR --- .../testData/klibABI/__utils__/__utils__.kt | 26 +++++++++++++------ .../klibABI/changeClassVisibility/main/m.kt | 3 +-- .../changeFunctionVisibility/main/m.kt | 3 +-- .../changePropertyVisibility/main/m.kt | 3 +-- .../klibABI/classTransformations/main/m.kt | 5 ++-- .../severalInheritedImplementations/main/m.kt | 2 +- .../kotlin/klib/PartialLinkageTestUtils.kt | 13 +++++++--- .../ir/AbstractJsPartialLinkageTestCase.kt | 12 ++++----- .../AbstractNativePartialLinkageTest.kt | 20 +++++++++----- 9 files changed, 53 insertions(+), 34 deletions(-) diff --git a/compiler/testData/klibABI/__utils__/__utils__.kt b/compiler/testData/klibABI/__utils__/__utils__.kt index 6f77de9a7fd..dc96cacfcce 100644 --- a/compiler/testData/klibABI/__utils__/__utils__.kt +++ b/compiler/testData/klibABI/__utils__/__utils__.kt @@ -24,19 +24,29 @@ sealed interface FailurePattern private typealias Block = () -> T -enum class TestMode(val isJs: Boolean = false, val isNative: Boolean = false, val hasCachesEnabled: Boolean = false) { - JS_NO_IC(isJs = true), - JS_WITH_IC(isJs = true), - NATIVE_CACHE_NO(isNative = true), - NATIVE_CACHE_STATIC_ONLY_DIST(isNative = true, hasCachesEnabled = true), - NATIVE_CACHE_STATIC_EVERYWHERE(isNative = true, hasCachesEnabled = true); +data class TestMode( + val isJs: Boolean = false, + val isNative: Boolean = false, + val staticCache: Scope = Scope.NOWHERE, + val lazyIr: Scope = Scope.NOWHERE +) { + enum class Scope { + NOWHERE, DISTRIBUTION, EVERYWHERE; + + val notUsed: Boolean get() = this == NOWHERE + val onlyDistribution: Boolean get() = this == DISTRIBUTION + val usedEverywhere: Boolean get() = this == EVERYWHERE + } init { check(isJs xor isNative) - check(isNative || !hasCachesEnabled) + check(isNative || staticCache.notUsed) + check(isNative || lazyIr.notUsed) } } +enum class LazyIrMode { NO, } + fun abiTest(init: TestBuilder.() -> Unit): String { val builder = TestBuilderImpl() builder.init() @@ -49,7 +59,7 @@ fun abiTest(init: TestBuilder.() -> Unit): String { private const val OK_STATUS = "OK" private class TestBuilderImpl : TestBuilder { - override val testMode = TestMode.__UNKNOWN__ + override val testMode = __UNKNOWN_TEST_MODE__ private val tests = mutableListOf() diff --git a/compiler/testData/klibABI/changeClassVisibility/main/m.kt b/compiler/testData/klibABI/changeClassVisibility/main/m.kt index 2594fc433e0..0738b269220 100644 --- a/compiler/testData/klibABI/changeClassVisibility/main/m.kt +++ b/compiler/testData/klibABI/changeClassVisibility/main/m.kt @@ -1,6 +1,5 @@ import abitestutils.abiTest import abitestutils.TestBuilder -import abitestutils.TestMode.NATIVE_CACHE_STATIC_EVERYWHERE fun box() = abiTest { success("PublicTopLevelClass") { PublicTopLevelClass_valueParameter(null) } @@ -104,7 +103,7 @@ private inline fun TestBuilder.unlinkedConstructorSymbol(signature: String, noin private inline fun TestBuilder.unlinkedSymbol(signature: String, functionName: String, noinline block: () -> Unit) { // Need to slightly adjust the expected IR linkage error message. Reason: When Lazy IR is used the type of the // symbol is determined more accurately. - val symbolKind = if ("InnerClass" in functionName && testMode == NATIVE_CACHE_STATIC_EVERYWHERE) + val symbolKind = if ("InnerClass" in functionName && testMode.lazyIr.usedEverywhere) "inner class" else "class" diff --git a/compiler/testData/klibABI/changeFunctionVisibility/main/m.kt b/compiler/testData/klibABI/changeFunctionVisibility/main/m.kt index 60ca3a1dd67..c726a4d86b6 100644 --- a/compiler/testData/klibABI/changeFunctionVisibility/main/m.kt +++ b/compiler/testData/klibABI/changeFunctionVisibility/main/m.kt @@ -1,6 +1,5 @@ import abitestutils.abiTest import abitestutils.TestBuilder -import abitestutils.TestMode.NATIVE_CACHE_STATIC_EVERYWHERE fun box() = abiTest { val c = Container() @@ -61,7 +60,7 @@ private inline fun TestBuilder.unlinkedSymbol(signature: String, noinline block: } private inline fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String, noinline block: () -> Unit) { - if (testMode == NATIVE_CACHE_STATIC_EVERYWHERE) { + if (testMode.lazyIr.usedEverywhere) { val functionName = signature.removePrefix("/").substringAfterLast(".") expectFailure(linkage("Function '$functionName' can not be called: Private function declared in module can not be accessed in module
"), block) } else diff --git a/compiler/testData/klibABI/changePropertyVisibility/main/m.kt b/compiler/testData/klibABI/changePropertyVisibility/main/m.kt index afbd96e9315..66a27e14d13 100644 --- a/compiler/testData/klibABI/changePropertyVisibility/main/m.kt +++ b/compiler/testData/klibABI/changePropertyVisibility/main/m.kt @@ -1,6 +1,5 @@ import abitestutils.abiTest import abitestutils.TestBuilder -import abitestutils.TestMode.NATIVE_CACHE_STATIC_EVERYWHERE fun box() = abiTest { val c = Container() @@ -124,7 +123,7 @@ private inline fun TestBuilder.unlinkedSymbol(signature: String, noinline block: } private inline fun TestBuilder.unlinkedTopLevelPrivateSymbol(signature: String, noinline block: () -> Unit) { - if (testMode == NATIVE_CACHE_STATIC_EVERYWHERE) { + if (testMode.lazyIr.usedEverywhere) { val accessorName = signature.removePrefix("/").split('.').takeLast(2).joinToString(".") expectFailure(linkage("Property accessor '$accessorName' can not be called: Private property accessor declared in module can not be accessed in module
"), block) } else diff --git a/compiler/testData/klibABI/classTransformations/main/m.kt b/compiler/testData/klibABI/classTransformations/main/m.kt index f42147b1dd4..2ed0bcf00e9 100644 --- a/compiler/testData/klibABI/classTransformations/main/m.kt +++ b/compiler/testData/klibABI/classTransformations/main/m.kt @@ -1,5 +1,4 @@ import abitestutils.abiTest -import abitestutils.TestMode.NATIVE_CACHE_STATIC_EVERYWHERE fun box() = abiTest { /** @@ -18,9 +17,9 @@ fun box() = abiTest { * The [adjustForLazyIr] function is used to adjust tested error messages depending on whether lazy IR is used or not. */ fun adjustForLazyIr(declaration: String) = - if (testMode == NATIVE_CACHE_STATIC_EVERYWHERE) "Expression" else declaration + if (testMode.lazyIr.usedEverywhere) "Expression" else declaration fun adjustNoClassFoundForLazyIr(signature: String) = - if (testMode == NATIVE_CACHE_STATIC_EVERYWHERE) "Expression uses unlinked class symbol '$signature'" else "No class found for symbol '$signature'" + if (testMode.lazyIr.usedEverywhere) "Expression uses unlinked class symbol '$signature'" else "No class found for symbol '$signature'" expectFailure(linkage("Function 'getClassToEnumFoo' can not be called: ${adjustForLazyIr("Function")} uses unlinked class symbol '/ClassToEnum.Foo'")) { getClassToEnumFoo() } expectFailure(linkage("Function 'getClassToEnumFooInline' can not be called: ${adjustForLazyIr("Function")} uses unlinked class symbol '/ClassToEnum.Foo'")) { getClassToEnumFooInline() } diff --git a/compiler/testData/klibABI/severalInheritedImplementations/main/m.kt b/compiler/testData/klibABI/severalInheritedImplementations/main/m.kt index a8ff061ba08..12e108ef20f 100644 --- a/compiler/testData/klibABI/severalInheritedImplementations/main/m.kt +++ b/compiler/testData/klibABI/severalInheritedImplementations/main/m.kt @@ -8,7 +8,7 @@ private fun TestBuilder.pe(className: String) = linkage("Property accessor 'bar. fun box() = abiTest { // For now it's not working with caches, because of incorrect lazy-IR usage. // Check KT-54019 for details. - if (testMode.hasCachesEnabled) { + if (!testMode.lazyIr.usedEverywhere) { expectSuccess("OK") { "OK" } return@abiTest } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/klib/PartialLinkageTestUtils.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/klib/PartialLinkageTestUtils.kt index 21c7e3dde4a..5c4a7d669d6 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/klib/PartialLinkageTestUtils.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/klib/PartialLinkageTestUtils.kt @@ -18,7 +18,7 @@ object PartialLinkageTestUtils { val testDir: File val buildDir: File val stdlibFile: File - val testModeName: String + val testModeConstructorParameters: Map // Customize the source code of a module before compiling it to a KLIB. fun customizeModuleSources(moduleName: String, moduleSourceDir: File) = Unit @@ -99,7 +99,14 @@ object PartialLinkageTestUtils { KtUsefulTestCase.assertExists(utilsDir) copySources(from = utilsDir, to = moduleBuildDirs.sourceDir) { contents -> - contents.replace(TEST_MODE_PLACEHOLDER, testModeName) + contents.replace( + TEST_MODE_PLACEHOLDER, + buildString { + append("TestMode(") + testModeConstructorParameters.entries.joinTo(this) { it.key + " = " + it.value } + append(")") + } + ) } } @@ -203,5 +210,5 @@ object PartialLinkageTestUtils { const val MAIN_MODULE_NAME = "main" private const val PL_UTILS_DIR = "__utils__" - private const val TEST_MODE_PLACEHOLDER = "TestMode.__UNKNOWN__" + private const val TEST_MODE_PLACEHOLDER = "__UNKNOWN_TEST_MODE__" } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/AbstractJsPartialLinkageTestCase.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/AbstractJsPartialLinkageTestCase.kt index b8cb5edce43..0764051ea7a 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/AbstractJsPartialLinkageTestCase.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/AbstractJsPartialLinkageTestCase.kt @@ -61,11 +61,11 @@ abstract class AbstractJsPartialLinkageWithICTestCase : AbstractJsPartialLinkage abstract class AbstractFirJsPartialLinkageNoICTestCase : AbstractJsPartialLinkageTestCase(CompilerType.K2_NO_IC) abstract class AbstractJsPartialLinkageTestCase(val compilerType: CompilerType) { - enum class CompilerType(val testModeName: String, val es6Mode: Boolean) { - K1_NO_IC("JS_NO_IC", false), - K1_NO_IC_WITH_ES6("JS_NO_IC", true), - K1_WITH_IC("JS_WITH_IC", false), - K2_NO_IC("JS_NO_IC", false) + enum class CompilerType(val es6Mode: Boolean) { + K1_NO_IC(false), + K1_NO_IC_WITH_ES6(true), + K1_WITH_IC(false), + K2_NO_IC(false) } private val zipAccessor = ZipFileSystemCacheableAccessor(2) @@ -96,7 +96,7 @@ abstract class AbstractJsPartialLinkageTestCase(val compilerType: CompilerType) override val testDir: File = File(testPath).absoluteFile override val buildDir: File get() = this@AbstractJsPartialLinkageTestCase.buildDir override val stdlibFile: File get() = File("libraries/stdlib/js-ir/build/classes/kotlin/js/main").absoluteFile - override val testModeName get() = this@AbstractJsPartialLinkageTestCase.compilerType.testModeName + override val testModeConstructorParameters = mapOf("isJs" to "true") override fun buildKlib( moduleName: String, diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativePartialLinkageTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativePartialLinkageTest.kt index af7a7e7d3cb..8ecb45a2340 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativePartialLinkageTest.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativePartialLinkageTest.kt @@ -34,14 +34,20 @@ abstract class AbstractNativePartialLinkageTest : AbstractNativeSimpleTest() { override val buildDir get() = this@AbstractNativePartialLinkageTest.buildDir override val stdlibFile get() = this@AbstractNativePartialLinkageTest.stdlibFile - override val testModeName = with(testRunSettings.get()) { - val cacheModeAlias = when { - !useStaticCacheForDistributionLibraries -> CacheMode.Alias.NO - !useStaticCacheForUserLibraries -> CacheMode.Alias.STATIC_ONLY_DIST - else -> CacheMode.Alias.STATIC_EVERYWHERE - } + override val testModeConstructorParameters = buildMap { + this["isNative"] = "true" - "NATIVE_CACHE_${cacheModeAlias}" + val cacheMode = testRunSettings.get() + when { + cacheMode.useStaticCacheForUserLibraries -> { + this["staticCache"] = "TestMode.Scope.EVERYWHERE" + this["lazyIr"] = "TestMode.Scope.NOWHERE" // by default LazyIR is disabled + } + cacheMode.useStaticCacheForDistributionLibraries -> { + this["staticCache"] = "TestMode.Scope.DISTRIBUTION" + this["lazyIr"] = "TestMode.Scope.NOWHERE" // by default LazyIR is disabled + } + } } override fun customizeModuleSources(moduleName: String, moduleSourceDir: File) {