JVM IR: do not generate Deprecated(HIDDEN) class as synthetic
#KT-41810 Fixed
This commit is contained in:
+10
-7
@@ -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.MultifileFacadeFileEntry
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.buildAssertionsDisabledField
|
import org.jetbrains.kotlin.backend.jvm.lower.buildAssertionsDisabledField
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.hasAssertionsDisabledField
|
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.AsmUtil
|
||||||
import org.jetbrains.kotlin.codegen.inline.*
|
import org.jetbrains.kotlin.codegen.inline.*
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
@@ -395,16 +396,18 @@ abstract class ClassCodegen protected constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val IrClass.flags: Int
|
private val IrClass.flags: Int
|
||||||
get() = origin.flags or getVisibilityAccessFlagForClass() or deprecationFlags or when {
|
get() = origin.flags or getVisibilityAccessFlagForClass() or
|
||||||
isAnnotationClass -> Opcodes.ACC_ANNOTATION or Opcodes.ACC_INTERFACE or Opcodes.ACC_ABSTRACT
|
(if (annotations.hasAnnotation(StandardNames.FqNames.deprecated)) Opcodes.ACC_DEPRECATED else 0) or
|
||||||
isInterface -> Opcodes.ACC_INTERFACE or Opcodes.ACC_ABSTRACT
|
when {
|
||||||
isEnumClass -> Opcodes.ACC_ENUM or Opcodes.ACC_SUPER or modality.flags
|
isAnnotationClass -> Opcodes.ACC_ANNOTATION or Opcodes.ACC_INTERFACE or Opcodes.ACC_ABSTRACT
|
||||||
else -> Opcodes.ACC_SUPER or modality.flags
|
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 =
|
private fun IrField.computeFieldFlags(languageVersionSettings: LanguageVersionSettings): Int =
|
||||||
origin.flags or visibility.flags or
|
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 (annotations.hasAnnotation(KOTLIN_DEPRECATED)) Opcodes.ACC_DEPRECATED else 0) or
|
||||||
(if (isFinal) Opcodes.ACC_FINAL else 0) or
|
(if (isFinal) Opcodes.ACC_FINAL else 0) or
|
||||||
(if (isStatic) Opcodes.ACC_STATIC else 0) or
|
(if (isStatic) Opcodes.ACC_STATIC else 0) or
|
||||||
|
|||||||
+2
-2
@@ -162,7 +162,7 @@ class FunctionCodegen(
|
|||||||
|
|
||||||
private fun IrFunction.calculateMethodFlags(): Int {
|
private fun IrFunction.calculateMethodFlags(): Int {
|
||||||
if (origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER) {
|
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
|
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 isStrict = hasAnnotation(STRICTFP_ANNOTATION_FQ_NAME)
|
||||||
val isSynchronized = hasAnnotation(SYNCHRONIZED_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 (isStatic) Opcodes.ACC_STATIC else 0) or
|
||||||
(if (isVararg) Opcodes.ACC_VARARGS else 0) or
|
(if (isVararg) Opcodes.ACC_VARARGS else 0) or
|
||||||
(if (isExternal) Opcodes.ACC_NATIVE else 0) or
|
(if (isExternal) Opcodes.ACC_NATIVE else 0) or
|
||||||
|
|||||||
+7
-8
@@ -408,13 +408,12 @@ fun IrClass.isOptionalAnnotationClass(): Boolean =
|
|||||||
isAnnotationClass &&
|
isAnnotationClass &&
|
||||||
hasAnnotation(ExpectedActualDeclarationChecker.OPTIONAL_EXPECTATION_FQ_NAME)
|
hasAnnotation(ExpectedActualDeclarationChecker.OPTIONAL_EXPECTATION_FQ_NAME)
|
||||||
|
|
||||||
val IrAnnotationContainer.deprecationFlags: Int
|
val IrDeclaration.callableDeprecationFlags: Int
|
||||||
get() {
|
get() {
|
||||||
val annotation = annotations.findAnnotation(FqNames.deprecated)
|
val annotation = annotations.findAnnotation(FqNames.deprecated)
|
||||||
?: return if ((this as? IrDeclaration)?.origin?.let {
|
?: return if ((this as? IrDeclaration)?.origin == JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY)
|
||||||
it == JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY
|
Opcodes.ACC_DEPRECATED
|
||||||
} == true
|
else 0
|
||||||
) Opcodes.ACC_DEPRECATED else 0
|
|
||||||
val isHidden = (annotation.getValueArgument(2) as? IrGetEnumValue)?.symbol?.owner
|
val isHidden = (annotation.getValueArgument(2) as? IrGetEnumValue)?.symbol?.owner
|
||||||
?.name?.asString() == DeprecationLevel.HIDDEN.name
|
?.name?.asString() == DeprecationLevel.HIDDEN.name
|
||||||
return Opcodes.ACC_DEPRECATED or if (isHidden) Opcodes.ACC_SYNTHETIC else 0
|
return Opcodes.ACC_DEPRECATED or if (isHidden) Opcodes.ACC_SYNTHETIC else 0
|
||||||
@@ -426,11 +425,11 @@ val IrAnnotationContainer.deprecationFlags: Int
|
|||||||
val IrFunction.isSyntheticMethodForProperty: Boolean
|
val IrFunction.isSyntheticMethodForProperty: Boolean
|
||||||
get() = name.asString().endsWith(JvmAbi.ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX)
|
get() = name.asString().endsWith(JvmAbi.ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX)
|
||||||
|
|
||||||
val IrFunction.deprecationFlags: Int
|
val IrFunction.functionDeprecationFlags: Int
|
||||||
get() {
|
get() {
|
||||||
val originFlags = if (isSyntheticMethodForProperty) Opcodes.ACC_DEPRECATED else 0
|
val originFlags = if (isSyntheticMethodForProperty) Opcodes.ACC_DEPRECATED else 0
|
||||||
val propertyFlags = (this as? IrSimpleFunction)?.correspondingPropertySymbol?.owner?.deprecationFlags ?: 0
|
val propertyFlags = (this as? IrSimpleFunction)?.correspondingPropertySymbol?.owner?.callableDeprecationFlags ?: 0
|
||||||
return originFlags or propertyFlags or (this as IrAnnotationContainer).deprecationFlags
|
return originFlags or propertyFlags or callableDeprecationFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
val IrDeclaration.psiElement: PsiElement?
|
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
|
||||||
|
}
|
||||||
+33
-15
@@ -49,21 +49,6 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
|
|||||||
runTest("compiler/testData/codegen/bytecodeListing/defaultImpls.kt");
|
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")
|
@TestMetadata("emptyMultifileFacade.kt")
|
||||||
public void testEmptyMultifileFacade() throws Exception {
|
public void testEmptyMultifileFacade() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeListing/emptyMultifileFacade.kt");
|
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")
|
@TestMetadata("compiler/testData/codegen/bytecodeListing/inline")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
+33
-15
@@ -49,21 +49,6 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes
|
|||||||
runTest("compiler/testData/codegen/bytecodeListing/defaultImpls.kt");
|
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")
|
@TestMetadata("emptyMultifileFacade.kt")
|
||||||
public void testEmptyMultifileFacade() throws Exception {
|
public void testEmptyMultifileFacade() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeListing/emptyMultifileFacade.kt");
|
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")
|
@TestMetadata("compiler/testData/codegen/bytecodeListing/inline")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user