[JS_IR] Don't capture the bound receiver of a CR
This commit is contained in:
Generated
+5
@@ -2045,6 +2045,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("dontShareReceiver.kt")
|
||||||
|
public void testDontShareReceiver() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/callableReference/bound/dontShareReceiver.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("emptyLHS.kt")
|
@TestMetadata("emptyLHS.kt")
|
||||||
public void testEmptyLHS() throws Exception {
|
public void testEmptyLHS() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
||||||
|
|||||||
+25
-14
@@ -14,10 +14,8 @@ import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
|||||||
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
|
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
|
import org.jetbrains.kotlin.ir.builders.*
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.*
|
import org.jetbrains.kotlin.ir.builders.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.builders.irBlockBody
|
|
||||||
import org.jetbrains.kotlin.ir.builders.irDelegatingConstructorCall
|
|
||||||
import org.jetbrains.kotlin.ir.builders.setSourceRange
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedReceiverParameterDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedReceiverParameterDescriptor
|
||||||
@@ -27,10 +25,7 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
|||||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||||
import org.jetbrains.kotlin.ir.util.defaultType
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.ir.util.explicitParameters
|
|
||||||
import org.jetbrains.kotlin.ir.util.isSuspend
|
|
||||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -84,8 +79,16 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
|
|||||||
clazz.parent = container
|
clazz.parent = container
|
||||||
|
|
||||||
return expression.run {
|
return expression.run {
|
||||||
val ctorCall =
|
val boundReceiver = expression.run { dispatchReceiver ?: extensionReceiver }
|
||||||
IrConstructorCallImpl(startOffset, endOffset, type, ctor.symbol, 0 /*TODO: properly set type arguments*/, 0, 0, CALLABLE_REFERENCE_CREATE)
|
val vpCount = if (boundReceiver != null) 1 else 0
|
||||||
|
val ctorCall = IrConstructorCallImpl(
|
||||||
|
startOffset, endOffset, type, ctor.symbol,
|
||||||
|
0 /*TODO: properly set type arguments*/, 0,
|
||||||
|
vpCount, CALLABLE_REFERENCE_CREATE).apply {
|
||||||
|
boundReceiver?.let {
|
||||||
|
putValueArgument(0, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
IrCompositeImpl(startOffset, endOffset, type, origin, listOf(clazz, ctorCall))
|
IrCompositeImpl(startOffset, endOffset, type, origin, listOf(clazz, ctorCall))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,10 +141,7 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
|
|||||||
val boundReceiver = funRef.run { dispatchReceiver ?: extensionReceiver }
|
val boundReceiver = funRef.run { dispatchReceiver ?: extensionReceiver }
|
||||||
|
|
||||||
if (boundReceiver != null) {
|
if (boundReceiver != null) {
|
||||||
boundReceiverField = addField(BOUND_RECEIVER_NAME, boundReceiver.type).apply {
|
boundReceiverField = addField(BOUND_RECEIVER_NAME, boundReceiver.type)
|
||||||
initializer = IrExpressionBodyImpl(boundReceiver.startOffset, boundReceiver.endOffset, boundReceiver)
|
|
||||||
parent = this@createReceiverField
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +162,14 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
|
|||||||
|
|
||||||
val superConstructor = superClass.classOrNull!!.owner.declarations.single { it is IrConstructor && it.isPrimary } as IrConstructor
|
val superConstructor = superClass.classOrNull!!.owner.declarations.single { it is IrConstructor && it.isPrimary } as IrConstructor
|
||||||
|
|
||||||
|
val boundReceiverParameter = boundReceiverField?.let {
|
||||||
|
addValueParameter {
|
||||||
|
name = BOUND_RECEIVER_NAME
|
||||||
|
type = it.type
|
||||||
|
index = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var continuation: IrValueParameter? = null
|
var continuation: IrValueParameter? = null
|
||||||
|
|
||||||
if (isSuspendLambda) {
|
if (isSuspendLambda) {
|
||||||
@@ -169,7 +177,7 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
|
|||||||
continuation = addValueParameter {
|
continuation = addValueParameter {
|
||||||
name = superContinuation.name
|
name = superContinuation.name
|
||||||
type = superContinuation.type
|
type = superContinuation.type
|
||||||
index = 0
|
index = if (boundReceiverParameter == null) 0 else 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +187,9 @@ class CallableReferenceLowering(private val context: CommonBackendContext) : Bod
|
|||||||
putValueArgument(0, getValue(it))
|
putValueArgument(0, getValue(it))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
boundReceiverParameter?.let {
|
||||||
|
+irSetField(irGet(clazz.thisReceiver!!), boundReceiverField!!, irGet(it))
|
||||||
|
}
|
||||||
+IrInstanceInitializerCallImpl(startOffset, endOffset, clazz.symbol, context.irBuiltIns.unitType)
|
+IrInstanceInitializerCallImpl(startOffset, endOffset, clazz.symbol, context.irBuiltIns.unitType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
var state = 0
|
||||||
|
val f = (state++)::toString
|
||||||
|
val s1 = f()
|
||||||
|
if (s1 != "0") return "fail 1: $s1"
|
||||||
|
++state
|
||||||
|
val s2 = f()
|
||||||
|
if (s2 != "0") return "fail 2: $s2"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+5
@@ -2065,6 +2065,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("dontShareReceiver.kt")
|
||||||
|
public void testDontShareReceiver() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/callableReference/bound/dontShareReceiver.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("emptyLHS.kt")
|
@TestMetadata("emptyLHS.kt")
|
||||||
public void testEmptyLHS() throws Exception {
|
public void testEmptyLHS() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
||||||
|
|||||||
+5
@@ -2065,6 +2065,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("dontShareReceiver.kt")
|
||||||
|
public void testDontShareReceiver() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/callableReference/bound/dontShareReceiver.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("emptyLHS.kt")
|
@TestMetadata("emptyLHS.kt")
|
||||||
public void testEmptyLHS() throws Exception {
|
public void testEmptyLHS() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
||||||
|
|||||||
+5
@@ -2045,6 +2045,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("dontShareReceiver.kt")
|
||||||
|
public void testDontShareReceiver() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/callableReference/bound/dontShareReceiver.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("emptyLHS.kt")
|
@TestMetadata("emptyLHS.kt")
|
||||||
public void testEmptyLHS() throws Exception {
|
public void testEmptyLHS() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
||||||
|
|||||||
Generated
+5
@@ -1480,6 +1480,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("dontShareReceiver.kt")
|
||||||
|
public void testDontShareReceiver() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/callableReference/bound/dontShareReceiver.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("emptyLHS.kt")
|
@TestMetadata("emptyLHS.kt")
|
||||||
public void testEmptyLHS() throws Exception {
|
public void testEmptyLHS() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
||||||
|
|||||||
+5
@@ -1480,6 +1480,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/companionObjectReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("dontShareReceiver.kt")
|
||||||
|
public void testDontShareReceiver() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/callableReference/bound/dontShareReceiver.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("emptyLHS.kt")
|
@TestMetadata("emptyLHS.kt")
|
||||||
public void testEmptyLHS() throws Exception {
|
public void testEmptyLHS() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
runTest("compiler/testData/codegen/box/callableReference/bound/emptyLHS.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user