JVM IR: do not generate Deprecated(HIDDEN) class as synthetic

#KT-41810 Fixed
This commit is contained in:
Alexander Udalov
2020-09-10 22:30:54 +02:00
parent 162dc3aa0c
commit 2a0f64ebcb
13 changed files with 113 additions and 47 deletions
@@ -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
@@ -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
@@ -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?
@@ -0,0 +1,8 @@
@Deprecated("", level = DeprecationLevel.WARNING)
class W
@Deprecated("", level = DeprecationLevel.ERROR)
class E
@Deprecated("", level = DeprecationLevel.HIDDEN)
class H
@@ -0,0 +1,20 @@
@kotlin.Deprecated
@kotlin.Metadata
public deprecated final class E {
// source: 'deprecatedClass.kt'
public method <init>(): void
}
@kotlin.Deprecated
@kotlin.Metadata
public deprecated final class H {
// source: 'deprecatedClass.kt'
public method <init>(): void
}
@kotlin.Deprecated
@kotlin.Metadata
public deprecated final class W {
// source: 'deprecatedClass.kt'
public method <init>(): void
}
@@ -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)
@@ -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)