diff --git a/compiler/testData/ir/irText/expressions/jvmFieldWithIntersectionTypes.kt.txt b/compiler/testData/ir/irText/expressions/jvmFieldReferenceWithIntersectionTypes.kt.txt similarity index 100% rename from compiler/testData/ir/irText/expressions/jvmFieldWithIntersectionTypes.kt.txt rename to compiler/testData/ir/irText/expressions/jvmFieldReferenceWithIntersectionTypes.kt.txt diff --git a/compiler/testData/ir/irText/expressions/signedToUnsignedConversions_test.kt.txt b/compiler/testData/ir/irText/expressions/signedToUnsignedConversions.kt.txt similarity index 84% rename from compiler/testData/ir/irText/expressions/signedToUnsignedConversions_test.kt.txt rename to compiler/testData/ir/irText/expressions/signedToUnsignedConversions.kt.txt index 5f4f54b6c20..6adfd3c2011 100644 --- a/compiler/testData/ir/irText/expressions/signedToUnsignedConversions_test.kt.txt +++ b/compiler/testData/ir/irText/expressions/signedToUnsignedConversions.kt.txt @@ -1,3 +1,13 @@ +// FILE: signedToUnsignedConversions_annotation.kt +package kotlin.internal + +annotation class ImplicitIntegerCoercion : Annotation { + constructor() /* primary */ + +} + +// FILE: signedToUnsignedConversions_test.kt + @ImplicitIntegerCoercion const val IMPLICIT_INT: Int field = 255 diff --git a/compiler/testData/ir/irText/expressions/signedToUnsignedConversions_annotation.kt.txt b/compiler/testData/ir/irText/expressions/signedToUnsignedConversions_annotation.kt.txt deleted file mode 100644 index 5ff874c983e..00000000000 --- a/compiler/testData/ir/irText/expressions/signedToUnsignedConversions_annotation.kt.txt +++ /dev/null @@ -1,7 +0,0 @@ -package kotlin.internal - -annotation class ImplicitIntegerCoercion : Annotation { - constructor() /* primary */ - -} - diff --git a/compiler/testData/ir/irText/firProblems/FirBuilder.kt.txt b/compiler/testData/ir/irText/firProblems/FirBuilder.kt.txt index bd90c729acd..aab5e1a0795 100644 --- a/compiler/testData/ir/irText/firProblems/FirBuilder.kt.txt +++ b/compiler/testData/ir/irText/firProblems/FirBuilder.kt.txt @@ -1,3 +1,22 @@ +// MODULE: m1 +// FILE: BaseFirBuilder.kt + +abstract class BaseFirBuilder { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + inline fun withCapturedTypeParameters(block: Function0): T { + return block.invoke() + } + +} + +// MODULE: m2 +// FILE: FirBuilder.kt + open class BaseConverter : BaseFirBuilder { constructor() /* primary */ { super/*BaseFirBuilder*/() diff --git a/compiler/testData/ir/irText/firProblems/v8arrayToList.kt.txt b/compiler/testData/ir/irText/firProblems/V8ArrayToList.kt.txt similarity index 100% rename from compiler/testData/ir/irText/firProblems/v8arrayToList.kt.txt rename to compiler/testData/ir/irText/firProblems/V8ArrayToList.kt.txt diff --git a/compiler/testData/ir/irText/lambdas/destructuringInLambda.kt.txt b/compiler/testData/ir/irText/lambdas/destructuringInLambda.kt.txt index b26f811287d..e649a874898 100644 --- a/compiler/testData/ir/irText/lambdas/destructuringInLambda.kt.txt +++ b/compiler/testData/ir/irText/lambdas/destructuringInLambda.kt.txt @@ -55,11 +55,12 @@ data class A { } var fn: Function1 - field = local fun (: A): Int { - val y: Int = .component2() + field = local fun ($dstr$_u24__u24$y: A): Int { + val y: Int = $dstr$_u24__u24$y.component2() return 42.plus(other = y) } get set + diff --git a/compiler/testData/ir/irText/stubs/genericClassInDifferentModule.kt.txt b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule.kt.txt new file mode 100644 index 00000000000..c9afe4180b8 --- /dev/null +++ b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule.kt.txt @@ -0,0 +1,53 @@ +// MODULE: m1 +// FILE: genericClassInDifferentModule_m1.kt + +abstract class Base { + constructor(x: T) /* primary */ { + super/*Any*/() + /* () */ + + } + + val x: T + field = x + get + + abstract fun foo(y: Y): T + abstract var bar: T + abstract get + abstract set + + abstract var Z.exn: T + abstract get + abstract set + +} + +// MODULE: m2 +// FILE: genericClassInDifferentModule_m2.kt + +class Derived1 : Base { + constructor(x: T) /* primary */ { + super/*Base*/(x = x) + /* () */ + + } + + override fun foo(y: Y): T { + return .() + } + + override var bar: T + field = x + override get + override set + + override var Z.exn: T + override get(): T { + return .() + } + override set(value: T) { + } + +} + diff --git a/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m1.kt.txt b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m1.kt.txt deleted file mode 100644 index fefa1a2c832..00000000000 --- a/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m1.kt.txt +++ /dev/null @@ -1,22 +0,0 @@ -abstract class Base { - constructor(x: T) /* primary */ { - super/*Any*/() - /* () */ - - } - - val x: T - field = x - get - - abstract fun foo(y: Y): T - abstract var bar: T - abstract get - abstract set - - abstract var Z.exn: T - abstract get - abstract set - -} - diff --git a/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.kt.txt b/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.kt.txt deleted file mode 100644 index 1143ff25dd0..00000000000 --- a/compiler/testData/ir/irText/stubs/genericClassInDifferentModule_m2.kt.txt +++ /dev/null @@ -1,25 +0,0 @@ -class Derived1 : Base { - constructor(x: T) /* primary */ { - super/*Base*/(x = x) - /* () */ - - } - - override fun foo(y: Y): T { - return .() - } - - override var bar: T - field = x - override get - override set - - override var Z.exn: T - override get(): T { - return .() - } - override set(value: T) { - } - -} - diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrPrettyKotlinDumpHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrPrettyKotlinDumpHandler.kt new file mode 100644 index 00000000000..9cf9e7fe0c9 --- /dev/null +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrPrettyKotlinDumpHandler.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.test.backend.handlers + +import org.jetbrains.kotlin.ir.util.FakeOverridesStrategy +import org.jetbrains.kotlin.ir.util.KotlinLikeDumpOptions +import org.jetbrains.kotlin.ir.util.dumpKotlinLike +import org.jetbrains.kotlin.test.backend.handlers.IrTextDumpHandler.Companion.computeDumpExtension +import org.jetbrains.kotlin.test.backend.handlers.IrTextDumpHandler.Companion.groupWithTestFiles +import org.jetbrains.kotlin.test.backend.ir.IrBackendInput +import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_KT_IR +import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.EXTERNAL_FILE +import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.SKIP_KT_DUMP +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.moduleStructure +import org.jetbrains.kotlin.test.utils.MultiModuleInfoDumperImpl +import org.jetbrains.kotlin.test.utils.withExtension + +class IrPrettyKotlinDumpHandler(testServices: TestServices) : AbstractIrHandler(testServices) { + private val dumper = MultiModuleInfoDumperImpl("// MODULE: %s") + + override fun processModule(module: TestModule, info: IrBackendInput) { + if (DUMP_KT_IR !in module.directives || SKIP_KT_DUMP in module.directives) return + + val irFiles = info.backendInput.irModuleFragment.files + val builder = dumper.builderForModule(module) + val filteredIrFiles = irFiles.groupWithTestFiles(module).filter { + EXTERNAL_FILE !in it.first.directives + }.map { it.second } + val printFileName = filteredIrFiles.size > 1 || testServices.moduleStructure.modules.size > 1 + for (irFile in filteredIrFiles) { + val dump = irFile.dumpKotlinLike( + KotlinLikeDumpOptions( + printFileName = printFileName, + printFilePath = false, + printFakeOverridesStrategy = FakeOverridesStrategy.NONE + ) + ) + builder.append(dump) + } + } + + override fun processAfterAllModules(someAssertionWasFailed: Boolean) { + if (dumper.isEmpty()) return + val moduleStructure = testServices.moduleStructure + val extension = computeDumpExtension(moduleStructure.modules.first(), "kt.txt") + val expectedFile = moduleStructure.originalTestDataFiles.first().withExtension(extension) + assertions.assertEqualsToFile(expectedFile, dumper.generateResultingDump()) + } +} diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTextDumpHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTextDumpHandler.kt index c012607e5de..964cd62f34e 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTextDumpHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrTextDumpHandler.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.test.backend.handlers import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor -import org.jetbrains.kotlin.config.languageVersionSettings import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies import org.jetbrains.kotlin.ir.IrVerifier @@ -26,6 +25,7 @@ import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.FIR_IDENTICAL import org.jetbrains.kotlin.test.directives.model.DirectivesContainer import org.jetbrains.kotlin.test.model.FrontendKinds +import org.jetbrains.kotlin.test.model.TestFile import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.moduleStructure @@ -35,6 +35,19 @@ import org.jetbrains.kotlin.test.utils.withSuffixAndExtension import java.io.File class IrTextDumpHandler(testServices: TestServices) : AbstractIrHandler(testServices) { + companion object { + fun computeDumpExtension(module: TestModule, defaultExtension: String): String { + return if (module.frontendKind == FrontendKinds.ClassicFrontend || FIR_IDENTICAL in module.directives) + defaultExtension else "fir.$defaultExtension" + } + + fun List.groupWithTestFiles(module: TestModule): List> = mapNotNull { irFile -> + val name = irFile.fileEntry.name.removePrefix("/") + val testFile = module.files.firstOrNull { it.name == name } ?: return@mapNotNull null + testFile to irFile + } + } + override val directivesContainers: List get() = listOf(CodegenTestDirectives, FirDiagnosticsDirectives) @@ -45,11 +58,7 @@ class IrTextDumpHandler(testServices: TestServices) : AbstractIrHandler(testServ override fun processModule(module: TestModule, info: IrBackendInput) { if (DUMP_IR !in module.directives) return val irFiles = info.backendInput.irModuleFragment.files - val testFileToIrFile = irFiles.mapNotNull { irFile -> - val name = irFile.fileEntry.name.removePrefix("/") - val testFile = module.files.firstOrNull { it.name == name } ?: return@mapNotNull null - testFile to irFile - } + val testFileToIrFile = irFiles.groupWithTestFiles(module) val builder = baseDumper.builderForModule(module) for ((testFile, irFile) in testFileToIrFile) { if (EXTERNAL_FILE in testFile.directives) continue @@ -112,5 +121,5 @@ class IrTextDumpHandler(testServices: TestServices) : AbstractIrHandler(testServ } private val TestModule.dumpExtension: String - get() = if (frontendKind == FrontendKinds.ClassicFrontend || FIR_IDENTICAL in directives) "txt" else "fir.txt" + get() = computeDumpExtension(this, "txt") } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/CodegenTestDirectives.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/CodegenTestDirectives.kt index 5a3dbfcd17b..0cacf9dcfee 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/CodegenTestDirectives.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/CodegenTestDirectives.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.test.directives import org.jetbrains.kotlin.test.TargetBackend +import org.jetbrains.kotlin.test.backend.handlers.IrPrettyKotlinDumpHandler import org.jetbrains.kotlin.test.backend.handlers.IrTextDumpHandler import org.jetbrains.kotlin.test.backend.handlers.NoCompilationErrorsHandler import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade @@ -76,4 +77,12 @@ object CodegenTestDirectives : SimpleDirectivesContainer() { description = "Indicates that test file is external and should be skipped in ${IrTextDumpHandler::class}", applicability = File ) + + val DUMP_KT_IR by directive( + description = "Dumps generated backend IR in pretty kotlin dump (enables ${IrPrettyKotlinDumpHandler::class})" + ) + + val SKIP_KT_DUMP by directive( + description = "Skips check pretty kt IR dump (disables ${IrPrettyKotlinDumpHandler::class})" + ) } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/AbstractIrTextTest.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/AbstractIrTextTest.kt index 6908a7392fa..ffdd84a09d2 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/AbstractIrTextTest.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/runners/ir/AbstractIrTextTest.kt @@ -7,10 +7,12 @@ package org.jetbrains.kotlin.test.runners.ir import org.jetbrains.kotlin.platform.jvm.JvmPlatforms import org.jetbrains.kotlin.test.TargetBackend +import org.jetbrains.kotlin.test.backend.handlers.IrPrettyKotlinDumpHandler import org.jetbrains.kotlin.test.backend.BlackBoxCodegenSuppressor import org.jetbrains.kotlin.test.backend.handlers.* import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_IR +import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_KT_IR import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2IrConverter import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade import org.jetbrains.kotlin.test.frontend.fir.Fir2IrResultsConverter @@ -37,6 +39,7 @@ abstract class AbstractIrTextTestBase( defaultDirectives { +DUMP_IR + +DUMP_KT_IR } useConfigurators( @@ -59,7 +62,10 @@ abstract class AbstractIrTextTestBase( ::Fir2IrResultsConverter ) - useBackendHandlers(::IrTextDumpHandler) + useBackendHandlers( + ::IrTextDumpHandler, + ::IrPrettyKotlinDumpHandler + ) } }