JVM: remove second parameter of putClosureParametersOnStack
Only used by the old backend.
This commit is contained in:
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor
|
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
|
||||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||||
import org.jetbrains.kotlin.resolve.inline.isInlineOnly
|
import org.jetbrains.kotlin.resolve.inline.isInlineOnly
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||||
@@ -37,7 +36,6 @@ import org.jetbrains.kotlin.types.model.TypeParameterMarker
|
|||||||
import org.jetbrains.org.objectweb.asm.Label
|
import org.jetbrains.org.objectweb.asm.Label
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
|
||||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||||
import org.jetbrains.org.objectweb.asm.tree.*
|
import org.jetbrains.org.objectweb.asm.tree.*
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
@@ -435,15 +433,15 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
|||||||
|
|
||||||
private fun putClosureParametersOnStack() {
|
private fun putClosureParametersOnStack() {
|
||||||
for (next in expressionMap.values) {
|
for (next in expressionMap.values) {
|
||||||
//closure parameters for bounded callable references are generated inplace
|
|
||||||
if (next is LambdaInfo) {
|
if (next is LambdaInfo) {
|
||||||
|
// Closure parameters for bound references have already been generated in between other arguments.
|
||||||
if (next is ExpressionLambda && next.isBoundCallableReference) continue
|
if (next is ExpressionLambda && next.isBoundCallableReference) continue
|
||||||
putClosureParametersOnStack(next, null)
|
putClosureParametersOnStack(next)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected fun putClosureParametersOnStack(next: LambdaInfo, functionReferenceReceiver: StackValue?)
|
protected abstract fun putClosureParametersOnStack(next: LambdaInfo)
|
||||||
|
|
||||||
protected fun rememberCapturedForDefaultLambda(defaultLambda: DefaultLambda) {
|
protected fun rememberCapturedForDefaultLambda(defaultLambda: DefaultLambda) {
|
||||||
for ((paramIndex, captured) in defaultLambda.capturedVars.withIndex()) {
|
for ((paramIndex, captured) in defaultLambda.capturedVars.withIndex()) {
|
||||||
|
|||||||
@@ -105,22 +105,28 @@ class PsiInlineCodegen(
|
|||||||
var activeLambda: LambdaInfo? = null
|
var activeLambda: LambdaInfo? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
override fun putClosureParametersOnStack(next: LambdaInfo, functionReferenceReceiver: StackValue?) {
|
override fun putClosureParametersOnStack(next: LambdaInfo) {
|
||||||
activeLambda = next
|
activeLambda = next
|
||||||
when (next) {
|
when (next) {
|
||||||
is PsiExpressionLambda -> codegen.pushClosureOnStack(next.classDescriptor, true, this, functionReferenceReceiver)
|
is PsiExpressionLambda -> {
|
||||||
|
val receiverValue = next.boundReceiver?.let { boundReceiver ->
|
||||||
|
val receiver = codegen.generateReceiverValue(boundReceiver, false)
|
||||||
|
val receiverKotlinType = receiver.kotlinType
|
||||||
|
val boxedReceiver =
|
||||||
|
if (receiverKotlinType != null)
|
||||||
|
DescriptorAsmUtil.boxType(receiver.type, receiverKotlinType, state.typeMapper)
|
||||||
|
else
|
||||||
|
AsmUtil.boxType(receiver.type)
|
||||||
|
StackValue.coercion(receiver, boxedReceiver, receiverKotlinType)
|
||||||
|
}
|
||||||
|
codegen.pushClosureOnStack(next.classDescriptor, true, this, receiverValue)
|
||||||
|
}
|
||||||
is DefaultLambda -> rememberCapturedForDefaultLambda(next)
|
is DefaultLambda -> rememberCapturedForDefaultLambda(next)
|
||||||
else -> throw RuntimeException("Unknown lambda: $next")
|
else -> throw RuntimeException("Unknown lambda: $next")
|
||||||
}
|
}
|
||||||
activeLambda = null
|
activeLambda = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getBoundCallableReferenceReceiver(argumentExpression: KtExpression): ReceiverValue? {
|
|
||||||
val deparenthesized = KtPsiUtil.deparenthesize(argumentExpression) as? KtCallableReferenceExpression ?: return null
|
|
||||||
val resolvedCall = deparenthesized.callableReference.getResolvedCallWithAssert(state.bindingContext)
|
|
||||||
return JvmCodegenUtil.getBoundCallableReferenceReceiver(resolvedCall)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*lambda or callable reference*/
|
/*lambda or callable reference*/
|
||||||
private fun isInliningParameter(expression: KtExpression, valueParameterDescriptor: ValueParameterDescriptor): Boolean {
|
private fun isInliningParameter(expression: KtExpression, valueParameterDescriptor: ValueParameterDescriptor): Boolean {
|
||||||
//TODO deparenthesize typed
|
//TODO deparenthesize typed
|
||||||
@@ -142,21 +148,9 @@ class PsiInlineCodegen(
|
|||||||
|
|
||||||
if (isInliningParameter(argumentExpression, valueParameterDescriptor)) {
|
if (isInliningParameter(argumentExpression, valueParameterDescriptor)) {
|
||||||
val lambdaInfo = rememberClosure(argumentExpression, parameterType.type, valueParameterDescriptor)
|
val lambdaInfo = rememberClosure(argumentExpression, parameterType.type, valueParameterDescriptor)
|
||||||
|
if (lambdaInfo.boundReceiver != null) {
|
||||||
val receiverValue = getBoundCallableReferenceReceiver(argumentExpression)
|
// Has to be done immediately to preserve evaluation order.
|
||||||
if (receiverValue != null) {
|
putClosureParametersOnStack(lambdaInfo)
|
||||||
val receiver = codegen.generateReceiverValue(receiverValue, false)
|
|
||||||
val receiverKotlinType = receiver.kotlinType
|
|
||||||
val boxedReceiver =
|
|
||||||
if (receiverKotlinType != null)
|
|
||||||
DescriptorAsmUtil.boxType(receiver.type, receiverKotlinType, state.typeMapper)
|
|
||||||
else
|
|
||||||
AsmUtil.boxType(receiver.type)
|
|
||||||
|
|
||||||
putClosureParametersOnStack(
|
|
||||||
lambdaInfo,
|
|
||||||
StackValue.coercion(receiver, boxedReceiver, receiverKotlinType)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val value = codegen.gen(argumentExpression)
|
val value = codegen.gen(argumentExpression)
|
||||||
@@ -176,13 +170,17 @@ class PsiInlineCodegen(
|
|||||||
private fun isCallSiteIsSuspend(descriptor: ValueParameterDescriptor): Boolean =
|
private fun isCallSiteIsSuspend(descriptor: ValueParameterDescriptor): Boolean =
|
||||||
state.bindingContext[CodegenBinding.CALL_SITE_IS_SUSPEND_FOR_CROSSINLINE_LAMBDA, descriptor] == true
|
state.bindingContext[CodegenBinding.CALL_SITE_IS_SUSPEND_FOR_CROSSINLINE_LAMBDA, descriptor] == true
|
||||||
|
|
||||||
private fun rememberClosure(expression: KtExpression, type: Type, parameter: ValueParameterDescriptor): LambdaInfo {
|
private fun rememberClosure(expression: KtExpression, type: Type, parameter: ValueParameterDescriptor): PsiExpressionLambda {
|
||||||
val ktLambda = KtPsiUtil.deparenthesize(expression)
|
val ktLambda = KtPsiUtil.deparenthesize(expression)
|
||||||
assert(isInlinableParameterExpression(ktLambda)) { "Couldn't find inline expression in ${expression.text}" }
|
assert(isInlinableParameterExpression(ktLambda)) { "Couldn't find inline expression in ${expression.text}" }
|
||||||
|
|
||||||
|
val boundReceiver = if (ktLambda is KtCallableReferenceExpression) {
|
||||||
|
val resolvedCall = ktLambda.callableReference.getResolvedCallWithAssert(state.bindingContext)
|
||||||
|
JvmCodegenUtil.getBoundCallableReferenceReceiver(resolvedCall)
|
||||||
|
} else null
|
||||||
|
|
||||||
return PsiExpressionLambda(
|
return PsiExpressionLambda(
|
||||||
ktLambda!!, state.typeMapper, state.languageVersionSettings,
|
ktLambda!!, state.typeMapper, state.languageVersionSettings, parameter.isCrossinline, boundReceiver
|
||||||
parameter.isCrossinline, getBoundCallableReferenceReceiver(expression) != null
|
|
||||||
).also { lambda ->
|
).also { lambda ->
|
||||||
val closureInfo = invocationParamBuilder.addNextValueParameter(type, true, null, parameter.index)
|
val closureInfo = invocationParamBuilder.addNextValueParameter(type, true, null, parameter.index)
|
||||||
closureInfo.functionalArgument = lambda
|
closureInfo.functionalArgument = lambda
|
||||||
@@ -233,8 +231,10 @@ class PsiExpressionLambda(
|
|||||||
private val typeMapper: KotlinTypeMapper,
|
private val typeMapper: KotlinTypeMapper,
|
||||||
private val languageVersionSettings: LanguageVersionSettings,
|
private val languageVersionSettings: LanguageVersionSettings,
|
||||||
isCrossInline: Boolean,
|
isCrossInline: Boolean,
|
||||||
override val isBoundCallableReference: Boolean
|
val boundReceiver: ReceiverValue?
|
||||||
) : ExpressionLambda(isCrossInline) {
|
) : ExpressionLambda(isCrossInline) {
|
||||||
|
override val isBoundCallableReference: Boolean
|
||||||
|
get() = boundReceiver != null
|
||||||
|
|
||||||
override val lambdaClassType: Type
|
override val lambdaClassType: Type
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ class IrInlineCodegen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun putClosureParametersOnStack(next: LambdaInfo, functionReferenceReceiver: StackValue?) {
|
override fun putClosureParametersOnStack(next: LambdaInfo) {
|
||||||
when (next) {
|
when (next) {
|
||||||
is IrExpressionLambdaImpl -> next.reference.getArgumentsWithIr().forEachIndexed { index, (_, ir) ->
|
is IrExpressionLambdaImpl -> next.reference.getArgumentsWithIr().forEachIndexed { index, (_, ir) ->
|
||||||
putCapturedValueOnStack(ir, next.capturedVars[index], index)
|
putCapturedValueOnStack(ir, next.capturedVars[index], index)
|
||||||
|
|||||||
Reference in New Issue
Block a user