[IR] Inliner: supported recursion in default arguments

This commit is contained in:
Igor Chevdar
2020-10-29 13:14:25 +05:00
parent 5f8fabed61
commit 94145f880c
2 changed files with 12 additions and 6 deletions
@@ -162,11 +162,17 @@ class FunctionInlining(
callee: IrFunction, callee: IrFunction,
performRecursiveInline: Boolean performRecursiveInline: Boolean
): IrReturnableBlock { ): IrReturnableBlock {
val copiedCallee = copyIrElement.copy(callee).let { val copiedCallee = (copyIrElement.copy(callee) as IrFunction).apply {
(it as IrFunction).parent = callee.parent parent = callee.parent
if (performRecursiveInline) if (performRecursiveInline) {
visitElement(it) as IrFunction body?.transformChildrenVoid()
else it valueParameters.forEachIndexed { index, param ->
if (callSite.getValueArgument(index) == null) {
// Default values can recursively reference [callee] - transform only needed.
param.defaultValue = param.defaultValue?.transform(this@FunctionInlining, null)
}
}
}
} }
val evaluationStatements = evaluateArguments(callSite, copiedCallee) val evaluationStatements = evaluateArguments(callSite, copiedCallee)
@@ -1,4 +1,4 @@
// IGNORE_BACKEND: JS, JS_IR // IGNORE_BACKEND: JS
@Suppress("RECURSION_IN_INLINE") @Suppress("RECURSION_IN_INLINE")
inline fun test(p: String = test("OK")): String { inline fun test(p: String = test("OK")): String {
return p return p