diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 2a336c39aa8..6441ede6b42 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -18475,6 +18475,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/invokedynamic/sam/primitiveVsWrapperInSam.kt"); } + @Test + @TestMetadata("samConversionInsideSamConvertedLambda.kt") + public void testSamConversionInsideSamConvertedLambda() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/samConversionInsideSamConvertedLambda.kt"); + } + @Test @TestMetadata("samConversionOnFunctionReference.kt") public void testSamConversionOnFunctionReference() throws Exception { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt index 84c43490af6..3f06295dccd 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/FunctionReferenceLowering.kt @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.backend.common.lower.parents import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin -import org.jetbrains.kotlin.backend.jvm.codegen.representativeUpperBound import org.jetbrains.kotlin.backend.jvm.ir.* import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.InlineClassAbi import org.jetbrains.kotlin.config.JvmSamConversions @@ -170,15 +169,12 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext) private fun IrType.isProhibitedTypeForIndySamConversion(): Boolean { if (this !is IrSimpleType) return false - val erasedType = when (val classifier = classifier.owner) { - is IrTypeParameter -> - classifier.representativeUpperBound.withHasQuestionMark(hasQuestionMark) - else -> - this + val erasedClass = when (val classifier = classifier.owner) { + is IrTypeParameter -> classifier.erasedUpperBound + is IrClass -> classifier + else -> throw AssertionError("Unexpected classifier: ${classifier.render()}") } - val erasedClass = erasedType.getClass() ?: return false - - if (!erasedType.isInlined()) return false + if (!erasedClass.isInline) return false val underlyingType = getInlineClassUnderlyingType(erasedClass) as? IrSimpleType ?: throw AssertionError("Underlying type for inline class should be a simple type: ${erasedClass.render()}") diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 27aabe3201f..9d5a61915f4 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -92,6 +92,9 @@ where advanced options include: profilerPath is a path to libasyncProfiler.so Example: -Xprofile=/async-profiler/build/libasyncProfiler.so:event=cpu,interval=1ms,threads,start,framebuf=50000000: -Xrepeat= Debug option: Repeats modules compilation times + -Xsam-conversions={class|indy} Select code generation scheme for SAM conversions. + -Xsam-conversions=indy Generate SAM conversions using `invokedynamic` with `LambdaMetafactory.metafactory`. Requires `-jvm-target 8` or greater. + -Xsam-conversions=class Generate SAM conversions as explicit classes -Xsanitize-parentheses Transform '(' and ')' in method names to some other character sequence. This mode can BREAK BINARY COMPATIBILITY and is only supposed to be used to workaround problems with parentheses in identifiers on certain platforms diff --git a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineAny.kt b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineAny.kt index 2de01599722..b6a56cecbad 100644 --- a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineAny.kt +++ b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineAny.kt @@ -1,4 +1,6 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_LIGHT_ANALYSIS // JVM_TARGET: 1.8 // SAM_CONVERSIONS: INDY diff --git a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineInt.kt b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineInt.kt index 56dd6f9f7a7..caa814094ed 100644 --- a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineInt.kt +++ b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineInt.kt @@ -1,4 +1,6 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_LIGHT_ANALYSIS // JVM_TARGET: 1.8 // SAM_CONVERSIONS: INDY diff --git a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNAny.kt b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNAny.kt index cb73273e940..7d76740d04b 100644 --- a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNAny.kt +++ b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNAny.kt @@ -1,4 +1,6 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_LIGHT_ANALYSIS // JVM_TARGET: 1.8 // SAM_CONVERSIONS: INDY diff --git a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNInt.kt b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNInt.kt index 772f4ce7d5f..2ad8e8cce29 100644 --- a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNInt.kt +++ b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNInt.kt @@ -1,4 +1,6 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_LIGHT_ANALYSIS // JVM_TARGET: 1.8 // SAM_CONVERSIONS: INDY diff --git a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNString.kt b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNString.kt index eea458ecb5d..47eae7cd1be 100644 --- a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNString.kt +++ b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNString.kt @@ -1,4 +1,6 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_LIGHT_ANALYSIS // JVM_TARGET: 1.8 // SAM_CONVERSIONS: INDY diff --git a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineString.kt b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineString.kt index 0406d90261f..6f6aa813c4b 100644 --- a/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineString.kt +++ b/compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineString.kt @@ -1,4 +1,6 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_LIGHT_ANALYSIS // JVM_TARGET: 1.8 // SAM_CONVERSIONS: INDY diff --git a/compiler/testData/codegen/box/invokedynamic/sam/samConversionInsideSamConvertedLambda.kt b/compiler/testData/codegen/box/invokedynamic/sam/samConversionInsideSamConvertedLambda.kt new file mode 100644 index 00000000000..760a18d50aa --- /dev/null +++ b/compiler/testData/codegen/box/invokedynamic/sam/samConversionInsideSamConvertedLambda.kt @@ -0,0 +1,16 @@ +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// SAM_CONVERSIONS: INDY + +fun interface IFoo { + fun foo(k: String): String +} + +fun fooK(iFoo: IFoo) = iFoo.foo("K") + +fun box() = + fooK { + fooK { + fooK { k -> "O" + k } + } + } \ No newline at end of file diff --git a/compiler/testData/codegen/box/invokedynamic/sam/streamApi1.kt b/compiler/testData/codegen/box/invokedynamic/sam/streamApi1.kt index ecda6899ee7..9ca50ed75bc 100644 --- a/compiler/testData/codegen/box/invokedynamic/sam/streamApi1.kt +++ b/compiler/testData/codegen/box/invokedynamic/sam/streamApi1.kt @@ -1,4 +1,5 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR // JVM_TARGET: 1.8 // SAM_CONVERSIONS: INDY // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/invokedynamic/sam/streamApi2.kt b/compiler/testData/codegen/box/invokedynamic/sam/streamApi2.kt index 0f0683fe00a..7463f0f7d5e 100644 --- a/compiler/testData/codegen/box/invokedynamic/sam/streamApi2.kt +++ b/compiler/testData/codegen/box/invokedynamic/sam/streamApi2.kt @@ -1,4 +1,5 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR // JVM_TARGET: 1.8 // SAM_CONVERSIONS: INDY // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/invokedynamic/sam/suspendFunInterface.kt b/compiler/testData/codegen/box/invokedynamic/sam/suspendFunInterface.kt index 23047631362..99927451d01 100644 --- a/compiler/testData/codegen/box/invokedynamic/sam/suspendFunInterface.kt +++ b/compiler/testData/codegen/box/invokedynamic/sam/suspendFunInterface.kt @@ -1,5 +1,7 @@ // !LANGUAGE: +SuspendFunctionsInFunInterfaces +JvmIrEnabledByDefault // TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// IGNORE_LIGHT_ANALYSIS // JVM_TARGET: 1.8 // SAM_CONVERSIONS: INDY // WITH_RUNTIME diff --git a/compiler/testData/codegen/bytecodeText/invokedynamic/streamApi.kt b/compiler/testData/codegen/bytecodeText/invokedynamic/streamApi.kt index 99dad35114a..52f0ae1029c 100644 --- a/compiler/testData/codegen/bytecodeText/invokedynamic/streamApi.kt +++ b/compiler/testData/codegen/bytecodeText/invokedynamic/streamApi.kt @@ -1,4 +1,5 @@ // TARGET_BACKEND: JVM +// IGNORE_BACKEND_FIR: JVM_IR // JVM_TARGET: 1.8 // SAM_CONVERSIONS: INDY // WITH_RUNTIME diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 46135a7b9eb..241a846a4dd 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -18475,6 +18475,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/invokedynamic/sam/primitiveVsWrapperInSam.kt"); } + @Test + @TestMetadata("samConversionInsideSamConvertedLambda.kt") + public void testSamConversionInsideSamConvertedLambda() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/samConversionInsideSamConvertedLambda.kt"); + } + @Test @TestMetadata("samConversionOnFunctionReference.kt") public void testSamConversionOnFunctionReference() throws Exception { 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 796a43c4270..f89dfecb257 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 @@ -18475,6 +18475,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/invokedynamic/sam/primitiveVsWrapperInSam.kt"); } + @Test + @TestMetadata("samConversionInsideSamConvertedLambda.kt") + public void testSamConversionInsideSamConvertedLambda() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/samConversionInsideSamConvertedLambda.kt"); + } + @Test @TestMetadata("samConversionOnFunctionReference.kt") public void testSamConversionOnFunctionReference() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 6b69b50e143..45e0b541a0d 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -16125,6 +16125,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class Sam extends AbstractLightAnalysisModeTest { + @TestMetadata("suspendFunInterface.kt") + public void ignoreSuspendFunInterface() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/suspendFunInterface.kt"); + } + private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } @@ -16198,6 +16203,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/invokedynamic/sam/primitiveVsWrapperInSam.kt"); } + @TestMetadata("samConversionInsideSamConvertedLambda.kt") + public void testSamConversionInsideSamConvertedLambda() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/samConversionInsideSamConvertedLambda.kt"); + } + @TestMetadata("samConversionOnFunctionReference.kt") public void testSamConversionOnFunctionReference() throws Exception { runTest("compiler/testData/codegen/box/invokedynamic/sam/samConversionOnFunctionReference.kt"); @@ -16223,11 +16233,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/invokedynamic/sam/streamApi2.kt"); } - @TestMetadata("suspendFunInterface.kt") - public void testSuspendFunInterface() throws Exception { - runTest("compiler/testData/codegen/box/invokedynamic/sam/suspendFunInterface.kt"); - } - @TestMetadata("unboundFunctionReferenceEquality.kt") public void testUnboundFunctionReferenceEquality() throws Exception { runTest("compiler/testData/codegen/box/invokedynamic/sam/unboundFunctionReferenceEquality.kt"); @@ -16270,6 +16275,36 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class InlineClassInSignature extends AbstractLightAnalysisModeTest { + @TestMetadata("funInterfaceWithInlineAny.kt") + public void ignoreFunInterfaceWithInlineAny() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineAny.kt"); + } + + @TestMetadata("funInterfaceWithInlineInt.kt") + public void ignoreFunInterfaceWithInlineInt() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineInt.kt"); + } + + @TestMetadata("funInterfaceWithInlineNAny.kt") + public void ignoreFunInterfaceWithInlineNAny() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNAny.kt"); + } + + @TestMetadata("funInterfaceWithInlineNInt.kt") + public void ignoreFunInterfaceWithInlineNInt() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNInt.kt"); + } + + @TestMetadata("funInterfaceWithInlineNString.kt") + public void ignoreFunInterfaceWithInlineNString() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNString.kt"); + } + + @TestMetadata("funInterfaceWithInlineString.kt") + public void ignoreFunInterfaceWithInlineString() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineString.kt"); + } + private void runTest(String testDataFilePath) throws Exception { KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); } @@ -16278,36 +16313,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); } - @TestMetadata("funInterfaceWithInlineAny.kt") - public void testFunInterfaceWithInlineAny() throws Exception { - runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineAny.kt"); - } - - @TestMetadata("funInterfaceWithInlineInt.kt") - public void testFunInterfaceWithInlineInt() throws Exception { - runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineInt.kt"); - } - - @TestMetadata("funInterfaceWithInlineNAny.kt") - public void testFunInterfaceWithInlineNAny() throws Exception { - runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNAny.kt"); - } - - @TestMetadata("funInterfaceWithInlineNInt.kt") - public void testFunInterfaceWithInlineNInt() throws Exception { - runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNInt.kt"); - } - - @TestMetadata("funInterfaceWithInlineNString.kt") - public void testFunInterfaceWithInlineNString() throws Exception { - runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineNString.kt"); - } - - @TestMetadata("funInterfaceWithInlineString.kt") - public void testFunInterfaceWithInlineString() throws Exception { - runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/funInterfaceWithInlineString.kt"); - } - @TestMetadata("genericFunInterfaceWithInlineAny.kt") public void testGenericFunInterfaceWithInlineAny() throws Exception { runTest("compiler/testData/codegen/box/invokedynamic/sam/inlineClassInSignature/genericFunInterfaceWithInlineAny.kt");