diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt index f8d603f44bd..ad78da2e2da 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/KonanDriver.kt @@ -4,6 +4,7 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult import org.jetbrains.kotlin.backend.konan.llvm.emitLLVM import org.jetbrains.kotlin.backend.konan.util.profile import org.jetbrains.kotlin.backend.konan.Context +import org.jetbrains.kotlin.backend.konan.ir.ModuleIndex import org.jetbrains.kotlin.cli.common.CLICompiler import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport @@ -67,6 +68,7 @@ public fun runTopLevelPhases(konanConfig: KonanConfig, environment: KotlinCoreEn phaser.phase(KonanPhase.BACKEND) { phaser.phase(KonanPhase.LOWER) { KonanLower(context).lower() + context.ir.moduleIndexForCodegen = ModuleIndex(context.ir.irModule) } phaser.phase(KonanPhase.BITCODE) { emitLLVM(context) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt index 9e72f50942b..02ba74f77c3 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt @@ -8,5 +8,7 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor internal class Ir(val context: Context, val irModule: IrModuleFragment) { val propertiesWithBackingFields = mutableSetOf() - val moduleIndex = ModuleIndex(irModule) + val originalModuleIndex = ModuleIndex(irModule) + + lateinit var moduleIndexForCodegen: ModuleIndex } diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt index 16c1b28264c..fc0f65ee207 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/ContextUtils.kt @@ -75,7 +75,7 @@ internal interface ContextUtils { // In this function we check the presence of the backing filed // two ways: first we check IR, then we check the annotation. - val irClass = context.ir.moduleIndex.classes[this.classId] + val irClass = context.ir.moduleIndexForCodegen.classes[this.classId] if (irClass != null) { val declarations = irClass.declarations diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt index 4a2777441a3..fea79580d6f 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/IrToBitcode.kt @@ -388,7 +388,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid LLVMSetInitializer(objectPtr, codegen.kNullObjHeaderPtr) } } - val irOfCurrentClass = context.ir.moduleIndex.classes[classDescriptor.classId] + val irOfCurrentClass = context.ir.moduleIndexForCodegen.classes[classDescriptor.classId] irOfCurrentClass!!.acceptChildrenVoid(object : IrElementVisitorVoid { override fun visitElement(element: IrElement) { element.acceptChildrenVoid(this) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt index 4e0d9f7433e..533802e0b84 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt @@ -24,7 +24,8 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoid( val functionDescriptor = expression.descriptor as FunctionDescriptor if (!functionDescriptor.isInline) return super.visitCall(expression) // Function is not to be inlined - do nothing. - val functionDeclaration = context.ir.moduleIndex.functions[functionDescriptor] // Get FunctionDeclaration by FunctionDescriptor. + val functionDeclaration = context.ir.originalModuleIndex + .functions[functionDescriptor] // Get FunctionDeclaration by FunctionDescriptor. if (functionDeclaration == null) return super.visitCall(expression) // Function is declared in another module. val copyFuncDeclaration = functionDeclaration.accept(DeepCopyIrTree(), null) as IrFunction // Create copy of the function.