JVM_IR KT-47449 handle star projection arguments in default lambda types
This commit is contained in:
committed by
teamcityserver
parent
5486fec0f9
commit
1298ba431b
+6
@@ -16340,6 +16340,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/functions/kt395.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt47449.kt")
|
||||
public void testKt47449() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt47449.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt785.kt")
|
||||
public void testKt785() throws Exception {
|
||||
|
||||
+28
-15
@@ -9,15 +9,17 @@ import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.isInlineClassType
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.isInlineParameter
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.InlineClassAbi
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.suspendFunctionOriginal
|
||||
import org.jetbrains.kotlin.codegen.IrExpressionLambda
|
||||
import org.jetbrains.kotlin.codegen.JvmKotlinType
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.codegen.ValueKind
|
||||
import org.jetbrains.kotlin.codegen.inline.*
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedKotlinType
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
@@ -195,16 +197,8 @@ class IrDefaultLambda(
|
||||
needReification: Boolean,
|
||||
sourceCompiler: IrSourceCompilerForInline
|
||||
) : DefaultLambda(lambdaClassType, capturedArgs, irValueParameter.isCrossinline, offset, needReification, sourceCompiler) {
|
||||
private val typeArguments: MutableList<IrType> =
|
||||
(irValueParameter.type as IrSimpleType).arguments.mapTo(mutableListOf()) { (it as IrTypeProjection).type }.apply {
|
||||
// Suspend function references: `suspend (A) -> B` => `invoke(A, Continuation<B>): Any?`
|
||||
// TODO: default suspend lambdas are currently uninlinable due to having a state machine
|
||||
if (irValueParameter.type.isSuspendFunction()) {
|
||||
val context = sourceCompiler.codegen.context
|
||||
set(size - 1, context.ir.symbols.continuationClass.typeWith(get(size - 1)))
|
||||
add(context.irBuiltIns.anyNType)
|
||||
}
|
||||
}
|
||||
|
||||
private val typeArguments: MutableList<IrType>
|
||||
|
||||
override val invokeMethodParameters: List<KotlinType>
|
||||
get() = typeArguments.dropLast(1).map { it.toIrBasedKotlinType() }
|
||||
@@ -213,9 +207,28 @@ class IrDefaultLambda(
|
||||
get() = typeArguments.last().toIrBasedKotlinType()
|
||||
|
||||
init {
|
||||
val context = sourceCompiler.codegen.context
|
||||
|
||||
typeArguments =
|
||||
(irValueParameter.type as IrSimpleType).arguments
|
||||
.mapTo(mutableListOf()) {
|
||||
when (it) {
|
||||
is IrTypeProjection -> it.type
|
||||
else -> context.irBuiltIns.anyNType
|
||||
}
|
||||
}
|
||||
.apply {
|
||||
// Suspend function references: `suspend (A) -> B` => `invoke(A, Continuation<B>): Any?`
|
||||
// TODO: default suspend lambdas are currently uninlinable due to having a state machine
|
||||
if (irValueParameter.type.isSuspendFunction()) {
|
||||
set(size - 1, context.ir.symbols.continuationClass.typeWith(get(size - 1)))
|
||||
add(context.irBuiltIns.anyNType)
|
||||
}
|
||||
}
|
||||
|
||||
val base = if (isPropertyReference) OperatorNameConventions.GET.asString() else OperatorNameConventions.INVOKE.asString()
|
||||
val name = InlineClassAbi.hashSuffix(
|
||||
sourceCompiler.codegen.context.state.useOldManglingSchemeForFunctionsWithInlineClassesInSignatures,
|
||||
context.state.useOldManglingSchemeForFunctionsWithInlineClassesInSignatures,
|
||||
typeArguments.dropLast(1),
|
||||
typeArguments.last().takeIf { it.isInlineClassType() }
|
||||
)?.let { "$base-$it" } ?: base
|
||||
@@ -223,7 +236,7 @@ class IrDefaultLambda(
|
||||
// it would be better to map to a non-erased signature if not a property reference.
|
||||
if (loadInvoke(sourceCompiler, base, Method(name, AsmTypes.OBJECT_TYPE, Array(typeArguments.size - 1) { AsmTypes.OBJECT_TYPE }))) {
|
||||
// If the loaded method is `invoke(Object, ...) -> Object`, then it expects boxed parameters and returns a boxed value.
|
||||
typeArguments.replaceAll { sourceCompiler.codegen.context.irBuiltIns.anyNType }
|
||||
typeArguments.replaceAll { context.irBuiltIns.anyNType }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// IGNORE_BACKEND: JS
|
||||
// IGNORE_BACKEND: WASM
|
||||
|
||||
typealias EmptyFunctionResult<T> = () -> T
|
||||
|
||||
typealias LoggingFunctionType<T> = (tag: String, message: String, throwable: Throwable?) -> T
|
||||
|
||||
fun box(): String {
|
||||
tryAndLog {
|
||||
throw RuntimeException()
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
inline fun <T> tryAndLog(
|
||||
title: String = "",
|
||||
message: String = "",
|
||||
logger: LoggingFunctionType<*> = L::error,
|
||||
throwableAction: EmptyFunctionResult<T>
|
||||
): T? {
|
||||
return try {
|
||||
throwableAction()
|
||||
} catch (e: Throwable) {
|
||||
logger(title, message, e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
open class LLogger {
|
||||
fun error(tag: String, message: String, exception: Throwable?): Unit {}
|
||||
}
|
||||
|
||||
object L : LLogger()
|
||||
+6
@@ -16310,6 +16310,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/functions/kt395.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt47449.kt")
|
||||
public void testKt47449() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt47449.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt785.kt")
|
||||
public void testKt785() throws Exception {
|
||||
|
||||
+6
@@ -16340,6 +16340,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/functions/kt395.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt47449.kt")
|
||||
public void testKt47449() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt47449.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt785.kt")
|
||||
public void testKt785() throws Exception {
|
||||
|
||||
+5
@@ -13450,6 +13450,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/functions/kt395.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt47449.kt")
|
||||
public void testKt47449() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt47449.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt785.kt")
|
||||
public void testKt785() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt785.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -11864,6 +11864,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/functions/kt395.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt47449.kt")
|
||||
public void testKt47449() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt47449.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt785.kt")
|
||||
public void testKt785() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt785.kt");
|
||||
|
||||
Generated
+5
@@ -11270,6 +11270,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/functions/kt395.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt47449.kt")
|
||||
public void testKt47449() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt47449.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt785.kt")
|
||||
public void testKt785() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt785.kt");
|
||||
|
||||
Generated
+5
@@ -11270,6 +11270,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/functions/kt395.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt47449.kt")
|
||||
public void testKt47449() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt47449.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt785.kt")
|
||||
public void testKt785() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt785.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -5745,6 +5745,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/functions/kt395.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt47449.kt")
|
||||
public void testKt47449() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt47449.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt785.kt")
|
||||
public void testKt785() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/functions/kt785.kt");
|
||||
|
||||
Reference in New Issue
Block a user