From 702322bd783077d10306021e493adca42c4c09e1 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Thu, 11 Apr 2019 14:16:20 +0300 Subject: [PATCH] Refactor InteropLowering to avoid using SymbolTable --- .../kotlin/backend/konan/ir/NewIrUtils.kt | 2 +- .../backend/konan/lower/InteropLowering.kt | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/NewIrUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/NewIrUtils.kt index b54fc063324..d844ac8836d 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/NewIrUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/NewIrUtils.kt @@ -124,7 +124,7 @@ fun IrValueParameter.isInlineParameter(): Boolean = val IrDeclaration.parentDeclarationsWithSelf: Sequence get() = generateSequence(this, { it.parent as? IrDeclaration }) -fun IrClass.companionObject() = this.declarations.singleOrNull {it is IrClass && it.isCompanion } +fun IrClass.companionObject() = this.declarations.filterIsInstance().atMostOne { it.isCompanion } val IrDeclaration.isGetter get() = this is IrSimpleFunction && this == this.correspondingProperty?.getter diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt index 7cf9521d6c0..58dac7de675 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.backend.konan.descriptors.allOverriddenFunctions import org.jetbrains.kotlin.backend.konan.descriptors.isInterface import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName import org.jetbrains.kotlin.backend.konan.ir.* +import org.jetbrains.kotlin.backend.konan.ir.companionObject import org.jetbrains.kotlin.backend.konan.objcexport.namePrefix import org.jetbrains.kotlin.backend.konan.llvm.IntrinsicType import org.jetbrains.kotlin.backend.konan.llvm.llvmSymbolOrigin @@ -95,7 +96,6 @@ internal abstract class BaseInteropIrTransformer(private val context: Context) : internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransformer(context), FileLoweringPass { private val symbols get() = context.ir.symbols - private val symbolTable get() = symbols.symbolTable lateinit var currentFile: IrFile @@ -595,16 +595,15 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo val initCall = builder.genLoweredObjCMethodCall( initMethodInfo, - superQualifier = symbolTable.referenceClass(expression.descriptor.constructedClass), + superQualifier = expression.symbol.owner.constructedClass.symbol, receiver = builder.getRawPtr(builder.irGet(constructedClass.thisReceiver!!)), arguments = initMethod.valueParameters.map { expression.getValueArgument(it.index)!! }, call = expression, method = initMethod ) - val superConstructor = symbolTable.referenceConstructor( - expression.descriptor.constructedClass.constructors.single { it.valueParameters.size == 0 } - ) + val superConstructor = expression.symbol.owner.constructedClass + .constructors.single { it.valueParameters.size == 0 }.symbol return builder.irBlock(expression) { // Required for the IR to be valid, will be ignored in codegen: @@ -727,11 +726,12 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo if (classSymbol == null) { expression } else { - val classDescriptor = classSymbol.descriptor - val companionObject = classDescriptor.companionObjectDescriptor ?: - error("native variable class $classDescriptor must have the companion object") + val irClass = classSymbol.owner - builder.at(expression).irGetObject(symbolTable.lazyWrapper.referenceClass(companionObject)) + val companionObject = irClass.companionObject() ?: + error("native variable class ${irClass.descriptor} must have the companion object") + + builder.at(expression).irGetObject(companionObject.symbol) } } else -> expression