Allow using 'invokedynamic' for lambdas without 'RUNTIME' annotations
The previous check, preventing from using 'invokedynamic' on
lambdas with annotations was to strict: Annotations without
'RUNTIME' retention will not cause to a different behavior on lambdas
generated by the LambdaMetafactory, as those annotations would
not be visible at runtime either way.
Motivation:
KT-75944 Allow using invokedynamic for lambdas with no 'Runtime' level retention annotations
KT-75768 Remembered Composable Lambdas produce non-durable class names
^KT-75944 fixed
diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLBlackBoxTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLBlackBoxTestGenerated.java
index 3baa9cf..bc3e7bd 100644
--- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLBlackBoxTestGenerated.java
+++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLBlackBoxTestGenerated.java
@@ -33362,12 +33362,6 @@
}
@Test
- @TestMetadata("anyAnnotationDisablesIndyLambdaGeneration.kt")
- public void testAnyAnnotationDisablesIndyLambdaGeneration() {
- runTest("compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt");
- }
-
- @Test
@TestMetadata("bigArityExtLambda.kt")
public void testBigArityExtLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/bigArityExtLambda.kt");
@@ -33500,12 +33494,24 @@
}
@Test
+ @TestMetadata("runtimeAnnotationDisablesIndyLambdaGeneration.kt")
+ public void testRuntimeAnnotationDisablesIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/runtimeAnnotationDisablesIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("simpleIndyLambda.kt")
public void testSimpleIndyLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt");
}
@Test
+ @TestMetadata("sourcesAnnotationAllowsIndyLambdaGeneration.kt")
+ public void testSourcesAnnotationAllowsIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/sourcesAnnotationAllowsIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("suspendLambda.kt")
public void testSuspendLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/suspendLambda.kt");
diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLReversedBlackBoxTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLReversedBlackBoxTestGenerated.java
index 4e5ea43..a13d367 100644
--- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLReversedBlackBoxTestGenerated.java
+++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLReversedBlackBoxTestGenerated.java
@@ -33362,12 +33362,6 @@
}
@Test
- @TestMetadata("anyAnnotationDisablesIndyLambdaGeneration.kt")
- public void testAnyAnnotationDisablesIndyLambdaGeneration() {
- runTest("compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt");
- }
-
- @Test
@TestMetadata("bigArityExtLambda.kt")
public void testBigArityExtLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/bigArityExtLambda.kt");
@@ -33500,12 +33494,24 @@
}
@Test
+ @TestMetadata("runtimeAnnotationDisablesIndyLambdaGeneration.kt")
+ public void testRuntimeAnnotationDisablesIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/runtimeAnnotationDisablesIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("simpleIndyLambda.kt")
public void testSimpleIndyLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt");
}
@Test
+ @TestMetadata("sourcesAnnotationAllowsIndyLambdaGeneration.kt")
+ public void testSourcesAnnotationAllowsIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/sourcesAnnotationAllowsIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("suspendLambda.kt")
public void testSuspendLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/suspendLambda.kt");
diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java
index 878b396..0df21ea 100644
--- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java
+++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java
@@ -33237,12 +33237,6 @@
}
@Test
- @TestMetadata("anyAnnotationDisablesIndyLambdaGeneration.kt")
- public void testAnyAnnotationDisablesIndyLambdaGeneration() {
- runTest("compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt");
- }
-
- @Test
@TestMetadata("bigArityExtLambda.kt")
public void testBigArityExtLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/bigArityExtLambda.kt");
@@ -33375,12 +33369,24 @@
}
@Test
+ @TestMetadata("runtimeAnnotationDisablesIndyLambdaGeneration.kt")
+ public void testRuntimeAnnotationDisablesIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/runtimeAnnotationDisablesIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("simpleIndyLambda.kt")
public void testSimpleIndyLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt");
}
@Test
+ @TestMetadata("sourcesAnnotationAllowsIndyLambdaGeneration.kt")
+ public void testSourcesAnnotationAllowsIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/sourcesAnnotationAllowsIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("suspendLambda.kt")
public void testSuspendLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/suspendLambda.kt");
diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java
index b174c0f..9941ea3 100644
--- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java
+++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java
@@ -33237,12 +33237,6 @@
}
@Test
- @TestMetadata("anyAnnotationDisablesIndyLambdaGeneration.kt")
- public void testAnyAnnotationDisablesIndyLambdaGeneration() {
- runTest("compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt");
- }
-
- @Test
@TestMetadata("bigArityExtLambda.kt")
public void testBigArityExtLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/bigArityExtLambda.kt");
@@ -33375,12 +33369,24 @@
}
@Test
+ @TestMetadata("runtimeAnnotationDisablesIndyLambdaGeneration.kt")
+ public void testRuntimeAnnotationDisablesIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/runtimeAnnotationDisablesIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("simpleIndyLambda.kt")
public void testSimpleIndyLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt");
}
@Test
+ @TestMetadata("sourcesAnnotationAllowsIndyLambdaGeneration.kt")
+ public void testSourcesAnnotationAllowsIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/sourcesAnnotationAllowsIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("suspendLambda.kt")
public void testSuspendLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/suspendLambda.kt");
diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt
index 37542ad..1bd31b09 100644
--- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt
+++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt
@@ -16,6 +16,7 @@
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.descriptors.Modality
+import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.builders.declarations.buildClass
import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter
@@ -173,7 +174,9 @@
// JDK LambdaMetafactory doesn't copy annotations from implementation method to an instance method in a
// corresponding synthetic class, which doesn't look like a binary compatible change.
// If 'indyAllowAnnotatedLambdas' is set to true, we can lift this restriction and use indy
- if (!context.config.indyAllowAnnotatedLambdas && reference.origin.isLambda && implFun.annotations.isNotEmpty()) {
+ if (!context.config.indyAllowAnnotatedLambdas && reference.origin.isLambda && implFun.annotations.any { annotation ->
+ annotation.symbol.owner.constructedClass.getAnnotationRetention() == KotlinRetention.RUNTIME
+ }) {
abiHazard = true
}
diff --git a/compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt b/compiler/testData/codegen/box/invokedynamic/lambdas/runtimeAnnotationDisablesIndyLambdaGeneration.kt
similarity index 82%
copy from compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt
copy to compiler/testData/codegen/box/invokedynamic/lambdas/runtimeAnnotationDisablesIndyLambdaGeneration.kt
index c50f85c..a74f250 100644
--- a/compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt
+++ b/compiler/testData/codegen/box/invokedynamic/lambdas/runtimeAnnotationDisablesIndyLambdaGeneration.kt
@@ -8,8 +8,8 @@
import kotlin.jvm.internal.Lambda
-@Target(AnnotationTarget.EXPRESSION)
-@Retention(AnnotationRetention.SOURCE)
+@Target(AnnotationTarget.FUNCTION)
+@Retention(AnnotationRetention.RUNTIME)
public annotation class SomeAnnotation
fun box(): String {
diff --git a/compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt b/compiler/testData/codegen/box/invokedynamic/lambdas/sourcesAnnotationAllowsIndyLambdaGeneration.kt
similarity index 90%
rename from compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt
rename to compiler/testData/codegen/box/invokedynamic/lambdas/sourcesAnnotationAllowsIndyLambdaGeneration.kt
index c50f85c..570eafa 100644
--- a/compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt
+++ b/compiler/testData/codegen/box/invokedynamic/lambdas/sourcesAnnotationAllowsIndyLambdaGeneration.kt
@@ -4,7 +4,7 @@
// WITH_STDLIB
// CHECK_BYTECODE_TEXT
-// 0 java/lang/invoke/LambdaMetafactory
+// 3 java/lang/invoke/LambdaMetafactory
import kotlin.jvm.internal.Lambda
diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java
index c6e7bc6..43faf7a 100644
--- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java
+++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/JvmAbiConsistencyTestBoxGenerated.java
@@ -33237,12 +33237,6 @@
}
@Test
- @TestMetadata("anyAnnotationDisablesIndyLambdaGeneration.kt")
- public void testAnyAnnotationDisablesIndyLambdaGeneration() {
- runTest("compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt");
- }
-
- @Test
@TestMetadata("bigArityExtLambda.kt")
public void testBigArityExtLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/bigArityExtLambda.kt");
@@ -33375,12 +33369,24 @@
}
@Test
+ @TestMetadata("runtimeAnnotationDisablesIndyLambdaGeneration.kt")
+ public void testRuntimeAnnotationDisablesIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/runtimeAnnotationDisablesIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("simpleIndyLambda.kt")
public void testSimpleIndyLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt");
}
@Test
+ @TestMetadata("sourcesAnnotationAllowsIndyLambdaGeneration.kt")
+ public void testSourcesAnnotationAllowsIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/sourcesAnnotationAllowsIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("suspendLambda.kt")
public void testSuspendLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/suspendLambda.kt");
diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java
index c66b013..47ecaef 100644
--- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java
+++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java
@@ -33237,12 +33237,6 @@
}
@Test
- @TestMetadata("anyAnnotationDisablesIndyLambdaGeneration.kt")
- public void testAnyAnnotationDisablesIndyLambdaGeneration() {
- runTest("compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt");
- }
-
- @Test
@TestMetadata("bigArityExtLambda.kt")
public void testBigArityExtLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/bigArityExtLambda.kt");
@@ -33375,12 +33369,24 @@
}
@Test
+ @TestMetadata("runtimeAnnotationDisablesIndyLambdaGeneration.kt")
+ public void testRuntimeAnnotationDisablesIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/runtimeAnnotationDisablesIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("simpleIndyLambda.kt")
public void testSimpleIndyLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt");
}
@Test
+ @TestMetadata("sourcesAnnotationAllowsIndyLambdaGeneration.kt")
+ public void testSourcesAnnotationAllowsIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/sourcesAnnotationAllowsIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("suspendLambda.kt")
public void testSuspendLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/suspendLambda.kt");
diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java
index afd1d99..1ca8bcb 100644
--- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java
+++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java
@@ -33237,12 +33237,6 @@
}
@Test
- @TestMetadata("anyAnnotationDisablesIndyLambdaGeneration.kt")
- public void testAnyAnnotationDisablesIndyLambdaGeneration() {
- runTest("compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt");
- }
-
- @Test
@TestMetadata("bigArityExtLambda.kt")
public void testBigArityExtLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/bigArityExtLambda.kt");
@@ -33375,12 +33369,24 @@
}
@Test
+ @TestMetadata("runtimeAnnotationDisablesIndyLambdaGeneration.kt")
+ public void testRuntimeAnnotationDisablesIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/runtimeAnnotationDisablesIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("simpleIndyLambda.kt")
public void testSimpleIndyLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt");
}
@Test
+ @TestMetadata("sourcesAnnotationAllowsIndyLambdaGeneration.kt")
+ public void testSourcesAnnotationAllowsIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/sourcesAnnotationAllowsIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("suspendLambda.kt")
public void testSuspendLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/suspendLambda.kt");
diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/inlineScopes/FirBlackBoxCodegenTestWithInlineScopesGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/inlineScopes/FirBlackBoxCodegenTestWithInlineScopesGenerated.java
index 3ad5e1c..e10ddcf 100644
--- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/inlineScopes/FirBlackBoxCodegenTestWithInlineScopesGenerated.java
+++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/inlineScopes/FirBlackBoxCodegenTestWithInlineScopesGenerated.java
@@ -33237,12 +33237,6 @@
}
@Test
- @TestMetadata("anyAnnotationDisablesIndyLambdaGeneration.kt")
- public void testAnyAnnotationDisablesIndyLambdaGeneration() {
- runTest("compiler/testData/codegen/box/invokedynamic/lambdas/anyAnnotationDisablesIndyLambdaGeneration.kt");
- }
-
- @Test
@TestMetadata("bigArityExtLambda.kt")
public void testBigArityExtLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/bigArityExtLambda.kt");
@@ -33375,12 +33369,24 @@
}
@Test
+ @TestMetadata("runtimeAnnotationDisablesIndyLambdaGeneration.kt")
+ public void testRuntimeAnnotationDisablesIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/runtimeAnnotationDisablesIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("simpleIndyLambda.kt")
public void testSimpleIndyLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt");
}
@Test
+ @TestMetadata("sourcesAnnotationAllowsIndyLambdaGeneration.kt")
+ public void testSourcesAnnotationAllowsIndyLambdaGeneration() {
+ runTest("compiler/testData/codegen/box/invokedynamic/lambdas/sourcesAnnotationAllowsIndyLambdaGeneration.kt");
+ }
+
+ @Test
@TestMetadata("suspendLambda.kt")
public void testSuspendLambda() {
runTest("compiler/testData/codegen/box/invokedynamic/lambdas/suspendLambda.kt");