From 0cca07fa194ad21fe34c45de89326822b44e6ec1 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 10 Mar 2021 11:34:10 +0300 Subject: [PATCH] Bump d8 used in box tests to 2.1.75 --- build.gradle.kts | 2 +- .../samWrappedLambdaVsReference.kt | 2 ++ .../sam/equality/functionReferencesUnbound.kt | 22 +++++++++-------- .../sam/equality/localFunctionReferences.kt | 16 +++++++------ .../boxInline/anonymousObject/sam/kt22304.kt | 2 ++ .../test/backend/handlers/DxCheckerHandler.kt | 18 ++++++++++++-- .../jetbrains/kotlin/codegen/D8Checker.java | 24 +++++++++---------- 7 files changed, 53 insertions(+), 33 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 8db42d12a5b..436c87125ed 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -182,7 +182,7 @@ extra["versions.jflex"] = "1.7.0" extra["versions.markdown"] = "0.1.25" extra["versions.trove4j"] = "1.0.20181211" extra["versions.completion-ranking-kotlin"] = "0.1.3" -extra["versions.r8"] = "2.0.88" +extra["versions.r8"] = "2.1.75" val immutablesVersion = "0.3.1" extra["versions.kotlinx-collections-immutable"] = immutablesVersion extra["versions.kotlinx-collections-immutable-jvm"] = immutablesVersion diff --git a/compiler/testData/codegen/box/reflection/genericSignature/samWrappedLambdaVsReference.kt b/compiler/testData/codegen/box/reflection/genericSignature/samWrappedLambdaVsReference.kt index a89030a4d27..ad85ca78f24 100644 --- a/compiler/testData/codegen/box/reflection/genericSignature/samWrappedLambdaVsReference.kt +++ b/compiler/testData/codegen/box/reflection/genericSignature/samWrappedLambdaVsReference.kt @@ -2,6 +2,8 @@ // TARGET_BACKEND: JVM // WITH_RUNTIME // FULL_JDK +// IGNORE_DEXING +// ^ https://issuetracker.google.com/issues/182339153 // FILE: Java.java diff --git a/compiler/testData/codegen/box/sam/equality/functionReferencesUnbound.kt b/compiler/testData/codegen/box/sam/equality/functionReferencesUnbound.kt index 99a23660144..c7415cf1e69 100644 --- a/compiler/testData/codegen/box/sam/equality/functionReferencesUnbound.kt +++ b/compiler/testData/codegen/box/sam/equality/functionReferencesUnbound.kt @@ -1,8 +1,10 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND: ANDROID +// ^ D8 merges method references with empty closure created by 'invokedynamic' // FILE: test.kt -fun checkNotEqual(x: Any, y: Any) { - if (x == y || y == x) throw AssertionError("$x and $y should NOT be equal") +fun checkNotEqual(marker: String, x: Any, y: Any) { + if (x == y || y == x) throw AssertionError("$marker: $x and $y should NOT be equal") } private fun id(f: Runnable): Any = f @@ -15,15 +17,15 @@ fun adapted2(vararg s: String): String = s[0] fun box(): String { // Since 1.0, SAM wrappers for Java do not implement equals/hashCode - checkNotEqual(id(::target1), id(::target1)) - checkNotEqual(id(::target1), target1FromOtherFile()) - checkNotEqual(id(::target1), id(::target2)) + checkNotEqual("id(::target1), id(::target1)", id(::target1), id(::target1)) + checkNotEqual("id(::target1), target1FromOtherFile()", id(::target1), target1FromOtherFile()) + checkNotEqual("id(::target1), id(::target2)", id(::target1), id(::target2)) - checkNotEqual(id(::adapted1), id(::adapted1)) - checkNotEqual(id(::adapted1), adapted1FromOtherFile()) - checkNotEqual(id(::adapted2), id(::adapted2)) - checkNotEqual(id(::adapted2), adapted2FromOtherFile()) - checkNotEqual(id(::adapted1), id(::adapted2)) + checkNotEqual("id(::adapted1), id(::adapted1)", id(::adapted1), id(::adapted1)) + checkNotEqual("id(::adapted1), adapted1FromOtherFile()", id(::adapted1), adapted1FromOtherFile()) + checkNotEqual("id(::adapted2), id(::adapted2)", id(::adapted2), id(::adapted2)) + checkNotEqual("id(::adapted2), adapted2FromOtherFile()", id(::adapted2), adapted2FromOtherFile()) + checkNotEqual("id(::adapted1), id(::adapted2)", id(::adapted1), id(::adapted2)) return "OK" } diff --git a/compiler/testData/codegen/box/sam/equality/localFunctionReferences.kt b/compiler/testData/codegen/box/sam/equality/localFunctionReferences.kt index 78cc674e8b7..a7a47c5cb05 100644 --- a/compiler/testData/codegen/box/sam/equality/localFunctionReferences.kt +++ b/compiler/testData/codegen/box/sam/equality/localFunctionReferences.kt @@ -1,7 +1,9 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND: ANDROID +// ^ D8 merges method references with empty closure created by 'invokedynamic' -fun checkNotEqual(x: Any, y: Any) { - if (x == y || y == x) throw AssertionError("$x and $y should NOT be equal") +fun checkNotEqual(marker: String, x: Any, y: Any) { + if (x == y || y == x) throw AssertionError("$marker: $x and $y should NOT be equal") } private fun id(f: Runnable): Any = f @@ -12,17 +14,17 @@ fun box(): String { fun local1() {} fun local2() {} - checkNotEqual(id(::local1), id(::local1)) - checkNotEqual(id(::local1), id(::local2)) + checkNotEqual("id(::local1), id(::local1)", id(::local1), id(::local1)) + checkNotEqual("id(::local1), id(::local2)", id(::local1), id(::local2)) fun String.localExt() {} - checkNotEqual(id("A"::localExt), id("A"::localExt)) - checkNotEqual(id("A"::localExt), id("B"::localExt)) + checkNotEqual("id(\"A\"::localExt), id(\"A\"::localExt)", id("A"::localExt), id("A"::localExt)) + checkNotEqual("id(\"A\"::localExt), id(\"B\"::localExt)", id("A"::localExt), id("B"::localExt)) fun adapted(default: String? = "", vararg va: Int): Int = 0 - checkNotEqual(id(::adapted), id(::adapted)) + checkNotEqual("id(::adapted), id(::adapted)", id(::adapted), id(::adapted)) return "OK" } diff --git a/compiler/testData/codegen/boxInline/anonymousObject/sam/kt22304.kt b/compiler/testData/codegen/boxInline/anonymousObject/sam/kt22304.kt index 84b94ee69ad..afb41bb0a06 100644 --- a/compiler/testData/codegen/boxInline/anonymousObject/sam/kt22304.kt +++ b/compiler/testData/codegen/boxInline/anonymousObject/sam/kt22304.kt @@ -1,5 +1,7 @@ // FULL_JDK // TARGET_BACKEND: JVM +// IGNORE_DEXING +// ^ 2.1.75 fails with AssertionError (2.0.88 doesn't). TODO: investigate in more detail. // FILE: 1.kt package test diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DxCheckerHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DxCheckerHandler.kt index e1e28b40d16..16b037a85a6 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DxCheckerHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DxCheckerHandler.kt @@ -6,6 +6,8 @@ package org.jetbrains.kotlin.test.backend.handlers import org.jetbrains.kotlin.codegen.D8Checker +import org.jetbrains.kotlin.codegen.getClassFiles +import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil import org.jetbrains.kotlin.test.directives.CodegenTestDirectives import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.IGNORE_DEXING import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.RUN_DEX_CHECKER @@ -13,6 +15,7 @@ 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 +import org.jetbrains.kotlin.test.services.jvm.compiledClassesManager class DxCheckerHandler(testServices: TestServices) : JvmBinaryArtifactHandler(testServices) { override val directivesContainers: List @@ -20,12 +23,23 @@ class DxCheckerHandler(testServices: TestServices) : JvmBinaryArtifactHandler(te override fun processModule(module: TestModule, info: BinaryArtifacts.Jvm) { if (RUN_DEX_CHECKER !in module.directives || IGNORE_DEXING in module.directives) return - val reportProblems = module.targetBackend !in module.directives[CodegenTestDirectives.IGNORE_BACKEND] + val compiledClassesManager = testServices.compiledClassesManager try { D8Checker.check(info.classFileFactory) } catch (e: Throwable) { - if (reportProblems) { + if (!GeneratorsFileUtil.isTeamCityBuild && + module.targetBackend !in module.directives[CodegenTestDirectives.IGNORE_BACKEND] + ) { try { + val javaDir = compiledClassesManager.getCompiledJavaDirForModule(module) + if (javaDir != null) { + println("Compiled Java files: ${javaDir.absolutePath}") + } + val kotlinDir = compiledClassesManager.getCompiledKotlinDirForModule(module) + println("Compiled Kotlin files: ${kotlinDir.absolutePath}") + info.classFileFactory.getClassFiles().forEach { + println(" * ${it.relativePath}") + } println(info.classFileFactory.createText()) } catch (_: Throwable) { // In FIR we have factory which can't print bytecode diff --git a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/D8Checker.java b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/D8Checker.java index 569b6e74a49..f9818c8daa7 100644 --- a/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/D8Checker.java +++ b/compiler/tests-compiler-utils/tests/org/jetbrains/kotlin/codegen/D8Checker.java @@ -27,22 +27,21 @@ public class D8Checker { public static void check(ClassFileFactory outputFiles) { if (!RUN_D8_CHECKER) return; + runD8(builder -> addOutputFiles(builder, outputFiles)); + } - runD8(builder -> { - for (OutputFile file : ClassFileUtilsKt.getClassFiles(outputFiles)) { - byte[] bytes = file.asByteArray(); - builder.addClassProgramData(bytes, new PathOrigin(Paths.get(file.getRelativePath()))); - } - }); + private static void addOutputFiles(D8Command.Builder builder, ClassFileFactory outputFiles) { + for (OutputFile file : ClassFileUtilsKt.getClassFiles(outputFiles)) { + byte[] bytes = file.asByteArray(); + builder.addClassProgramData(bytes, new PathOrigin(Paths.get(file.getRelativePath()))); + } } public static void checkFilesWithD8(Collection> classFiles) { if (!RUN_D8_CHECKER) return; - runD8(builder -> { - classFiles.forEach(pair -> { - builder.addClassProgramData(pair.getFirst(), new PathOrigin(Paths.get(pair.getSecond()))); - }); - }); + runD8(builder -> classFiles.forEach( + pair -> builder.addClassProgramData(pair.getFirst(), new PathOrigin(Paths.get(pair.getSecond()))) + )); } // Compilation with D8 should proceed with no output. There should be no info, warnings, or errors. @@ -82,8 +81,7 @@ public class D8Checker { StringWriter writer = new StringWriter(); try (PrintWriter printWriter = new PrintWriter(writer)) { e.printStackTrace(printWriter); - String stackTrace = writer.toString(); - return stackTrace; + return writer.toString(); } } }