JVM: rename a couple ValueKinds to make their purpose clearer

This commit is contained in:
pyos
2021-09-20 11:51:33 +02:00
committed by Ilmir Usmanov
parent f786084a0a
commit ade9f5a1e8
9 changed files with 18 additions and 19 deletions
@@ -18,8 +18,8 @@ enum class ValueKind {
DEFAULT_INLINE_PARAMETER,
DEFAULT_MASK,
METHOD_HANDLE_IN_DEFAULT,
NON_INLINEABLE_ARGUMENT_FOR_INLINE_PARAMETER_CALLED_IN_SUSPEND,
NON_INLINEABLE_ARGUMENT_FOR_INLINE_SUSPEND_PARAMETER
READ_OF_INLINE_LAMBDA_FOR_INLINE_SUSPEND_PARAMETER,
READ_OF_OBJECT_FOR_INLINE_SUSPEND_PARAMETER
}
interface CallGenerator {
@@ -556,7 +556,7 @@ class AnonymousObjectTransformer(
else
capturedParamBuilder.addCapturedParam(desc, addUniqueField(desc.fieldName + INLINE_TRANSFORMATION_SUFFIX), false)
if (desc.isSuspend) {
recapturedParamInfo.functionalArgument = NonInlineableArgumentForInlineableParameterCalledInSuspend
recapturedParamInfo.functionalArgument = NonInlineArgumentForInlineSuspendParameter.INLINE_LAMBDA_AS_VARIABLE
}
val composed = StackValue.field(
desc.type,
@@ -233,10 +233,10 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
val info = invocationParamBuilder.addNextValueParameter(jvmKotlinType.type, false, null, parameterIndex)
info.functionalArgument = when (kind) {
ValueKind.NON_INLINEABLE_ARGUMENT_FOR_INLINE_PARAMETER_CALLED_IN_SUSPEND ->
NonInlineableArgumentForInlineableParameterCalledInSuspend
ValueKind.NON_INLINEABLE_ARGUMENT_FOR_INLINE_SUSPEND_PARAMETER ->
NonInlineableArgumentForInlineableSuspendParameter
ValueKind.READ_OF_INLINE_LAMBDA_FOR_INLINE_SUSPEND_PARAMETER ->
NonInlineArgumentForInlineSuspendParameter.INLINE_LAMBDA_AS_VARIABLE
ValueKind.READ_OF_OBJECT_FOR_INLINE_SUSPEND_PARAMETER ->
NonInlineArgumentForInlineSuspendParameter.OTHER
ValueKind.DEFAULT_INLINE_PARAMETER ->
DefaultValueOfInlineParameter
else -> null
@@ -51,7 +51,7 @@ abstract class LambdaInfo : FunctionalArgument {
?: error("Captured field not found: " + info.containingLambdaName + "." + info.fieldName)
val recapturedParamInfo = builder.addCapturedParam(field, info.fieldName)
if (info.isSuspend) {
recapturedParamInfo.functionalArgument = NonInlineableArgumentForInlineableParameterCalledInSuspend
recapturedParamInfo.functionalArgument = NonInlineArgumentForInlineSuspendParameter.INLINE_LAMBDA_AS_VARIABLE
}
}
@@ -65,8 +65,7 @@ abstract class LambdaInfo : FunctionalArgument {
}
}
object NonInlineableArgumentForInlineableParameterCalledInSuspend : FunctionalArgument
object NonInlineableArgumentForInlineableSuspendParameter : FunctionalArgument
enum class NonInlineArgumentForInlineSuspendParameter : FunctionalArgument { INLINE_LAMBDA_AS_VARIABLE, OTHER }
object DefaultValueOfInlineParameter : FunctionalArgument
abstract class ExpressionLambda : LambdaInfo() {
@@ -885,7 +885,7 @@ class MethodInliner(
insnNode is FieldInsnNode && insnNode.name.startsWith(CAPTURED_FIELD_FOLD_PREFIX) ->
findCapturedField(insnNode, nodeRemapper).functionalArgument
insnNode is FieldInsnNode && inliningContext.root.sourceCompilerForInline.isSuspendLambdaCapturedByOuterObjectOrLambda(insnNode.name) ->
NonInlineableArgumentForInlineableParameterCalledInSuspend
NonInlineArgumentForInlineSuspendParameter.INLINE_LAMBDA_AS_VARIABLE
else ->
null
}
@@ -127,8 +127,8 @@ class PsiInlineCodegen(
val value = codegen.gen(argumentExpression)
val kind = when {
isCallSiteIsSuspend(valueParameterDescriptor) && parameterType.kotlinType?.isSuspendFunctionTypeOrSubtype == true ->
ValueKind.NON_INLINEABLE_ARGUMENT_FOR_INLINE_PARAMETER_CALLED_IN_SUSPEND
isInlineSuspendParameter(valueParameterDescriptor) -> ValueKind.NON_INLINEABLE_ARGUMENT_FOR_INLINE_SUSPEND_PARAMETER
ValueKind.READ_OF_INLINE_LAMBDA_FOR_INLINE_SUSPEND_PARAMETER
isInlineSuspendParameter(valueParameterDescriptor) -> ValueKind.READ_OF_OBJECT_FOR_INLINE_SUSPEND_PARAMETER
else -> ValueKind.GENERAL
}
putValueIfNeeded(parameterType, value, kind, parameterIndex)
@@ -97,7 +97,7 @@ class AnonymousObjectTransformationInfo internal constructor(
// to map the inner reference to the outer regenerated type and producing an infinite recursion.
override fun shouldRegenerate(sameModule: Boolean): Boolean = alreadyRegenerated ||
!sameModule || capturedOuterRegenerated || needReification || capturesAnonymousObjectThatMustBeRegenerated ||
functionalArguments.values.any { it != NonInlineableArgumentForInlineableParameterCalledInSuspend }
functionalArguments.values.any { it != NonInlineArgumentForInlineSuspendParameter.INLINE_LAMBDA_AS_VARIABLE }
override fun canRemoveAfterTransformation(): Boolean {
// Note: It is unsafe to remove anonymous class that is referenced by GETSTATIC within lambda
@@ -177,9 +177,9 @@ private const val NOINLINE_CALL_MARKER = "\$\$\$\$\$NOINLINE_CALL_MARKER\$\$\$\$
fun markNoinlineLambdaIfSuspend(mv: MethodVisitor, info: FunctionalArgument?) {
when (info) {
NonInlineableArgumentForInlineableSuspendParameter ->
NonInlineArgumentForInlineSuspendParameter.OTHER ->
mv.visitMethodInsn(Opcodes.INVOKESTATIC, NOINLINE_CALL_MARKER, "always", "()V", false)
NonInlineableArgumentForInlineableParameterCalledInSuspend ->
NonInlineArgumentForInlineSuspendParameter.INLINE_LAMBDA_AS_VARIABLE -> // depends on how it's substituted later
mv.visitMethodInsn(Opcodes.INVOKESTATIC, NOINLINE_CALL_MARKER, "conditional", "()V", false)
}
}
@@ -111,9 +111,9 @@ class IrInlineCodegen(
ValueKind.DEFAULT_PARAMETER
isInlineParameter && irValueParameter.type.isSuspendFunction() ->
if (argumentExpression.isReadOfInlineLambda())
ValueKind.NON_INLINEABLE_ARGUMENT_FOR_INLINE_PARAMETER_CALLED_IN_SUSPEND
ValueKind.READ_OF_INLINE_LAMBDA_FOR_INLINE_SUSPEND_PARAMETER
else
ValueKind.NON_INLINEABLE_ARGUMENT_FOR_INLINE_SUSPEND_PARAMETER
ValueKind.READ_OF_OBJECT_FOR_INLINE_SUSPEND_PARAMETER
else ->
ValueKind.GENERAL
}
@@ -196,7 +196,7 @@ class IrExpressionLambdaImpl(
val captureStart = if (isExtensionLambda) 1 else 0 // extension receiver comes before captures
val captureEnd = captureStart + capturedParameters.size
capturedVars = capturedParameters.mapIndexed { index, (parameter, _) ->
val isSuspend = parameter.isInlineParameter() && parameter.type.isSuspendFunctionTypeOrSubtype()
val isSuspend = parameter.isInlineParameter() && parameter.type.isSuspendFunction()
capturedParamDesc(parameter.name.asString(), asmMethod.argumentTypes[captureStart + index], isSuspend)
}
// The parameter list should include the continuation if this is a suspend lambda. In the IR backend,