From 3f758a3fa2087049edce178c342a063de8292c26 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 25 Jan 2021 16:54:32 +0300 Subject: [PATCH] [Test] Make BytecodeInliningHandler for new infrastructure --- .../kotlin/codegen/InlineTestUtil.kt | 22 ++++++------- .../handlers/BytecodeInliningHandler.kt | 32 +++++++++++++++++++ .../test/directives/CodegenTestDirectives.kt | 13 +++++--- .../AbstractBlackBoxInlineCodegenTest.kt | 6 +++- ...actCompileKotlinAgainstInlineKotlinTest.kt | 6 +++- 5 files changed, 61 insertions(+), 18 deletions(-) rename compiler/{tests-common => test-infrastructure-utils}/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt (95%) create mode 100644 compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/BytecodeInliningHandler.kt diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt similarity index 95% rename from compiler/tests-common/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt rename to compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt index 19a156fc3bd..a255eb00427 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt +++ b/compiler/test-infrastructure-utils/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt @@ -25,13 +25,16 @@ import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.load.kotlin.FileBasedKotlinClass import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader -import org.jetbrains.kotlin.test.KotlinBaseTest import org.jetbrains.org.objectweb.asm.* import org.jetbrains.org.objectweb.asm.tree.MethodNode import java.util.* object InlineTestUtil { - fun checkNoCallsToInline(outputFiles: Iterable, files: List) { + fun checkNoCallsToInline( + outputFiles: Iterable, + skipParameterCheckingInDirectives: Boolean, + skippedMethods: Set + ) { val inlineInfo = obtainInlineInfo(outputFiles) val inlineMethods = inlineInfo.inlineMethods assert(inlineMethods.isNotEmpty()) { "There are no inline methods" } @@ -39,12 +42,10 @@ object InlineTestUtil { val notInlinedCalls = checkInlineMethodNotInvoked(outputFiles, inlineMethods) assert(notInlinedCalls.isEmpty()) { "All inline methods should be inlined but:\n" + notInlinedCalls.joinToString("\n") } - val skipParameterChecking = files.any { - "NO_CHECK_LAMBDA_INLINING" in it.directives - } || !doLambdaInliningCheck(outputFiles, inlineInfo) + val skipParameterChecking = skipParameterCheckingInDirectives || !doLambdaInliningCheck(outputFiles, inlineInfo) if (!skipParameterChecking) { - val notInlinedParameters = checkParametersInlined(outputFiles, inlineInfo, files) + val notInlinedParameters = checkParametersInlined(outputFiles, inlineInfo, skippedMethods) assert(notInlinedParameters.isEmpty()) { "All inline parameters should be inlined but:\n${notInlinedParameters.joinToString("\n")}\n" + "but if you have not inlined lambdas or anonymous objects enable NO_CHECK_LAMBDA_INLINING directive" @@ -166,13 +167,10 @@ object InlineTestUtil { } private fun checkParametersInlined( - outputFiles: Iterable, inlineInfo: InlineInfo, files: List + outputFiles: Iterable, + inlineInfo: InlineInfo, + skipMethods: Set ): ArrayList { - val skipMethods = - files.flatMap { - it.directives.listValues("SKIP_INLINE_CHECK_IN") ?: emptyList() - }.toSet() - val inlinedMethods = inlineInfo.inlineMethods val notInlinedParameters = ArrayList() for (file in outputFiles) { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/BytecodeInliningHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/BytecodeInliningHandler.kt new file mode 100644 index 00000000000..0d1acc2a738 --- /dev/null +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/BytecodeInliningHandler.kt @@ -0,0 +1,32 @@ +/* + * 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.codegen.InlineTestUtil +import org.jetbrains.kotlin.codegen.filterClassFiles +import org.jetbrains.kotlin.codegen.getClassFiles +import org.jetbrains.kotlin.test.directives.CodegenTestDirectives +import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.NO_CHECK_LAMBDA_INLINING +import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.SKIP_INLINE_CHECK_IN +import org.jetbrains.kotlin.test.directives.model.DirectivesContainer +import org.jetbrains.kotlin.test.model.BinaryArtifacts +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.services.TestServices + +class BytecodeInliningHandler(testServices: TestServices) : JvmBinaryArtifactHandler(testServices) { + override val directivesContainers: List + get() = listOf(CodegenTestDirectives) + + override fun processModule(module: TestModule, info: BinaryArtifacts.Jvm) { + InlineTestUtil.checkNoCallsToInline( + info.classFileFactory.getClassFiles(), + skipParameterCheckingInDirectives = NO_CHECK_LAMBDA_INLINING in module.directives, + skippedMethods = module.directives[SKIP_INLINE_CHECK_IN].toSet() + ) + } + + override fun processAfterAllModules(someAssertionWasFailed: Boolean) {} +} 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 dbb639e7e88..22a47501f5d 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,10 +6,7 @@ package org.jetbrains.kotlin.test.directives import org.jetbrains.kotlin.test.TargetBackend -import org.jetbrains.kotlin.test.backend.handlers.BytecodeTextHandler -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.handlers.* import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability.File import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability.Global @@ -90,4 +87,12 @@ object CodegenTestDirectives : SimpleDirectivesContainer() { val TREAT_AS_ONE_FILE by directive( description = "Treat bytecode from all files as one in ${BytecodeTextHandler::class}" ) + + val NO_CHECK_LAMBDA_INLINING by directive( + description = "Skip checking of lambda inlining in ${BytecodeInliningHandler::class.java}" + ) + + val SKIP_INLINE_CHECK_IN by stringDirective( + description = "Skip checking of specific methods in ${BytecodeInliningHandler::class.java}" + ) } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxInlineCodegenTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxInlineCodegenTest.kt index 236ff9051db..8f4c1956fb8 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxInlineCodegenTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxInlineCodegenTest.kt @@ -24,7 +24,11 @@ abstract class AbstractBlackBoxInlineCodegenTest : AbstractBlackBoxCodegenTest() override fun doMultiFileTest(wholeFile: File, files: List) { super.doMultiFileTest(wholeFile, files) try { - InlineTestUtil.checkNoCallsToInline(initializedClassLoader.allGeneratedFiles.filterClassFiles(), files) + InlineTestUtil.checkNoCallsToInline( + initializedClassLoader.allGeneratedFiles.filterClassFiles(), + skipParameterCheckingInDirectives = files.any { "NO_CHECK_LAMBDA_INLINING" in it.directives }, + skippedMethods = files.flatMapTo(mutableSetOf()) { it.directives.listValues("SKIP_INLINE_CHECK_IN") ?: emptyList() } + ) SMAPTestUtil.checkSMAP(files, generateClassesInFile().getClassFiles(), false) } catch (e: Throwable) { println(generateToText()) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractCompileKotlinAgainstInlineKotlinTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractCompileKotlinAgainstInlineKotlinTest.kt index ae071deb409..3c7f7a6e4c5 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractCompileKotlinAgainstInlineKotlinTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractCompileKotlinAgainstInlineKotlinTest.kt @@ -28,7 +28,11 @@ abstract class AbstractCompileKotlinAgainstInlineKotlinTest : AbstractCompileKot ) try { val allGeneratedFiles = factory1.asList() + factory2.asList() - InlineTestUtil.checkNoCallsToInline(allGeneratedFiles.filterClassFiles(), files) + InlineTestUtil.checkNoCallsToInline( + allGeneratedFiles.filterClassFiles(), + skipParameterCheckingInDirectives = files.any { "NO_CHECK_LAMBDA_INLINING" in it.directives }, + skippedMethods = files.flatMapTo(mutableSetOf()) { it.directives.listValues("SKIP_INLINE_CHECK_IN") ?: emptyList() } + ) SMAPTestUtil.checkSMAP(files, allGeneratedFiles.filterClassFiles(), true) } catch (e: Throwable) { if (!isIgnored) {