JVM: inline createInlineMethodNode into InlineCodegenForDefaultBody
Most of it is unused, since there we know the target function will also need to be compiled from source.
This commit is contained in:
@@ -2969,7 +2969,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
}
|
||||
Type methodOwner = typeMapper.mapImplementationOwner(functionDescriptor);
|
||||
if (isDefaultCompilation) {
|
||||
return new InlineCodegenForDefaultBody(functionDescriptor, this, state, methodOwner, signature, sourceCompiler);
|
||||
return new InlineCodegenForDefaultBody(functionDescriptor, this, state, signature, sourceCompiler);
|
||||
}
|
||||
else {
|
||||
return new PsiInlineCodegen(this, state, functionDescriptor, methodOwner, signature, typeParameterMappings, sourceCompiler,
|
||||
|
||||
@@ -59,11 +59,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
||||
private val initialFrameSize = codegen.frameMap.currentSize
|
||||
|
||||
protected val invocationParamBuilder = ParametersBuilder.newBuilder()
|
||||
|
||||
protected val expressionMap = linkedMapOf<Int, FunctionalArgument>()
|
||||
|
||||
private val sourceMapper = sourceCompiler.lazySourceMapper
|
||||
|
||||
protected val maskValues = ArrayList<Int>()
|
||||
protected var maskStartIndex = -1
|
||||
protected var methodHandleInDefaultMethodIndex = -1
|
||||
@@ -209,6 +205,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
||||
sourceCompiler, sourceCompiler.inlineCallSiteInfo, reifiedTypeInliner, typeParameterMappings
|
||||
)
|
||||
|
||||
val sourceMapper = sourceCompiler.sourceMapper
|
||||
val sourceInfo = sourceMapper.sourceInfo!!
|
||||
val callSite = SourcePosition(codegen.lastLineNumber, sourceInfo.sourceFileName!!, sourceInfo.pathOrCleanFQN)
|
||||
val inliner = MethodInliner(
|
||||
@@ -431,8 +428,7 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
internal fun createInlineMethodNode(
|
||||
private fun createInlineMethodNode(
|
||||
callDefault: Boolean,
|
||||
typeArguments: List<TypeParameterMarker>?,
|
||||
typeSystem: TypeSystemCommonBackendContext
|
||||
|
||||
+13
-25
@@ -15,15 +15,13 @@ import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Label
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
|
||||
class InlineCodegenForDefaultBody(
|
||||
private val function: FunctionDescriptor,
|
||||
codegen: ExpressionCodegen,
|
||||
val state: GenerationState,
|
||||
private val methodOwner: Type,
|
||||
private val jvmSignature: JvmMethodSignature,
|
||||
private val sourceCompilerForInline: SourceCompilerForInline
|
||||
private val sourceCompilerForInline: PsiSourceCompilerForInline
|
||||
) : CallGenerator {
|
||||
private val sourceMapper: SourceMapper = codegen.parentCodegen.orCreateSourceMapper
|
||||
|
||||
@@ -39,32 +37,22 @@ class InlineCodegenForDefaultBody(
|
||||
}
|
||||
|
||||
override fun genCallInner(callableMethod: Callable, resolvedCall: ResolvedCall<*>?, callDefault: Boolean, codegen: ExpressionCodegen) {
|
||||
val nodeAndSmap = PsiInlineCodegen(
|
||||
codegen, state, function, methodOwner, jvmSignature, TypeParameterMappings(), sourceCompilerForInline
|
||||
).createInlineMethodNode(
|
||||
callDefault, null, codegen.typeSystem
|
||||
)
|
||||
val childSourceMapper = SourceMapCopier(sourceMapper, nodeAndSmap.classSMAP)
|
||||
|
||||
val node = nodeAndSmap.node
|
||||
val transformedMethod = MethodNode(
|
||||
node.access,
|
||||
node.name,
|
||||
node.desc,
|
||||
node.signature,
|
||||
node.exceptions.toTypedArray()
|
||||
)
|
||||
assert(!callDefault) { "inlining default stub into another default stub" }
|
||||
val (node, smap) = sourceCompilerForInline.compileInlineFunction(jvmSignature, callDefault, jvmSignature.asmMethod)
|
||||
val childSourceMapper = SourceMapCopier(sourceMapper, smap)
|
||||
|
||||
val argsSize =
|
||||
(Type.getArgumentsAndReturnSizes(jvmSignature.asmMethod.descriptor) ushr 2) - if (callableMethod.isStaticCall()) 1 else 0
|
||||
node.accept(object : InlineAdapter(transformedMethod, 0, childSourceMapper) {
|
||||
override fun visitLocalVariable(name: String, desc: String, signature: String?, start: Label, end: Label, index: Int) {
|
||||
val startLabel = if (index < argsSize) methodStartLabel else start
|
||||
super.visitLocalVariable(name, desc, signature, startLabel, end, index)
|
||||
}
|
||||
})
|
||||
// `$default` is only for Kotlin use so it has no `$$forInline` version - this *is* what the inliner will use.
|
||||
node.preprocessSuspendMarkers(forInline = true, keepFakeContinuation = false)
|
||||
node.accept(object : MethodBodyVisitor(codegen.visitor) {
|
||||
// The LVT was not generated at all, so move the start of parameters to the start of the method.
|
||||
override fun visitLocalVariable(name: String, desc: String, signature: String?, start: Label, end: Label, index: Int) =
|
||||
super.visitLocalVariable(name, desc, signature, if (index < argsSize) methodStartLabel else start, end, index)
|
||||
|
||||
transformedMethod.accept(MethodBodyVisitor(codegen.visitor))
|
||||
override fun visitLineNumber(line: Int, start: Label) =
|
||||
super.visitLineNumber(childSourceMapper.mapLineNumber(line), start)
|
||||
})
|
||||
}
|
||||
|
||||
override fun genValueAndPut(
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ class PsiSourceCompilerForInline(
|
||||
)
|
||||
}
|
||||
|
||||
override val lazySourceMapper
|
||||
override val sourceMapper
|
||||
get() = codegen.parentCodegen.orCreateSourceMapper
|
||||
|
||||
override fun generateLambdaBody(lambdaInfo: ExpressionLambda, reifiedTypeParameters: ReifiedTypeParametersUsages): SMAPAndMethodNode {
|
||||
|
||||
@@ -33,7 +33,7 @@ interface SourceCompilerForInline {
|
||||
|
||||
val inlineCallSiteInfo: InlineCallSiteInfo
|
||||
|
||||
val lazySourceMapper: SourceMapper
|
||||
val sourceMapper: SourceMapper
|
||||
|
||||
fun generateLambdaBody(lambdaInfo: ExpressionLambda, reifiedTypeParameters: ReifiedTypeParametersUsages): SMAPAndMethodNode
|
||||
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ class IrSourceCompilerForInline(
|
||||
)
|
||||
}
|
||||
|
||||
override val lazySourceMapper: SourceMapper
|
||||
override val sourceMapper: SourceMapper
|
||||
get() = codegen.smap
|
||||
|
||||
override fun generateLambdaBody(lambdaInfo: ExpressionLambda, reifiedTypeParameters: ReifiedTypeParametersUsages): SMAPAndMethodNode {
|
||||
|
||||
Reference in New Issue
Block a user