[IR] Correctly transform KCallable.name call to optimize it later

We need to transform call from `KFunction(N).name` to
`KFunction(N+1).name`. This way we keep IR correct and if something
goes wrong during interpretation, we still will have compilable code.

This commit suppose to fix three failing tests on Native aggregate
build:
1. `FirNativePartialLinkageTestGenerated.
testReferencingUnusableDeclarations`
2. `FirNativeCodegenBoxTestGenerated$Box$CallableReference$Bound.
testKCallableNameIntrinsic`
3. `FirNativeCodegenBoxTestNoPLGenerated$Box$CallableReference$Bound
.testKCallableNameIntrinsic`
This commit is contained in:
Ivan Kylchik
2023-06-20 18:15:03 +02:00
committed by Space Team
parent ce4ad0e42a
commit bde6df8ca1
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.ir.types.typeOrNull
import org.jetbrains.kotlin.ir.types.typeWith
import org.jetbrains.kotlin.ir.util.isKFunction
import org.jetbrains.kotlin.ir.util.isSubclassOf
import org.jetbrains.kotlin.ir.util.properties
import org.jetbrains.kotlin.name.SpecialNames
// Note: this class still will not allow us to evaluate things like `A()::a.name + `A()::b.name`.
@@ -41,6 +42,9 @@ class IrInterpreterKCallableNamePreprocessor : IrInterpreterPreprocessor {
callableReference.type = newType
}
// We want to change symbol to keep IR correct. If something goes wrong during interpretation, we still will have compilable code.
expression.symbol = data.irBuiltIns.kCallableClass.owner.properties.single { it.name.asString() == "name" }.getter!!.symbol
callableReference.dispatchReceiver = null
callableReference.extensionReceiver = null
if (receiver is IrGetValue && receiver.symbol.owner.name == SpecialNames.THIS) return expression