Use JVM IR backend in light analysis mode tests

Add some more filters on private/synthetic stuff (which doesn't matter
in practice) to make full and light analysis mode dumps as similar as
possible, so that all existing tests will pass for JVM IR. Unmute some
tests which were failing with the old JVM backend.

Tests on repeatable annotations are muted because in full analysis,
annotations are wrapped into the container (e.g. `@A(1) @A(2)` ->
`@A$Container(A(1), A(2))`), but they are no in the light analysis mode.
So there's always going to be a difference for these tests between full
and light analysis, unless we're going to change behavior of kapt, which
would be a kind of a breaking change.

 #KT-58497 Fixed
This commit is contained in:
Alexander Udalov
2022-06-01 23:18:27 +02:00
parent 6cce510319
commit cab53361f3
15 changed files with 4225 additions and 2064 deletions
@@ -7,6 +7,10 @@
// java.lang.NoSuchMethodError: java.lang.Class.getAnnotationsByType // java.lang.NoSuchMethodError: java.lang.Class.getAnnotationsByType
// IGNORE_BACKEND: ANDROID // IGNORE_BACKEND: ANDROID
// In light analysis mode, repeated annotations are not wrapped into the container. This is by design, so that in kapt stubs repeated
// annotations will be visible unwrapped.
// IGNORE_LIGHT_ANALYSIS
// FILE: box.kt // FILE: box.kt
import test.A import test.A
@@ -9,6 +9,10 @@
// java.lang.NoSuchMethodError: java.lang.Class.getAnnotationsByType // java.lang.NoSuchMethodError: java.lang.Class.getAnnotationsByType
// IGNORE_BACKEND: ANDROID // IGNORE_BACKEND: ANDROID
// In light analysis mode, repeated annotations are not wrapped into the container. This is by design, so that in kapt stubs repeated
// annotations will be visible unwrapped.
// IGNORE_LIGHT_ANALYSIS
@JvmRepeatable(As::class) @JvmRepeatable(As::class)
annotation class A(val value: String) annotation class A(val value: String)
@@ -7,6 +7,10 @@
// java.lang.NoSuchMethodError: java.lang.Class.getAnnotationsByType // java.lang.NoSuchMethodError: java.lang.Class.getAnnotationsByType
// IGNORE_BACKEND: ANDROID // IGNORE_BACKEND: ANDROID
// In light analysis mode, repeated annotations are not wrapped into the container. This is by design, so that in kapt stubs repeated
// annotations will be visible unwrapped.
// IGNORE_LIGHT_ANALYSIS
// FILE: box.kt // FILE: box.kt
@Repeatable @Repeatable
@@ -9,6 +9,10 @@
// java.lang.NoSuchMethodError: java.lang.Class.getAnnotationsByType // java.lang.NoSuchMethodError: java.lang.Class.getAnnotationsByType
// IGNORE_BACKEND: ANDROID // IGNORE_BACKEND: ANDROID
// In light analysis mode, repeated annotations are not wrapped into the container. This is by design, so that in kapt stubs repeated
// annotations will be visible unwrapped.
// IGNORE_LIGHT_ANALYSIS
@Repeatable @Repeatable
@JvmRepeatable(As::class) @JvmRepeatable(As::class)
annotation class A(val value: String) annotation class A(val value: String)
+3
View File
@@ -1,5 +1,8 @@
// IGNORE_BACKEND: JVM // IGNORE_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// ^ FUNCTION_EXPECTED: Expression 's' of type 'Any' cannot be invoked as a function. The function 'invoke()' is not found
object A { object A {
private val s = object { private val s = object {
inline operator fun invoke(): String = "OK" inline operator fun invoke(): String = "OK"
@@ -2,9 +2,6 @@
// WITH_COROUTINES // WITH_COROUTINES
// SKIP_MANGLE_VERIFICATION // SKIP_MANGLE_VERIFICATION
// Light analysis mode test is muted because of some bug related to the old JVM backend. To be unmuted once the test is migrated to JVM IR.
// IGNORE_LIGHT_ANALYSIS
import helpers.* import helpers.*
import kotlin.coroutines.* import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.* import kotlin.coroutines.intrinsics.*
@@ -1,8 +1,5 @@
// ISSUE: KT-35707 // ISSUE: KT-35707
// Light analysis mode test is muted because of some bug related to the old JVM backend. To be unmuted once the test is migrated to JVM IR.
// IGNORE_LIGHT_ANALYSIS
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
interface PropertyDelegate { interface PropertyDelegate {
@@ -1,6 +1,9 @@
// TARGET_BACKEND: JVM_IR // TARGET_BACKEND: JVM_IR
// ISSUE: KT-59140 // ISSUE: KT-59140
// IGNORE_LIGHT_ANALYSIS
// ^ MISSING_DEPENDENCY_SUPERCLASS: Cannot access 'pkg.CommonFoo' which is a supertype of 'pkg.Foo'. Check your module classpath for missing or conflicting dependencies
// FILE: pkg/Foo.java // FILE: pkg/Foo.java
package pkg; package pkg;
@@ -3,6 +3,11 @@
// JVM_TARGET: 1.8 // JVM_TARGET: 1.8
// FULL_JDK // FULL_JDK
// WITH_REFLECT // WITH_REFLECT
// In light analysis mode, repeated annotations are not wrapped into the container. This is by design, so that in kapt stubs repeated
// annotations will be visible unwrapped.
// IGNORE_LIGHT_ANALYSIS
// FILE: box.kt // FILE: box.kt
import kotlin.reflect.full.findAnnotation import kotlin.reflect.full.findAnnotation
@@ -7,6 +7,10 @@
// Android doesn't have @Repeatable before API level 24, so findAnnotations can't unpack repeatable annotations. // Android doesn't have @Repeatable before API level 24, so findAnnotations can't unpack repeatable annotations.
// IGNORE_BACKEND: ANDROID // IGNORE_BACKEND: ANDROID
// In light analysis mode, repeated annotations are not wrapped into the container. This is by design, so that in kapt stubs repeated
// annotations will be visible unwrapped.
// IGNORE_LIGHT_ANALYSIS
import kotlin.reflect.full.findAnnotation import kotlin.reflect.full.findAnnotation
import kotlin.reflect.full.findAnnotations import kotlin.reflect.full.findAnnotations
import kotlin.reflect.full.hasAnnotation import kotlin.reflect.full.hasAnnotation
@@ -4,6 +4,10 @@
// FULL_JDK // FULL_JDK
// WITH_REFLECT // WITH_REFLECT
// In light analysis mode, repeated annotations are not wrapped into the container. This is by design, so that in kapt stubs repeated
// annotations will be visible unwrapped.
// IGNORE_LIGHT_ANALYSIS
import kotlin.annotation.AnnotationTarget.* import kotlin.annotation.AnnotationTarget.*
import kotlin.reflect.KAnnotatedElement import kotlin.reflect.KAnnotatedElement
import kotlin.reflect.full.findAnnotation import kotlin.reflect.full.findAnnotation
@@ -7,6 +7,10 @@
// Android doesn't have @Repeatable before API level 24, so findAnnotations can't unpack repeatable annotations. // Android doesn't have @Repeatable before API level 24, so findAnnotations can't unpack repeatable annotations.
// IGNORE_BACKEND: ANDROID // IGNORE_BACKEND: ANDROID
// In light analysis mode, repeated annotations are not wrapped into the container. This is by design, so that in kapt stubs repeated
// annotations will be visible unwrapped.
// IGNORE_LIGHT_ANALYSIS
// FILE: A.kt // FILE: A.kt
@java.lang.annotation.Repeatable(A.Container::class) @java.lang.annotation.Repeatable(A.Container::class)
annotation class A(val value: String) { annotation class A(val value: String) {
@@ -5,8 +5,10 @@
package org.jetbrains.kotlin.codegen package org.jetbrains.kotlin.codegen
import org.jetbrains.kotlin.checkers.CompilerTestLanguageVersionSettings
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.container.StorageComponentContainer import org.jetbrains.kotlin.container.StorageComponentContainer
import org.jetbrains.kotlin.container.useInstance import org.jetbrains.kotlin.container.useInstance
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
@@ -21,6 +23,7 @@ import org.jetbrains.kotlin.resolve.jvm.AsmTypes
import org.jetbrains.kotlin.resolve.jvm.ReplaceWithSupertypeAnonymousTypeTransformer import org.jetbrains.kotlin.resolve.jvm.ReplaceWithSupertypeAnonymousTypeTransformer
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
import org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension import org.jetbrains.kotlin.resolve.jvm.extensions.PartialAnalysisHandlerExtension
import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.test.util.KtTestUtil.getAnnotationsJar import org.jetbrains.kotlin.test.util.KtTestUtil.getAnnotationsJar
import org.jetbrains.org.objectweb.asm.Opcodes.* import org.jetbrains.org.objectweb.asm.Opcodes.*
import org.jetbrains.org.objectweb.asm.tree.ClassNode import org.jetbrains.org.objectweb.asm.tree.ClassNode
@@ -40,13 +43,15 @@ abstract class AbstractLightAnalysisModeTest : CodegenTestCase() {
) )
} }
override val backend: TargetBackend
get() = TargetBackend.JVM_IR
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>) { override fun doMultiFileTest(wholeFile: File, files: List<TestFile>) {
for (file in files) { for (file in files) {
if (ignoreDirectives.any { file.content.contains(it) }) return if (ignoreDirectives.any { file.content.contains(it) }) return
} }
val fullTxt = compileWithFullAnalysis(files) val fullTxt = compileWithFullAnalysis(files)
.replace("final enum class", "enum class")
val liteTxt = compileWithLightAnalysis(wholeFile, files) val liteTxt = compileWithLightAnalysis(wholeFile, files)
.replace("@synthetic.kotlin.jvm.GeneratedByJvmOverloads ", "") .replace("@synthetic.kotlin.jvm.GeneratedByJvmOverloads ", "")
@@ -64,6 +69,7 @@ abstract class AbstractLightAnalysisModeTest : CodegenTestCase() {
// Fail if this test is not under codegen/box // Fail if this test is not under codegen/box
assert(!relativePath.startsWith("..")) assert(!relativePath.startsWith(".."))
configurationKind = extractConfigurationKind(files)
val configuration = createConfiguration( val configuration = createConfiguration(
configurationKind, getTestJdkKind(files), backend, listOf(getAnnotationsJar()), listOfNotNull(writeJavaFiles(files)), files configurationKind, getTestJdkKind(files), backend, listOf(getAnnotationsJar()), listOfNotNull(writeJavaFiles(files)), files
) )
@@ -91,6 +97,26 @@ abstract class AbstractLightAnalysisModeTest : CodegenTestCase() {
return BytecodeListingTextCollectingVisitor.getText(classFileFactory, ListAnalysisFilter()) return BytecodeListingTextCollectingVisitor.getText(classFileFactory, ListAnalysisFilter())
} }
override fun updateConfiguration(configuration: CompilerConfiguration) {
super.updateConfiguration(configuration)
configureIrAnalysisFlag(configuration)
}
// TODO: rewrite the test on the new infrastructure, so that this won't be needed.
private fun configureIrAnalysisFlag(configuration: CompilerConfiguration) {
val irFlag: Map<AnalysisFlag<*>, Boolean> = mapOf(JvmAnalysisFlags.useIR to backend.isIR)
val lvs = configuration.languageVersionSettings
if (lvs is CompilerTestLanguageVersionSettings) {
configuration.languageVersionSettings = LanguageVersionSettingsImpl(
lvs.languageVersion, lvs.apiVersion, lvs.analysisFlags + irFlag, lvs.extraLanguageFeatures,
)
} else {
configuration.languageVersionSettings = LanguageVersionSettingsImpl(
LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, irFlag,
)
}
}
private class ListAnalysisFilter : BytecodeListingTextCollectingVisitor.Filter { private class ListAnalysisFilter : BytecodeListingTextCollectingVisitor.Filter {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
override fun shouldWriteClass(node: ClassNode): Boolean { override fun shouldWriteClass(node: ClassNode): Boolean {
@@ -82,7 +82,7 @@ fun generateJUnit3CompilerTests(args: Array<String>) {
// There isn't much to be gained from running light analysis tests on them. // There isn't much to be gained from running light analysis tests on them.
model( model(
"codegen/box", "codegen/box",
targetBackend = TargetBackend.JVM, targetBackend = TargetBackend.JVM_IR,
skipIgnored = true, skipIgnored = true,
excludeDirs = listOf( excludeDirs = listOf(
"ranges/stepped", "ranges/stepped",
File diff suppressed because it is too large Load Diff