JVM: move activeLambda to PsiInlineCodegen

This commit is contained in:
pyos
2021-05-25 14:01:38 +02:00
committed by max-kammerer
parent 7333abf50d
commit b6c3c9942d
4 changed files with 19 additions and 25 deletions
@@ -1261,8 +1261,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
if (closure.isSuspendLambda()) {
// When inlining crossinline lambda, the ACONST_NULL is never popped.
// Thus, do not generate it. Otherwise, it leads to VerifyError on run-time.
boolean isCrossinlineLambda = (callGenerator instanceof InlineCodegen<?>) &&
Objects.requireNonNull(((InlineCodegen) callGenerator).getActiveLambda(),
boolean isCrossinlineLambda = (callGenerator instanceof PsiInlineCodegen) &&
Objects.requireNonNull(((PsiInlineCodegen) callGenerator).getActiveLambda(),
"no active lambda found").isCrossInline;
if (!isCrossinlineLambda) {
v.aconst(null);
@@ -69,9 +69,6 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
protected val expressionMap = linkedMapOf<Int, FunctionalArgument>()
var activeLambda: LambdaInfo? = null
protected set
private val sourceMapper = sourceCompiler.lazySourceMapper
protected var delayedHiddenWriting: Function0<Unit>? = null
@@ -356,7 +353,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
protected fun putArgumentOrCapturedToLocalVal(
jvmKotlinType: JvmKotlinType,
stackValue: StackValue,
capturedParamIndex: Int,
capturedParam: CapturedParamDesc?,
parameterIndex: Int,
kind: ValueKind
) {
@@ -373,9 +370,8 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
val remappedValue = if (couldBeRemapped) stackValue else null
val info: ParameterInfo
if (capturedParamIndex >= 0) {
val capturedParamInfoInLambda = activeLambda!!.capturedVars[capturedParamIndex]
info = invocationParamBuilder.addCapturedParam(capturedParamInfoInLambda, capturedParamInfoInLambda.fieldName, false)
if (capturedParam != null) {
info = invocationParamBuilder.addCapturedParam(capturedParam, capturedParam.fieldName, false)
info.remapValue = remappedValue
} else {
info = invocationParamBuilder.addNextValueParameter(jvmType, false, remappedValue, parameterIndex)
@@ -456,7 +452,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
//HACK: actually parameter would be placed on stack in default function
// also see ValueKind.DEFAULT_LAMBDA_CAPTURED_PARAMETER check
StackValue.onStack(captured.type),
paramIndex,
captured,
paramIndex,
ValueKind.DEFAULT_LAMBDA_CAPTURED_PARAMETER
)
@@ -102,6 +102,9 @@ class PsiInlineCodegen(
delayedHiddenWriting = recordParameterValueInLocalVal(justProcess, false, *hiddenParameters.toTypedArray())
}
var activeLambda: LambdaInfo? = null
private set
override fun putClosureParametersOnStack(next: LambdaInfo, functionReferenceReceiver: StackValue?) {
activeLambda = next
when (next) {
@@ -192,12 +195,13 @@ class PsiInlineCodegen(
assert(maskValues.isEmpty()) { "Additional default call arguments should be last ones, but $value" }
putArgumentOrCapturedToLocalVal(parameterType, value, -1, parameterIndex, kind)
putArgumentOrCapturedToLocalVal(parameterType, value, null, parameterIndex, kind)
}
override fun putCapturedValueOnStack(stackValue: StackValue, valueType: Type, paramIndex: Int) {
val param = activeLambda!!.capturedVars[paramIndex]
putArgumentOrCapturedToLocalVal(
JvmKotlinType(stackValue.type, stackValue.kotlinType), stackValue, paramIndex, paramIndex, ValueKind.CAPTURED
JvmKotlinType(stackValue.type, stackValue.kotlinType), stackValue, param, paramIndex, ValueKind.CAPTURED
)
}