[DFG][Interop] Handle references to Obj-C companions

We generate LazyIR for Obj-C classes from metadata-based interop libraries.
Thus, singletons have not constructors (because these constructors are private).
This commit is contained in:
Sergey Bogolepov
2020-02-14 11:09:08 +07:00
committed by Sergey Bogolepov
parent 5887bd54a9
commit 07e6d9d0ad
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.backend.konan.llvm.functionName
import org.jetbrains.kotlin.backend.konan.llvm.localHash import org.jetbrains.kotlin.backend.konan.llvm.localHash
import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyClass
import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
@@ -577,12 +578,21 @@ internal class ModuleDFGBuilder(val context: Context, val irModule: IrModuleFrag
else else
DataFlowIR.Node.SimpleConst(symbolTable.mapType(value.type), value.value!!) DataFlowIR.Node.SimpleConst(symbolTable.mapType(value.type), value.value!!)
is IrGetObjectValue -> DataFlowIR.Node.Singleton( is IrGetObjectValue -> {
symbolTable.mapType(value.type), val constructor = if (value.type.isNothing()) {
if (value.type.isNothing()) // <Nothing> is not a singleton though its instance is get with <IrGetObject> operation. // <Nothing> is not a singleton though its instance is get with <IrGetObject> operation.
null
} else {
val objectClass = value.symbol.owner
if (objectClass is IrLazyClass) {
// Singleton has a private constructor which is not deserialized.
null null
else symbolTable.mapFunction(value.symbol.owner.constructors.single()) } else {
) symbolTable.mapFunction(objectClass.constructors.single())
}
}
DataFlowIR.Node.Singleton(symbolTable.mapType(value.type), constructor)
}
is IrConstructorCall -> { is IrConstructorCall -> {
val callee = value.symbol.owner val callee = value.symbol.owner