From 6064012efa1492233662902d66975c7c2d699bf5 Mon Sep 17 00:00:00 2001 From: Sergej Jaskiewicz Date: Mon, 12 Jun 2023 18:21:45 +0200 Subject: [PATCH] [test] Print NATIVE for newly generated check blocks in signature tests Since we know that in most cases signatures for JS and NATIVE are the same, when running a signature test for the first time, let's print `// CHECK JS NATIVE:` instead of `// CHECK JS:` or `// CHECK NATIVE:`. ^KT-59204 Fixed --- .../IrMangledNameAndSignatureDumpHandler.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrMangledNameAndSignatureDumpHandler.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrMangledNameAndSignatureDumpHandler.kt index dfc90b9f100..261da7bc3a4 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrMangledNameAndSignatureDumpHandler.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/IrMangledNameAndSignatureDumpHandler.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmSymbols import org.jetbrains.kotlin.backend.jvm.ir.hasPlatformDependent import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.descriptors.DescriptorVisibilities +import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.fir.backend.FirMetadataSource import org.jetbrains.kotlin.fir.signaturer.FirMangler import org.jetbrains.kotlin.ir.IrBuiltIns @@ -24,6 +25,7 @@ import org.jetbrains.kotlin.ir.types.classOrNull import org.jetbrains.kotlin.ir.types.isUnit import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.load.java.JvmAnnotationNames +import org.jetbrains.kotlin.load.java.lazy.descriptors.isJavaField import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.test.TargetBackend @@ -174,15 +176,27 @@ class IrMangledNameAndSignatureDumpHandler(testServices: TestServices) : Abstrac private val IrDeclaration.isMainFunction: Boolean get() = isTopLevel && this is IrSimpleFunction && name.asString() == "main" + @ObsoleteDescriptorBasedAPI private val IrDeclaration.potentiallyHasDifferentMangledNamesDependingOnBackend: Boolean get() = isMainFunction || isFunctionWithNonUnitReturnType || + (symbol.descriptor as? PropertyDescriptor)?.isJavaField == true || parent.let { it is IrDeclaration && it.potentiallyHasDifferentMangledNamesDependingOnBackend } private fun IrSimpleFunction.isHiddenEnumMethod() = allOverridden(includeSelf = true).any { it.dispatchReceiverParameter?.type?.classOrNull == irBuiltIns.enumClass && it.name in HIDDEN_ENUM_METHOD_NAMES } + private fun Printer.printCheckMarkerForNewDeclaration() { + printlnCheckMarker( + when (targetBackend) { + // In most cases the mangled names and signatures generated for JS are the same as for Native. + TargetBackend.JS_IR, TargetBackend.NATIVE -> listOf(TargetBackend.JS_IR, TargetBackend.NATIVE) + else -> listOf(targetBackend) + } + ) + } + @OptIn(ObsoleteDescriptorBasedAPI::class) private fun Printer.printSignatureAndMangledName(declaration: IrDeclaration) { @@ -224,8 +238,9 @@ class IrMangledNameAndSignatureDumpHandler(testServices: TestServices) : Abstrac checkBlock.expectations.forEach(this::println) } } + // No `// CHECK` block found for the current backend. if (!printedActualMangledNameAndSignature) { - printlnCheckMarker(listOf(targetBackend)) + printCheckMarkerForNewDeclaration() printActualMangledNamesAndSignatures() } } else { @@ -233,7 +248,7 @@ class IrMangledNameAndSignatureDumpHandler(testServices: TestServices) : Abstrac // This is a heuristic to print `// CHECK :` instead of just `// CHECK:` for new declarations // for which the difference between backend-specific manglers is known to take place. // This is purely for convenience when adding a new test. - printlnCheckMarker(listOf(targetBackend)) + printCheckMarkerForNewDeclaration() } else { printlnCheckMarker(emptyList()) }