IR: make calls with explicit singleton receiver tailrec [KT-48602]
This commit is contained in:
committed by
TeamCityServer
parent
8525b4932b
commit
3c84fbcab1
+10
@@ -16,11 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.types.isUnit
|
||||
import org.jetbrains.kotlin.ir.util.usesDefaultArguments
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
@@ -107,6 +110,13 @@ fun collectTailRecursionCalls(irFunction: IrFunction): Set<IrCall> {
|
||||
// Overridden functions using default arguments at tail call are not included: KT-4285
|
||||
return
|
||||
}
|
||||
val dispatchReceiverType = irFunction.dispatchReceiverParameter?.type
|
||||
if (dispatchReceiverType?.classOrNull?.owner?.kind?.isSingleton == true) {
|
||||
// Dispatch receiver type is singleton and hence it can't be changed and the call must be tailrec.
|
||||
result.add(expression)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
expression.dispatchReceiver?.let {
|
||||
if (it !is IrGetValue || it.symbol.owner != irFunction.dispatchReceiverParameter) {
|
||||
|
||||
Reference in New Issue
Block a user