From 851980e36f5b2b41ab768c9eee25e696d86a59c1 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 26 Apr 2021 17:17:25 +0300 Subject: [PATCH] JVM_IR KT-45103 optimize direct invoke for lambdas and callable refs --- .../FirBlackBoxCodegenTestGenerated.java | 70 +++++++++++ .../jvm/lower/FunctionReferenceLowering.kt | 105 +++++++++++++++- .../kotlin/ir/util/AdditionalIrUtils.kt | 2 + .../asJava/lightClasses/LocalFunctions.java | 8 ++ .../asJava/lightClasses/LocalFunctions.kt | 25 ++++ ...eticAccessorForPropertiesSignatureClash.kt | 15 +-- ...ticAccessorForPropertiesSignatureClash.out | 16 +-- ...ticAccessorPropertyAndFunSignatureClash.kt | 20 +-- ...icAccessorPropertyAndFunSignatureClash.out | 16 +-- .../asmLike/typeAnnotations/implicit_ir.kt | 4 + .../asmLike/typeAnnotations/implicit_ir.txt | 8 +- .../testData/codegen/box/arrays/kt4118.kt | 5 +- .../multiDecl/MultiDeclForValCaptured.kt | 4 +- ...tiDeclForComponentExtensionsValCaptured.kt | 4 +- ...tiDeclForComponentExtensionsValCaptured.kt | 4 +- .../box/assert/jvm/lambdaNotEvaluated.kt | 10 +- .../testData/codegen/box/classes/kt1578.kt | 5 +- .../closures/captureExtensionReceiverX2.kt | 4 +- .../outerCapturedInNestedLambda.kt | 7 +- .../box/closures/closureOnTopLevel1.kt | 8 +- .../box/closures/closureOnTopLevel2.kt | 8 +- .../testData/codegen/box/closures/kt10044.kt | 10 +- .../testData/codegen/box/closures/kt4106.kt | 6 +- .../codegen/box/constants/privateConst.kt | 6 +- .../local/useReflectionForLocalVarInLambda.kt | 6 +- .../optimizedDelegatedProperties/kt40815.kt | 12 +- .../boundInnerContructorRef.kt | 13 ++ .../boundMemberRef.kt | 11 ++ .../capturingLambda.kt | 11 ++ .../directInvokeOptimization/contructorRef.kt | 10 ++ .../directInvokeOptimization/nestedLambdas.kt | 12 ++ .../simpleAnonymousFun.kt | 10 ++ .../directInvokeOptimization/simpleFunRef.kt | 8 ++ .../directInvokeOptimization/simpleLambda.kt | 10 ++ .../unboundInnerContructorRef.kt | 12 ++ .../unboundMemberRef.kt | 2 + .../overloadedLocalFunction2.kt | 6 +- ...ccessPrivateInlineClassMethodFromLambda.kt | 4 +- .../lambdaInInlineClassFun.kt | 4 +- .../codegen/box/inlineClasses/kt28585.kt | 6 +- .../localClassOuterDiffersFromInnerOuter.kt | 10 +- .../objectOuterDiffersFromInnerOuter.kt | 10 +- .../invokedynamic/lambdas/bigArityLambda.kt | 16 +-- .../invokedynamic/lambdas/capturingValue.kt | 3 +- .../box/invokedynamic/lambdas/capturingVar.kt | 3 +- .../lambdas/nestedIndyLambdas.kt | 9 +- .../lambdas/primitiveValueParameters.kt | 3 +- .../invokedynamic/lambdas/simpleIndyLambda.kt | 5 +- .../invokedynamic/lambdas/voidReturnType.kt | 3 +- .../box/jvmField/capturePackageFields.kt | 11 +- .../codegen/box/localClasses/kt2700.kt | 10 +- .../localClassInParameterInitializer.kt | 6 +- ...onObjectAccessedFromLambdaInNestedClass.kt | 4 +- ...FunctionFromClosureInInitializer_kt5582.kt | 6 +- .../privateTopLevelPropAndVarInInner.kt | 4 +- .../box/privateConstructors/captured.kt | 4 +- .../box/properties/classFieldInsideLambda.kt | 4 +- .../classFieldInsideLocalInSetter.kt | 4 +- .../classFieldInsideNestedLambda.kt | 4 +- .../classFieldInsideNestedNestedLambda.kt | 4 +- .../properties/companionFieldInsideLambda.kt | 4 +- .../companionPrivateFieldInsideLambda.kt | 4 +- .../box/properties/fieldInsideLambda.kt | 4 +- .../codegen/box/properties/kt10729.kt | 4 +- .../testData/codegen/box/properties/kt4340.kt | 10 +- .../testData/codegen/box/properties/kt9603.kt | 4 +- .../lateinit/accessorExceptionPublic.kt | 4 +- .../nonInlineLambda.kt | 4 +- .../referenceToJavaFieldViaBridge.kt | 4 +- .../box/reflection/enclosing/classInLambda.kt | 8 +- .../reflection/enclosing/objectInLambda.kt | 9 +- .../properties/localDelegated/inLambda.kt | 6 +- .../inlineIntoTwoConstructors.kt | 4 +- .../testData/codegen/box/statics/kt8089.kt | 4 +- .../codegen/box/statics/protectedStatic2.kt | 23 ++-- .../testData/codegen/box/super/kt4173_3.kt | 16 +-- .../accessorForAbstractProtected.kt | 4 +- .../codegen/box/syntheticAccessors/kt10047.kt | 6 +- .../syntheticAccessors/kt21258_indirect.kt | 4 +- .../box/syntheticAccessors/kt21258_simple.kt | 4 +- .../box/topLevelPrivate/syntheticAccessor.kt | 6 +- .../syntheticAccessorInMultiFile.kt | 6 +- .../inlineCallInsideInlineLambda.kt | 5 +- .../inlineCallInsideInlineLambda.smap | 12 +- .../smap/newsmap/mappingInSubInlineLambda.kt | 6 +- .../newsmap/mappingInSubInlineLambda.smap | 12 +- .../mappingInSubInlineLambdaSameFileInline.kt | 6 +- ...appingInSubInlineLambdaSameFileInline.smap | 12 +- ...rProtectedStaticJavaFieldInOtherPackage.kt | 4 +- ...ProtectedStaticJavaFieldInOtherPackage.txt | 6 + ...tectedStaticJavaFieldInOtherPackage_ir.txt | 6 + .../inline/enclosingInfo/kt10259.kt | 10 +- .../inline/enclosingInfo/kt10259.txt | 1 + .../inline/enclosingInfo/kt10259_ir.txt | 1 + .../bytecodeText/constClosureOptimization.kt | 23 ++-- .../directInvoke/callableReference.kt | 3 +- .../directInvoke/inplaceClosure.kt | 4 +- .../inline/deleteClassOnTransformation.kt | 14 ++- .../bytecodeText/invokedynamic/lambdas.kt | 9 +- .../testData/codegen/bytecodeText/kt10259.kt | 16 ++- .../codegen/bytecodeText/kt10259_3.kt | 23 ++-- .../debug/stepping/anonymousFunction.kt | 16 ++- .../debug/stepping/anonymousFunctionDirect.kt | 17 +++ ...ectedAccessToBaseMethodDifferentPackage.kt | 6 +- .../codegen/BlackBoxCodegenTestGenerated.java | 70 +++++++++++ .../IrBlackBoxCodegenTestGenerated.java | 70 +++++++++++ .../kotlin/asJava/LightClassTestCommon.kt | 14 ++- .../kotlin/asJava/PsiClassRenderer.kt | 116 +++++++++++------- .../CompilerLightClassTestGenerated.java | 5 + .../LightAnalysisModeTestGenerated.java | 63 ++++++++++ .../IrSteppingTestGenerated.java | 6 + .../SteppingTestGenerated.java | 6 + .../classes/FirLightClassTestGenerated.java | 5 + .../AbstractUltraLightClassLoadingTest.kt | 3 - .../AbstractUltraLightScriptLoadingTest.kt | 3 +- .../UltraLightClassSanityTestGenerated.java | 5 + .../resolve/AbstractIdeLightClassTest.kt | 50 ++++++-- .../IdeCompiledLightClassTestGenerated.java | 5 + .../resolve/IdeLightClassTestGenerated.java | 5 + .../kotlin/idea/perf/UltraLightChecker.kt | 2 +- .../IrJsCodegenBoxES6TestGenerated.java | 63 ++++++++++ .../IrJsCodegenBoxTestGenerated.java | 63 ++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 63 ++++++++++ .../IrCodegenBoxWasmTestGenerated.java | 63 ++++++++++ 124 files changed, 1340 insertions(+), 324 deletions(-) create mode 100644 compiler/testData/asJava/lightClasses/LocalFunctions.java create mode 100644 compiler/testData/asJava/lightClasses/LocalFunctions.kt create mode 100644 compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt create mode 100644 compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt create mode 100644 compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt create mode 100644 compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt create mode 100644 compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt create mode 100644 compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt create mode 100644 compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt create mode 100644 compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt create mode 100644 compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt create mode 100644 compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt create mode 100644 compiler/testData/debug/stepping/anonymousFunctionDirect.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 5b2a4c3e0a7..4a944da22af 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -14171,6 +14171,76 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT } } + @Nested + @TestMetadata("compiler/testData/codegen/box/directInvokeOptimization") + @TestDataPath("$PROJECT_ROOT") + public class DirectInvokeOptimization { + @Test + public void testAllFilesPresentInDirectInvokeOptimization() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/directInvokeOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("boundInnerContructorRef.kt") + public void testBoundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt"); + } + + @Test + @TestMetadata("boundMemberRef.kt") + public void testBoundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt"); + } + + @Test + @TestMetadata("capturingLambda.kt") + public void testCapturingLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt"); + } + + @Test + @TestMetadata("contructorRef.kt") + public void testContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt"); + } + + @Test + @TestMetadata("nestedLambdas.kt") + public void testNestedLambdas() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt"); + } + + @Test + @TestMetadata("simpleAnonymousFun.kt") + public void testSimpleAnonymousFun() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt"); + } + + @Test + @TestMetadata("simpleFunRef.kt") + public void testSimpleFunRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt"); + } + + @Test + @TestMetadata("simpleLambda.kt") + public void testSimpleLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt"); + } + + @Test + @TestMetadata("unboundInnerContructorRef.kt") + public void testUnboundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt"); + } + + @Test + @TestMetadata("unboundMemberRef.kt") + public void testUnboundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/elvis") @TestDataPath("$PROJECT_ROOT") 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 ffbad6d3011..3bf27e23569 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 @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext import org.jetbrains.kotlin.backend.common.ir.* import org.jetbrains.kotlin.backend.common.lower.SamEqualsHashCodeMethodsGenerator +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 @@ -27,10 +28,7 @@ import org.jetbrains.kotlin.ir.builders.* import org.jetbrains.kotlin.ir.builders.declarations.* import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* -import org.jetbrains.kotlin.ir.expressions.impl.IrClassReferenceImpl -import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl -import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl -import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl +import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.util.* @@ -38,6 +36,7 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.SpecialNames +import org.jetbrains.kotlin.util.OperatorNameConventions internal val functionReferencePhase = makeIrFilePhase( ::FunctionReferenceLowering, @@ -113,6 +112,104 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext) return FunctionReferenceBuilder(reference).build() } + override fun visitCall(expression: IrCall): IrExpression { + if (expression.symbol.owner.isInvokeOperator()) { + when (val receiver = expression.dispatchReceiver) { + is IrFunctionReference -> { + rewriteDirectInvokeToFunctionReference(expression, receiver)?.let { + it.transformChildrenVoid() + return it + } + } + is IrBlock -> { + val last = receiver.statements.last() + if (last is IrFunctionReference) { + rewriteDirectInvokeToLambda(expression, receiver, last)?.let { + it.transformChildrenVoid() + return it + } + } + } + } + } + + expression.transformChildrenVoid(this) + return expression + } + + private fun IrFunction.isInvokeOperator(): Boolean { + // For now, it's enough to check that the function name is 'invoke', + // because later we are looking at the dispatch receiver and check whether it's a function reference + // or a block returning a function reference. + return name == OperatorNameConventions.INVOKE + } + + private fun rewriteDirectInvokeToLambda(irInvokeCall: IrCall, irBlock: IrBlock, lastFunRef: IrFunctionReference): IrExpression? { + val callee = lastFunRef.symbol.owner + if (callee.origin != IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA && !callee.isAnonymousFunction) + return null + if (callee.parents.any { it is IrSimpleFunction && it.isInline }) { + // TODO investigate why inliner gets confused when we pass it a function with some optimized direct invoke. + return null + } + val irDirectCall = rewriteDirectInvokeToFunctionReference(irInvokeCall, lastFunRef) + ?: return null + val newBlock = IrBlockImpl(irBlock.startOffset, irBlock.endOffset, irDirectCall.type) + newBlock.statements.addAll(irBlock.statements) + newBlock.statements[newBlock.statements.lastIndex] = irDirectCall + return newBlock + } + + private fun rewriteDirectInvokeToFunctionReference(irInvokeCall: IrCall, irFunRef: IrFunctionReference): IrExpression? { + // TODO deal with type parameters somehow? + // It seems we can't encounter them in the code written by user, + // but this might be important later if we actually perform inlining and optimizations on IR. + return when (val irFun = irFunRef.symbol.owner) { + is IrSimpleFunction -> { + if (irFun.typeParameters.isNotEmpty()) return null + IrCallImpl( + irInvokeCall.startOffset, irInvokeCall.endOffset, irInvokeCall.type, + irFun.symbol, + typeArgumentsCount = irFun.typeParameters.size, valueArgumentsCount = irFun.valueParameters.size + ).apply { + copyReceiverAndValueArgumentsForDirectInvoke(irFunRef, irInvokeCall) + } + } + is IrConstructor -> + IrConstructorCallImpl( + irInvokeCall.startOffset, irInvokeCall.endOffset, irInvokeCall.type, + irFun.symbol, + typeArgumentsCount = irFun.typeParameters.size, + constructorTypeArgumentsCount = 0, + valueArgumentsCount = irFun.valueParameters.size + ).apply { + copyReceiverAndValueArgumentsForDirectInvoke(irFunRef, irInvokeCall) + } + else -> + throw AssertionError("Simple function or constructor expected: ${irFun.render()}") + } + } + + private fun IrFunctionAccessExpression.copyReceiverAndValueArgumentsForDirectInvoke( + irFunRef: IrFunctionReference, + irInvokeCall: IrFunctionAccessExpression + ) { + val irFun = irFunRef.symbol.owner + var invokeArgIndex = 0 + if (irFun.dispatchReceiverParameter != null) { + dispatchReceiver = irFunRef.dispatchReceiver ?: irInvokeCall.getValueArgument(invokeArgIndex++) + } + if (irFun.extensionReceiverParameter != null) { + extensionReceiver = irFunRef.extensionReceiver ?: irInvokeCall.getValueArgument(invokeArgIndex++) + } + if (invokeArgIndex + valueArgumentsCount != irInvokeCall.valueArgumentsCount) { + throw AssertionError("Mismatching value arguments: $invokeArgIndex arguments used for receivers\n${irInvokeCall.dump()}") + } + for (i in 0 until valueArgumentsCount) { + putValueArgument(i, irInvokeCall.getValueArgument(invokeArgIndex++)) + } + } + private fun wrapLambdaReferenceWithIndySamConversion( expression: IrBlock, reference: IrFunctionReference, diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt index 9e86bf94510..241e25b5d7e 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/AdditionalIrUtils.kt @@ -131,6 +131,8 @@ val IrDeclaration.isTopLevelDeclaration get() = val IrDeclaration.isAnonymousObject get() = this is IrClass && name == SpecialNames.NO_NAME_PROVIDED +val IrDeclaration.isAnonymousFunction get() = this is IrSimpleFunction && name == SpecialNames.NO_NAME_PROVIDED + val IrDeclaration.isLocal: Boolean get() { var current: IrElement = this diff --git a/compiler/testData/asJava/lightClasses/LocalFunctions.java b/compiler/testData/asJava/lightClasses/LocalFunctions.java new file mode 100644 index 00000000000..383ff46dddb --- /dev/null +++ b/compiler/testData/asJava/lightClasses/LocalFunctions.java @@ -0,0 +1,8 @@ +public final class A /* p.A*/ { + public A(int);// .ctor(int) + + public final int getProperty();// getProperty() + + public final void memberFun();// memberFun() + +} \ No newline at end of file diff --git a/compiler/testData/asJava/lightClasses/LocalFunctions.kt b/compiler/testData/asJava/lightClasses/LocalFunctions.kt new file mode 100644 index 00000000000..8a0efc7e886 --- /dev/null +++ b/compiler/testData/asJava/lightClasses/LocalFunctions.kt @@ -0,0 +1,25 @@ +// p.A + +package p + +class A { + init { + fun localFunInInit() {} + } + + constructor(x: Int) { + fun localFunInConstructor() {} + } + + fun memberFun() { + fun localFunInMemberFun() {} + } + + val property: Int + get() { + fun localFunInPropertyAccessor() {} + return 1 + } +} + +// FIR_COMPARISON diff --git a/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt b/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt index 5349fb419d9..0fb430e4be0 100644 --- a/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt +++ b/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt @@ -1,6 +1,7 @@ -class A { +fun eval(f: () -> T) = f() - private var foo = 1; +class A { + private var foo = 1 fun `access$getFoo$p`(a: A): Int = 1 fun `access$setFoo$p`(a: A, d: Int) {} @@ -21,10 +22,10 @@ class A { get() = field fun test() { - { - foo = 2; + eval { + foo = 2 foo - }() + } } fun `access$getFoo$p`(p: A.Companion): Int = 1 @@ -32,9 +33,9 @@ class A { } fun test() { - { + eval { foo = 2; foo + bar - }() + } } } \ No newline at end of file diff --git a/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.out b/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.out index 28ecabd8855..95e33f76f20 100644 --- a/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.out +++ b/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.out @@ -1,39 +1,39 @@ -compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:1:7: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA;)I): +compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:3:7: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA;)I): fun `access$getFoo$p`(`$this`: A): Int defined in A fun `access$getFoo$p`(a: A): Int defined in A class A { ^ -compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:1:7: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA;I)V): +compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:3:7: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA;I)V): fun `access$setFoo$p`(`$this`: A, ``: Int): Unit defined in A fun `access$setFoo$p`(a: A, d: Int): Unit defined in A class A { ^ -compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:1:7: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$cp()I): +compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:3:7: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$cp()I): fun `access$getFoo$cp`(): Int defined in A fun `access$getFoo$cp`(): Int defined in A class A { ^ -compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:1:7: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$cp(I)V): +compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:3:7: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$cp(I)V): fun `access$setFoo$cp`(``: Int): Unit defined in A fun `access$setFoo$cp`(d: Int): Unit defined in A class A { ^ -compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:5:5: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA;)I): +compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:6:5: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA;)I): fun `access$getFoo$p`(`$this`: A): Int defined in A fun `access$getFoo$p`(a: A): Int defined in A fun `access$getFoo$p`(a: A): Int = 1 ^ -compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:6:5: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA;I)V): +compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:7:5: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA;I)V): fun `access$setFoo$p`(`$this`: A, ``: Int): Unit defined in A fun `access$setFoo$p`(a: A, d: Int): Unit defined in A fun `access$setFoo$p`(a: A, d: Int) {} ^ -compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:9:5: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$cp()I): +compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:10:5: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$cp()I): fun `access$getFoo$cp`(): Int defined in A fun `access$getFoo$cp`(): Int defined in A fun `access$getFoo$cp`(): Int = 1 ^ -compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:10:5: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$cp(I)V): +compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.kt:11:5: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$cp(I)V): fun `access$setFoo$cp`(``: Int): Unit defined in A fun `access$setFoo$cp`(d: Int): Unit defined in A fun `access$setFoo$cp`(d: Int) {} diff --git a/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt b/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt index bef9f3bdcfb..5a2d2b0b8f8 100644 --- a/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt +++ b/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt @@ -1,25 +1,25 @@ -class A { +fun eval(f: () -> T) = f() - private var foo = 1; +class A { + private var foo = 1 fun `access$getFoo$p`(a: A): Int = 1 fun `access$setFoo$p`(a: A, d: Int) {} - private fun getFoo() = 1; + private fun getFoo() = 1 private fun setFoo(i: Int) {} fun `access$getFoo`(a: A): Int = 1 fun `access$setFoo`(a: A, d: Int) {} fun test() { - { - foo = 2; + eval { + foo = 2 foo - }(); - - { + } + eval { setFoo(2) - getFoo(); - }() + getFoo() + } } } \ No newline at end of file diff --git a/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.out b/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.out index 623e736c7a2..ac66c774877 100644 --- a/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.out +++ b/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.out @@ -1,39 +1,39 @@ -compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:1:7: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA;)I): +compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:3:7: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA;)I): fun `access$getFoo$p`(`$this`: A): Int defined in A fun `access$getFoo$p`(a: A): Int defined in A class A { ^ -compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:1:7: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA;I)V): +compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:3:7: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA;I)V): fun `access$setFoo$p`(`$this`: A, ``: Int): Unit defined in A fun `access$setFoo$p`(a: A, d: Int): Unit defined in A class A { ^ -compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:1:7: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo(LA;)I): +compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:3:7: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo(LA;)I): fun `access$getFoo`(`$this`: A): Int defined in A fun `access$getFoo`(a: A): Int defined in A class A { ^ -compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:1:7: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo(LA;I)V): +compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:3:7: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo(LA;I)V): fun `access$setFoo`(`$this`: A, i: Int): Unit defined in A fun `access$setFoo`(a: A, d: Int): Unit defined in A class A { ^ -compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:5:5: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA;)I): +compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:6:5: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo$p(LA;)I): fun `access$getFoo$p`(`$this`: A): Int defined in A fun `access$getFoo$p`(a: A): Int defined in A fun `access$getFoo$p`(a: A): Int = 1 ^ -compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:6:5: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA;I)V): +compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:7:5: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo$p(LA;I)V): fun `access$setFoo$p`(`$this`: A, ``: Int): Unit defined in A fun `access$setFoo$p`(a: A, d: Int): Unit defined in A fun `access$setFoo$p`(a: A, d: Int) {} ^ -compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:11:5: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo(LA;)I): +compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:12:5: error: platform declaration clash: The following declarations have the same JVM signature (access$getFoo(LA;)I): fun `access$getFoo`(`$this`: A): Int defined in A fun `access$getFoo`(a: A): Int defined in A fun `access$getFoo`(a: A): Int = 1 ^ -compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:12:5: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo(LA;I)V): +compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.kt:13:5: error: platform declaration clash: The following declarations have the same JVM signature (access$setFoo(LA;I)V): fun `access$setFoo`(`$this`: A, i: Int): Unit defined in A fun `access$setFoo`(a: A, d: Int): Unit defined in A fun `access$setFoo`(a: A, d: Int) {} diff --git a/compiler/testData/codegen/asmLike/typeAnnotations/implicit_ir.kt b/compiler/testData/codegen/asmLike/typeAnnotations/implicit_ir.kt index 0dc6667505d..4c4beba1bb3 100644 --- a/compiler/testData/codegen/asmLike/typeAnnotations/implicit_ir.kt +++ b/compiler/testData/codegen/asmLike/typeAnnotations/implicit_ir.kt @@ -26,4 +26,8 @@ class Kotlin { fun foo4() = { foo2() }() + fun foo5() { + val lambda = { foo2() } + lambda() + } } diff --git a/compiler/testData/codegen/asmLike/typeAnnotations/implicit_ir.txt b/compiler/testData/codegen/asmLike/typeAnnotations/implicit_ir.txt index 10cf8cb3e92..2841809f8bb 100644 --- a/compiler/testData/codegen/asmLike/typeAnnotations/implicit_ir.txt +++ b/compiler/testData/codegen/asmLike/typeAnnotations/implicit_ir.txt @@ -1,5 +1,5 @@ Lkotlin/jvm/internal/Lambda;Lkotlin/jvm/functions/Function0; -final class foo/Kotlin$foo4$1 : kotlin/jvm/internal/Lambda, kotlin/jvm/functions/Function0 { +final class foo/Kotlin$foo5$lambda$1 : kotlin/jvm/internal/Lambda, kotlin/jvm/functions/Function0 { final foo.Kotlin this$0 void (foo.Kotlin $receiver) @@ -29,6 +29,12 @@ public final class foo/Kotlin : java/lang/Object { @Lorg/jetbrains/annotations/NotNull;([]) // invisible @Lfoo/TypeAnn;([name="2"]) : METHOD_RETURN, null @Lfoo/TypeAnnBinary;([]) : METHOD_RETURN, null // invisible + + private final static java.lang.String foo4$lambda-0(foo.Kotlin this$0) + @Lfoo/TypeAnn;([name="2"]) : METHOD_RETURN, null + @Lfoo/TypeAnnBinary;([]) : METHOD_RETURN, null // invisible + + public final void foo5() } public abstract interface foo/TypeAnn : java/lang/Object, java/lang/annotation/Annotation { diff --git a/compiler/testData/codegen/box/arrays/kt4118.kt b/compiler/testData/codegen/box/arrays/kt4118.kt index 979effeed54..eccf16888ef 100644 --- a/compiler/testData/codegen/box/arrays/kt4118.kt +++ b/compiler/testData/codegen/box/arrays/kt4118.kt @@ -4,7 +4,10 @@ fun Array.test1(): Array { } fun Array.test1Nested(): Array { - val func = { i: Int -> { this }()} + val func = { i: Int -> + val lam = { this } + lam() + } return func(1) } diff --git a/compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForValCaptured.kt b/compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForValCaptured.kt index f25b504d607..b78832a2ab2 100644 --- a/compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForValCaptured.kt +++ b/compiler/testData/codegen/box/arrays/multiDecl/MultiDeclForValCaptured.kt @@ -3,10 +3,12 @@ class C(val i: Int) { operator fun component2() = i + 2 } +fun eval(fn: () -> T) = fn() + fun doTest(l : Array): String { var s = "" for ((a, b) in l) { - s += {"$a:$b;"}() + s += eval {"$a:$b;"} } return s } diff --git a/compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentExtensionsValCaptured.kt b/compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentExtensionsValCaptured.kt index 3dda25067f3..d0d6637977f 100644 --- a/compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentExtensionsValCaptured.kt +++ b/compiler/testData/codegen/box/arrays/multiDecl/int/MultiDeclForComponentExtensionsValCaptured.kt @@ -1,10 +1,12 @@ operator fun Int.component1() = this + 1 operator fun Int.component2() = this + 2 +fun eval(fn: () -> T) = fn() + fun doTest(l : Array): String { var s = "" for ((a, b) in l) { - s += {"$a:$b;"}() + s += eval {"$a:$b;"} } return s } diff --git a/compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentExtensionsValCaptured.kt b/compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentExtensionsValCaptured.kt index 3e610b49997..4dfe5f891c8 100644 --- a/compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentExtensionsValCaptured.kt +++ b/compiler/testData/codegen/box/arrays/multiDecl/long/MultiDeclForComponentExtensionsValCaptured.kt @@ -1,10 +1,12 @@ operator fun Long.component1() = this + 1 operator fun Long.component2() = this + 2 +fun eval(fn: () -> T) = fn() + fun doTest(l : Array): String { var s = "" for ((a, b) in l) { - s += {"$a:$b;"}() + s += eval { "$a:$b;" } } return s } diff --git a/compiler/testData/codegen/box/assert/jvm/lambdaNotEvaluated.kt b/compiler/testData/codegen/box/assert/jvm/lambdaNotEvaluated.kt index 0f66c5ca378..61af8a5d0ba 100644 --- a/compiler/testData/codegen/box/assert/jvm/lambdaNotEvaluated.kt +++ b/compiler/testData/codegen/box/assert/jvm/lambdaNotEvaluated.kt @@ -15,10 +15,11 @@ interface Checker { class Checker1 : Checker { override fun check(): Boolean { var result = true - assert(true, { + val lam = { result = false { "Assertion failure" } - }()) + } + assert(true, lam()) return result } } @@ -26,10 +27,11 @@ class Checker1 : Checker { class Checker2 : Checker { override fun check(): Boolean { var result = true - assert(true, { + val lam = { result = false { "Assertion failure" } - }()) + } + assert(true, lam()) return result } } diff --git a/compiler/testData/codegen/box/classes/kt1578.kt b/compiler/testData/codegen/box/classes/kt1578.kt index e485684b4da..d1aeecf86bf 100644 --- a/compiler/testData/codegen/box/classes/kt1578.kt +++ b/compiler/testData/codegen/box/classes/kt1578.kt @@ -1,8 +1,7 @@ fun box() : String { var i = 0 - { - i++ - }() + val lambda = { i++ } + lambda() i++ //the problem is here // i = i + 1 //this way it works return if (i == 2) "OK" else "fail" diff --git a/compiler/testData/codegen/box/closures/captureExtensionReceiverX2.kt b/compiler/testData/codegen/box/closures/captureExtensionReceiverX2.kt index 95ba048f18e..0b8367771fe 100644 --- a/compiler/testData/codegen/box/closures/captureExtensionReceiverX2.kt +++ b/compiler/testData/codegen/box/closures/captureExtensionReceiverX2.kt @@ -1,5 +1,7 @@ +fun eval(fn: () -> T) = fn() + fun String.f(x: String): String { - fun String.g() = { this@f + this@g }() + fun String.g() = eval { this@f + this@g } return x.g() } diff --git a/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/outerCapturedInNestedLambda.kt b/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/outerCapturedInNestedLambda.kt index d64208612bc..49a19e26a46 100644 --- a/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/outerCapturedInNestedLambda.kt +++ b/compiler/testData/codegen/box/closures/captureInSuperConstructorCall/outerCapturedInNestedLambda.kt @@ -3,7 +3,12 @@ open class Base(val callback: () -> String) class Outer { val ok = "OK" - inner class Inner : Base({ { ok }() }) + inner class Inner : Base( + { + val lambda = { ok } + lambda() + } + ) } fun box(): String = diff --git a/compiler/testData/codegen/box/closures/closureOnTopLevel1.kt b/compiler/testData/codegen/box/closures/closureOnTopLevel1.kt index 7c4d0ec14c6..701049588fb 100644 --- a/compiler/testData/codegen/box/closures/closureOnTopLevel1.kt +++ b/compiler/testData/codegen/box/closures/closureOnTopLevel1.kt @@ -7,12 +7,14 @@ package test -val p = { "OK" }() +fun eval(lambda: () -> T) = lambda() + +val p = eval { "OK" } val getter: String - get() = { "OK" }() + get() = eval { "OK" } -fun f() = { "OK" }() +fun f() = eval { "OK" } val obj = object : Function0 { override fun invoke() = "OK" diff --git a/compiler/testData/codegen/box/closures/closureOnTopLevel2.kt b/compiler/testData/codegen/box/closures/closureOnTopLevel2.kt index 9d7209bce04..2cca171e17d 100644 --- a/compiler/testData/codegen/box/closures/closureOnTopLevel2.kt +++ b/compiler/testData/codegen/box/closures/closureOnTopLevel2.kt @@ -5,12 +5,14 @@ // TODO: muted automatically, investigate should it be ran for JS or not // IGNORE_BACKEND: JS -val p = { "OK" }() +fun eval(lambda: () -> T) = lambda() + +val p = eval { "OK" } val getter: String - get() = { "OK" }() + get() = eval { "OK" } -fun f() = { "OK" }() +fun f() = eval { "OK" } val obj = object : Function0 { override fun invoke() = "OK" diff --git a/compiler/testData/codegen/box/closures/kt10044.kt b/compiler/testData/codegen/box/closures/kt10044.kt index 277f356c76c..79d5fc7666b 100644 --- a/compiler/testData/codegen/box/closures/kt10044.kt +++ b/compiler/testData/codegen/box/closures/kt10044.kt @@ -12,9 +12,8 @@ class Example : JClass { var result: String? = null init { - { - result = obj?.test() - }() + val lambda = { result = obj?.test() } + lambda() } } @@ -26,9 +25,8 @@ class Example2 : JClass { var result: String? = null init { - { - result = obj?.test() - }() + val lambda = { result = obj?.test() } + lambda() } } diff --git a/compiler/testData/codegen/box/closures/kt4106.kt b/compiler/testData/codegen/box/closures/kt4106.kt index f190819f8d5..e1cc3164b0c 100644 --- a/compiler/testData/codegen/box/closures/kt4106.kt +++ b/compiler/testData/codegen/box/closures/kt4106.kt @@ -1,8 +1,10 @@ +fun eval(fn: () -> T) = fn() + class Foo(private val s: String) { inner class Inner { - private val x = { + private val x = eval { this@Foo.s - }() + } } val f = Inner() diff --git a/compiler/testData/codegen/box/constants/privateConst.kt b/compiler/testData/codegen/box/constants/privateConst.kt index 041cc94e9fd..94cb598b250 100644 --- a/compiler/testData/codegen/box/constants/privateConst.kt +++ b/compiler/testData/codegen/box/constants/privateConst.kt @@ -1,7 +1,7 @@ +fun eval(fn: () -> T) = fn() + private const val z = "OK"; fun box(): String { - return { - z - }() + return eval { z } } \ No newline at end of file diff --git a/compiler/testData/codegen/box/delegatedProperty/local/useReflectionForLocalVarInLambda.kt b/compiler/testData/codegen/box/delegatedProperty/local/useReflectionForLocalVarInLambda.kt index 401c5c786cb..7875568f64a 100644 --- a/compiler/testData/codegen/box/delegatedProperty/local/useReflectionForLocalVarInLambda.kt +++ b/compiler/testData/codegen/box/delegatedProperty/local/useReflectionForLocalVarInLambda.kt @@ -3,12 +3,14 @@ import kotlin.reflect.* +fun eval(fn: () -> T) = fn() + object E operator fun E.getValue(receiver: Any?, property: KProperty<*>): String = if (property.returnType.classifier == String::class) "OK" else "Fail" -fun box(): String = { +fun box(): String = eval { val x: String by E x -}() +} diff --git a/compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt40815.kt b/compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt40815.kt index 270c8d4a208..a03f0005603 100644 --- a/compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt40815.kt +++ b/compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt40815.kt @@ -3,10 +3,8 @@ import kotlin.reflect.KProperty operator fun Int.provideDelegate(thiz: Any?, property: KProperty<*>): String = property.name inline operator fun String.getValue(thiz: Any?, property: KProperty<*>): String = property.name -fun box(): String = with(42) { - val O by this - O -} + { - val K by "" - K -}() +fun eval(fn: () -> T) = fn() + +fun box(): String = + with(42) { val O by this; O } + eval { val K by ""; K } + diff --git a/compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt b/compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt new file mode 100644 index 00000000000..79f36cc3295 --- /dev/null +++ b/compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt @@ -0,0 +1,13 @@ +// IGNORE_BACKEND: WASM +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 Function(^.)*.invoke + +class Outer (val x: String) { + inner class Inner(val y: String) { + val yx = y + x + } +} + +fun box() = + Outer("K")::Inner.invoke("O").yx diff --git a/compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt b/compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt new file mode 100644 index 00000000000..bbf17dbbd9f --- /dev/null +++ b/compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt @@ -0,0 +1,11 @@ +// IGNORE_BACKEND: WASM +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 Function(^.)*.invoke + +class C(val x: String) { + fun foo(s: String) = x + s +} + +fun box() = + C("O")::foo.invoke("K") diff --git a/compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt b/compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt new file mode 100644 index 00000000000..bbf670eb1be --- /dev/null +++ b/compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt @@ -0,0 +1,11 @@ +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 invoke + +fun box(): String { + var ok = "FAILED" + { s: String -> + ok = s + }("OK") + return ok +} diff --git a/compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt b/compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt new file mode 100644 index 00000000000..8cba2f2fc05 --- /dev/null +++ b/compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt @@ -0,0 +1,10 @@ +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 Function(^.)*.invoke + +class C(x: String, y: String) { + val yx = y + x +} + +fun box() = + ::C.invoke("K", "O").yx diff --git a/compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt b/compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt new file mode 100644 index 00000000000..b5d3c0e510b --- /dev/null +++ b/compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt @@ -0,0 +1,12 @@ +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 Function(^.)*.invoke + +fun box() = + { k: String -> + { o: String -> + var ok = o + ok += k + ok + }("O") + }("K") diff --git a/compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt b/compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt new file mode 100644 index 00000000000..d848a3f1acb --- /dev/null +++ b/compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt @@ -0,0 +1,10 @@ +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 Function(^.)*.invoke + +fun box() = + (fun (s: String): String { + var ok = "O" + ok += s + return ok + }).invoke("K") diff --git a/compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt b/compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt new file mode 100644 index 00000000000..5e93e88af0e --- /dev/null +++ b/compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt @@ -0,0 +1,8 @@ +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 Function(^.)*.invoke + +fun ok(s: String) = "O" + s + +fun box() = + ::ok.invoke("K") diff --git a/compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt b/compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt new file mode 100644 index 00000000000..acd0bd104b0 --- /dev/null +++ b/compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt @@ -0,0 +1,10 @@ +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 Function(^.)*.invoke + +fun box() = + { s: String -> + var ok = "O" + ok += s + ok + }.invoke("K") diff --git a/compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt b/compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt new file mode 100644 index 00000000000..91e3013d38d --- /dev/null +++ b/compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt @@ -0,0 +1,12 @@ +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 Function(^.)*.invoke + +class Outer (val x: String) { + inner class Inner(val y: String) { + val yx = y + x + } +} + +fun box() = + (Outer::Inner).invoke(Outer("K"), "O").yx diff --git a/compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt b/compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt new file mode 100644 index 00000000000..ac729cf310c --- /dev/null +++ b/compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt @@ -0,0 +1,2 @@ +fun box(): String = + (String::plus)("O", "K") diff --git a/compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunction2.kt b/compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunction2.kt index 1cf01ce4e21..a6494cb1374 100644 --- a/compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunction2.kt +++ b/compiler/testData/codegen/box/functions/localFunctions/overloadedLocalFunction2.kt @@ -1,3 +1,5 @@ +fun eval(fn: () -> T) = fn() + fun box(): String { var s = "" var foo = "K" @@ -11,10 +13,10 @@ fun box(): String { s += x } - { + eval { foo("O") foo(foo, 1) - }() + } } test() diff --git a/compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/accessPrivateInlineClassMethodFromLambda.kt b/compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/accessPrivateInlineClassMethodFromLambda.kt index a0b031aa46d..c8fe3872c2c 100644 --- a/compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/accessPrivateInlineClassMethodFromLambda.kt +++ b/compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/accessPrivateInlineClassMethodFromLambda.kt @@ -1,7 +1,9 @@ // !LANGUAGE: +InlineClasses +fun eval(fn: () -> T) = fn() + inline class R(private val r: Int) { - fun test() = { ok() }() + fun test() = eval { ok() } private fun ok() = "OK" } diff --git a/compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/lambdaInInlineClassFun.kt b/compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/lambdaInInlineClassFun.kt index 7f9f68de251..5cc3e13e978 100644 --- a/compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/lambdaInInlineClassFun.kt +++ b/compiler/testData/codegen/box/inlineClasses/contextsAndAccessors/lambdaInInlineClassFun.kt @@ -1,7 +1,9 @@ // !LANGUAGE: +InlineClasses +fun eval(fn: () -> T) = fn() + inline class R(private val r: Int) { - fun test() = { "OK" }() + fun test() = eval { "OK" } } fun box() = R(0).test() \ No newline at end of file diff --git a/compiler/testData/codegen/box/inlineClasses/kt28585.kt b/compiler/testData/codegen/box/inlineClasses/kt28585.kt index 2a5795b0e4e..e92376fbe84 100644 --- a/compiler/testData/codegen/box/inlineClasses/kt28585.kt +++ b/compiler/testData/codegen/box/inlineClasses/kt28585.kt @@ -4,17 +4,19 @@ // !LANGUAGE: +InlineClasses // WITH_RUNTIME +fun eval(fn: () -> T) = fn() + fun box(): String { var uint1 = 1u var uint2 = 2u var uint3 = 3u val uintSet = mutableSetOf(uint1) uintSet.add(uint2); - { + eval { uintSet.add(uint3) if (!uintSet.contains(1u)) throw AssertionError() if (!uintSet.contains(2u)) throw AssertionError() if (!uintSet.contains(3u)) throw AssertionError() - }() + } return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/localClassOuterDiffersFromInnerOuter.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/localClassOuterDiffersFromInnerOuter.kt index cf1db10e27c..a0ae2cc84d1 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/localClassOuterDiffersFromInnerOuter.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/localClassOuterDiffersFromInnerOuter.kt @@ -1,13 +1,15 @@ +fun eval(fn: () -> T) = fn() + class A { fun bar(): Any { - return { - { + return eval { + eval { class Local : Inner() { override fun toString() = foo() } Local() - }() - }() + } + } } open inner class Inner diff --git a/compiler/testData/codegen/box/innerNested/superConstructorCall/objectOuterDiffersFromInnerOuter.kt b/compiler/testData/codegen/box/innerNested/superConstructorCall/objectOuterDiffersFromInnerOuter.kt index e6fe2b05cf9..ce9ca159cb1 100644 --- a/compiler/testData/codegen/box/innerNested/superConstructorCall/objectOuterDiffersFromInnerOuter.kt +++ b/compiler/testData/codegen/box/innerNested/superConstructorCall/objectOuterDiffersFromInnerOuter.kt @@ -1,12 +1,14 @@ +fun eval(fn: () -> T) = fn() + class A { fun bar(): Any { - return { - { + return eval { + eval { object : Inner() { override fun toString() = foo() } - }() - }() + } + } } open inner class Inner diff --git a/compiler/testData/codegen/box/invokedynamic/lambdas/bigArityLambda.kt b/compiler/testData/codegen/box/invokedynamic/lambdas/bigArityLambda.kt index 71d42c7785d..561f6426b28 100644 --- a/compiler/testData/codegen/box/invokedynamic/lambdas/bigArityLambda.kt +++ b/compiler/testData/codegen/box/invokedynamic/lambdas/bigArityLambda.kt @@ -5,13 +5,13 @@ // CHECK_BYTECODE_TEXT // JVM_IR_TEMPLATES // 0 java/lang/invoke/LambdaMetafactory\.metafactory -// 1 final class BigArityLambdaKt\$box\$1 +// 1 final class BigArityLambdaKt\$box\$lam\$1 -fun box() = - { p0: String, p1: String, p2: Int, p3: Int, p4: Int, p5: Int, p6: Int, p7: Int, p8: Int, p9: Int, - p10: Int, p11: Int, p12: Int, p13: Int, p14: Int, p15: Int, p16: Int, p17: Int, p18: Int, p19: Int, - p20: Int, p21: Int, p22: Int, p23: Int, p24: Int, p25: Int, p26: Int, p27: Int, p28: Int, p29: Int +fun box(): String { + val lam = { p0: String, p1: String, p2: Int, p3: Int, p4: Int, p5: Int, p6: Int, p7: Int, p8: Int, p9: Int, + p10: Int, p11: Int, p12: Int, p13: Int, p14: Int, p15: Int, p16: Int, p17: Int, p18: Int, p19: Int, + p20: Int, p21: Int, p22: Int, p23: Int, p24: Int, p25: Int, p26: Int, p27: Int, p28: Int, p29: Int -> p0 + p1 - }( - "O", "K", 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 - ) \ No newline at end of file + } + return lam("O", "K", 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29) +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/invokedynamic/lambdas/capturingValue.kt b/compiler/testData/codegen/box/invokedynamic/lambdas/capturingValue.kt index 8170eb9fb1c..704c13d2761 100644 --- a/compiler/testData/codegen/box/invokedynamic/lambdas/capturingValue.kt +++ b/compiler/testData/codegen/box/invokedynamic/lambdas/capturingValue.kt @@ -8,5 +8,6 @@ fun box(): String { val ok = "OK" - return { ok }() + val lam = { ok } + return lam() } diff --git a/compiler/testData/codegen/box/invokedynamic/lambdas/capturingVar.kt b/compiler/testData/codegen/box/invokedynamic/lambdas/capturingVar.kt index eed0926146f..57c1ba8835e 100644 --- a/compiler/testData/codegen/box/invokedynamic/lambdas/capturingVar.kt +++ b/compiler/testData/codegen/box/invokedynamic/lambdas/capturingVar.kt @@ -8,6 +8,7 @@ fun box(): String { var ok = "Failed" - { ok = "OK" }() + val lam = { ok = "OK" } + lam() return ok } diff --git a/compiler/testData/codegen/box/invokedynamic/lambdas/nestedIndyLambdas.kt b/compiler/testData/codegen/box/invokedynamic/lambdas/nestedIndyLambdas.kt index 02b7dc5e986..78deecd64e9 100644 --- a/compiler/testData/codegen/box/invokedynamic/lambdas/nestedIndyLambdas.kt +++ b/compiler/testData/codegen/box/invokedynamic/lambdas/nestedIndyLambdas.kt @@ -6,4 +6,11 @@ // JVM_IR_TEMPLATES // 3 java/lang/invoke/LambdaMetafactory -fun box() = { { "O" }() + { "K" }() }() +fun box(): String { + val lam1 = { + val lamO = { "O" } + val lamK = { "K" } + lamO() + lamK() + } + return lam1() +} diff --git a/compiler/testData/codegen/box/invokedynamic/lambdas/primitiveValueParameters.kt b/compiler/testData/codegen/box/invokedynamic/lambdas/primitiveValueParameters.kt index 90d85fc9d0d..ce6ee9e7ac5 100644 --- a/compiler/testData/codegen/box/invokedynamic/lambdas/primitiveValueParameters.kt +++ b/compiler/testData/codegen/box/invokedynamic/lambdas/primitiveValueParameters.kt @@ -7,7 +7,8 @@ // 1 java/lang/invoke/LambdaMetafactory fun box(): String { - val test = { i: Int -> i + 40 }(2) + val lam = { i: Int -> i + 40 } + val test = lam(2) if (test != 42) return "Failed: test=$test" return "OK" diff --git a/compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt b/compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt index 786456cd70f..2595faf43fc 100644 --- a/compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt +++ b/compiler/testData/codegen/box/invokedynamic/lambdas/simpleIndyLambda.kt @@ -6,4 +6,7 @@ // JVM_IR_TEMPLATES // 1 java/lang/invoke/LambdaMetafactory -fun box() = { "OK" }() +fun box(): String { + val lam = { "OK" } + return lam() +} diff --git a/compiler/testData/codegen/box/invokedynamic/lambdas/voidReturnType.kt b/compiler/testData/codegen/box/invokedynamic/lambdas/voidReturnType.kt index 68d658093be..ea86ddcb65f 100644 --- a/compiler/testData/codegen/box/invokedynamic/lambdas/voidReturnType.kt +++ b/compiler/testData/codegen/box/invokedynamic/lambdas/voidReturnType.kt @@ -9,6 +9,7 @@ var ok = "Failed" fun box(): String { - { ok = "OK" }() + val lam = { ok = "OK" } + lam() return ok } diff --git a/compiler/testData/codegen/box/jvmField/capturePackageFields.kt b/compiler/testData/codegen/box/jvmField/capturePackageFields.kt index 9c5ddfffe9c..03591e82534 100644 --- a/compiler/testData/codegen/box/jvmField/capturePackageFields.kt +++ b/compiler/testData/codegen/box/jvmField/capturePackageFields.kt @@ -5,12 +5,13 @@ @JvmField public val publicField = "1"; @JvmField internal val internalField = "23"; -fun test(): String { - return { - publicField + internalField - }() -} +fun eval(fn: () -> T) = fn() +fun test(): String { + return eval { + publicField + internalField + } +} fun box(): String { return if (test() == "123") return "OK" else "fail" diff --git a/compiler/testData/codegen/box/localClasses/kt2700.kt b/compiler/testData/codegen/box/localClasses/kt2700.kt index 3baacf0b21f..150a047eea3 100644 --- a/compiler/testData/codegen/box/localClasses/kt2700.kt +++ b/compiler/testData/codegen/box/localClasses/kt2700.kt @@ -1,16 +1,16 @@ package a.b +fun eval(fn: () -> T) = fn() + interface Test { fun invoke(): String { return "OK" } } -private val a : Test = { - object : Test { - - } -}() +private val a : Test = eval { + object : Test {} +} fun box(): String { return a.invoke(); diff --git a/compiler/testData/codegen/box/localClasses/localClassInParameterInitializer.kt b/compiler/testData/codegen/box/localClasses/localClassInParameterInitializer.kt index 2b5c62666e6..35e2bd6d06f 100644 --- a/compiler/testData/codegen/box/localClasses/localClassInParameterInitializer.kt +++ b/compiler/testData/codegen/box/localClasses/localClassInParameterInitializer.kt @@ -1,5 +1,7 @@ +fun eval(fn: () -> T) = fn() + class A( - val a: String = { + val a: String = eval { open class B() { open fun s() : String = "O" } @@ -9,7 +11,7 @@ class A( } B().s() + o.s() - }() + } ) fun box() : String { diff --git a/compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromLambdaInNestedClass.kt b/compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromLambdaInNestedClass.kt index 661ab5543be..c2eee11fc67 100644 --- a/compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromLambdaInNestedClass.kt +++ b/compiler/testData/codegen/box/objects/companionObjectAccess/privateCompanionObjectAccessedFromLambdaInNestedClass.kt @@ -1,12 +1,14 @@ // !LANGUAGE: +ProperVisibilityForCompanionObjectInstanceField +fun eval(fn: () -> T) = fn() + class Outer { private companion object { val result = "OK" } class Nested { - fun foo() = { result }() + fun foo() = eval { result } } fun test() = Nested().foo() diff --git a/compiler/testData/codegen/box/objects/privateFunctionFromClosureInInitializer_kt5582.kt b/compiler/testData/codegen/box/objects/privateFunctionFromClosureInInitializer_kt5582.kt index 5b71ab435fe..0f9e302d737 100644 --- a/compiler/testData/codegen/box/objects/privateFunctionFromClosureInInitializer_kt5582.kt +++ b/compiler/testData/codegen/box/objects/privateFunctionFromClosureInInitializer_kt5582.kt @@ -1,12 +1,14 @@ interface T +fun eval(fn: () -> T) = fn() + object Foo { private fun foo(p: T) = p - private val v: Int = { + private val v: Int = eval { val x = foo(O) 42 - }() + } private object O : T diff --git a/compiler/testData/codegen/box/package/privateTopLevelPropAndVarInInner.kt b/compiler/testData/codegen/box/package/privateTopLevelPropAndVarInInner.kt index b61fd243ab9..ceaf63b9cb5 100644 --- a/compiler/testData/codegen/box/package/privateTopLevelPropAndVarInInner.kt +++ b/compiler/testData/codegen/box/package/privateTopLevelPropAndVarInInner.kt @@ -1,4 +1,6 @@ +fun eval(fn: () -> T) = fn() + private var x = "O" private fun f() = "K" -fun box() = { x + f() }() +fun box() = eval { x + f() } diff --git a/compiler/testData/codegen/box/privateConstructors/captured.kt b/compiler/testData/codegen/box/privateConstructors/captured.kt index 83b38054d77..ef17e141f2a 100644 --- a/compiler/testData/codegen/box/privateConstructors/captured.kt +++ b/compiler/testData/codegen/box/privateConstructors/captured.kt @@ -1,7 +1,9 @@ +fun eval(fn: () -> T) = fn() + public open class Outer private constructor(val s: String) { companion object { - fun test () = { Outer("OK") }() + fun test () = eval { Outer("OK") } } } diff --git a/compiler/testData/codegen/box/properties/classFieldInsideLambda.kt b/compiler/testData/codegen/box/properties/classFieldInsideLambda.kt index 121ac3426b4..6e674a98441 100644 --- a/compiler/testData/codegen/box/properties/classFieldInsideLambda.kt +++ b/compiler/testData/codegen/box/properties/classFieldInsideLambda.kt @@ -1,6 +1,8 @@ +fun eval(fn: () -> T) = fn() + class My { val my: String = "O" - get() = { field }() + "K" + get() = eval { field } + "K" } fun box() = My().my \ No newline at end of file diff --git a/compiler/testData/codegen/box/properties/classFieldInsideLocalInSetter.kt b/compiler/testData/codegen/box/properties/classFieldInsideLocalInSetter.kt index e6e1c9f17f4..96ec7d9816b 100644 --- a/compiler/testData/codegen/box/properties/classFieldInsideLocalInSetter.kt +++ b/compiler/testData/codegen/box/properties/classFieldInsideLocalInSetter.kt @@ -1,6 +1,8 @@ +fun eval(fn: () -> T) = fn() + class My { var my: String = "U" - get() = { field }() + get() = eval { field } set(arg) { class Local { fun foo() { diff --git a/compiler/testData/codegen/box/properties/classFieldInsideNestedLambda.kt b/compiler/testData/codegen/box/properties/classFieldInsideNestedLambda.kt index 04ae80f0564..60b9e83d51a 100644 --- a/compiler/testData/codegen/box/properties/classFieldInsideNestedLambda.kt +++ b/compiler/testData/codegen/box/properties/classFieldInsideNestedLambda.kt @@ -1,6 +1,8 @@ +fun eval(fn: () -> T) = fn() + class My { val my: String = "O" - get() = { { field }() }() + "K" + get() = eval { eval { field } } + "K" } fun box() = My().my \ No newline at end of file diff --git a/compiler/testData/codegen/box/properties/classFieldInsideNestedNestedLambda.kt b/compiler/testData/codegen/box/properties/classFieldInsideNestedNestedLambda.kt index 19ed7be9324..f460e7684e7 100644 --- a/compiler/testData/codegen/box/properties/classFieldInsideNestedNestedLambda.kt +++ b/compiler/testData/codegen/box/properties/classFieldInsideNestedNestedLambda.kt @@ -1,6 +1,8 @@ +fun eval(fn: () -> T) = fn() + class My { val my: String = "O" - get() = { { { field }() }() }() + "K" + get() = eval { eval { eval { field } } } + "K" } fun box() = My().my \ No newline at end of file diff --git a/compiler/testData/codegen/box/properties/companionFieldInsideLambda.kt b/compiler/testData/codegen/box/properties/companionFieldInsideLambda.kt index 4e4f60b9df7..1ca14bf93ad 100644 --- a/compiler/testData/codegen/box/properties/companionFieldInsideLambda.kt +++ b/compiler/testData/codegen/box/properties/companionFieldInsideLambda.kt @@ -1,7 +1,9 @@ +fun eval(fn: () -> T) = fn() + class My { companion object { val my: String = "O" - get() = { field }() + "K" + get() = eval { field } + "K" } } diff --git a/compiler/testData/codegen/box/properties/companionPrivateFieldInsideLambda.kt b/compiler/testData/codegen/box/properties/companionPrivateFieldInsideLambda.kt index 7219fcd4d3d..af9c6701e02 100644 --- a/compiler/testData/codegen/box/properties/companionPrivateFieldInsideLambda.kt +++ b/compiler/testData/codegen/box/properties/companionPrivateFieldInsideLambda.kt @@ -1,7 +1,9 @@ +fun eval(fn: () -> T) = fn() + class My { companion object { private val my: String = "O" - get() = { field }() + "K" + get() = eval { field } + "K" fun getValue() = my } diff --git a/compiler/testData/codegen/box/properties/fieldInsideLambda.kt b/compiler/testData/codegen/box/properties/fieldInsideLambda.kt index ebf3cb6cfb7..208ebe4234a 100644 --- a/compiler/testData/codegen/box/properties/fieldInsideLambda.kt +++ b/compiler/testData/codegen/box/properties/fieldInsideLambda.kt @@ -1,4 +1,6 @@ +fun eval(fn: () -> T) = fn() + val my: String = "O" - get() = { field }() + "K" + get() = eval { field } + "K" fun box() = my diff --git a/compiler/testData/codegen/box/properties/kt10729.kt b/compiler/testData/codegen/box/properties/kt10729.kt index 9b0db522f25..9028fae2bfd 100644 --- a/compiler/testData/codegen/box/properties/kt10729.kt +++ b/compiler/testData/codegen/box/properties/kt10729.kt @@ -1,3 +1,5 @@ +fun eval(fn: () -> T) = fn() + class IntentionsBundle { companion object { fun message(key: String): String { @@ -5,7 +7,7 @@ class IntentionsBundle { } fun message2(key: String): String { - return { key + BUNDLE }() + return eval { key + BUNDLE } } private const val BUNDLE = "K" diff --git a/compiler/testData/codegen/box/properties/kt4340.kt b/compiler/testData/codegen/box/properties/kt4340.kt index 63a97eb0f44..8a7573360a2 100644 --- a/compiler/testData/codegen/box/properties/kt4340.kt +++ b/compiler/testData/codegen/box/properties/kt4340.kt @@ -1,3 +1,5 @@ +fun eval(fn: () -> T) = fn() + class A { var result: Int = 0; @@ -12,15 +14,11 @@ class A { } fun test(p: Int):Int { - return { - p.times3 - }() + return eval { p.times3 } } fun test2(p: Int, s: Int):Int { - { - p.times = s - }() + eval { p.times = s } return result } } diff --git a/compiler/testData/codegen/box/properties/kt9603.kt b/compiler/testData/codegen/box/properties/kt9603.kt index ddbabfcc99b..0fe5ad36d88 100644 --- a/compiler/testData/codegen/box/properties/kt9603.kt +++ b/compiler/testData/codegen/box/properties/kt9603.kt @@ -1,10 +1,12 @@ +fun eval(fn: () -> T) = fn() + class A { public var prop = "OK" private set fun test(): String { - return { prop }() + return eval { prop } } } diff --git a/compiler/testData/codegen/box/properties/lateinit/accessorExceptionPublic.kt b/compiler/testData/codegen/box/properties/lateinit/accessorExceptionPublic.kt index b5e2cf5e05a..142f9165e69 100644 --- a/compiler/testData/codegen/box/properties/lateinit/accessorExceptionPublic.kt +++ b/compiler/testData/codegen/box/properties/lateinit/accessorExceptionPublic.kt @@ -1,5 +1,7 @@ // DONT_TARGET_EXACT_BACKEND: WASM // WASM_MUTE_REASON: EXCEPTIONS_NOT_IMPLEMENTED +fun eval(fn: () -> T) = fn() + public class A { fun getFromClass(): Boolean { try { @@ -12,7 +14,7 @@ public class A { fun getFromLambda(): Boolean { try { - val a = { str }() + val a = eval { str } return false } catch (e: RuntimeException) { return true diff --git a/compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/nonInlineLambda.kt b/compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/nonInlineLambda.kt index 7081da4455f..70d39328995 100644 --- a/compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/nonInlineLambda.kt +++ b/compiler/testData/codegen/box/properties/lateinit/isInitializedAndDeinitialize/nonInlineLambda.kt @@ -1,10 +1,12 @@ // WITH_RUNTIME +fun eval(fn: () -> T) = fn() + class Foo { private lateinit var foo: String fun test(): Boolean { - val result = { ::foo.isInitialized }() + val result = eval { ::foo.isInitialized } foo = "" return result } diff --git a/compiler/testData/codegen/box/properties/referenceToJavaFieldViaBridge.kt b/compiler/testData/codegen/box/properties/referenceToJavaFieldViaBridge.kt index a317b22cd9a..54624b659c7 100644 --- a/compiler/testData/codegen/box/properties/referenceToJavaFieldViaBridge.kt +++ b/compiler/testData/codegen/box/properties/referenceToJavaFieldViaBridge.kt @@ -13,9 +13,11 @@ public class D { import test.D +fun eval(fn: () -> T) = fn() + class A : D() { fun a(): String { - return {field!!}() + return eval { field!! } } } diff --git a/compiler/testData/codegen/box/reflection/enclosing/classInLambda.kt b/compiler/testData/codegen/box/reflection/enclosing/classInLambda.kt index 1026c9bafa6..9e31087a5f7 100644 --- a/compiler/testData/codegen/box/reflection/enclosing/classInLambda.kt +++ b/compiler/testData/codegen/box/reflection/enclosing/classInLambda.kt @@ -4,16 +4,18 @@ fun box(): String { - val classInLambda = { + val lambda = { class Z {} Z() - }() + } + + val classInLambda = lambda() val enclosingMethod = classInLambda.javaClass.getEnclosingMethod() if (enclosingMethod?.getName() != "invoke") return "method: $enclosingMethod" val enclosingClass = classInLambda.javaClass.getEnclosingClass()!!.getName() - if (enclosingClass != "ClassInLambdaKt\$box\$classInLambda\$1") return "enclosing class: $enclosingClass" + if (enclosingClass != "ClassInLambdaKt\$box\$lambda\$1") return "enclosing class: $enclosingClass" val declaringClass = classInLambda.javaClass.getDeclaringClass() if (declaringClass != null) return "class has a declaring class" diff --git a/compiler/testData/codegen/box/reflection/enclosing/objectInLambda.kt b/compiler/testData/codegen/box/reflection/enclosing/objectInLambda.kt index bcd8f0773c2..b0f36c241b5 100644 --- a/compiler/testData/codegen/box/reflection/enclosing/objectInLambda.kt +++ b/compiler/testData/codegen/box/reflection/enclosing/objectInLambda.kt @@ -3,16 +3,17 @@ // WITH_REFLECT fun box(): String { - - val objectInLambda = { + val lambda = { object : Any () {} - }() + } + + val objectInLambda = lambda() val enclosingMethod = objectInLambda.javaClass.getEnclosingMethod() if (enclosingMethod?.getName() != "invoke") return "method: $enclosingMethod" val enclosingClass = objectInLambda.javaClass.getEnclosingClass()!!.getName() - if (enclosingClass != "ObjectInLambdaKt\$box\$objectInLambda\$1") return "enclosing class: $enclosingClass" + if (enclosingClass != "ObjectInLambdaKt\$box\$lambda\$1") return "enclosing class: $enclosingClass" val declaringClass = objectInLambda.javaClass.getDeclaringClass() if (declaringClass != null) return "anonymous object has a declaring class" diff --git a/compiler/testData/codegen/box/reflection/properties/localDelegated/inLambda.kt b/compiler/testData/codegen/box/reflection/properties/localDelegated/inLambda.kt index 266206c850f..4fff3162c7e 100644 --- a/compiler/testData/codegen/box/reflection/properties/localDelegated/inLambda.kt +++ b/compiler/testData/codegen/box/reflection/properties/localDelegated/inLambda.kt @@ -2,10 +2,12 @@ // WITH_REFLECT import kotlin.reflect.* +fun eval(fn: () -> T) = fn() + inline operator fun String.getValue(t:Any?, p: KProperty<*>): String = if (p.returnType.classifier == String::class) this else "fail" -fun box() = { +fun box() = eval { val x by "OK" x -}() +} diff --git a/compiler/testData/codegen/box/secondaryConstructors/inlineIntoTwoConstructors.kt b/compiler/testData/codegen/box/secondaryConstructors/inlineIntoTwoConstructors.kt index c76a5666763..3ac99e9cc16 100644 --- a/compiler/testData/codegen/box/secondaryConstructors/inlineIntoTwoConstructors.kt +++ b/compiler/testData/codegen/box/secondaryConstructors/inlineIntoTwoConstructors.kt @@ -1,7 +1,9 @@ inline fun myRun(x: () -> String) = x() +fun eval(fn: () -> T) = fn() + class C { - val x = myRun { { "OK" }() } + val x = myRun { eval { "OK" } } constructor(y: Int) constructor(y: String) diff --git a/compiler/testData/codegen/box/statics/kt8089.kt b/compiler/testData/codegen/box/statics/kt8089.kt index 2fee361d80d..046b894d82e 100644 --- a/compiler/testData/codegen/box/statics/kt8089.kt +++ b/compiler/testData/codegen/box/statics/kt8089.kt @@ -1,3 +1,5 @@ +fun eval(fn: () -> T) = fn() + class C { companion object { private val s: String @@ -17,5 +19,5 @@ class C { } fun box(): String { - return C.foo() + {C.bar2(); C.foo2()}() + return C.foo() + eval { C.bar2(); C.foo2() } } \ No newline at end of file diff --git a/compiler/testData/codegen/box/statics/protectedStatic2.kt b/compiler/testData/codegen/box/statics/protectedStatic2.kt index 5b584a702a4..0627da75319 100644 --- a/compiler/testData/codegen/box/statics/protectedStatic2.kt +++ b/compiler/testData/codegen/box/statics/protectedStatic2.kt @@ -32,24 +32,25 @@ package anotherPackage import Base.Derived import Base +fun eval(fn: () -> T) = fn() + class Kotlin : Base.Derived() { fun doTest(): String { - if ({ TEST }() != "DERIVED") return "fail 1" - if ({ test() }() != "DERIVED") return "fail 2" + if (eval { TEST } != "DERIVED") return "fail 1" + if (eval { test() } != "DERIVED") return "fail 2" - if ({ Derived.TEST }() != "DERIVED") return "fail 3" - if ({ Derived.test() }() != "DERIVED") return "fail 4" + if (eval { Derived.TEST } != "DERIVED") return "fail 3" + if (eval { Derived.test() } != "DERIVED") return "fail 4" - if ({ Base.TEST }() != "BASE") return "fail 5" - if ({ Base.test() }() != "BASE") return "fail 6" + if (eval { Base.TEST } != "BASE") return "fail 5" + if (eval { Base.test() } != "BASE") return "fail 6" + if (eval { Base.BASE_ONLY } != "BASE") return "fail 7" + if (eval { Base.baseOnly() } != "BASE") return "fail 8" - if ({ Base.BASE_ONLY }() != "BASE") return "fail 7" - if ({ Base.baseOnly() }() != "BASE") return "fail 8" - - if ({ BASE_ONLY }() != "BASE") return "fail 9" - if ({ baseOnly() }() != "BASE") return "fail 10" + if (eval { BASE_ONLY } != "BASE") return "fail 9" + if (eval { baseOnly() } != "BASE") return "fail 10" return "OK" } diff --git a/compiler/testData/codegen/box/super/kt4173_3.kt b/compiler/testData/codegen/box/super/kt4173_3.kt index 8c23cf83f28..e737847388d 100644 --- a/compiler/testData/codegen/box/super/kt4173_3.kt +++ b/compiler/testData/codegen/box/super/kt4173_3.kt @@ -1,20 +1,14 @@ -open class C(s: Int) { - fun test() { +fun eval(fn: () -> T) = fn() - } +open class C(s: Int) { + fun test() {} } class B(var x: Int) { fun foo() { - class A(val a: Int) : C({a}()) { - - } + class A(val a: Int) : C(eval { a }) A(11).test() - - - class B(val a: Int) : C(a) { - } - + class B(val a: Int) : C(a) B(11).test() } } diff --git a/compiler/testData/codegen/box/syntheticAccessors/accessorForAbstractProtected.kt b/compiler/testData/codegen/box/syntheticAccessors/accessorForAbstractProtected.kt index d029bbeec6e..e41b839b7e9 100644 --- a/compiler/testData/codegen/box/syntheticAccessors/accessorForAbstractProtected.kt +++ b/compiler/testData/codegen/box/syntheticAccessors/accessorForAbstractProtected.kt @@ -1,8 +1,10 @@ // FILE: 1.kt import a.* +fun eval(fn: () -> T) = fn() + abstract class B : A() { - fun g() = { f() }() + fun g() = eval { f() } } fun box() = object : B() { diff --git a/compiler/testData/codegen/box/syntheticAccessors/kt10047.kt b/compiler/testData/codegen/box/syntheticAccessors/kt10047.kt index 8317ac0f765..f579850e0d1 100644 --- a/compiler/testData/codegen/box/syntheticAccessors/kt10047.kt +++ b/compiler/testData/codegen/box/syntheticAccessors/kt10047.kt @@ -5,13 +5,15 @@ package test2 import test.Actor import test.O2dScriptAction +fun eval(fn: () -> T) = fn() + class CompositeActor : Actor() public open class O2dDialog : O2dScriptAction() { - fun test() = { owner }() + fun test() = eval { owner } - fun test2() = { calc() }() + fun test2() = eval { calc() } } fun box(): String { diff --git a/compiler/testData/codegen/box/syntheticAccessors/kt21258_indirect.kt b/compiler/testData/codegen/box/syntheticAccessors/kt21258_indirect.kt index 951d2ead0c9..1523f9a5f7f 100644 --- a/compiler/testData/codegen/box/syntheticAccessors/kt21258_indirect.kt +++ b/compiler/testData/codegen/box/syntheticAccessors/kt21258_indirect.kt @@ -1,6 +1,8 @@ +fun eval(fn: () -> T) = fn() + class Foo { private val fld: String = "O" - get() = { field }() + "K" + get() = eval { field } + "K" val indirectFldGetter: () -> String = { fld } } diff --git a/compiler/testData/codegen/box/syntheticAccessors/kt21258_simple.kt b/compiler/testData/codegen/box/syntheticAccessors/kt21258_simple.kt index df6d81ce1d2..025fe5dac26 100644 --- a/compiler/testData/codegen/box/syntheticAccessors/kt21258_simple.kt +++ b/compiler/testData/codegen/box/syntheticAccessors/kt21258_simple.kt @@ -1,6 +1,8 @@ +fun eval(fn: () -> T) = fn() + class Foo { private val fld: String = "O" - get() = { field }() + "K" + get() = eval { field } + "K" val indirectFldGetter: () -> String = { fld } diff --git a/compiler/testData/codegen/box/topLevelPrivate/syntheticAccessor.kt b/compiler/testData/codegen/box/topLevelPrivate/syntheticAccessor.kt index 68d402f57bc..f821517ec4d 100644 --- a/compiler/testData/codegen/box/topLevelPrivate/syntheticAccessor.kt +++ b/compiler/testData/codegen/box/topLevelPrivate/syntheticAccessor.kt @@ -1,11 +1,11 @@ package test +fun eval(fn: () -> T) = fn() + private val prop = "O" private fun test() = "K" fun box(): String { - return { - prop + test() - }() + return eval { prop + test() } } \ No newline at end of file diff --git a/compiler/testData/codegen/box/topLevelPrivate/syntheticAccessorInMultiFile.kt b/compiler/testData/codegen/box/topLevelPrivate/syntheticAccessorInMultiFile.kt index c7c72020467..f49bcb735d8 100644 --- a/compiler/testData/codegen/box/topLevelPrivate/syntheticAccessorInMultiFile.kt +++ b/compiler/testData/codegen/box/topLevelPrivate/syntheticAccessorInMultiFile.kt @@ -5,12 +5,12 @@ @file:kotlin.jvm.JvmName("TestKt") package test +fun eval(fn: () -> T) = fn() + private val prop = "O" private fun test() = "K" fun box(): String { - return { - prop + test() - }() + return eval { prop + test() } } diff --git a/compiler/testData/codegen/boxInline/anonymousObject/inlineCallInsideInlineLambda.kt b/compiler/testData/codegen/boxInline/anonymousObject/inlineCallInsideInlineLambda.kt index fb13f42a35a..a175ad844a0 100644 --- a/compiler/testData/codegen/boxInline/anonymousObject/inlineCallInsideInlineLambda.kt +++ b/compiler/testData/codegen/boxInline/anonymousObject/inlineCallInsideInlineLambda.kt @@ -19,16 +19,17 @@ object B { // FILE: 2.kt import test.* +fun eval(f: () -> T) = f() fun box(): String { var z = "fail" B.test2 { - { // regenerated object in inline lambda + eval { // regenerated object in inline lambda A.test { z = "OK" } - }() + } } return z; } diff --git a/compiler/testData/codegen/boxInline/anonymousObject/inlineCallInsideInlineLambda.smap b/compiler/testData/codegen/boxInline/anonymousObject/inlineCallInsideInlineLambda.smap index 61545021938..4fe96468eaa 100644 --- a/compiler/testData/codegen/boxInline/anonymousObject/inlineCallInsideInlineLambda.smap +++ b/compiler/testData/codegen/boxInline/anonymousObject/inlineCallInsideInlineLambda.smap @@ -11,14 +11,14 @@ _2Kt + 2 1.kt test/B *L -1#1,36:1 -15#2,2:37 +1#1,37:1 +15#2,2:38 *S KotlinDebug *F + 1 2.kt _2Kt *L -26#1:37,2 +27#1:38,2 *E SMAP @@ -31,13 +31,13 @@ _2Kt$box$1$1 + 2 1.kt test/A *L -1#1,36:1 -9#2,2:37 +1#1,37:1 +9#2,2:38 *S KotlinDebug *F + 1 2.kt _2Kt$box$1$1 *L -28#1:37,2 +29#1:38,2 *E diff --git a/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambda.kt b/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambda.kt index b53a141a4a5..14ba612fee3 100644 --- a/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambda.kt +++ b/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambda.kt @@ -18,15 +18,17 @@ inline fun test2(s: () -> String): String { import test.* +fun eval(f: () -> T) = f() + fun box(): String { var result = "fail" test { - { + eval { result = test2 { "OK" } - }() + } } return result diff --git a/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambda.smap b/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambda.smap index 5740242bf9c..eee3f1b5ef2 100644 --- a/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambda.smap +++ b/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambda.smap @@ -11,14 +11,14 @@ _2Kt + 2 1.kt test/_1Kt *L -1#1,34:1 -6#2,4:35 +1#1,36:1 +6#2,4:37 *S KotlinDebug *F + 1 2.kt _2Kt *L -24#1:35,4 +26#1:37,4 *E SMAP @@ -31,13 +31,13 @@ _2Kt$box$1$1 + 2 1.kt test/_1Kt *L -1#1,34:1 -12#2,3:35 +1#1,36:1 +12#2,3:37 *S KotlinDebug *F + 1 2.kt _2Kt$box$1$1 *L -26#1:35,3 +28#1:37,3 *E diff --git a/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambdaSameFileInline.kt b/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambdaSameFileInline.kt index df77eecc24d..734480c867d 100644 --- a/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambdaSameFileInline.kt +++ b/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambdaSameFileInline.kt @@ -18,15 +18,17 @@ inline fun test2(s: () -> String): String { return res } +fun eval(f: () -> T) = f() + fun box(): String { var result = "fail" test { - { + eval { result = test2 { "OK" } - }() + } } return result diff --git a/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambdaSameFileInline.smap b/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambdaSameFileInline.smap index 4510273b380..b91f412a440 100644 --- a/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambdaSameFileInline.smap +++ b/compiler/testData/codegen/boxInline/smap/newsmap/mappingInSubInlineLambdaSameFileInline.smap @@ -11,14 +11,14 @@ _2Kt + 2 1.kt test/_1Kt *L -1#1,34:1 -6#2,4:35 +1#1,36:1 +6#2,4:37 *S KotlinDebug *F + 1 2.kt _2Kt *L -24#1:35,4 +26#1:37,4 *E SMAP @@ -31,13 +31,13 @@ _2Kt$box$1$1 + 2 2.kt _2Kt *L -1#1,34:1 -16#2,3:35 +1#1,36:1 +16#2,3:37 *S KotlinDebug *F + 1 2.kt _2Kt$box$1$1 *L -26#1:35,3 +28#1:37,3 *E diff --git a/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage.kt b/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage.kt index 1b4cc64ff53..ee48f566e95 100644 --- a/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage.kt +++ b/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage.kt @@ -1,12 +1,14 @@ // FILE: C.kt package test +fun eval(f: () -> T) = f() + class C: A.B() { // For binary compatibility, two accessibility bridges should be generated in C: // one for A.x and one for A.B.x. // Otherwise, if a static 'x' field is added to A.B either A.x or A.B.x will be ignored. // The JVM backend generates accessibility bridges for setters as well which is not necessary. - fun f() = ({ A.x + x })() + fun f() = eval { A.x + x } // Similarly for static functions. Two bridges should be generated for binary compatibility. fun g() = ({ A.h() + h() }) } diff --git a/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage.txt b/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage.txt index df53b286d3c..6656b17980a 100644 --- a/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage.txt +++ b/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage.txt @@ -37,3 +37,9 @@ public final class test/C { public final @org.jetbrains.annotations.NotNull method f(): java.lang.String public final @org.jetbrains.annotations.NotNull method g(): kotlin.jvm.functions.Function0 } + +@kotlin.Metadata +public final class test/CKt { + // source: 'C.kt' + public final static method eval(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0): java.lang.Object +} diff --git a/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage_ir.txt b/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage_ir.txt index 757bed47689..d73bbae302a 100644 --- a/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage_ir.txt +++ b/compiler/testData/codegen/bytecodeListing/accessorsForProtectedStaticJavaFieldInOtherPackage_ir.txt @@ -35,3 +35,9 @@ public final class test/C { public final @org.jetbrains.annotations.NotNull method f(): java.lang.String public final @org.jetbrains.annotations.NotNull method g(): kotlin.jvm.functions.Function0 } + +@kotlin.Metadata +public final class test/CKt { + // source: 'C.kt' + public final static method eval(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0): java.lang.Object +} diff --git a/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259.kt b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259.kt index 656a3d40c7b..772e6e5d175 100644 --- a/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259.kt +++ b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259.kt @@ -10,17 +10,19 @@ inline fun test(s: () -> Unit) { import test.* +fun eval(f: () -> T) = f() + fun box() { var s1 = "" var s2 = "" test { - { + eval { val p = object {} s1 = p.toString(); - { + eval { val q = object {} s2 = q.toString() - }() - }() + } + } } } diff --git a/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259.txt b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259.txt index a3c15ddbfcf..de4170a0e13 100644 --- a/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259.txt +++ b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259.txt @@ -48,6 +48,7 @@ final class _2Kt$box$$inlined$test$lambda$1 { public final class _2Kt { // source: '2.kt' public final static method box(): void + public final static method eval(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0): java.lang.Object } @kotlin.Metadata diff --git a/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259_ir.txt b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259_ir.txt index 5f093f069c8..e7372a0a149 100644 --- a/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259_ir.txt +++ b/compiler/testData/codegen/bytecodeListing/inline/enclosingInfo/kt10259_ir.txt @@ -49,6 +49,7 @@ public final class _2Kt { // source: '2.kt' inner (anonymous) class _2Kt$box$1$1 public final static method box(): void + public final static method eval(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function0): java.lang.Object } @kotlin.Metadata diff --git a/compiler/testData/codegen/bytecodeText/constClosureOptimization.kt b/compiler/testData/codegen/bytecodeText/constClosureOptimization.kt index c8e3a272503..3c8d43cec05 100644 --- a/compiler/testData/codegen/bytecodeText/constClosureOptimization.kt +++ b/compiler/testData/codegen/bytecodeText/constClosureOptimization.kt @@ -1,28 +1,31 @@ fun test() { fun local(){ - { + val lam = { //static instance access local() - }() + } + lam() } //static instance access - { + val lam = { //static instance access local() - }() + } + lam() //static instance access - (::local)() + val cr = ::local + cr() } // JVM_TEMPLATES // 3 GETSTATIC ConstClosureOptimizationKt\$test\$1\.INSTANCE -// 1 GETSTATIC ConstClosureOptimizationKt\$test\$2\.INSTANCE -// 1 GETSTATIC ConstClosureOptimizationKt\$test\$3\.INSTANCE +// 1 GETSTATIC ConstClosureOptimizationKt\$test\$lam\$1\.INSTANCE +// 1 GETSTATIC ConstClosureOptimizationKt\$test\$cr\$1\.INSTANCE // JVM_IR_TEMPLATES -// 1 GETSTATIC ConstClosureOptimizationKt\$test\$1.INSTANCE -// 1 GETSTATIC ConstClosureOptimizationKt\$test\$2.INSTANCE -// 1 GETSTATIC ConstClosureOptimizationKt\$test\$local\$1.INSTANCE \ No newline at end of file +// 1 GETSTATIC ConstClosureOptimizationKt\$test\$cr\$1.INSTANCE +// 1 GETSTATIC ConstClosureOptimizationKt\$test\$lam\$1.INSTANCE +// 1 GETSTATIC ConstClosureOptimizationKt\$test\$local\$lam\$1.INSTANCE diff --git a/compiler/testData/codegen/bytecodeText/directInvoke/callableReference.kt b/compiler/testData/codegen/bytecodeText/directInvoke/callableReference.kt index dd9fd0af1bd..bfd45710ee6 100644 --- a/compiler/testData/codegen/bytecodeText/directInvoke/callableReference.kt +++ b/compiler/testData/codegen/bytecodeText/directInvoke/callableReference.kt @@ -3,7 +3,8 @@ class Z{ fun a(s: Int) {} fun b() { - (Z::a)(Z(), 1) + val cr = (Z::a) + cr(Z(), 1) } } diff --git a/compiler/testData/codegen/bytecodeText/directInvoke/inplaceClosure.kt b/compiler/testData/codegen/bytecodeText/directInvoke/inplaceClosure.kt index 797dd1e360f..47cd5c5cac7 100644 --- a/compiler/testData/codegen/bytecodeText/directInvoke/inplaceClosure.kt +++ b/compiler/testData/codegen/bytecodeText/directInvoke/inplaceClosure.kt @@ -1,6 +1,6 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun test() { - 1.(fun Int.() = 2)() + val fn = fun Int.() = 2 + 1.fn() } // 1 invoke \(I\)I \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inline/deleteClassOnTransformation.kt b/compiler/testData/codegen/bytecodeText/inline/deleteClassOnTransformation.kt index ab29ce72152..680d4180464 100644 --- a/compiler/testData/codegen/bytecodeText/inline/deleteClassOnTransformation.kt +++ b/compiler/testData/codegen/bytecodeText/inline/deleteClassOnTransformation.kt @@ -1,6 +1,7 @@ fun test() { { - {}() + val lam = {} + lam() }() } @@ -11,16 +12,19 @@ inline fun ifun(s: () -> Unit) { fun test2() { var z = 1; ifun { - { z = 2 }() + val lam = { z = 2 } + lam() } } -// 1 class DeleteClassOnTransformationKt\$test\$1\$1 // JVM_TEMPLATES: +// 1 class DeleteClassOnTransformationKt\$test\$1 extends +// 1 class DeleteClassOnTransformationKt\$test\$1\$lam\$1 extends // 0 class DeleteClassOnTransformationKt\$test2\$1\$1 // 1 class DeleteClassOnTransformationKt\$test2\$\$inlined\$ifun\$lambda\$1 // JVM_IR_TEMPLATES: -// 1 class DeleteClassOnTransformationKt\$test2\$1\$1 -// 0 class DeleteClassOnTransformationKt\$test2\$\$inlined +// 3 final class +// 1 class DeleteClassOnTransformationKt\$test\$1\$lam\$1 +// 1 class DeleteClassOnTransformationKt\$test2\$1\$lam\$1 diff --git a/compiler/testData/codegen/bytecodeText/invokedynamic/lambdas.kt b/compiler/testData/codegen/bytecodeText/invokedynamic/lambdas.kt index 847147f71c3..7ebecfe7dd8 100644 --- a/compiler/testData/codegen/bytecodeText/invokedynamic/lambdas.kt +++ b/compiler/testData/codegen/bytecodeText/invokedynamic/lambdas.kt @@ -3,7 +3,14 @@ // JVM_TARGET: 1.8 // LAMBDAS: INDY -fun test() = { { "O" }() + { "K" }() }() +fun test(): String { + val lam = { + val lamO = { "O" } + val lamK = { "K" } + lamO() + lamK() + } + return lam() +} // JVM_IR_TEMPLATES // 3 INVOKEDYNAMIC diff --git a/compiler/testData/codegen/bytecodeText/kt10259.kt b/compiler/testData/codegen/bytecodeText/kt10259.kt index 0f18e54a4f7..4ee2690ed4d 100644 --- a/compiler/testData/codegen/bytecodeText/kt10259.kt +++ b/compiler/testData/codegen/bytecodeText/kt10259.kt @@ -2,12 +2,12 @@ fun box(): String { var encl1 = "fail" var encl2 = "fail" test { - { + val lam1 = { encl1 = "OK" - { - encl2 = "OK" - }() - }() + val lam2 = { encl2 = "OK" } + lam2() + } + lam1() } return "OK" @@ -28,7 +28,5 @@ inline fun test(s: () -> Unit) { // JVM_IR_TEMPLATES // 5 INNERCLASS -// 3 INNERCLASS Kt10259Kt\$box\$1\$1\s -// 2 INNERCLASS Kt10259Kt\$box\$1\$1\$1 -// 1 class Kt10259Kt\$box\$1\$1\ extends -// 1 class Kt10259Kt\$box\$1\$1\$1 extends \ No newline at end of file +// 3 INNERCLASS Kt10259Kt\$box\$1\$lam1\$1 null null +// 2 INNERCLASS Kt10259Kt\$box\$1\$lam1\$1\$lam2\$1 diff --git a/compiler/testData/codegen/bytecodeText/kt10259_3.kt b/compiler/testData/codegen/bytecodeText/kt10259_3.kt index 5eade375019..b765e567015 100644 --- a/compiler/testData/codegen/bytecodeText/kt10259_3.kt +++ b/compiler/testData/codegen/bytecodeText/kt10259_3.kt @@ -1,11 +1,11 @@ fun box(): String { var encl1 = "fail"; test { - { - { - encl1 = "OK" - }() - }() + val lam1 = { + val lam2 = { encl1 = "OK" } + lam2() + } + lam1() } return encl1 @@ -31,7 +31,7 @@ inline fun test(crossinline s: () -> Unit) { // 2 INNERCLASS Kt10259_3Kt\$box\$\$inlined\$test\$1\$1\$lambda\$1\$1\s // NB JVM_IR generates -// final static INNERCLASS Kt10259_3Kt$box$1$1 null null +// final static INNERCLASS Kt10259_3Kt$box$1$lam1$1 null null // public final static INNERCLASS Kt10259_3Kt$test$1 null null // in Kt10259_3Kt. // Although Oracle JVM doesn't check for consistency of InnerClasses attributes, @@ -39,7 +39,10 @@ inline fun test(crossinline s: () -> Unit) { // JVM_IR_TEMPLATES // 14 INNERCLASS -// 3 INNERCLASS Kt10259_3Kt\$box\$1\$1\s -// 2 INNERCLASS Kt10259_3Kt\$box\$1\$1\$1\s -// 3 INNERCLASS Kt10259_3Kt\$test\$1\s -// 2 INNERCLASS Kt10259_3Kt\$test\$1\$1\s +// 3 INNERCLASS Kt10259_3Kt\$box\$1\$lam1\$1 null null +// 2 INNERCLASS Kt10259_3Kt\$box\$1\$lam1\$1\$lam2\$1 null null +// 2 INNERCLASS Kt10259_3Kt\$box\$\$inlined\$test\$1 null null +// 2 INNERCLASS Kt10259_3Kt\$box\$\$inlined\$test\$1\$1 null null +// 3 INNERCLASS Kt10259_3Kt\$test\$1 null null +// 2 INNERCLASS Kt10259_3Kt\$test\$1\$1 null null + diff --git a/compiler/testData/debug/stepping/anonymousFunction.kt b/compiler/testData/debug/stepping/anonymousFunction.kt index f8770c87f79..e60811a00ad 100644 --- a/compiler/testData/debug/stepping/anonymousFunction.kt +++ b/compiler/testData/debug/stepping/anonymousFunction.kt @@ -1,13 +1,17 @@ // FILE: test.kt +fun eval(f: () -> T) = f() + fun box() { - { + eval { "OK" - }() + } } // LINENUMBERS -// test.kt:4 box -// test.kt:5 invoke -// test.kt:4 box -// test.kt:7 box \ No newline at end of file +// test.kt:6 box +// test.kt:3 eval +// test.kt:7 invoke +// test.kt:3 eval +// test.kt:6 box +// test.kt:9 box \ No newline at end of file diff --git a/compiler/testData/debug/stepping/anonymousFunctionDirect.kt b/compiler/testData/debug/stepping/anonymousFunctionDirect.kt new file mode 100644 index 00000000000..7bf460b8864 --- /dev/null +++ b/compiler/testData/debug/stepping/anonymousFunctionDirect.kt @@ -0,0 +1,17 @@ +// FILE: test.kt + +fun box() { + { + "OK" + }() +} + +// LINENUMBERS +// test.kt:4 box +// LINENUMBERS JVM +// test.kt:5 invoke +// LINENUMBERS JVM_IR +// test.kt:5 box$lambda-0 +// LINENUMBERS +// test.kt:4 box +// test.kt:7 box diff --git a/compiler/testData/writeFlags/protectedAccessToBaseMethodDifferentPackage.kt b/compiler/testData/writeFlags/protectedAccessToBaseMethodDifferentPackage.kt index 7c8ce2414dc..d94eb597a6c 100644 --- a/compiler/testData/writeFlags/protectedAccessToBaseMethodDifferentPackage.kt +++ b/compiler/testData/writeFlags/protectedAccessToBaseMethodDifferentPackage.kt @@ -20,10 +20,12 @@ package differentPackage; import Base.Derived import Base +fun eval(f: () -> T) = f() + class Kotlin : Base.Derived() { fun doTest(): String { - if ({ Base.baseOnly() }() != "BASE") return "fail 8" - if ({ baseOnly() }() != "BASE") return "fail 10" + if (eval { Base.baseOnly() } != "BASE") return "fail 8" + if (eval { baseOnly() } != "BASE") return "fail 10" return "FAIL" } } 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 b4f7a10b741..c8c8c628312 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 @@ -14171,6 +14171,76 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @Nested + @TestMetadata("compiler/testData/codegen/box/directInvokeOptimization") + @TestDataPath("$PROJECT_ROOT") + public class DirectInvokeOptimization { + @Test + public void testAllFilesPresentInDirectInvokeOptimization() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/directInvokeOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @Test + @TestMetadata("boundInnerContructorRef.kt") + public void testBoundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt"); + } + + @Test + @TestMetadata("boundMemberRef.kt") + public void testBoundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt"); + } + + @Test + @TestMetadata("capturingLambda.kt") + public void testCapturingLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt"); + } + + @Test + @TestMetadata("contructorRef.kt") + public void testContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt"); + } + + @Test + @TestMetadata("nestedLambdas.kt") + public void testNestedLambdas() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt"); + } + + @Test + @TestMetadata("simpleAnonymousFun.kt") + public void testSimpleAnonymousFun() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt"); + } + + @Test + @TestMetadata("simpleFunRef.kt") + public void testSimpleFunRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt"); + } + + @Test + @TestMetadata("simpleLambda.kt") + public void testSimpleLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt"); + } + + @Test + @TestMetadata("unboundInnerContructorRef.kt") + public void testUnboundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt"); + } + + @Test + @TestMetadata("unboundMemberRef.kt") + public void testUnboundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/elvis") @TestDataPath("$PROJECT_ROOT") 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 68da2942479..e761322c7dd 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 @@ -14171,6 +14171,76 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @Nested + @TestMetadata("compiler/testData/codegen/box/directInvokeOptimization") + @TestDataPath("$PROJECT_ROOT") + public class DirectInvokeOptimization { + @Test + public void testAllFilesPresentInDirectInvokeOptimization() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/directInvokeOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("boundInnerContructorRef.kt") + public void testBoundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt"); + } + + @Test + @TestMetadata("boundMemberRef.kt") + public void testBoundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt"); + } + + @Test + @TestMetadata("capturingLambda.kt") + public void testCapturingLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt"); + } + + @Test + @TestMetadata("contructorRef.kt") + public void testContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt"); + } + + @Test + @TestMetadata("nestedLambdas.kt") + public void testNestedLambdas() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt"); + } + + @Test + @TestMetadata("simpleAnonymousFun.kt") + public void testSimpleAnonymousFun() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt"); + } + + @Test + @TestMetadata("simpleFunRef.kt") + public void testSimpleFunRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt"); + } + + @Test + @TestMetadata("simpleLambda.kt") + public void testSimpleLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt"); + } + + @Test + @TestMetadata("unboundInnerContructorRef.kt") + public void testUnboundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt"); + } + + @Test + @TestMetadata("unboundMemberRef.kt") + public void testUnboundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/elvis") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/asJava/LightClassTestCommon.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/asJava/LightClassTestCommon.kt index 793a18d2fc5..c399890e90a 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/asJava/LightClassTestCommon.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/asJava/LightClassTestCommon.kt @@ -8,9 +8,7 @@ package org.jetbrains.kotlin.asJava import com.intellij.openapi.util.io.FileUtil import com.intellij.psi.PsiClass import junit.framework.TestCase -import org.jetbrains.kotlin.asJava.PsiClassRenderer.renderClass import org.jetbrains.kotlin.asJava.classes.KtLightClass -import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File import java.util.regex.Pattern @@ -22,6 +20,7 @@ object LightClassTestCommon { testDataFile: File, findLightClass: (String) -> PsiClass?, normalizeText: (String) -> String, + membersFilter: PsiClassRenderer.MembersFilter = PsiClassRenderer.MembersFilter.DEFAULT ): String { val text = FileUtil.loadFile(testDataFile, true) val matcher = SUBJECT_FQ_NAME_PATTERN.matcher(text) @@ -30,15 +29,20 @@ object LightClassTestCommon { val lightClass = findLightClass(fqName) - return actualText(fqName, lightClass, normalizeText) + return actualText(fqName, lightClass, normalizeText, membersFilter) } - private fun actualText(fqName: String?, lightClass: PsiClass?, normalizeText: (String) -> String): String { + private fun actualText( + fqName: String?, + lightClass: PsiClass?, + normalizeText: (String) -> String, + membersFilter: PsiClassRenderer.MembersFilter + ): String { if (lightClass == null) { return NOT_GENERATED_DIRECTIVE } TestCase.assertTrue("Not a light class: $lightClass ($fqName)", lightClass is KtLightClass) - return normalizeText(lightClass.renderClass(renderInner = true)) + return normalizeText(PsiClassRenderer.renderClass(lightClass, renderInner = true, membersFilter = membersFilter)) } // Actual text for light class is generated with ClsElementImpl.appendMirrorText() that can find empty DefaultImpl inner class in stubs diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/asJava/PsiClassRenderer.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/asJava/PsiClassRenderer.kt index 4c24f54b13f..4078199f396 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/asJava/PsiClassRenderer.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/asJava/PsiClassRenderer.kt @@ -14,11 +14,67 @@ import org.jetbrains.kotlin.load.kotlin.NON_EXISTENT_CLASS_NAME import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name +fun PsiClass.renderClass() = PsiClassRenderer.renderClass(this) -object PsiClassRenderer { +class PsiClassRenderer private constructor( + private val renderInner: Boolean, + private val membersFilter: MembersFilter +) { - var extendedTypeRenderer = false + interface MembersFilter { + fun includeEnumConstant(psiEnumConstant: PsiEnumConstant): Boolean = true + fun includeField(psiField: PsiField): Boolean = true + fun includeMethod(psiMethod: PsiMethod): Boolean = true + fun includeClass(psiClass: PsiClass): Boolean = true + + companion object { + val DEFAULT = object : MembersFilter {} + } + } + + companion object { + var extendedTypeRenderer = false + + fun renderClass( + psiClass: PsiClass, + renderInner: Boolean = false, + membersFilter: MembersFilter = MembersFilter.DEFAULT + ): String = + PsiClassRenderer(renderInner, membersFilter).renderClass(psiClass) + } + + private fun renderClass(psiClass: PsiClass): String = + buildString { + val classWord = when { + psiClass.isAnnotationType -> "@interface" + psiClass.isInterface -> "interface" + psiClass.isEnum -> "enum" + else -> "class" + } + + append(psiClass.renderModifiers()) + append("$classWord ") + append("${psiClass.name} /* ${psiClass.qualifiedName}*/") + append(psiClass.typeParameters.renderTypeParams()) + append(psiClass.extendsList.renderRefList("extends")) + append(psiClass.implementsList.renderRefList("implements")) + appendLine(" {") + + if (psiClass.isEnum) { + append( + psiClass.fields + .filterIsInstance() + .filter { membersFilter.includeEnumConstant(it) } + .joinToString(",\n") { it.renderEnumConstant() }.prependDefaultIndent() + ) + append(";\n\n") + } + + append(psiClass.renderMembers()) + + append("}") + } private fun PsiType.renderType() = StringBuffer().also { renderType(it) }.toString() private fun PsiType.renderType(sb: StringBuffer) { @@ -126,69 +182,41 @@ object PsiClassRenderer { return "$typeParams $name$paramTypes" } - private fun PsiEnumConstant.renderEnumConstant(renderInner: Boolean): String { + private fun PsiEnumConstant.renderEnumConstant(): String { val initializingClass = initializingClass ?: return name return buildString { appendLine("$name {") - append(initializingClass.renderMembers(renderInner)) + append(initializingClass.renderMembers()) append("}") } } - fun PsiClass.renderClass(renderInner: Boolean = false): String { - val classWord = when { - isAnnotationType -> "@interface" - isInterface -> "interface" - isEnum -> "enum" - else -> "class" - } - - return buildString { - append(renderModifiers()) - append("$classWord ") - append("$name /* $qualifiedName*/") - append(typeParameters.renderTypeParams()) - append(extendsList.renderRefList("extends")) - append(implementsList.renderRefList("implements")) - appendLine(" {") - - if (isEnum) { - append( - fields - .filterIsInstance() - .joinToString(",\n") { it.renderEnumConstant(renderInner) }.prependDefaultIndent() - ) - append(";\n\n") - } - - append(renderMembers(renderInner)) - - append("}") - } - } - - private fun PsiClass.renderMembers(renderInner: Boolean): String { + private fun PsiClass.renderMembers(): String { return buildString { appendSorted( fields .filterNot { it is PsiEnumConstant } + .filter { membersFilter.includeField(it) } .map { it.renderVar().prependDefaultIndent() + ";\n\n" } ) appendSorted( methods + .filter { membersFilter.includeMethod(it) } .map { it.renderMethod().prependDefaultIndent() + "\n\n" } ) appendSorted( - innerClasses.map { - appendLine() - if (renderInner) - it.renderClass(renderInner) - else - "class ${it.name} ...\n\n".prependDefaultIndent() - } + innerClasses + .filter { membersFilter.includeClass(it) } + .map { + appendLine() + if (renderInner) + renderClass(it, renderInner) + else + "class ${it.name} ...\n\n".prependDefaultIndent() + } ) } } diff --git a/compiler/tests-gen/org/jetbrains/kotlin/asJava/CompilerLightClassTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/asJava/CompilerLightClassTestGenerated.java index d4cd77b162d..69663d70ac3 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/asJava/CompilerLightClassTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/asJava/CompilerLightClassTestGenerated.java @@ -124,6 +124,11 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT runTest("compiler/testData/asJava/lightClasses/JvmStatic.kt"); } + @TestMetadata("LocalFunctions.kt") + public void testLocalFunctions() throws Exception { + runTest("compiler/testData/asJava/lightClasses/LocalFunctions.kt"); + } + @TestMetadata("NestedObjects.kt") public void testNestedObjects() throws Exception { runTest("compiler/testData/asJava/lightClasses/NestedObjects.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 1e37a84f80a..34055dd8169 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -11584,6 +11584,69 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/directInvokeOptimization") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class DirectInvokeOptimization extends AbstractLightAnalysisModeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInDirectInvokeOptimization() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/directInvokeOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("boundInnerContructorRef.kt") + public void testBoundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt"); + } + + @TestMetadata("boundMemberRef.kt") + public void testBoundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt"); + } + + @TestMetadata("capturingLambda.kt") + public void testCapturingLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt"); + } + + @TestMetadata("contructorRef.kt") + public void testContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt"); + } + + @TestMetadata("nestedLambdas.kt") + public void testNestedLambdas() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt"); + } + + @TestMetadata("simpleAnonymousFun.kt") + public void testSimpleAnonymousFun() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt"); + } + + @TestMetadata("simpleFunRef.kt") + public void testSimpleFunRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt"); + } + + @TestMetadata("simpleLambda.kt") + public void testSimpleLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt"); + } + + @TestMetadata("unboundInnerContructorRef.kt") + public void testUnboundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt"); + } + + @TestMetadata("unboundMemberRef.kt") + public void testUnboundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/elvis") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java index 67733e9ebee..65c004e5b29 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/IrSteppingTestGenerated.java @@ -38,6 +38,12 @@ public class IrSteppingTestGenerated extends AbstractIrSteppingTest { runTest("compiler/testData/debug/stepping/anonymousFunction.kt"); } + @Test + @TestMetadata("anonymousFunctionDirect.kt") + public void testAnonymousFunctionDirect() throws Exception { + runTest("compiler/testData/debug/stepping/anonymousFunctionDirect.kt"); + } + @Test @TestMetadata("assertion.kt") public void testAssertion() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java index a720f285ea7..50ca7426b44 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/debugInformation/SteppingTestGenerated.java @@ -38,6 +38,12 @@ public class SteppingTestGenerated extends AbstractSteppingTest { runTest("compiler/testData/debug/stepping/anonymousFunction.kt"); } + @Test + @TestMetadata("anonymousFunctionDirect.kt") + public void testAnonymousFunctionDirect() throws Exception { + runTest("compiler/testData/debug/stepping/anonymousFunctionDirect.kt"); + } + @Test @TestMetadata("assertion.kt") public void testAssertion() throws Exception { diff --git a/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/FirLightClassTestGenerated.java b/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/FirLightClassTestGenerated.java index b71f544de78..ae75c171ff4 100644 --- a/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/FirLightClassTestGenerated.java +++ b/idea/idea-fir/tests/org/jetbrains/kotlin/asJava/classes/FirLightClassTestGenerated.java @@ -124,6 +124,11 @@ public class FirLightClassTestGenerated extends AbstractFirLightClassTest { runTest("compiler/testData/asJava/lightClasses/JvmStatic.kt"); } + @TestMetadata("LocalFunctions.kt") + public void testLocalFunctions() throws Exception { + runTest("compiler/testData/asJava/lightClasses/LocalFunctions.kt"); + } + @TestMetadata("NestedObjects.kt") public void testNestedObjects() throws Exception { runTest("compiler/testData/asJava/lightClasses/NestedObjects.kt"); diff --git a/idea/tests/org/jetbrains/kotlin/asJava/classes/AbstractUltraLightClassLoadingTest.kt b/idea/tests/org/jetbrains/kotlin/asJava/classes/AbstractUltraLightClassLoadingTest.kt index fb050f385a8..dbf55d022d9 100644 --- a/idea/tests/org/jetbrains/kotlin/asJava/classes/AbstractUltraLightClassLoadingTest.kt +++ b/idea/tests/org/jetbrains/kotlin/asJava/classes/AbstractUltraLightClassLoadingTest.kt @@ -7,8 +7,6 @@ package org.jetbrains.kotlin.asJava.classes import com.intellij.testFramework.LightProjectDescriptor import org.jetbrains.kotlin.asJava.LightClassGenerationSupport -import org.jetbrains.kotlin.asJava.PsiClassRenderer -import org.jetbrains.kotlin.asJava.PsiClassRenderer.renderClass import org.jetbrains.kotlin.idea.perf.UltraLightChecker import org.jetbrains.kotlin.idea.perf.UltraLightChecker.checkByJavaFile import org.jetbrains.kotlin.idea.perf.UltraLightChecker.checkDescriptorsLeak @@ -17,7 +15,6 @@ import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescrip import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.InTextDirectivesUtils -import org.jetbrains.kotlin.test.KotlinTestUtils import java.io.File abstract class AbstractUltraLightClassLoadingTest : KotlinLightCodeInsightFixtureTestCase() { diff --git a/idea/tests/org/jetbrains/kotlin/asJava/classes/AbstractUltraLightScriptLoadingTest.kt b/idea/tests/org/jetbrains/kotlin/asJava/classes/AbstractUltraLightScriptLoadingTest.kt index 85bcf00d4c6..5f6f13d22f3 100644 --- a/idea/tests/org/jetbrains/kotlin/asJava/classes/AbstractUltraLightScriptLoadingTest.kt +++ b/idea/tests/org/jetbrains/kotlin/asJava/classes/AbstractUltraLightScriptLoadingTest.kt @@ -8,7 +8,7 @@ package org.jetbrains.kotlin.asJava.classes import com.intellij.testFramework.LightProjectDescriptor import junit.framework.TestCase import org.jetbrains.kotlin.asJava.LightClassGenerationSupport -import org.jetbrains.kotlin.asJava.PsiClassRenderer.renderClass +import org.jetbrains.kotlin.asJava.renderClass import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager import org.jetbrains.kotlin.idea.perf.UltraLightChecker import org.jetbrains.kotlin.idea.perf.UltraLightChecker.checkDescriptorsLeak @@ -16,7 +16,6 @@ import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.KotlinTestUtils -import org.junit.Assert import java.io.File abstract class AbstractUltraLightScriptLoadingTest : KotlinLightCodeInsightFixtureTestCase() { diff --git a/idea/tests/org/jetbrains/kotlin/asJava/classes/UltraLightClassSanityTestGenerated.java b/idea/tests/org/jetbrains/kotlin/asJava/classes/UltraLightClassSanityTestGenerated.java index b21d568ccae..91667c480ca 100644 --- a/idea/tests/org/jetbrains/kotlin/asJava/classes/UltraLightClassSanityTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/asJava/classes/UltraLightClassSanityTestGenerated.java @@ -124,6 +124,11 @@ public class UltraLightClassSanityTestGenerated extends AbstractUltraLightClassS runTest("compiler/testData/asJava/lightClasses/JvmStatic.kt"); } + @TestMetadata("LocalFunctions.kt") + public void testLocalFunctions() throws Exception { + runTest("compiler/testData/asJava/lightClasses/LocalFunctions.kt"); + } + @TestMetadata("NestedObjects.kt") public void testNestedObjects() throws Exception { runTest("compiler/testData/asJava/lightClasses/NestedObjects.kt"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt index fb29c585dd8..85f9c4c8826 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt @@ -15,6 +15,7 @@ import com.intellij.psi.util.PsiTreeUtil import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.Nullable import org.jetbrains.kotlin.asJava.LightClassTestCommon +import org.jetbrains.kotlin.asJava.PsiClassRenderer import org.jetbrains.kotlin.asJava.builder.LightClassConstructionContext import org.jetbrains.kotlin.asJava.builder.StubComputationTracker import org.jetbrains.kotlin.asJava.classes.KtLightClass @@ -126,20 +127,48 @@ abstract class AbstractIdeCompiledLightClassTest : KotlinDaemonAnalyzerTestCase( fun doTest(testDataPath: String) { val testDataFile = File(testDataPath) - val expectedFile = KotlinTestUtils.replaceExtension( - testDataFile, "compiled.java" - ).let { if (it.exists()) it else KotlinTestUtils.replaceExtension(testDataFile, "java") } + val expectedFile = KotlinTestUtils.replaceExtension(testDataFile, "compiled.java").let { + if (it.exists()) it else KotlinTestUtils.replaceExtension(testDataFile, "java") + } withCustomCompilerOptions(testDataFile.readText(), project, module) { - testLightClass(expectedFile, testDataFile, { it }, { - findClass(it, null, project)?.apply { - PsiElementChecker.checkPsiElementStructure(this) - } - }) + testLightClass( + expectedFile, + testDataFile, + { it }, + { + findClass(it, null, project)?.apply { + PsiElementChecker.checkPsiElementStructure(this) + } + }, + MembersFilterForCompiledClasses + ) + } + } + + private object MembersFilterForCompiledClasses : PsiClassRenderer.MembersFilter { + override fun includeMethod(psiMethod: PsiMethod): Boolean { + // Exclude methods for local functions. + // JVM_IR generates local functions (and some lambdas) as private methods in the surrounding class. + // Such methods are private and have names such as 'foo$...'. + // They are not a part of the public API, and are not represented in the light classes. + // NB this is a heuristic, and it will obviously fail for declarations such as 'private fun `foo$bar`() {}'. + // However, it allows writing code in more or less "idiomatic" style in the light class tests + // without thinking about private ABI and compiler optimizations. + if (psiMethod.modifierList.hasExplicitModifier(PsiModifier.PRIVATE)) { + return '$' !in psiMethod.name + } + return super.includeMethod(psiMethod) } } } -private fun testLightClass(expected: File, testData: File, normalize: (String) -> String, findLightClass: (String) -> PsiClass?) { +private fun testLightClass( + expected: File, + testData: File, + normalize: (String) -> String, + findLightClass: (String) -> PsiClass?, + membersFilter: PsiClassRenderer.MembersFilter = PsiClassRenderer.MembersFilter.DEFAULT +) { val actual = LightClassTestCommon.getActualLightClassText( testData, findLightClass = findLightClass, @@ -153,7 +182,8 @@ private fun testLightClass(expected: File, testData: File, normalize: (String) - .replace("java.lang.String[] strings", "java.lang.String[] p") .removeLinesStartingWith("@" + JvmAnnotationNames.METADATA_FQ_NAME.asString()) .run(normalize) - } + }, + membersFilter = membersFilter ) KotlinTestUtils.assertEqualsToFile(expected, actual) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeCompiledLightClassTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeCompiledLightClassTestGenerated.java index 7d130e525d0..b5d4ef3ae87 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeCompiledLightClassTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeCompiledLightClassTestGenerated.java @@ -124,6 +124,11 @@ public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLight runTest("compiler/testData/asJava/lightClasses/JvmStatic.kt"); } + @TestMetadata("LocalFunctions.kt") + public void testLocalFunctions() throws Exception { + runTest("compiler/testData/asJava/lightClasses/LocalFunctions.kt"); + } + @TestMetadata("NestedObjects.kt") public void testNestedObjects() throws Exception { runTest("compiler/testData/asJava/lightClasses/NestedObjects.kt"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeLightClassTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeLightClassTestGenerated.java index 4f292bc941a..1a2fde1b0d7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeLightClassTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/caches/resolve/IdeLightClassTestGenerated.java @@ -124,6 +124,11 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest { runTest("compiler/testData/asJava/lightClasses/JvmStatic.kt"); } + @TestMetadata("LocalFunctions.kt") + public void testLocalFunctions() throws Exception { + runTest("compiler/testData/asJava/lightClasses/LocalFunctions.kt"); + } + @TestMetadata("NestedObjects.kt") public void testNestedObjects() throws Exception { runTest("compiler/testData/asJava/lightClasses/NestedObjects.kt"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/perf/UltraLightChecker.kt b/idea/tests/org/jetbrains/kotlin/idea/perf/UltraLightChecker.kt index 1e40aced24e..4092d5eded5 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/perf/UltraLightChecker.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/perf/UltraLightChecker.kt @@ -21,8 +21,8 @@ import junit.framework.TestCase import org.jetbrains.kotlin.asJava.KotlinAsJavaSupport import org.jetbrains.kotlin.asJava.LightClassGenerationSupport import org.jetbrains.kotlin.asJava.PsiClassRenderer -import org.jetbrains.kotlin.asJava.PsiClassRenderer.renderClass import org.jetbrains.kotlin.asJava.classes.* +import org.jetbrains.kotlin.asJava.renderClass import org.jetbrains.kotlin.config.JvmAnalysisFlags import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.DeclarationDescriptor diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index 9188ab9fd52..1be9bf81a19 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -10353,6 +10353,69 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes } } + @TestMetadata("compiler/testData/codegen/box/directInvokeOptimization") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class DirectInvokeOptimization extends AbstractIrJsCodegenBoxES6Test { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath); + } + + public void testAllFilesPresentInDirectInvokeOptimization() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/directInvokeOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true); + } + + @TestMetadata("boundInnerContructorRef.kt") + public void testBoundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt"); + } + + @TestMetadata("boundMemberRef.kt") + public void testBoundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt"); + } + + @TestMetadata("capturingLambda.kt") + public void testCapturingLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt"); + } + + @TestMetadata("contructorRef.kt") + public void testContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt"); + } + + @TestMetadata("nestedLambdas.kt") + public void testNestedLambdas() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt"); + } + + @TestMetadata("simpleAnonymousFun.kt") + public void testSimpleAnonymousFun() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt"); + } + + @TestMetadata("simpleFunRef.kt") + public void testSimpleFunRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt"); + } + + @TestMetadata("simpleLambda.kt") + public void testSimpleLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt"); + } + + @TestMetadata("unboundInnerContructorRef.kt") + public void testUnboundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt"); + } + + @TestMetadata("unboundMemberRef.kt") + public void testUnboundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/elvis") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 0a1be8319de..0444162f70e 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -9759,6 +9759,69 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/directInvokeOptimization") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class DirectInvokeOptimization extends AbstractIrJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); + } + + public void testAllFilesPresentInDirectInvokeOptimization() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/directInvokeOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @TestMetadata("boundInnerContructorRef.kt") + public void testBoundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt"); + } + + @TestMetadata("boundMemberRef.kt") + public void testBoundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt"); + } + + @TestMetadata("capturingLambda.kt") + public void testCapturingLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt"); + } + + @TestMetadata("contructorRef.kt") + public void testContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt"); + } + + @TestMetadata("nestedLambdas.kt") + public void testNestedLambdas() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt"); + } + + @TestMetadata("simpleAnonymousFun.kt") + public void testSimpleAnonymousFun() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt"); + } + + @TestMetadata("simpleFunRef.kt") + public void testSimpleFunRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt"); + } + + @TestMetadata("simpleLambda.kt") + public void testSimpleLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt"); + } + + @TestMetadata("unboundInnerContructorRef.kt") + public void testUnboundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt"); + } + + @TestMetadata("unboundMemberRef.kt") + public void testUnboundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/elvis") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 19cfb06df6c..7b547f6e757 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -9759,6 +9759,69 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/directInvokeOptimization") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class DirectInvokeOptimization extends AbstractJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + public void testAllFilesPresentInDirectInvokeOptimization() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/directInvokeOptimization"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); + } + + @TestMetadata("boundInnerContructorRef.kt") + public void testBoundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt"); + } + + @TestMetadata("boundMemberRef.kt") + public void testBoundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt"); + } + + @TestMetadata("capturingLambda.kt") + public void testCapturingLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt"); + } + + @TestMetadata("contructorRef.kt") + public void testContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt"); + } + + @TestMetadata("nestedLambdas.kt") + public void testNestedLambdas() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt"); + } + + @TestMetadata("simpleAnonymousFun.kt") + public void testSimpleAnonymousFun() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt"); + } + + @TestMetadata("simpleFunRef.kt") + public void testSimpleFunRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt"); + } + + @TestMetadata("simpleLambda.kt") + public void testSimpleLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt"); + } + + @TestMetadata("unboundInnerContructorRef.kt") + public void testUnboundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt"); + } + + @TestMetadata("unboundMemberRef.kt") + public void testUnboundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/elvis") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index f2c83f14d6f..27cc8f5ac08 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -4642,6 +4642,69 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest } } + @TestMetadata("compiler/testData/codegen/box/directInvokeOptimization") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class DirectInvokeOptimization extends AbstractIrCodegenBoxWasmTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath); + } + + public void testAllFilesPresentInDirectInvokeOptimization() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/directInvokeOptimization"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); + } + + @TestMetadata("boundInnerContructorRef.kt") + public void testBoundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundInnerContructorRef.kt"); + } + + @TestMetadata("boundMemberRef.kt") + public void testBoundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/boundMemberRef.kt"); + } + + @TestMetadata("capturingLambda.kt") + public void testCapturingLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/capturingLambda.kt"); + } + + @TestMetadata("contructorRef.kt") + public void testContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/contructorRef.kt"); + } + + @TestMetadata("nestedLambdas.kt") + public void testNestedLambdas() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/nestedLambdas.kt"); + } + + @TestMetadata("simpleAnonymousFun.kt") + public void testSimpleAnonymousFun() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleAnonymousFun.kt"); + } + + @TestMetadata("simpleFunRef.kt") + public void testSimpleFunRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleFunRef.kt"); + } + + @TestMetadata("simpleLambda.kt") + public void testSimpleLambda() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/simpleLambda.kt"); + } + + @TestMetadata("unboundInnerContructorRef.kt") + public void testUnboundInnerContructorRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundInnerContructorRef.kt"); + } + + @TestMetadata("unboundMemberRef.kt") + public void testUnboundMemberRef() throws Exception { + runTest("compiler/testData/codegen/box/directInvokeOptimization/unboundMemberRef.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/elvis") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)