Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
Fix bug in KType support affecting only stdlib
Browse files Browse the repository at this point in the history
Don't use IrClass.declarations to find enum entries during lowerings,
because this enum might already be lowered and thus have all entries
removed.
  • Loading branch information
SvyatoslavScherbina committed Mar 19, 2021
1 parent 146c510 commit dc27df9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IrEnumEntry>()
.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 <T> IrBuilderWithScope.irKTypeLikeList(
Expand Down

0 comments on commit dc27df9

Please sign in to comment.