JVM: remove InlineCodegen.expressionMap
#KT-48180 Fixed
This commit is contained in:
+2
-5
@@ -520,13 +520,10 @@ class AnonymousObjectTransformer(
|
|||||||
val paramTypes = transformationInfo.constructorDesc?.let { Type.getArgumentTypes(it) } ?: emptyArray()
|
val paramTypes = transformationInfo.constructorDesc?.let { Type.getArgumentTypes(it) } ?: emptyArray()
|
||||||
for (type in paramTypes) {
|
for (type in paramTypes) {
|
||||||
val info = indexToFunctionalArgument[constructorParamBuilder.nextParameterOffset]
|
val info = indexToFunctionalArgument[constructorParamBuilder.nextParameterOffset]
|
||||||
|
val isCaptured = capturedParams.contains(constructorParamBuilder.nextParameterOffset)
|
||||||
val parameterInfo = constructorParamBuilder.addNextParameter(type, info is LambdaInfo)
|
val parameterInfo = constructorParamBuilder.addNextParameter(type, info is LambdaInfo)
|
||||||
parameterInfo.functionalArgument = info
|
parameterInfo.functionalArgument = info
|
||||||
if (capturedParams.contains(parameterInfo.index)) {
|
parameterInfo.isCaptured = isCaptured
|
||||||
parameterInfo.isCaptured = true
|
|
||||||
} else {
|
|
||||||
//otherwise it's super constructor parameter
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//For all inlined lambdas add their captured parameters
|
//For all inlined lambdas add their captured parameters
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
|||||||
private val initialFrameSize = codegen.frameMap.currentSize
|
private val initialFrameSize = codegen.frameMap.currentSize
|
||||||
|
|
||||||
protected val invocationParamBuilder = ParametersBuilder.newBuilder()
|
protected val invocationParamBuilder = ParametersBuilder.newBuilder()
|
||||||
protected val expressionMap = linkedMapOf<Int, FunctionalArgument>()
|
|
||||||
private val maskValues = ArrayList<Int>()
|
private val maskValues = ArrayList<Int>()
|
||||||
private var maskStartIndex = -1
|
private var maskStartIndex = -1
|
||||||
private var methodHandleInDefaultMethodIndex = -1
|
private var methodHandleInDefaultMethodIndex = -1
|
||||||
@@ -80,8 +79,6 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
|||||||
for (info in infos) {
|
for (info in infos) {
|
||||||
val lambda = DefaultLambda(info, sourceCompiler)
|
val lambda = DefaultLambda(info, sourceCompiler)
|
||||||
parameters.getParameterByDeclarationSlot(info.offset).functionalArgument = lambda
|
parameters.getParameterByDeclarationSlot(info.offset).functionalArgument = lambda
|
||||||
val prev = expressionMap.put(info.offset, lambda)
|
|
||||||
assert(prev == null) { "Lambda with offset ${info.offset} already exists: $prev" }
|
|
||||||
if (info.needReification) {
|
if (info.needReification) {
|
||||||
lambda.reifiedTypeParametersUsages.mergeAll(reifiedTypeInliner.reifyInstructions(lambda.node.node))
|
lambda.reifiedTypeParametersUsages.mergeAll(reifiedTypeInliner.reifyInstructions(lambda.node.node))
|
||||||
}
|
}
|
||||||
@@ -98,7 +95,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
|||||||
val parameters = invocationParamBuilder.buildParameters()
|
val parameters = invocationParamBuilder.buildParameters()
|
||||||
|
|
||||||
val info = RootInliningContext(
|
val info = RootInliningContext(
|
||||||
expressionMap, state, codegen.inlineNameGenerator.subGenerator(jvmSignature.asmMethod.name),
|
state, codegen.inlineNameGenerator.subGenerator(jvmSignature.asmMethod.name),
|
||||||
sourceCompiler, sourceCompiler.inlineCallSiteInfo, reifiedTypeInliner, typeParameterMappings
|
sourceCompiler, sourceCompiler.inlineCallSiteInfo, reifiedTypeInliner, typeParameterMappings
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -213,9 +210,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun rememberClosure(parameterType: Type, index: Int, lambdaInfo: LambdaInfo) {
|
protected fun rememberClosure(parameterType: Type, index: Int, lambdaInfo: LambdaInfo) {
|
||||||
val closureInfo = invocationParamBuilder.addNextValueParameter(parameterType, true, null, index)
|
invocationParamBuilder.addNextValueParameter(parameterType, true, null, index).functionalArgument = lambdaInfo
|
||||||
closureInfo.functionalArgument = lambdaInfo
|
|
||||||
expressionMap[closureInfo.index] = lambdaInfo
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun putCapturedToLocalVal(stackValue: StackValue, capturedParam: CapturedParamDesc, kotlinType: KotlinType?) {
|
protected fun putCapturedToLocalVal(stackValue: StackValue, capturedParam: CapturedParamDesc, kotlinType: KotlinType?) {
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.codegen.ClassBuilder
|
|||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
|
|
||||||
class RootInliningContext(
|
class RootInliningContext(
|
||||||
expressionMap: Map<Int, FunctionalArgument>,
|
|
||||||
state: GenerationState,
|
state: GenerationState,
|
||||||
nameGenerator: NameGenerator,
|
nameGenerator: NameGenerator,
|
||||||
val sourceCompilerForInline: SourceCompilerForInline,
|
val sourceCompilerForInline: SourceCompilerForInline,
|
||||||
@@ -17,12 +16,11 @@ class RootInliningContext(
|
|||||||
val inlineMethodReifier: ReifiedTypeInliner<*>,
|
val inlineMethodReifier: ReifiedTypeInliner<*>,
|
||||||
typeParameterMappings: TypeParameterMappings<*>
|
typeParameterMappings: TypeParameterMappings<*>
|
||||||
) : InliningContext(
|
) : InliningContext(
|
||||||
null, expressionMap, state, nameGenerator, TypeRemapper.createRoot(typeParameterMappings), null, false
|
null, state, nameGenerator, TypeRemapper.createRoot(typeParameterMappings), null, false
|
||||||
)
|
)
|
||||||
|
|
||||||
class RegeneratedClassContext(
|
class RegeneratedClassContext(
|
||||||
parent: InliningContext,
|
parent: InliningContext,
|
||||||
expressionMap: Map<Int, FunctionalArgument>,
|
|
||||||
state: GenerationState,
|
state: GenerationState,
|
||||||
nameGenerator: NameGenerator,
|
nameGenerator: NameGenerator,
|
||||||
typeRemapper: TypeRemapper,
|
typeRemapper: TypeRemapper,
|
||||||
@@ -30,14 +28,13 @@ class RegeneratedClassContext(
|
|||||||
override val callSiteInfo: InlineCallSiteInfo,
|
override val callSiteInfo: InlineCallSiteInfo,
|
||||||
override val transformationInfo: TransformationInfo
|
override val transformationInfo: TransformationInfo
|
||||||
) : InliningContext(
|
) : InliningContext(
|
||||||
parent, expressionMap, state, nameGenerator, typeRemapper, lambdaInfo, true
|
parent, state, nameGenerator, typeRemapper, lambdaInfo, true
|
||||||
) {
|
) {
|
||||||
val continuationBuilders: MutableMap<String, ClassBuilder> = hashMapOf()
|
val continuationBuilders: MutableMap<String, ClassBuilder> = hashMapOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
open class InliningContext(
|
open class InliningContext(
|
||||||
val parent: InliningContext?,
|
val parent: InliningContext?,
|
||||||
val expressionMap: Map<Int, FunctionalArgument>,
|
|
||||||
val state: GenerationState,
|
val state: GenerationState,
|
||||||
val nameGenerator: NameGenerator,
|
val nameGenerator: NameGenerator,
|
||||||
val typeRemapper: TypeRemapper,
|
val typeRemapper: TypeRemapper,
|
||||||
@@ -97,7 +94,7 @@ open class InliningContext(
|
|||||||
callSiteInfo: InlineCallSiteInfo,
|
callSiteInfo: InlineCallSiteInfo,
|
||||||
transformationInfo: TransformationInfo
|
transformationInfo: TransformationInfo
|
||||||
): InliningContext = RegeneratedClassContext(
|
): InliningContext = RegeneratedClassContext(
|
||||||
this, expressionMap, state, generator, TypeRemapper.createFrom(typeRemapper, newTypeMappings),
|
this, state, generator, TypeRemapper.createFrom(typeRemapper, newTypeMappings),
|
||||||
lambdaInfo, callSiteInfo, transformationInfo
|
lambdaInfo, callSiteInfo, transformationInfo
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -110,7 +107,7 @@ open class InliningContext(
|
|||||||
): InliningContext {
|
): InliningContext {
|
||||||
val isInliningLambda = lambdaInfo != null
|
val isInliningLambda = lambdaInfo != null
|
||||||
return InliningContext(
|
return InliningContext(
|
||||||
this, expressionMap, state, generator,
|
this, state, generator,
|
||||||
TypeRemapper.createFrom(
|
TypeRemapper.createFrom(
|
||||||
typeRemapper,
|
typeRemapper,
|
||||||
additionalTypeMappings,
|
additionalTypeMappings,
|
||||||
|
|||||||
@@ -62,19 +62,16 @@ class PsiInlineCodegen(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
val registerLineNumber = registerLineNumberAfterwards(resolvedCall)
|
for (info in closuresToGenerate) {
|
||||||
for (info in expressionMap.values) {
|
// Can't be done immediately in `rememberClosure` for some reason:
|
||||||
if (info is PsiExpressionLambda) {
|
info.generateLambdaBody(sourceCompiler)
|
||||||
// Can't be done immediately in `rememberClosure` for some reason:
|
// Requires `generateLambdaBody` first if the closure is non-empty (for bound callable references,
|
||||||
info.generateLambdaBody(sourceCompiler)
|
// or indeed any callable references, it *is* empty, so this was done in `rememberClosure`):
|
||||||
// Requires `generateLambdaBody` first if the closure is non-empty (for bound callable references,
|
if (!info.isBoundCallableReference) {
|
||||||
// or indeed any callable references, it *is* empty, so this was done in `rememberClosure`):
|
putClosureParametersOnStack(info, null)
|
||||||
if (!info.isBoundCallableReference) {
|
|
||||||
putClosureParametersOnStack(info, null)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
performInline(registerLineNumber, functionDescriptor.isInlineOnly())
|
performInline(registerLineNumberAfterwards(resolvedCall), functionDescriptor.isInlineOnly())
|
||||||
} finally {
|
} finally {
|
||||||
state.globalInlineContext.exitFromInlining()
|
state.globalInlineContext.exitFromInlining()
|
||||||
}
|
}
|
||||||
@@ -144,6 +141,8 @@ 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 val closuresToGenerate = mutableListOf<PsiExpressionLambda>()
|
||||||
|
|
||||||
private fun rememberClosure(expression: KtExpression, type: Type, parameter: ValueParameterDescriptor) {
|
private fun rememberClosure(expression: KtExpression, type: Type, parameter: ValueParameterDescriptor) {
|
||||||
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}" }
|
||||||
@@ -155,6 +154,7 @@ class PsiInlineCodegen(
|
|||||||
|
|
||||||
val lambda = PsiExpressionLambda(ktLambda!!, state, parameter.isCrossinline, boundReceiver != null)
|
val lambda = PsiExpressionLambda(ktLambda!!, state, parameter.isCrossinline, boundReceiver != null)
|
||||||
rememberClosure(type, parameter.index, lambda)
|
rememberClosure(type, parameter.index, lambda)
|
||||||
|
closuresToGenerate += lambda
|
||||||
if (boundReceiver != null) {
|
if (boundReceiver != null) {
|
||||||
// Has to be done immediately to preserve evaluation order.
|
// Has to be done immediately to preserve evaluation order.
|
||||||
val receiver = codegen.generateReceiverValue(boundReceiver, false)
|
val receiver = codegen.generateReceiverValue(boundReceiver, false)
|
||||||
|
|||||||
Reference in New Issue
Block a user