Revert "JVM IR: Move direct invoke optimization into a separate pass"

This reverts commit f0760e0550.

The reason is that it leads to KT-53202.
This commit is contained in:
Alexander Udalov
2022-07-15 15:11:10 +02:00
parent 497bb9a05c
commit b50d2ff20a
19 changed files with 417 additions and 191 deletions
@@ -30,7 +30,12 @@ class IrInvokable(val invokable: IrValueDeclaration) : IrInlinable()
class IrInlinableLambda(val function: IrSimpleFunction, val boundReceiver: IrValueDeclaration?) : IrInlinable()
// Return the underlying function for a lambda argument without bound or default parameters or varargs.
fun IrExpression.asInlinableFunctionReference(): IrFunctionReference? {
private fun IrExpression.asInlinableLambda(builder: IrStatementsBuilder<*>): IrInlinableLambda? {
if (this is IrFunctionExpression) {
if (function.valueParameters.any { it.isVararg || it.defaultValue != null })
return null
return IrInlinableLambda(function, null)
}
// A lambda is represented as a block with a function declaration and a reference to it.
// Inlinable function references are also a kind of lambda; bound receivers are represented as extension receivers.
if (this !is IrBlock || statements.size != 2)
@@ -44,18 +49,7 @@ fun IrExpression.asInlinableFunctionReference(): IrFunctionReference? {
return null
if (function.valueParameters.any { it.isVararg || it.defaultValue != null })
return null
return reference
}
private fun IrExpression.asInlinableLambda(builder: IrStatementsBuilder<*>): IrInlinableLambda? {
if (this is IrFunctionExpression) {
if (function.valueParameters.any { it.isVararg || it.defaultValue != null })
return null
return IrInlinableLambda(function, null)
}
return asInlinableFunctionReference()?.let { reference ->
IrInlinableLambda(reference.symbol.owner as IrSimpleFunction, reference.extensionReceiver?.let { builder.irTemporary(it) })
}
return IrInlinableLambda(function, reference.extensionReceiver?.let { builder.irTemporary(it) })
}
fun IrExpression.asInlinable(builder: IrStatementsBuilder<*>): IrInlinable =
@@ -104,7 +98,7 @@ private fun IrBody.move(
// TODO use a generic inliner (e.g. JS/Native's FunctionInlining.Inliner)
// Inline simple function calls without type parameters, default parameters, or varargs.
fun IrFunction.inline(target: IrDeclarationParent, arguments: List<IrValueDeclaration> = listOf()): IrReturnableBlock =
private fun IrFunction.inline(target: IrDeclarationParent, arguments: List<IrValueDeclaration> = listOf()): IrReturnableBlock =
IrReturnableBlockImpl(startOffset, endOffset, returnType, IrReturnableBlockSymbolImpl(), null, symbol).apply {
statements += body!!.move(this@inline, target, symbol, explicitParameters.zip(arguments).toMap()).statements
}