[JVM] Improve code coverage of EntriesMapping

Ensure that when .entries is accessed from an inline function body
or lambda argument, EntriesMapping are properly generated and used
without excessive mappings and duplicated fields

#KT-53236
This commit is contained in:
Vsevolod Tolstopyatov
2022-07-22 17:31:56 +02:00
committed by Space
parent 8a181cf2bd
commit c0f81cbc45
21 changed files with 495 additions and 0 deletions
@@ -488,6 +488,40 @@ public class FirBlackBoxInlineCodegenTestGenerated extends AbstractFirBlackBoxIn
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("callSite.kt")
public void testCallSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/callSite.kt");
}
@Test
@TestMetadata("declSite.kt")
public void testDeclSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSite.kt");
}
@Test
@TestMetadata("declSiteSeveralMappings.kt")
public void testDeclSiteSeveralMappings() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappings.kt");
}
@Test
@TestMetadata("declSiteSeveralMappingsDifOrder.kt")
public void testDeclSiteSeveralMappingsDifOrder() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappingsDifOrder.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -3414,6 +3414,12 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest {
runTest("compiler/testData/codegen/bytecodeText/inline/deleteClassOnTransformation.kt");
}
@Test
@TestMetadata("entriesMappingOnCallSite.kt")
public void testEntriesMappingOnCallSite() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/inline/entriesMappingOnCallSite.kt");
}
@Test
@TestMetadata("finallyMarkers.kt")
public void testFinallyMarkers() throws Exception {
@@ -488,6 +488,40 @@ public class FirLightTreeBlackBoxInlineCodegenTestGenerated extends AbstractFirL
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("callSite.kt")
public void testCallSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/callSite.kt");
}
@Test
@TestMetadata("declSite.kt")
public void testDeclSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSite.kt");
}
@Test
@TestMetadata("declSiteSeveralMappings.kt")
public void testDeclSiteSeveralMappings() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappings.kt");
}
@Test
@TestMetadata("declSiteSeveralMappingsDifOrder.kt")
public void testDeclSiteSeveralMappingsDifOrder() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappingsDifOrder.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -488,6 +488,40 @@ public class FirSerializeCompileKotlinAgainstInlineKotlinTestGenerated extends A
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR_SERIALIZE, true);
}
@Test
@TestMetadata("callSite.kt")
public void testCallSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/callSite.kt");
}
@Test
@TestMetadata("declSite.kt")
public void testDeclSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSite.kt");
}
@Test
@TestMetadata("declSiteSeveralMappings.kt")
public void testDeclSiteSeveralMappings() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappings.kt");
}
@Test
@TestMetadata("declSiteSeveralMappingsDifOrder.kt")
public void testDeclSiteSeveralMappingsDifOrder() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappingsDifOrder.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -0,0 +1,35 @@
// TARGET_BACKEND: JVM_IR
// NO_CHECK_LAMBDA_INLINING
// WITH_RUNTIME
// WITH_STDLIB
// MODULE: lib
// FILE: MyEnum.kt
package test
enum class X {
O,
K
}
inline fun test(block: () -> String): String {
return block()
}
// MODULE: caller(lib)
// !LANGUAGE: +EnumEntries
// FILE: 2.kt
import test.*
@OptIn(ExperimentalStdlibApi::class)
fun box(): String {
return test {
X.entries[0].toString()
} + test {
X.entries[1].toString()
}
}
@@ -0,0 +1,28 @@
// TARGET_BACKEND: JVM_IR
// WITH_RUNTIME
// WITH_STDLIB
// MODULE: lib
// FILE: 1.kt
package test
enum class X {
O,
K
}
// MODULE: caller(lib)
// !LANGUAGE: +EnumEntries
// FILE: 2.kt
import test.*
@OptIn(ExperimentalStdlibApi::class)
inline fun test(idx: Int): String {
return X.entries[idx].toString()
}
fun box(): String {
return test(0) + test(1)
}
@@ -0,0 +1,38 @@
// TARGET_BACKEND: JVM_IR
// WITH_RUNTIME
// WITH_STDLIB
// MODULE: lib
// FILE: 1.kt
package test
enum class X {
O,
K
}
enum class Y {
O,
K
}
// MODULE: caller(lib)
// !LANGUAGE: +EnumEntries
// FILE: 2.kt
import test.*
@OptIn(ExperimentalStdlibApi::class)
fun funForAdditionalMappingArrayInMappingFile(): String = Y.entries[1].toString()
@OptIn(ExperimentalStdlibApi::class)
inline fun test(idx: Int): String = X.entries[idx].toString()
// FILE: 3.kt
import test.*
fun box(): String {
return test(0) + test(1)
}
@@ -0,0 +1,38 @@
// TARGET_BACKEND: JVM_IR
// WITH_RUNTIME
// WITH_STDLIB
// MODULE: lib
// FILE: 1.kt
package test
enum class X {
O,
K
}
enum class Y {
O,
K
}
// MODULE: caller(lib)
// !LANGUAGE: +EnumEntries
// FILE: 2.kt
import test.*
@OptIn(ExperimentalStdlibApi::class)
inline fun test(idx: Int): String = X.entries[idx].toString()
@OptIn(ExperimentalStdlibApi::class)
fun funForAdditionalMappingArrayInMappingFile(): String = Y.entries[1].toString()
// FILE: 3.kt
import test.*
fun box(): String {
return test(0) + test(1)
}
@@ -0,0 +1,31 @@
// TARGET_BACKEND: JVM_IR
// WITH_STDLIB
// WITH_RUNTIME
// MODULE: lib
// FILE: 1.kt
enum class X {
O,
K
}
// MODULE: caller(lib)
// !LANGUAGE: +EnumEntries
// FILE: F.kt
inline fun test(idx: Int, block: () -> String): String {
return block()
}
@OptIn(ExperimentalStdlibApi::class)
fun box(): String {
return test(0) { X.entries[0].toString() } +
test(1) { X.entries[1].toString() }
}
// no additional mappings cause when in inline lambda (same module)
// 1 class FKt\$EntriesMappings
// 1 Lkotlin\/enums\/EnumEntries; entries\$0
// 0 Lkotlin\/enums\/EnumEntries; entries\$1
@@ -488,6 +488,16 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -488,6 +488,16 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -488,6 +488,40 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("callSite.kt")
public void testCallSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/callSite.kt");
}
@Test
@TestMetadata("declSite.kt")
public void testDeclSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSite.kt");
}
@Test
@TestMetadata("declSiteSeveralMappings.kt")
public void testDeclSiteSeveralMappings() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappings.kt");
}
@Test
@TestMetadata("declSiteSeveralMappingsDifOrder.kt")
public void testDeclSiteSeveralMappingsDifOrder() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappingsDifOrder.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -3414,6 +3414,12 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
runTest("compiler/testData/codegen/bytecodeText/inline/deleteClassOnTransformation.kt");
}
@Test
@TestMetadata("entriesMappingOnCallSite.kt")
public void testEntriesMappingOnCallSite() throws Exception {
runTest("compiler/testData/codegen/bytecodeText/inline/entriesMappingOnCallSite.kt");
}
@Test
@TestMetadata("finallyMarkers.kt")
public void testFinallyMarkers() throws Exception {
@@ -488,6 +488,40 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("callSite.kt")
public void testCallSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/callSite.kt");
}
@Test
@TestMetadata("declSite.kt")
public void testDeclSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSite.kt");
}
@Test
@TestMetadata("declSiteSeveralMappings.kt")
public void testDeclSiteSeveralMappings() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappings.kt");
}
@Test
@TestMetadata("declSiteSeveralMappingsDifOrder.kt")
public void testDeclSiteSeveralMappingsDifOrder() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappingsDifOrder.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -488,6 +488,40 @@ public class IrSerializeCompileKotlinAgainstInlineKotlinTestGenerated extends Ab
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("callSite.kt")
public void testCallSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/callSite.kt");
}
@Test
@TestMetadata("declSite.kt")
public void testDeclSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSite.kt");
}
@Test
@TestMetadata("declSiteSeveralMappings.kt")
public void testDeclSiteSeveralMappings() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappings.kt");
}
@Test
@TestMetadata("declSiteSeveralMappingsDifOrder.kt")
public void testDeclSiteSeveralMappingsDifOrder() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappingsDifOrder.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -488,6 +488,40 @@ public class JvmIrAgainstOldBoxInlineTestGenerated extends AbstractJvmIrAgainstO
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_MULTI_MODULE_IR_AGAINST_OLD, true);
}
@Test
@TestMetadata("callSite.kt")
public void testCallSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/callSite.kt");
}
@Test
@TestMetadata("declSite.kt")
public void testDeclSite() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSite.kt");
}
@Test
@TestMetadata("declSiteSeveralMappings.kt")
public void testDeclSiteSeveralMappings() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappings.kt");
}
@Test
@TestMetadata("declSiteSeveralMappingsDifOrder.kt")
public void testDeclSiteSeveralMappingsDifOrder() throws Exception {
runTest("compiler/testData/codegen/boxInline/anonymousObject/enumEntries/declSiteSeveralMappingsDifOrder.kt");
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -488,6 +488,16 @@ public class JvmOldAgainstIrBoxInlineTestGenerated extends AbstractJvmOldAgainst
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_MULTI_MODULE_OLD_AGAINST_IR, true);
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -440,6 +440,16 @@ public class JsCodegenInlineTestGenerated extends AbstractJsCodegenInlineTest {
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -440,6 +440,16 @@ public class IrJsCodegenInlineTestGenerated extends AbstractIrJsCodegenInlineTes
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@@ -385,6 +385,19 @@ public class IrCodegenBoxInlineWasmTestGenerated extends AbstractIrCodegenBoxInl
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class EnumEntries extends AbstractIrCodegenBoxInlineWasmTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath);
}
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.WASM, true);
}
}
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -40478,6 +40478,18 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest
runTest("compiler/testData/codegen/boxInline/anonymousObject/withInlineMethod.kt");
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumEntries")
@TestDataPath("$PROJECT_ROOT")
@Tag("codegen")
@UseExtTestCaseGroupProvider()
public class EnumEntries {
@Test
public void testAllFilesPresentInEnumEntries() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/anonymousObject/enumEntries"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true);
}
}
@Nested
@TestMetadata("compiler/testData/codegen/boxInline/anonymousObject/enumWhen")
@TestDataPath("$PROJECT_ROOT")