[K/N] Remove some descriptor usages from Ir.kt
This commit is contained in:
+1
-1
@@ -280,7 +280,7 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val reflectionTypes: KonanReflectionTypes by lazy(PUBLICATION) {
|
val reflectionTypes: KonanReflectionTypes by lazy(PUBLICATION) {
|
||||||
KonanReflectionTypes(moduleDescriptor, KonanFqNames.internalPackageName)
|
KonanReflectionTypes(moduleDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove after adding special <userData> property to IrDeclaration.
|
// TODO: Remove after adding special <userData> property to IrDeclaration.
|
||||||
|
|||||||
-14
@@ -10,26 +10,18 @@ import org.jetbrains.kotlin.backend.common.DefaultMapping
|
|||||||
import org.jetbrains.kotlin.backend.common.Mapping
|
import org.jetbrains.kotlin.backend.common.Mapping
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.KonanSharedVariablesManager
|
import org.jetbrains.kotlin.backend.konan.descriptors.KonanSharedVariablesManager
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.findPackage
|
import org.jetbrains.kotlin.backend.konan.descriptors.findPackage
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.kotlinNativeInternal
|
|
||||||
import org.jetbrains.kotlin.backend.konan.ir.KonanIr
|
import org.jetbrains.kotlin.backend.konan.ir.KonanIr
|
||||||
import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns
|
import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns
|
||||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
|
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFactory
|
import org.jetbrains.kotlin.ir.declarations.IrFactory
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
|
|
||||||
internal abstract class KonanBackendContext(val config: KonanConfig) : CommonBackendContext {
|
internal abstract class KonanBackendContext(val config: KonanConfig) : CommonBackendContext {
|
||||||
abstract override val builtIns: KonanBuiltIns
|
abstract override val builtIns: KonanBuiltIns
|
||||||
@@ -44,12 +36,6 @@ internal abstract class KonanBackendContext(val config: KonanConfig) : CommonBac
|
|||||||
KonanSharedVariablesManager(this)
|
KonanSharedVariablesManager(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getKonanInternalClass(name: String): ClassDescriptor =
|
|
||||||
builtIns.kotlinNativeInternal.getContributedClassifier(Name.identifier(name), NoLookupLocation.FROM_BACKEND) as ClassDescriptor
|
|
||||||
|
|
||||||
fun getKonanInternalFunctions(name: String): List<FunctionDescriptor> =
|
|
||||||
builtIns.kotlinNativeInternal.getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND).toList()
|
|
||||||
|
|
||||||
val messageCollector: MessageCollector
|
val messageCollector: MessageCollector
|
||||||
get() = config.configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
get() = config.configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||||
|
|
||||||
|
|||||||
+1
-33
@@ -10,54 +10,22 @@ import org.jetbrains.kotlin.builtins.StandardNames.KOTLIN_REFLECT_FQ_NAME
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import kotlin.reflect.KProperty
|
|
||||||
|
|
||||||
class KonanReflectionTypes(module: ModuleDescriptor, internalPackage: FqName) {
|
class KonanReflectionTypes(module: ModuleDescriptor) {
|
||||||
|
|
||||||
private val kotlinReflectScope: MemberScope by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
private val kotlinReflectScope: MemberScope by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||||
module.getPackage(KOTLIN_REFLECT_FQ_NAME).memberScope
|
module.getPackage(KOTLIN_REFLECT_FQ_NAME).memberScope
|
||||||
}
|
}
|
||||||
|
|
||||||
private val internalScope: MemberScope by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
|
||||||
module.getPackage(internalPackage).memberScope
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun find(memberScope: MemberScope, className: String): ClassDescriptor {
|
private fun find(memberScope: MemberScope, className: String): ClassDescriptor {
|
||||||
val name = Name.identifier(className)
|
val name = Name.identifier(className)
|
||||||
return memberScope.getContributedClassifier(name, NoLookupLocation.FROM_REFLECTION) as ClassDescriptor
|
return memberScope.getContributedClassifier(name, NoLookupLocation.FROM_REFLECTION) as ClassDescriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ClassLookup(val memberScope: MemberScope) {
|
|
||||||
operator fun getValue(types: KonanReflectionTypes, property: KProperty<*>): ClassDescriptor {
|
|
||||||
return types.find(memberScope, property.name.replaceFirstChar(Char::uppercaseChar))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getKFunction(n: Int): ClassDescriptor = find(kotlinReflectScope, "KFunction$n")
|
fun getKFunction(n: Int): ClassDescriptor = find(kotlinReflectScope, "KFunction$n")
|
||||||
|
|
||||||
fun getKSuspendFunction(n: Int): ClassDescriptor = find(kotlinReflectScope, "KSuspendFunction$n")
|
fun getKSuspendFunction(n: Int): ClassDescriptor = find(kotlinReflectScope, "KSuspendFunction$n")
|
||||||
|
|
||||||
val kProperty0: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
|
||||||
val kMutableProperty0: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
|
||||||
val kMutableProperty1: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
|
||||||
val kMutableProperty2: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
|
||||||
val kTypeProjection: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
|
||||||
val kType: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
|
||||||
val kVariance: ClassDescriptor by ClassLookup(kotlinReflectScope)
|
|
||||||
|
|
||||||
val kFunctionImpl: ClassDescriptor by ClassLookup(internalScope)
|
|
||||||
val kSuspendFunctionImpl: ClassDescriptor by ClassLookup(internalScope)
|
|
||||||
val kProperty0Impl: ClassDescriptor by ClassLookup(internalScope)
|
|
||||||
val kProperty1Impl: ClassDescriptor by ClassLookup(internalScope)
|
|
||||||
val kProperty2Impl: ClassDescriptor by ClassLookup(internalScope)
|
|
||||||
val kMutableProperty0Impl: ClassDescriptor by ClassLookup(internalScope)
|
|
||||||
val kMutableProperty1Impl: ClassDescriptor by ClassLookup(internalScope)
|
|
||||||
val kMutableProperty2Impl: ClassDescriptor by ClassLookup(internalScope)
|
|
||||||
val kLocalDelegatedPropertyImpl: ClassDescriptor by ClassLookup(internalScope)
|
|
||||||
val kLocalDelegatedMutablePropertyImpl: ClassDescriptor by ClassLookup(internalScope)
|
|
||||||
|
|
||||||
val typeOf = kotlinReflectScope.getContributedFunctions(Name.identifier("typeOf"), NoLookupLocation.FROM_REFLECTION).single()
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -22,6 +22,7 @@ object RuntimeNames {
|
|||||||
val independent = FqName("kotlin.native.internal.Independent")
|
val independent = FqName("kotlin.native.internal.Independent")
|
||||||
val filterExceptions = FqName("kotlin.native.internal.FilterExceptions")
|
val filterExceptions = FqName("kotlin.native.internal.FilterExceptions")
|
||||||
val kotlinNativeInternalPackageName = FqName.fromSegments(listOf("kotlin", "native", "internal"))
|
val kotlinNativeInternalPackageName = FqName.fromSegments(listOf("kotlin", "native", "internal"))
|
||||||
|
val kotlinNativeCoroutinesInternalPackageName = FqName.fromSegments(listOf("kotlin", "coroutines", "native", "internal"))
|
||||||
val associatedObjectKey = FqName("kotlin.reflect.AssociatedObjectKey")
|
val associatedObjectKey = FqName("kotlin.reflect.AssociatedObjectKey")
|
||||||
val typedIntrinsicAnnotation = FqName("kotlin.native.internal.TypedIntrinsic")
|
val typedIntrinsicAnnotation = FqName("kotlin.native.internal.TypedIntrinsic")
|
||||||
val cleaner = FqName("kotlin.native.internal.Cleaner")
|
val cleaner = FqName("kotlin.native.internal.Cleaner")
|
||||||
|
|||||||
-6
@@ -43,12 +43,6 @@ internal val ClassDescriptor.isArray: Boolean
|
|||||||
internal val ClassDescriptor.isInterface: Boolean
|
internal val ClassDescriptor.isInterface: Boolean
|
||||||
get() = (this.kind == ClassKind.INTERFACE)
|
get() = (this.kind == ClassKind.INTERFACE)
|
||||||
|
|
||||||
/**
|
|
||||||
* @return `konan.internal` member scope
|
|
||||||
*/
|
|
||||||
internal val KonanBuiltIns.kotlinNativeInternal: MemberScope
|
|
||||||
get() = this.builtInsModule.getPackage(RuntimeNames.kotlinNativeInternalPackageName).memberScope
|
|
||||||
|
|
||||||
internal fun ClassDescriptor.isUnit() = this.defaultType.isUnit()
|
internal fun ClassDescriptor.isUnit() = this.defaultType.isUnit()
|
||||||
|
|
||||||
internal fun ClassDescriptor.isNothing() = this.defaultType.isNothing()
|
internal fun ClassDescriptor.isNothing() = this.defaultType.isNothing()
|
||||||
|
|||||||
+65
-177
@@ -9,33 +9,22 @@ import org.jetbrains.kotlin.backend.common.COROUTINE_SUSPENDED_NAME
|
|||||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||||
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
||||||
import org.jetbrains.kotlin.backend.konan.*
|
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.llvm.findMainEntryPoint
|
||||||
import org.jetbrains.kotlin.backend.konan.lower.TestProcessor
|
import org.jetbrains.kotlin.backend.konan.lower.TestProcessor
|
||||||
import org.jetbrains.kotlin.builtins.StandardNames
|
import org.jetbrains.kotlin.builtins.StandardNames
|
||||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltInsOverDescriptors
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltInsOverDescriptors
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
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
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.defaultType
|
import org.jetbrains.kotlin.ir.types.defaultType
|
||||||
import org.jetbrains.kotlin.ir.types.typeWith
|
import org.jetbrains.kotlin.ir.types.typeWith
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.types.Variance
|
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
object KonanNameConventions {
|
object KonanNameConventions {
|
||||||
@@ -89,25 +78,15 @@ internal class KonanSymbols(
|
|||||||
allIntegerClasses.map { toClass ->
|
allIntegerClasses.map { toClass ->
|
||||||
val name = Name.identifier("to${toClass.descriptor.name.asString().replaceFirstChar(Char::uppercaseChar)}")
|
val name = Name.identifier("to${toClass.descriptor.name.asString().replaceFirstChar(Char::uppercaseChar)}")
|
||||||
val symbol = if (fromClass in signedIntegerClasses && toClass in unsignedIntegerClasses) {
|
val symbol = if (fromClass in signedIntegerClasses && toClass in unsignedIntegerClasses) {
|
||||||
irBuiltIns.findFunctions(name, "kotlin")
|
irBuiltIns.getNonBuiltInFunctionsByExtensionReceiver(name, "kotlin")[fromClass]!!
|
||||||
.single {
|
|
||||||
it.descriptor.dispatchReceiverParameter == null &&
|
|
||||||
it.descriptor.extensionReceiverParameter?.type == fromClass.descriptor.defaultType &&
|
|
||||||
it.descriptor.valueParameters.isEmpty()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
irBuiltIns.findBuiltInClassMemberFunctions(fromClass, name)
|
irBuiltIns.findBuiltInClassMemberFunctions(fromClass, name).single()
|
||||||
.single {
|
|
||||||
it.descriptor.extensionReceiverParameter == null && it.descriptor.valueParameters.isEmpty()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(fromClass to toClass) to symbol
|
(fromClass to toClass) to symbol
|
||||||
}
|
}
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
|
||||||
val arrayList = symbolTable.referenceClass(getArrayListClassDescriptor(context))
|
|
||||||
|
|
||||||
val symbolName = topLevelClass(RuntimeNames.symbolNameAnnotation)
|
val symbolName = topLevelClass(RuntimeNames.symbolNameAnnotation)
|
||||||
val gcUnsafeCall = topLevelClass(KonanFqNames.gcUnsafeCall)
|
val gcUnsafeCall = topLevelClass(KonanFqNames.gcUnsafeCall)
|
||||||
val filterExceptions = topLevelClass(RuntimeNames.filterExceptions)
|
val filterExceptions = topLevelClass(RuntimeNames.filterExceptions)
|
||||||
@@ -214,12 +193,7 @@ internal class KonanSymbols(
|
|||||||
val readBits = interopFunction("readBits")
|
val readBits = interopFunction("readBits")
|
||||||
val writeBits = interopFunction("writeBits")
|
val writeBits = interopFunction("writeBits")
|
||||||
|
|
||||||
val objCExportTrapOnUndeclaredException =
|
val objCExportTrapOnUndeclaredException = internalFunction("trapOnUndeclaredException")
|
||||||
symbolTable.referenceSimpleFunction(context.builtIns.kotlinNativeInternal.getContributedFunctions(
|
|
||||||
Name.identifier("trapOnUndeclaredException"),
|
|
||||||
NoLookupLocation.FROM_BACKEND
|
|
||||||
).single())
|
|
||||||
|
|
||||||
val objCExportResumeContinuation = internalFunction("resumeContinuation")
|
val objCExportResumeContinuation = internalFunction("resumeContinuation")
|
||||||
val objCExportResumeContinuationWithException = internalFunction("resumeContinuationWithException")
|
val objCExportResumeContinuationWithException = internalFunction("resumeContinuationWithException")
|
||||||
val objCExportGetCoroutineSuspended = internalFunction("getCoroutineSuspended")
|
val objCExportGetCoroutineSuspended = internalFunction("getCoroutineSuspended")
|
||||||
@@ -227,12 +201,12 @@ internal class KonanSymbols(
|
|||||||
|
|
||||||
val getNativeNullPtr = symbolTable.referenceSimpleFunction(context.getNativeNullPtr)
|
val getNativeNullPtr = symbolTable.referenceSimpleFunction(context.getNativeNullPtr)
|
||||||
|
|
||||||
val boxCachePredicates = BoxCache.values().associate {
|
val boxCachePredicates = BoxCache.values().associateWith {
|
||||||
it to internalFunction("in${it.name.lowercase().replaceFirstChar(Char::uppercaseChar)}BoxCache")
|
internalFunction("in${it.name.lowercase().replaceFirstChar(Char::uppercaseChar)}BoxCache")
|
||||||
}
|
}
|
||||||
|
|
||||||
val boxCacheGetters = BoxCache.values().associate {
|
val boxCacheGetters = BoxCache.values().associateWith {
|
||||||
it to internalFunction("getCached${it.name.lowercase().replaceFirstChar(Char::uppercaseChar)}Box")
|
internalFunction("getCached${it.name.lowercase().replaceFirstChar(Char::uppercaseChar)}Box")
|
||||||
}
|
}
|
||||||
|
|
||||||
val immutableBlob = irBuiltIns.findClass(Name.identifier("ImmutableBlob"), "kotlin", "native")!!
|
val immutableBlob = irBuiltIns.findClass(Name.identifier("ImmutableBlob"), "kotlin", "native")!!
|
||||||
@@ -240,22 +214,17 @@ internal class KonanSymbols(
|
|||||||
val executeImpl =
|
val executeImpl =
|
||||||
irBuiltIns.findFunctions(Name.identifier("executeImpl"),"kotlin", "native", "concurrent").single()
|
irBuiltIns.findFunctions(Name.identifier("executeImpl"),"kotlin", "native", "concurrent").single()
|
||||||
|
|
||||||
val createCleaner =
|
val createCleaner = internalFunction("createCleaner")
|
||||||
irBuiltIns.findFunctions(Name.identifier("createCleaner"),"kotlin", "native", "internal").single()
|
|
||||||
|
|
||||||
val areEqualByValue = context.getKonanInternalFunctions("areEqualByValue").map {
|
val areEqualByValue = internalFunctions("areEqualByValue").associateBy {
|
||||||
symbolTable.referenceSimpleFunction(it)
|
it.descriptor.valueParameters[0].type.computePrimitiveBinaryTypeOrNull()!!
|
||||||
}.associateBy { it.descriptor.valueParameters[0].type.computePrimitiveBinaryTypeOrNull()!! }
|
}
|
||||||
|
|
||||||
val reinterpret = internalFunction("reinterpret")
|
val reinterpret = internalFunction("reinterpret")
|
||||||
|
|
||||||
val ieee754Equals = context.getKonanInternalFunctions("ieee754Equals").map {
|
val ieee754Equals = internalFunctions("ieee754Equals")
|
||||||
symbolTable.referenceSimpleFunction(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
val equals = context.builtIns.any.unsubstitutedMemberScope
|
val equals = irBuiltIns.findBuiltInClassMemberFunctions(any, Name.identifier("equals")).single()
|
||||||
.getContributedFunctions(Name.identifier("equals"), NoLookupLocation.FROM_BACKEND)
|
|
||||||
.single().let { symbolTable.referenceSimpleFunction(it) }
|
|
||||||
|
|
||||||
val throwArithmeticException = internalFunction("ThrowArithmeticException")
|
val throwArithmeticException = internalFunction("ThrowArithmeticException")
|
||||||
|
|
||||||
@@ -282,18 +251,19 @@ internal class KonanSymbols(
|
|||||||
|
|
||||||
override val stringBuilder = irBuiltIns.findClass(Name.identifier("StringBuilder"),"kotlin", "text")!!
|
override val stringBuilder = irBuiltIns.findClass(Name.identifier("StringBuilder"),"kotlin", "text")!!
|
||||||
|
|
||||||
override val defaultConstructorMarker = symbolTable.referenceClass(
|
override val defaultConstructorMarker = internalClass("DefaultConstructorMarker")
|
||||||
context.getKonanInternalClass("DefaultConstructorMarker")
|
|
||||||
)
|
|
||||||
|
|
||||||
val checkProgressionStep = context.getKonanInternalFunctions("checkProgressionStep")
|
private fun arrayToExtensionSymbolMap(name: String, filter: (FunctionDescriptor) -> Boolean = { true }) =
|
||||||
.map { Pair(it.returnType, symbolTable.referenceSimpleFunction(it)) }.toMap()
|
arrays.associateWith { classSymbol ->
|
||||||
val getProgressionLast = context.getKonanInternalFunctions("getProgressionLast")
|
irBuiltIns.findFunctions(Name.identifier(name), "kotlin", "collections")
|
||||||
.map { Pair(it.returnType, symbolTable.referenceSimpleFunction(it)) }.toMap()
|
.singleOrNull { function ->
|
||||||
|
function.descriptor.let {
|
||||||
private fun arrayToExtensionSymbolMap(name: String, filter: (FunctionDescriptor) -> Boolean = { true }) = arrays.associateWith {
|
it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor == classSymbol.descriptor
|
||||||
findArrayExtension(it, name, filter)
|
&& !it.isExpect
|
||||||
}
|
&& filter(it)
|
||||||
|
}
|
||||||
|
} ?: error(classSymbol.toString())
|
||||||
|
}
|
||||||
|
|
||||||
val arrayContentToString = arrayToExtensionSymbolMap("contentToString") {
|
val arrayContentToString = arrayToExtensionSymbolMap("contentToString") {
|
||||||
it.extensionReceiverParameter?.type?.isMarkedNullable == false
|
it.extensionReceiverParameter?.type?.isMarkedNullable == false
|
||||||
@@ -307,34 +277,12 @@ internal class KonanSymbols(
|
|||||||
|
|
||||||
override val arraysContentEquals by lazy { arrayContentEquals.mapKeys { it.key.defaultType } }
|
override val arraysContentEquals by lazy { arrayContentEquals.mapKeys { it.key.defaultType } }
|
||||||
|
|
||||||
private fun findArrayExtension(classSymbol: IrClassSymbol, name: String, filter: (FunctionDescriptor) -> Boolean): IrSimpleFunctionSymbol =
|
|
||||||
irBuiltIns.findFunctions(Name.identifier(name), "kotlin", "collections")
|
|
||||||
.singleOrNull {
|
|
||||||
it.descriptor.let {
|
|
||||||
it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor == classSymbol.descriptor
|
|
||||||
&& !it.isExpect
|
|
||||||
&& filter(it)
|
|
||||||
}
|
|
||||||
} ?: error(classSymbol.toString())
|
|
||||||
|
|
||||||
|
|
||||||
fun getNoParamFunction(name: Name, receiverType: KotlinType): IrFunctionSymbol {
|
|
||||||
val descriptor = receiverType.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND)
|
|
||||||
.first { it.valueParameters.isEmpty() }
|
|
||||||
return symbolTable.referenceFunction(descriptor)
|
|
||||||
}
|
|
||||||
|
|
||||||
val copyInto = arrayToExtensionSymbolMap("copyInto")
|
val copyInto = arrayToExtensionSymbolMap("copyInto")
|
||||||
val copyOf = arrayToExtensionSymbolMap("copyOf") { it.valueParameters.isEmpty() }
|
val copyOf = arrayToExtensionSymbolMap("copyOf") { it.valueParameters.isEmpty() }
|
||||||
|
|
||||||
val arrayGet = arrays.associateWith { it.descriptor.unsubstitutedMemberScope
|
val arrayGet = arrays.associateWith { irBuiltIns.findBuiltInClassMemberFunctions(it, Name.identifier("get")).single() }
|
||||||
.getContributedFunctions(Name.identifier("get"), NoLookupLocation.FROM_BACKEND)
|
|
||||||
.single().let { symbolTable.referenceSimpleFunction(it) } }
|
|
||||||
|
|
||||||
val arraySet = arrays.associateWith { it.descriptor.unsubstitutedMemberScope
|
|
||||||
.getContributedFunctions(Name.identifier("set"), NoLookupLocation.FROM_BACKEND)
|
|
||||||
.single().let { symbolTable.referenceSimpleFunction(it) } }
|
|
||||||
|
|
||||||
|
val arraySet = arrays.associateWith { irBuiltIns.findBuiltInClassMemberFunctions(it, Name.identifier("set")).single() }
|
||||||
|
|
||||||
val arraySize = arrays.associateWith { it.descriptor.unsubstitutedMemberScope
|
val arraySize = arrays.associateWith { it.descriptor.unsubstitutedMemberScope
|
||||||
.getContributedVariables(Name.identifier("size"), NoLookupLocation.FROM_BACKEND)
|
.getContributedVariables(Name.identifier("size"), NoLookupLocation.FROM_BACKEND)
|
||||||
@@ -378,20 +326,14 @@ internal class KonanSymbols(
|
|||||||
|
|
||||||
override val coroutineImpl get() = TODO()
|
override val coroutineImpl get() = TODO()
|
||||||
|
|
||||||
val baseContinuationImpl =
|
val baseContinuationImpl = internalCoroutinesClass("BaseContinuationImpl")
|
||||||
irBuiltIns.findClass(Name.identifier("BaseContinuationImpl"), "kotlin", "coroutines", "native", "internal")!!
|
|
||||||
|
|
||||||
val restrictedContinuationImpl =
|
val restrictedContinuationImpl = internalCoroutinesClass("RestrictedContinuationImpl")
|
||||||
irBuiltIns.findClass(Name.identifier("RestrictedContinuationImpl"), "kotlin", "coroutines", "native", "internal")!!
|
|
||||||
|
|
||||||
val continuationImpl = irBuiltIns.findClass(Name.identifier("ContinuationImpl"), "kotlin", "coroutines", "native", "internal")!!
|
val continuationImpl = internalCoroutinesClass("ContinuationImpl")
|
||||||
|
|
||||||
val invokeSuspendFunction =
|
val invokeSuspendFunction =
|
||||||
symbolTable.referenceSimpleFunction(
|
irBuiltIns.findBuiltInClassMemberFunctions(baseContinuationImpl, Name.identifier("invokeSuspend")).single()
|
||||||
baseContinuationImpl.descriptor.unsubstitutedMemberScope
|
|
||||||
.getContributedFunctions(Name.identifier("invokeSuspend"), NoLookupLocation.FROM_BACKEND)
|
|
||||||
.single()
|
|
||||||
)
|
|
||||||
|
|
||||||
override val coroutineSuspendedGetter = symbolTable.referenceSimpleFunction(
|
override val coroutineSuspendedGetter = symbolTable.referenceSimpleFunction(
|
||||||
coroutinesIntrinsicsPackage
|
coroutinesIntrinsicsPackage
|
||||||
@@ -408,117 +350,72 @@ internal class KonanSymbols(
|
|||||||
it.descriptor.extensionReceiverParameter?.type?.constructor?.declarationDescriptor == kotlinResult.descriptor
|
it.descriptor.extensionReceiverParameter?.type?.constructor?.declarationDescriptor == kotlinResult.descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
override val functionAdapter = symbolTable.referenceClass(context.getKonanInternalClass("FunctionAdapter"))
|
override val functionAdapter = internalClass("FunctionAdapter")
|
||||||
|
|
||||||
val refClass = symbolTable.referenceClass(context.getKonanInternalClass("Ref"))
|
val refClass = internalClass("Ref")
|
||||||
|
|
||||||
val kFunctionImpl = symbolTable.referenceClass(context.reflectionTypes.kFunctionImpl)
|
private fun reflectionClass(name: String) = irBuiltIns.findClass(Name.identifier(name), StandardNames.KOTLIN_REFLECT_FQ_NAME)!!
|
||||||
val kSuspendFunctionImpl = symbolTable.referenceClass(context.reflectionTypes.kSuspendFunctionImpl)
|
|
||||||
|
|
||||||
val kMutableProperty0 = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty0)
|
val kFunctionImpl = internalClass("KFunctionImpl")
|
||||||
val kMutableProperty1 = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty1)
|
val kSuspendFunctionImpl = internalClass("KSuspendFunctionImpl")
|
||||||
val kMutableProperty2 = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty2)
|
|
||||||
|
|
||||||
val kProperty0Impl = symbolTable.referenceClass(context.reflectionTypes.kProperty0Impl)
|
val kMutableProperty0 = reflectionClass("KMutableProperty0")
|
||||||
val kProperty1Impl = symbolTable.referenceClass(context.reflectionTypes.kProperty1Impl)
|
val kMutableProperty1 = reflectionClass("KMutableProperty1")
|
||||||
val kProperty2Impl = symbolTable.referenceClass(context.reflectionTypes.kProperty2Impl)
|
val kMutableProperty2 = reflectionClass("KMutableProperty2")
|
||||||
val kMutableProperty0Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty0Impl)
|
|
||||||
val kMutableProperty1Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty1Impl)
|
|
||||||
val kMutableProperty2Impl = symbolTable.referenceClass(context.reflectionTypes.kMutableProperty2Impl)
|
|
||||||
|
|
||||||
val kLocalDelegatedPropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedPropertyImpl)
|
val kProperty0Impl = internalClass("KProperty0Impl")
|
||||||
val kLocalDelegatedMutablePropertyImpl = symbolTable.referenceClass(context.reflectionTypes.kLocalDelegatedMutablePropertyImpl)
|
val kProperty1Impl = internalClass("KProperty1Impl")
|
||||||
|
val kProperty2Impl = internalClass("KProperty2Impl")
|
||||||
|
val kMutableProperty0Impl = internalClass("KMutableProperty0Impl")
|
||||||
|
val kMutableProperty1Impl = internalClass("KMutableProperty1Impl")
|
||||||
|
val kMutableProperty2Impl = internalClass("KMutableProperty2Impl")
|
||||||
|
|
||||||
val typeOf = symbolTable.referenceSimpleFunction(context.reflectionTypes.typeOf)
|
val kLocalDelegatedPropertyImpl = internalClass("KLocalDelegatedPropertyImpl")
|
||||||
|
val kLocalDelegatedMutablePropertyImpl = internalClass("KLocalDelegatedMutablePropertyImpl")
|
||||||
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 kType = reflectionClass("KType")
|
||||||
val getObjectTypeInfo = internalFunction("getObjectTypeInfo")
|
val getObjectTypeInfo = internalFunction("getObjectTypeInfo")
|
||||||
val kClassImpl = internalClass("KClassImpl")
|
val kClassImpl = internalClass("KClassImpl")
|
||||||
val kClassImplConstructor by lazy { kClassImpl.constructors.single { it.descriptor.isPrimary } }
|
val kClassImplConstructor by lazy { kClassImpl.constructors.single { it.descriptor.isPrimary } }
|
||||||
val kClassImplIntrinsicConstructor by lazy { kClassImpl.constructors.single { it.descriptor.valueParameters.isEmpty() } }
|
val kClassImplIntrinsicConstructor by lazy { kClassImpl.constructors.single { it.descriptor.valueParameters.isEmpty() } }
|
||||||
val kClassUnsupportedImpl = internalClass("KClassUnsupportedImpl")
|
val kClassUnsupportedImpl = internalClass("KClassUnsupportedImpl")
|
||||||
val kClassUnsupportedImplConstructor by lazy { kClassUnsupportedImpl.constructors.single() }
|
|
||||||
val kTypeParameterImpl = internalClass("KTypeParameterImpl")
|
val kTypeParameterImpl = internalClass("KTypeParameterImpl")
|
||||||
val kTypeImpl = internalClass("KTypeImpl")
|
val kTypeImpl = internalClass("KTypeImpl")
|
||||||
val kTypeImplIntrinsicConstructor by lazy { kTypeImpl.constructors.single { it.descriptor.valueParameters.isEmpty() } }
|
val kTypeImplIntrinsicConstructor by lazy { kTypeImpl.constructors.single { it.descriptor.valueParameters.isEmpty() } }
|
||||||
val kTypeImplForTypeParametersWithRecursiveBounds = internalClass("KTypeImplForTypeParametersWithRecursiveBounds")
|
val kTypeImplForTypeParametersWithRecursiveBounds = internalClass("KTypeImplForTypeParametersWithRecursiveBounds")
|
||||||
val kTypeProjectionList = internalClass("KTypeProjectionList")
|
val kTypeProjectionList = internalClass("KTypeProjectionList")
|
||||||
|
|
||||||
val kTypeProjection = symbolTable.referenceClass(context.reflectionTypes.kTypeProjection)
|
|
||||||
|
|
||||||
private val kTypeProjectionCompanionDescriptor = context.reflectionTypes.kTypeProjection.companionObjectDescriptor!!
|
|
||||||
|
|
||||||
val kTypeProjectionCompanion = symbolTable.referenceClass(kTypeProjectionCompanionDescriptor)
|
|
||||||
|
|
||||||
val kTypeProjectionStar = symbolTable.referenceProperty(
|
|
||||||
kTypeProjectionCompanionDescriptor.unsubstitutedMemberScope
|
|
||||||
.getContributedVariables(Name.identifier("STAR"), NoLookupLocation.FROM_BACKEND).single()
|
|
||||||
)
|
|
||||||
|
|
||||||
val kTypeProjectionFactories: Map<Variance, IrSimpleFunctionSymbol> = Variance.values().toList().associateWith {
|
|
||||||
val factoryName = when (it) {
|
|
||||||
Variance.INVARIANT -> "invariant"
|
|
||||||
Variance.IN_VARIANCE -> "contravariant"
|
|
||||||
Variance.OUT_VARIANCE -> "covariant"
|
|
||||||
}
|
|
||||||
|
|
||||||
symbolTable.referenceSimpleFunction(
|
|
||||||
kTypeProjectionCompanionDescriptor.unsubstitutedMemberScope
|
|
||||||
.getContributedFunctions(Name.identifier(factoryName), NoLookupLocation.FROM_BACKEND).single()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val emptyList = irBuiltIns.findFunctions(Name.identifier("emptyList"), "kotlin", "collections")
|
|
||||||
.single { it.descriptor.valueParameters.isEmpty() }
|
|
||||||
|
|
||||||
val listOf = irBuiltIns.findFunctions(Name.identifier("listOf"), "kotlin", "collections")
|
|
||||||
.single { it.descriptor.valueParameters.size == 1 && it.descriptor.valueParameters[0].isVararg }
|
|
||||||
|
|
||||||
val arrayAsList = internalClass("ArrayAsList")
|
val arrayAsList = internalClass("ArrayAsList")
|
||||||
|
|
||||||
val threadLocal = symbolTable.referenceClass(
|
val threadLocal = topLevelClass(KonanFqNames.threadLocal)
|
||||||
context.builtIns.builtInsModule.findClassAcrossModuleDependencies(
|
|
||||||
ClassId.topLevel(KonanFqNames.threadLocal))!!)
|
|
||||||
|
|
||||||
val sharedImmutable = symbolTable.referenceClass(
|
val sharedImmutable = topLevelClass(KonanFqNames.sharedImmutable)
|
||||||
context.builtIns.builtInsModule.findClassAcrossModuleDependencies(
|
|
||||||
ClassId.topLevel(KonanFqNames.sharedImmutable))!!)
|
|
||||||
|
|
||||||
val eagerInitialization = symbolTable.referenceClass(
|
val eagerInitialization = topLevelClass(KonanFqNames.eagerInitialization)
|
||||||
context.builtIns.builtInsModule.findClassAcrossModuleDependencies(
|
|
||||||
ClassId.topLevel(KonanFqNames.eagerInitialization))!!)
|
|
||||||
|
|
||||||
private fun topLevelClass(fqName: FqName): IrClassSymbol = irBuiltIns.findClass(fqName.shortName(), fqName.parent())!!
|
private fun topLevelClass(fqName: FqName): IrClassSymbol = irBuiltIns.findClass(fqName.shortName(), fqName.parent())!!
|
||||||
|
|
||||||
private fun internalFunction(name: String): IrSimpleFunctionSymbol =
|
private fun internalFunction(name: String) =
|
||||||
symbolTable.referenceSimpleFunction(context.getKonanInternalFunctions(name).single())
|
irBuiltIns.findFunctions(Name.identifier(name), RuntimeNames.kotlinNativeInternalPackageName).single()
|
||||||
|
|
||||||
private fun internalClass(name: String): IrClassSymbol =
|
private fun internalFunctions(name: String) =
|
||||||
symbolTable.referenceClass(context.getKonanInternalClass(name))
|
irBuiltIns.findFunctions(Name.identifier(name), RuntimeNames.kotlinNativeInternalPackageName).toList()
|
||||||
|
|
||||||
|
private fun internalClass(name: String) =
|
||||||
|
irBuiltIns.findClass(Name.identifier(name), RuntimeNames.kotlinNativeInternalPackageName)!!
|
||||||
|
|
||||||
|
private fun internalCoroutinesClass(name: String) =
|
||||||
|
irBuiltIns.findClass(Name.identifier(name), RuntimeNames.kotlinNativeCoroutinesInternalPackageName)!!
|
||||||
|
|
||||||
private fun getKonanTestClass(className: String) =
|
private fun getKonanTestClass(className: String) =
|
||||||
irBuiltIns.findClass(Name.identifier(className), "kotlin", "native", "internal", "test")!!
|
irBuiltIns.findClass(Name.identifier(className), "kotlin", "native", "internal", "test")!!
|
||||||
|
|
||||||
private fun interopFunction(name: String) = symbolTable.referenceSimpleFunction(
|
private fun interopFunction(name: String) =
|
||||||
context.interopBuiltIns.packageScope
|
irBuiltIns.findFunctions(Name.identifier(name), InteropFqNames.packageName).single()
|
||||||
.getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND)
|
|
||||||
.single()
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun interopClass(name: String) = symbolTable.referenceClass(
|
private fun interopClass(name: String) =
|
||||||
context.interopBuiltIns.packageScope
|
irBuiltIns.findClass(Name.identifier(name), InteropFqNames.packageName)!!
|
||||||
.getContributedClassifier(Name.identifier(name), NoLookupLocation.FROM_BACKEND) as ClassDescriptor
|
|
||||||
)
|
|
||||||
|
|
||||||
fun kFunctionN(n: Int) = irBuiltIns.kFunctionN(n).symbol
|
fun kFunctionN(n: Int) = irBuiltIns.kFunctionN(n).symbol
|
||||||
|
|
||||||
@@ -547,12 +444,3 @@ internal class KonanSymbols(
|
|||||||
|
|
||||||
fun getTestFunctionKind(kind: TestProcessor.FunctionKind) = testFunctionKindCache[kind]!!
|
fun getTestFunctionKind(kind: TestProcessor.FunctionKind) = testFunctionKindCache[kind]!!
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getArrayListClassDescriptor(context: Context): ClassDescriptor {
|
|
||||||
val module = context.builtIns.builtInsModule
|
|
||||||
val pkg = module.getPackage(FqName.fromSegments(listOf("kotlin", "collections")))
|
|
||||||
val classifier = pkg.memberScope.getContributedClassifier(Name.identifier("ArrayList"),
|
|
||||||
NoLookupLocation.FROM_BACKEND)
|
|
||||||
|
|
||||||
return classifier as ClassDescriptor
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user