Add flag -Xno-new-java-annotation-targets
Do not generate TYPE_USE/TYPE_PARAMETER Java annotation targets when this flag is specified. #KT-53712 Fixed
This commit is contained in:
@@ -348,6 +348,8 @@ class GenerationState private constructor(
|
|||||||
|
|
||||||
val abiStability = configuration.get(JVMConfigurationKeys.ABI_STABILITY)
|
val abiStability = configuration.get(JVMConfigurationKeys.ABI_STABILITY)
|
||||||
|
|
||||||
|
val noNewJavaAnnotationTargets = configuration.getBoolean(JVMConfigurationKeys.NO_NEW_JAVA_ANNOTATION_TARGETS)
|
||||||
|
|
||||||
val globalSerializationBindings = JvmSerializationBindings()
|
val globalSerializationBindings = JvmSerializationBindings()
|
||||||
var mapInlineClass: (ClassDescriptor) -> Type = { descriptor -> typeMapper.mapType(descriptor.defaultType) }
|
var mapInlineClass: (ClassDescriptor) -> Type = { descriptor -> typeMapper.mapType(descriptor.defaultType) }
|
||||||
|
|
||||||
|
|||||||
+6
@@ -524,6 +524,12 @@ Also sets `-jvm-target` value equal to the selected JDK version"""
|
|||||||
)
|
)
|
||||||
var ignoreConstOptimizationErrors: Boolean by FreezableVar(false)
|
var ignoreConstOptimizationErrors: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
|
@Argument(
|
||||||
|
value = "-Xno-new-java-annotation-targets",
|
||||||
|
description = "Do not generate Java 1.8+ targets for Kotlin annotation classes"
|
||||||
|
)
|
||||||
|
var noNewJavaAnnotationTargets: Boolean by FreezableVar(false)
|
||||||
|
|
||||||
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> {
|
override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap<AnalysisFlag<*>, Any> {
|
||||||
val result = super.configureAnalysisFlags(collector, languageVersion)
|
val result = super.configureAnalysisFlags(collector, languageVersion)
|
||||||
result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics
|
result[JvmAnalysisFlags.strictMetadataVersionSemantics] = strictMetadataVersionSemantics
|
||||||
|
|||||||
@@ -312,6 +312,7 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
|
|||||||
|
|
||||||
put(JVMConfigurationKeys.ENABLE_DEBUG_MODE, arguments.enableDebugMode)
|
put(JVMConfigurationKeys.ENABLE_DEBUG_MODE, arguments.enableDebugMode)
|
||||||
put(JVMConfigurationKeys.IGNORE_CONST_OPTIMIZATION_ERRORS, arguments.ignoreConstOptimizationErrors)
|
put(JVMConfigurationKeys.IGNORE_CONST_OPTIMIZATION_ERRORS, arguments.ignoreConstOptimizationErrors)
|
||||||
|
put(JVMConfigurationKeys.NO_NEW_JAVA_ANNOTATION_TARGETS, arguments.noNewJavaAnnotationTargets)
|
||||||
|
|
||||||
val assertionsMode =
|
val assertionsMode =
|
||||||
JVMAssertionsMode.fromStringOrNull(arguments.assertionsMode)
|
JVMAssertionsMode.fromStringOrNull(arguments.assertionsMode)
|
||||||
|
|||||||
@@ -162,4 +162,7 @@ public class JVMConfigurationKeys {
|
|||||||
|
|
||||||
public static final CompilerConfigurationKey<Boolean> IGNORE_CONST_OPTIMIZATION_ERRORS =
|
public static final CompilerConfigurationKey<Boolean> IGNORE_CONST_OPTIMIZATION_ERRORS =
|
||||||
CompilerConfigurationKey.create("Ignore errors from IrConstTransformer");
|
CompilerConfigurationKey.create("Ignore errors from IrConstTransformer");
|
||||||
|
|
||||||
|
public static final CompilerConfigurationKey<Boolean> NO_NEW_JAVA_ANNOTATION_TARGETS =
|
||||||
|
CompilerConfigurationKey.create("Do not generate Java 1.8+ targets for Kotlin annotation classes");
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -287,6 +287,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfDependOnJvm6.kt");
|
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfDependOnJvm6.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("noTypeUseIfFlagIsSpecified.kt")
|
||||||
|
public void testNoTypeUseIfFlagIsSpecified() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfFlagIsSpecified.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("objectConstValInAnnotationArgument.kt")
|
@TestMetadata("objectConstValInAnnotationArgument.kt")
|
||||||
public void testObjectConstValInAnnotationArgument() throws Exception {
|
public void testObjectConstValInAnnotationArgument() throws Exception {
|
||||||
|
|||||||
+4
-2
@@ -43,6 +43,8 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC
|
|||||||
context.state.jvmBackendClassResolver.resolveToClassDescriptors(
|
context.state.jvmBackendClassResolver.resolveToClassDescriptors(
|
||||||
Type.getObjectType("java/lang/invoke/LambdaMetafactory")
|
Type.getObjectType("java/lang/invoke/LambdaMetafactory")
|
||||||
).isNotEmpty()
|
).isNotEmpty()
|
||||||
|
private val noNewJavaAnnotationTargets =
|
||||||
|
context.state.noNewJavaAnnotationTargets || !isCompilingAgainstJdk8OrLater
|
||||||
|
|
||||||
override fun lower(irClass: IrClass) {
|
override fun lower(irClass: IrClass) {
|
||||||
if (!irClass.isAnnotationClass) return
|
if (!irClass.isAnnotationClass) return
|
||||||
@@ -113,8 +115,8 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC
|
|||||||
|
|
||||||
private fun mapTarget(target: KotlinTarget): IrEnumEntry? =
|
private fun mapTarget(target: KotlinTarget): IrEnumEntry? =
|
||||||
when (target) {
|
when (target) {
|
||||||
KotlinTarget.TYPE_PARAMETER -> symbols.typeParameterTarget.takeUnless { isCompilingAgainstJdk8OrLater }
|
KotlinTarget.TYPE_PARAMETER -> symbols.typeParameterTarget.takeUnless { noNewJavaAnnotationTargets }
|
||||||
KotlinTarget.TYPE -> symbols.typeUseTarget.takeUnless { isCompilingAgainstJdk8OrLater }
|
KotlinTarget.TYPE -> symbols.typeUseTarget.takeUnless { noNewJavaAnnotationTargets }
|
||||||
else -> symbols.jvmTargetMap[target]
|
else -> symbols.jvmTargetMap[target]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
@@ -74,6 +74,7 @@ object LanguageSettingsDirectives : SimpleDirectivesContainer() {
|
|||||||
val NO_UNIFIED_NULL_CHECKS by directive("No unified null checks")
|
val NO_UNIFIED_NULL_CHECKS by directive("No unified null checks")
|
||||||
val PARAMETERS_METADATA by directive("Add parameters metadata for 1.8 reflection")
|
val PARAMETERS_METADATA by directive("Add parameters metadata for 1.8 reflection")
|
||||||
val USE_TYPE_TABLE by directive("Use type table in metadata serialization")
|
val USE_TYPE_TABLE by directive("Use type table in metadata serialization")
|
||||||
|
val NO_NEW_JAVA_ANNOTATION_TARGETS by directive("Do not generate Java annotation targets TYPE_USE/TYPE_PARAMETER for Kotlin annotation classes with Kotlin targets TYPE/TYPE_PARAMETER")
|
||||||
|
|
||||||
// --------------------- Utils ---------------------
|
// --------------------- Utils ---------------------
|
||||||
|
|
||||||
|
|||||||
+2
@@ -93,6 +93,8 @@ where advanced options include:
|
|||||||
-Xno-call-assertions Don't generate not-null assertions for arguments of platform types
|
-Xno-call-assertions Don't generate not-null assertions for arguments of platform types
|
||||||
-Xno-kotlin-nothing-value-exception
|
-Xno-kotlin-nothing-value-exception
|
||||||
Do not use KotlinNothingValueException available since 1.4
|
Do not use KotlinNothingValueException available since 1.4
|
||||||
|
-Xno-new-java-annotation-targets
|
||||||
|
Do not generate Java 1.8+ targets for Kotlin annotation classes
|
||||||
-Xno-optimize Disable optimizations
|
-Xno-optimize Disable optimizations
|
||||||
-Xno-optimized-callable-references
|
-Xno-optimized-callable-references
|
||||||
Do not use optimized callable reference superclasses available from 1.4
|
Do not use optimized callable reference superclasses available from 1.4
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
// This test checks that we don't generate target TYPE_USE if `-Xno-new-java-annotation-targets` is used.
|
||||||
|
// It's important that this test depends on _full JDK_, which has ElementType.TYPE_USE, to check that filtering based on
|
||||||
|
// the compiler argument is taking place.
|
||||||
|
|
||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// IGNORE_BACKEND: JVM
|
||||||
|
// NO_NEW_JAVA_ANNOTATION_TARGETS
|
||||||
|
// FULL_JDK
|
||||||
|
// WITH_STDLIB
|
||||||
|
|
||||||
|
import kotlin.annotation.AnnotationTarget.*
|
||||||
|
|
||||||
|
@Target(
|
||||||
|
CLASS,
|
||||||
|
ANNOTATION_CLASS,
|
||||||
|
TYPE_PARAMETER,
|
||||||
|
PROPERTY,
|
||||||
|
FIELD,
|
||||||
|
LOCAL_VARIABLE,
|
||||||
|
VALUE_PARAMETER,
|
||||||
|
CONSTRUCTOR,
|
||||||
|
FUNCTION,
|
||||||
|
PROPERTY_GETTER,
|
||||||
|
PROPERTY_SETTER,
|
||||||
|
TYPE,
|
||||||
|
EXPRESSION,
|
||||||
|
FILE,
|
||||||
|
TYPEALIAS,
|
||||||
|
)
|
||||||
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
|
annotation class A
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val targets = A::class.java.getAnnotation(java.lang.annotation.Target::class.java).value
|
||||||
|
if (targets.toList().toString() != "[TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE]")
|
||||||
|
return "Fail: Java annotation target list should not contain TYPE_USE/TYPE_PARAMETER: ${targets.toList()}"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+6
@@ -275,6 +275,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfDependOnJvm6.kt");
|
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfDependOnJvm6.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("noTypeUseIfFlagIsSpecified.kt")
|
||||||
|
public void testNoTypeUseIfFlagIsSpecified() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfFlagIsSpecified.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("parameterAnnotationInDefaultImpls.kt")
|
@TestMetadata("parameterAnnotationInDefaultImpls.kt")
|
||||||
public void testParameterAnnotationInDefaultImpls() throws Exception {
|
public void testParameterAnnotationInDefaultImpls() throws Exception {
|
||||||
|
|||||||
+6
@@ -287,6 +287,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfDependOnJvm6.kt");
|
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfDependOnJvm6.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("noTypeUseIfFlagIsSpecified.kt")
|
||||||
|
public void testNoTypeUseIfFlagIsSpecified() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfFlagIsSpecified.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("objectConstValInAnnotationArgument.kt")
|
@TestMetadata("objectConstValInAnnotationArgument.kt")
|
||||||
public void testObjectConstValInAnnotationArgument() throws Exception {
|
public void testObjectConstValInAnnotationArgument() throws Exception {
|
||||||
|
|||||||
+2
@@ -48,6 +48,7 @@ import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.NO_OPTIMI
|
|||||||
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.NO_UNIFIED_NULL_CHECKS
|
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.NO_UNIFIED_NULL_CHECKS
|
||||||
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.PARAMETERS_METADATA
|
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.PARAMETERS_METADATA
|
||||||
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.JDK_RELEASE
|
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.JDK_RELEASE
|
||||||
|
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.NO_NEW_JAVA_ANNOTATION_TARGETS
|
||||||
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.USE_TYPE_TABLE
|
import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives.USE_TYPE_TABLE
|
||||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||||
import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives
|
import org.jetbrains.kotlin.test.directives.model.RegisteredDirectives
|
||||||
@@ -173,6 +174,7 @@ class JvmEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfig
|
|||||||
register(JDK_RELEASE, JVMConfigurationKeys.JDK_RELEASE)
|
register(JDK_RELEASE, JVMConfigurationKeys.JDK_RELEASE)
|
||||||
register(USE_TYPE_TABLE, JVMConfigurationKeys.USE_TYPE_TABLE)
|
register(USE_TYPE_TABLE, JVMConfigurationKeys.USE_TYPE_TABLE)
|
||||||
register(ENABLE_DEBUG_MODE, JVMConfigurationKeys.ENABLE_DEBUG_MODE)
|
register(ENABLE_DEBUG_MODE, JVMConfigurationKeys.ENABLE_DEBUG_MODE)
|
||||||
|
register(NO_NEW_JAVA_ANNOTATION_TARGETS, JVMConfigurationKeys.NO_NEW_JAVA_ANNOTATION_TARGETS)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) {
|
override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) {
|
||||||
|
|||||||
+10
-5
@@ -35,6 +35,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class Annotations extends AbstractLightAnalysisModeTest {
|
public static class Annotations extends AbstractLightAnalysisModeTest {
|
||||||
|
@TestMetadata("noTypeUseIfDependOnJvm6.kt")
|
||||||
|
public void ignoreNoTypeUseIfDependOnJvm6() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfDependOnJvm6.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noTypeUseIfFlagIsSpecified.kt")
|
||||||
|
public void ignoreNoTypeUseIfFlagIsSpecified() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfFlagIsSpecified.kt");
|
||||||
|
}
|
||||||
|
|
||||||
private void runTest(String testDataFilePath) throws Exception {
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||||
}
|
}
|
||||||
@@ -238,11 +248,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/annotations/nestedClassesInAnnotations.kt");
|
runTest("compiler/testData/codegen/box/annotations/nestedClassesInAnnotations.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("noTypeUseIfDependOnJvm6.kt")
|
|
||||||
public void testNoTypeUseIfDependOnJvm6() throws Exception {
|
|
||||||
runTest("compiler/testData/codegen/box/annotations/noTypeUseIfDependOnJvm6.kt");
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("parameterAnnotationInDefaultImpls.kt")
|
@TestMetadata("parameterAnnotationInDefaultImpls.kt")
|
||||||
public void testParameterAnnotationInDefaultImpls() throws Exception {
|
public void testParameterAnnotationInDefaultImpls() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/annotations/parameterAnnotationInDefaultImpls.kt");
|
runTest("compiler/testData/codegen/box/annotations/parameterAnnotationInDefaultImpls.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user