From 2a0f64ebcb8e825f700d6c0df6ec07bfed359e67 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 10 Sep 2020 22:30:54 +0200 Subject: [PATCH] JVM IR: do not generate Deprecated(HIDDEN) class as synthetic #KT-41810 Fixed --- .../backend/jvm/codegen/ClassCodegen.kt | 17 ++++--- .../backend/jvm/codegen/FunctionCodegen.kt | 4 +- .../backend/jvm/codegen/irCodegenUtils.kt | 15 +++--- .../deprecated/deprecatedClass.kt | 8 ++++ .../deprecated/deprecatedClass.txt | 20 ++++++++ .../deprecatedEnumEntryFields.kt | 0 .../deprecatedEnumEntryFields.txt | 0 .../{ => deprecated}/deprecatedLateinitVar.kt | 0 .../deprecatedLateinitVar.txt | 0 .../{ => deprecated}/deprecatedProperty.kt | 0 .../{ => deprecated}/deprecatedProperty.txt | 0 .../codegen/BytecodeListingTestGenerated.java | 48 +++++++++++++------ .../ir/IrBytecodeListingTestGenerated.java | 48 +++++++++++++------ 13 files changed, 113 insertions(+), 47 deletions(-) create mode 100644 compiler/testData/codegen/bytecodeListing/deprecated/deprecatedClass.kt create mode 100644 compiler/testData/codegen/bytecodeListing/deprecated/deprecatedClass.txt rename compiler/testData/codegen/bytecodeListing/{ => deprecated}/deprecatedEnumEntryFields.kt (100%) rename compiler/testData/codegen/bytecodeListing/{ => deprecated}/deprecatedEnumEntryFields.txt (100%) rename compiler/testData/codegen/bytecodeListing/{ => deprecated}/deprecatedLateinitVar.kt (100%) rename compiler/testData/codegen/bytecodeListing/{ => deprecated}/deprecatedLateinitVar.txt (100%) rename compiler/testData/codegen/bytecodeListing/{ => deprecated}/deprecatedProperty.kt (100%) rename compiler/testData/codegen/bytecodeListing/{ => deprecated}/deprecatedProperty.txt (100%) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt index 02976f25a44..644e0253d37 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.backend.jvm.lower.MultifileFacadeFileEntry import org.jetbrains.kotlin.backend.jvm.lower.buildAssertionsDisabledField import org.jetbrains.kotlin.backend.jvm.lower.hasAssertionsDisabledField +import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.codegen.AsmUtil import org.jetbrains.kotlin.codegen.inline.* import org.jetbrains.kotlin.config.LanguageFeature @@ -395,16 +396,18 @@ abstract class ClassCodegen protected constructor( } private val IrClass.flags: Int - get() = origin.flags or getVisibilityAccessFlagForClass() or deprecationFlags or when { - isAnnotationClass -> Opcodes.ACC_ANNOTATION or Opcodes.ACC_INTERFACE or Opcodes.ACC_ABSTRACT - isInterface -> Opcodes.ACC_INTERFACE or Opcodes.ACC_ABSTRACT - isEnumClass -> Opcodes.ACC_ENUM or Opcodes.ACC_SUPER or modality.flags - else -> Opcodes.ACC_SUPER or modality.flags - } + get() = origin.flags or getVisibilityAccessFlagForClass() or + (if (annotations.hasAnnotation(StandardNames.FqNames.deprecated)) Opcodes.ACC_DEPRECATED else 0) or + when { + isAnnotationClass -> Opcodes.ACC_ANNOTATION or Opcodes.ACC_INTERFACE or Opcodes.ACC_ABSTRACT + isInterface -> Opcodes.ACC_INTERFACE or Opcodes.ACC_ABSTRACT + isEnumClass -> Opcodes.ACC_ENUM or Opcodes.ACC_SUPER or modality.flags + else -> Opcodes.ACC_SUPER or modality.flags + } private fun IrField.computeFieldFlags(languageVersionSettings: LanguageVersionSettings): Int = origin.flags or visibility.flags or - this.specialDeprecationFlag or (correspondingPropertySymbol?.owner?.deprecationFlags ?: 0) or + this.specialDeprecationFlag or (correspondingPropertySymbol?.owner?.callableDeprecationFlags ?: 0) or (if (annotations.hasAnnotation(KOTLIN_DEPRECATED)) Opcodes.ACC_DEPRECATED else 0) or (if (isFinal) Opcodes.ACC_FINAL else 0) or (if (isStatic) Opcodes.ACC_STATIC else 0) or diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt index 2314a29de47..afe5369e9d6 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt @@ -162,7 +162,7 @@ class FunctionCodegen( private fun IrFunction.calculateMethodFlags(): Int { if (origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER) { - return getVisibilityForDefaultArgumentStub() or Opcodes.ACC_SYNTHETIC or deprecationFlags.let { + return getVisibilityForDefaultArgumentStub() or Opcodes.ACC_SYNTHETIC or functionDeprecationFlags.let { if (this is IrConstructor) it else it or Opcodes.ACC_STATIC } } @@ -186,7 +186,7 @@ class FunctionCodegen( val isStrict = hasAnnotation(STRICTFP_ANNOTATION_FQ_NAME) val isSynchronized = hasAnnotation(SYNCHRONIZED_ANNOTATION_FQ_NAME) - return getVisibilityAccessFlag() or modalityFlag or deprecationFlags or + return getVisibilityAccessFlag() or modalityFlag or functionDeprecationFlags or (if (isStatic) Opcodes.ACC_STATIC else 0) or (if (isVararg) Opcodes.ACC_VARARGS else 0) or (if (isExternal) Opcodes.ACC_NATIVE else 0) or diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt index 945a542486f..2cbc79a0e94 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/irCodegenUtils.kt @@ -408,13 +408,12 @@ fun IrClass.isOptionalAnnotationClass(): Boolean = isAnnotationClass && hasAnnotation(ExpectedActualDeclarationChecker.OPTIONAL_EXPECTATION_FQ_NAME) -val IrAnnotationContainer.deprecationFlags: Int +val IrDeclaration.callableDeprecationFlags: Int get() { val annotation = annotations.findAnnotation(FqNames.deprecated) - ?: return if ((this as? IrDeclaration)?.origin?.let { - it == JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY - } == true - ) Opcodes.ACC_DEPRECATED else 0 + ?: return if ((this as? IrDeclaration)?.origin == JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY) + Opcodes.ACC_DEPRECATED + else 0 val isHidden = (annotation.getValueArgument(2) as? IrGetEnumValue)?.symbol?.owner ?.name?.asString() == DeprecationLevel.HIDDEN.name return Opcodes.ACC_DEPRECATED or if (isHidden) Opcodes.ACC_SYNTHETIC else 0 @@ -426,11 +425,11 @@ val IrAnnotationContainer.deprecationFlags: Int val IrFunction.isSyntheticMethodForProperty: Boolean get() = name.asString().endsWith(JvmAbi.ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX) -val IrFunction.deprecationFlags: Int +val IrFunction.functionDeprecationFlags: Int get() { val originFlags = if (isSyntheticMethodForProperty) Opcodes.ACC_DEPRECATED else 0 - val propertyFlags = (this as? IrSimpleFunction)?.correspondingPropertySymbol?.owner?.deprecationFlags ?: 0 - return originFlags or propertyFlags or (this as IrAnnotationContainer).deprecationFlags + val propertyFlags = (this as? IrSimpleFunction)?.correspondingPropertySymbol?.owner?.callableDeprecationFlags ?: 0 + return originFlags or propertyFlags or callableDeprecationFlags } val IrDeclaration.psiElement: PsiElement? diff --git a/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedClass.kt b/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedClass.kt new file mode 100644 index 00000000000..05c79e9598f --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedClass.kt @@ -0,0 +1,8 @@ +@Deprecated("", level = DeprecationLevel.WARNING) +class W + +@Deprecated("", level = DeprecationLevel.ERROR) +class E + +@Deprecated("", level = DeprecationLevel.HIDDEN) +class H diff --git a/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedClass.txt b/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedClass.txt new file mode 100644 index 00000000000..9b56375fc6e --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedClass.txt @@ -0,0 +1,20 @@ +@kotlin.Deprecated +@kotlin.Metadata +public deprecated final class E { + // source: 'deprecatedClass.kt' + public method (): void +} + +@kotlin.Deprecated +@kotlin.Metadata +public deprecated final class H { + // source: 'deprecatedClass.kt' + public method (): void +} + +@kotlin.Deprecated +@kotlin.Metadata +public deprecated final class W { + // source: 'deprecatedClass.kt' + public method (): void +} diff --git a/compiler/testData/codegen/bytecodeListing/deprecatedEnumEntryFields.kt b/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedEnumEntryFields.kt similarity index 100% rename from compiler/testData/codegen/bytecodeListing/deprecatedEnumEntryFields.kt rename to compiler/testData/codegen/bytecodeListing/deprecated/deprecatedEnumEntryFields.kt diff --git a/compiler/testData/codegen/bytecodeListing/deprecatedEnumEntryFields.txt b/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedEnumEntryFields.txt similarity index 100% rename from compiler/testData/codegen/bytecodeListing/deprecatedEnumEntryFields.txt rename to compiler/testData/codegen/bytecodeListing/deprecated/deprecatedEnumEntryFields.txt diff --git a/compiler/testData/codegen/bytecodeListing/deprecatedLateinitVar.kt b/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedLateinitVar.kt similarity index 100% rename from compiler/testData/codegen/bytecodeListing/deprecatedLateinitVar.kt rename to compiler/testData/codegen/bytecodeListing/deprecated/deprecatedLateinitVar.kt diff --git a/compiler/testData/codegen/bytecodeListing/deprecatedLateinitVar.txt b/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedLateinitVar.txt similarity index 100% rename from compiler/testData/codegen/bytecodeListing/deprecatedLateinitVar.txt rename to compiler/testData/codegen/bytecodeListing/deprecated/deprecatedLateinitVar.txt diff --git a/compiler/testData/codegen/bytecodeListing/deprecatedProperty.kt b/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedProperty.kt similarity index 100% rename from compiler/testData/codegen/bytecodeListing/deprecatedProperty.kt rename to compiler/testData/codegen/bytecodeListing/deprecated/deprecatedProperty.kt diff --git a/compiler/testData/codegen/bytecodeListing/deprecatedProperty.txt b/compiler/testData/codegen/bytecodeListing/deprecated/deprecatedProperty.txt similarity index 100% rename from compiler/testData/codegen/bytecodeListing/deprecatedProperty.txt rename to compiler/testData/codegen/bytecodeListing/deprecated/deprecatedProperty.txt diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index ab4387d8978..488ff8bf96b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -49,21 +49,6 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/defaultImpls.kt"); } - @TestMetadata("deprecatedEnumEntryFields.kt") - public void testDeprecatedEnumEntryFields() throws Exception { - runTest("compiler/testData/codegen/bytecodeListing/deprecatedEnumEntryFields.kt"); - } - - @TestMetadata("deprecatedLateinitVar.kt") - public void testDeprecatedLateinitVar() throws Exception { - runTest("compiler/testData/codegen/bytecodeListing/deprecatedLateinitVar.kt"); - } - - @TestMetadata("deprecatedProperty.kt") - public void testDeprecatedProperty() throws Exception { - runTest("compiler/testData/codegen/bytecodeListing/deprecatedProperty.kt"); - } - @TestMetadata("emptyMultifileFacade.kt") public void testEmptyMultifileFacade() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/emptyMultifileFacade.kt"); @@ -390,6 +375,39 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { } } + @TestMetadata("compiler/testData/codegen/bytecodeListing/deprecated") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Deprecated extends AbstractBytecodeListingTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInDeprecated() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/deprecated"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("deprecatedClass.kt") + public void testDeprecatedClass() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/deprecatedClass.kt"); + } + + @TestMetadata("deprecatedEnumEntryFields.kt") + public void testDeprecatedEnumEntryFields() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/deprecatedEnumEntryFields.kt"); + } + + @TestMetadata("deprecatedLateinitVar.kt") + public void testDeprecatedLateinitVar() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/deprecatedLateinitVar.kt"); + } + + @TestMetadata("deprecatedProperty.kt") + public void testDeprecatedProperty() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/deprecatedProperty.kt"); + } + } + @TestMetadata("compiler/testData/codegen/bytecodeListing/inline") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index 856a241bc12..43f6da344cf 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -49,21 +49,6 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/defaultImpls.kt"); } - @TestMetadata("deprecatedEnumEntryFields.kt") - public void testDeprecatedEnumEntryFields() throws Exception { - runTest("compiler/testData/codegen/bytecodeListing/deprecatedEnumEntryFields.kt"); - } - - @TestMetadata("deprecatedLateinitVar.kt") - public void testDeprecatedLateinitVar() throws Exception { - runTest("compiler/testData/codegen/bytecodeListing/deprecatedLateinitVar.kt"); - } - - @TestMetadata("deprecatedProperty.kt") - public void testDeprecatedProperty() throws Exception { - runTest("compiler/testData/codegen/bytecodeListing/deprecatedProperty.kt"); - } - @TestMetadata("emptyMultifileFacade.kt") public void testEmptyMultifileFacade() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/emptyMultifileFacade.kt"); @@ -360,6 +345,39 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes } } + @TestMetadata("compiler/testData/codegen/bytecodeListing/deprecated") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Deprecated extends AbstractIrBytecodeListingTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInDeprecated() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/deprecated"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @TestMetadata("deprecatedClass.kt") + public void testDeprecatedClass() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/deprecatedClass.kt"); + } + + @TestMetadata("deprecatedEnumEntryFields.kt") + public void testDeprecatedEnumEntryFields() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/deprecatedEnumEntryFields.kt"); + } + + @TestMetadata("deprecatedLateinitVar.kt") + public void testDeprecatedLateinitVar() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/deprecatedLateinitVar.kt"); + } + + @TestMetadata("deprecatedProperty.kt") + public void testDeprecatedProperty() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/deprecated/deprecatedProperty.kt"); + } + } + @TestMetadata("compiler/testData/codegen/bytecodeListing/inline") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)