From dc27df932280ffe0bb00990761090cea8f5ae711 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Fri, 19 Mar 2021 18:38:03 +0300 Subject: [PATCH] Fix bug in KType support affecting only stdlib Don't use IrClass.declarations to find enum entries during lowerings, because this enum might already be lowered and thus have all entries removed. --- .../org/jetbrains/kotlin/backend/konan/ir/Ir.kt | 10 ++++++++++ .../backend/konan/lower/ReflectionSupport.kt | 15 +++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) 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 a4b38853084..d2ddda68962 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 @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.backend.common.COROUTINE_SUSPENDED_NAME import org.jetbrains.kotlin.backend.common.ir.Ir import org.jetbrains.kotlin.backend.common.ir.Symbols import org.jetbrains.kotlin.backend.konan.* +import org.jetbrains.kotlin.backend.konan.descriptors.enumEntries import org.jetbrains.kotlin.backend.konan.descriptors.kotlinNativeInternal import org.jetbrains.kotlin.backend.konan.llvm.findMainEntryPoint import org.jetbrains.kotlin.backend.konan.lower.TestProcessor @@ -23,6 +24,7 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.types.IrType @@ -455,6 +457,14 @@ internal class KonanSymbols( val kType = symbolTable.referenceClass(context.reflectionTypes.kType) val kVariance = symbolTable.referenceClass(context.reflectionTypes.kVariance) + val kVarianceIn = getKVarianceEnumEntry("IN") + val kVarianceOut = getKVarianceEnumEntry("OUT") + val kVarianceInvariant = getKVarianceEnumEntry("INVARIANT") + + private fun getKVarianceEnumEntry(name: String): IrEnumEntrySymbol { + val descriptor = context.reflectionTypes.kVariance.enumEntries.single { it.name.asString() == name } + return symbolTable.referenceEnumEntry(descriptor) + } val getClassTypeInfo = internalFunction("getClassTypeInfo") val getObjectTypeInfo = internalFunction("getObjectTypeInfo") diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ReflectionSupport.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ReflectionSupport.kt index 8364b0eb0e7..07d1bb10214 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ReflectionSupport.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/ReflectionSupport.kt @@ -126,20 +126,15 @@ internal class KTypeGenerator( else -> parent.fqNameForIrSerialization.asString() } - private val Variance.kVarianceName: String - get() = when (this) { - Variance.INVARIANT -> "INVARIANT" - Variance.IN_VARIANCE -> "IN" - Variance.OUT_VARIANCE -> "OUT" - } - private fun IrBuilderWithScope.irKVariance(variance: Variance) = IrGetEnumValueImpl( startOffset, endOffset, symbols.kVariance.defaultType, - symbols.kVariance.owner.declarations - .filterIsInstance() - .single { it.name.asString() == variance.kVarianceName }.symbol + when (variance) { + Variance.INVARIANT -> symbols.kVarianceInvariant + Variance.IN_VARIANCE -> symbols.kVarianceIn + Variance.OUT_VARIANCE -> symbols.kVarianceOut + } ) private fun IrBuilderWithScope.irKTypeLikeList(