JVM: remove second parameter of putClosureParametersOnStack

Only used by the old backend.
This commit is contained in:
pyos
2021-05-25 14:11:02 +02:00
committed by max-kammerer
parent d4c8a033b1
commit 90412ade8a
3 changed files with 31 additions and 33 deletions
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils
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.isInlineOnly
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.Opcodes
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.tree.*
import kotlin.math.max
@@ -435,15 +433,15 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
private fun putClosureParametersOnStack() {
for (next in expressionMap.values) {
//closure parameters for bounded callable references are generated inplace
if (next is LambdaInfo) {
// Closure parameters for bound references have already been generated in between other arguments.
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) {
for ((paramIndex, captured) in defaultLambda.capturedVars.withIndex()) {
@@ -105,22 +105,28 @@ class PsiInlineCodegen(
var activeLambda: LambdaInfo? = null
private set
override fun putClosureParametersOnStack(next: LambdaInfo, functionReferenceReceiver: StackValue?) {
override fun putClosureParametersOnStack(next: LambdaInfo) {
activeLambda = 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)
else -> throw RuntimeException("Unknown lambda: $next")
}
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*/
private fun isInliningParameter(expression: KtExpression, valueParameterDescriptor: ValueParameterDescriptor): Boolean {
//TODO deparenthesize typed
@@ -142,21 +148,9 @@ class PsiInlineCodegen(
if (isInliningParameter(argumentExpression, valueParameterDescriptor)) {
val lambdaInfo = rememberClosure(argumentExpression, parameterType.type, valueParameterDescriptor)
val receiverValue = getBoundCallableReferenceReceiver(argumentExpression)
if (receiverValue != null) {
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)
)
if (lambdaInfo.boundReceiver != null) {
// Has to be done immediately to preserve evaluation order.
putClosureParametersOnStack(lambdaInfo)
}
} else {
val value = codegen.gen(argumentExpression)
@@ -176,13 +170,17 @@ class PsiInlineCodegen(
private fun isCallSiteIsSuspend(descriptor: ValueParameterDescriptor): Boolean =
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)
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(
ktLambda!!, state.typeMapper, state.languageVersionSettings,
parameter.isCrossinline, getBoundCallableReferenceReceiver(expression) != null
ktLambda!!, state.typeMapper, state.languageVersionSettings, parameter.isCrossinline, boundReceiver
).also { lambda ->
val closureInfo = invocationParamBuilder.addNextValueParameter(type, true, null, parameter.index)
closureInfo.functionalArgument = lambda
@@ -233,8 +231,10 @@ class PsiExpressionLambda(
private val typeMapper: KotlinTypeMapper,
private val languageVersionSettings: LanguageVersionSettings,
isCrossInline: Boolean,
override val isBoundCallableReference: Boolean
val boundReceiver: ReceiverValue?
) : ExpressionLambda(isCrossInline) {
override val isBoundCallableReference: Boolean
get() = boundReceiver != null
override val lambdaClassType: Type
@@ -57,7 +57,7 @@ class IrInlineCodegen(
}
}
override fun putClosureParametersOnStack(next: LambdaInfo, functionReferenceReceiver: StackValue?) {
override fun putClosureParametersOnStack(next: LambdaInfo) {
when (next) {
is IrExpressionLambdaImpl -> next.reference.getArgumentsWithIr().forEachIndexed { index, (_, ir) ->
putCapturedValueOnStack(ir, next.capturedVars[index], index)