IR: Refactor IrBuiltIns to abstract it from descriptors
This commit is contained in:
committed by
TeamCityServer
parent
25d2e61a82
commit
dee0487185
+1
-1
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.backend.common
|
||||
import org.jetbrains.kotlin.backend.common.ir.Ir
|
||||
import org.jetbrains.kotlin.backend.common.ir.SharedVariablesManager
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFactory
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeSystemContext
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
|
||||
+1
-1
@@ -7,10 +7,10 @@ package org.jetbrains.kotlin.backend.common
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
|
||||
-3
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.extensions
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.BuiltinSymbolsBase
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
@@ -35,8 +34,6 @@ interface IrPluginContext : IrGeneratorContext {
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
val typeTranslator: TypeTranslator
|
||||
|
||||
val symbols: BuiltinSymbolsBase
|
||||
|
||||
val platform: TargetPlatform?
|
||||
|
||||
/**
|
||||
|
||||
+2
-4
@@ -5,15 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.extensions
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.BuiltinSymbolsBase
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
@@ -35,8 +34,7 @@ open class IrPluginContextImpl constructor(
|
||||
override val typeTranslator: TypeTranslator,
|
||||
override val irBuiltIns: IrBuiltIns,
|
||||
val linker: IrDeserializer,
|
||||
private val diagnosticReporter: IrMessageLogger,
|
||||
override val symbols: BuiltinSymbolsBase = BuiltinSymbolsBase(irBuiltIns, irBuiltIns.builtIns, st)
|
||||
private val diagnosticReporter: IrMessageLogger
|
||||
) : IrPluginContext {
|
||||
|
||||
override val platform: TargetPlatform? = module.platform
|
||||
|
||||
@@ -7,28 +7,26 @@ package org.jetbrains.kotlin.backend.common.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.lower.LocalDeclarationsLowering
|
||||
import org.jetbrains.kotlin.builtins.*
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.KOTLIN_REFLECT_FQ_NAME
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.types.defaultType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.defaultType
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
import org.jetbrains.kotlin.ir.util.getPackageFragment
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.toLowerCaseAsciiOnly
|
||||
|
||||
// This is what Context collects about IR.
|
||||
abstract class Ir<out T : CommonBackendContext>(val context: T, val irModule: IrModuleFragment) {
|
||||
@@ -46,32 +44,15 @@ abstract class Ir<out T : CommonBackendContext>(val context: T, val irModule: Ir
|
||||
open fun shouldGenerateHandlerParameterForDefaultBodyFun() = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Symbols for builtins that are available without any context and are not specific to any backend
|
||||
*/
|
||||
open class BuiltinSymbolsBase(protected val irBuiltIns: IrBuiltIns, protected val builtIns: KotlinBuiltIns, private val symbolTable: ReferenceSymbolTable) {
|
||||
protected fun builtInsPackage(vararg packageNameSegments: String) =
|
||||
builtIns.builtInsModule.getPackage(FqName.fromSegments(listOf(*packageNameSegments))).memberScope
|
||||
|
||||
// consider making this public so it can be used to easily locate stdlib functions from any place (in particular, plugins and lowerings)
|
||||
private fun getSimpleFunction(
|
||||
name: Name,
|
||||
vararg packageNameSegments: String = arrayOf("kotlin"),
|
||||
condition: (SimpleFunctionDescriptor) -> Boolean
|
||||
): IrSimpleFunctionSymbol =
|
||||
symbolTable.referenceSimpleFunction(
|
||||
builtInsPackage(*packageNameSegments).getContributedFunctions(name, NoLookupLocation.FROM_BACKEND)
|
||||
.first(condition)
|
||||
)
|
||||
// Some symbols below are used in kotlin-native, so they can't be private
|
||||
@Suppress("MemberVisibilityCanBePrivate", "PropertyName")
|
||||
abstract class Symbols<out T : CommonBackendContext>(
|
||||
val context: T, val irBuiltIns: IrBuiltIns, private val symbolTable: ReferenceSymbolTable
|
||||
) {
|
||||
|
||||
private fun getClass(name: Name, vararg packageNameSegments: String = arrayOf("kotlin")): IrClassSymbol =
|
||||
getClassOrNull(name, *packageNameSegments) ?: error("Class '$name' not found in package '${packageNameSegments.joinToString(".")}'")
|
||||
|
||||
private fun getClassOrNull(name: Name, vararg packageNameSegments: String = arrayOf("kotlin")): IrClassSymbol? =
|
||||
(builtInsPackage(*packageNameSegments).getContributedClassifier(
|
||||
name,
|
||||
NoLookupLocation.FROM_BACKEND
|
||||
) as? ClassDescriptor)?.let { symbolTable.referenceClass(it) }
|
||||
irBuiltIns.findClass(name, *packageNameSegments)
|
||||
?: error("Class '$name' not found in package '${packageNameSegments.joinToString(".")}'")
|
||||
|
||||
/**
|
||||
* Use this table to reference external dependencies.
|
||||
@@ -89,25 +70,23 @@ open class BuiltinSymbolsBase(protected val irBuiltIns: IrBuiltIns, protected va
|
||||
type to iteratorClass
|
||||
}
|
||||
|
||||
val asserts = builtInsPackage("kotlin")
|
||||
.getContributedFunctions(Name.identifier("assert"), NoLookupLocation.FROM_BACKEND)
|
||||
.map { symbolTable.referenceFunction(it) }
|
||||
val asserts = irBuiltIns.findFunctions(Name.identifier("assert"), "kotlin")
|
||||
|
||||
private fun progression(name: String) = getClass(Name.identifier(name), "kotlin", "ranges")
|
||||
private fun progressionOrNull(name: String) = getClassOrNull(Name.identifier(name), "kotlin", "ranges")
|
||||
private fun progressionOrNull(name: String) = irBuiltIns.findClass(Name.identifier(name), "kotlin", "ranges")
|
||||
|
||||
// The "...OrNull" variants are used for the classes below because the minimal stdlib used in tests do not include those classes.
|
||||
// It was not feasible to add them to the JS reduced runtime because all its transitive dependencies also need to be
|
||||
// added, which would include a lot of the full stdlib.
|
||||
open val uByte = getClassOrNull(Name.identifier("UByte"), "kotlin")
|
||||
open val uShort = getClassOrNull(Name.identifier("UShort"), "kotlin")
|
||||
open val uInt = getClassOrNull(Name.identifier("UInt"), "kotlin")
|
||||
open val uLong = getClassOrNull(Name.identifier("ULong"), "kotlin")
|
||||
open val uByte = irBuiltIns.findClass(Name.identifier("UByte"), "kotlin")
|
||||
open val uShort = irBuiltIns.findClass(Name.identifier("UShort"), "kotlin")
|
||||
open val uInt = irBuiltIns.findClass(Name.identifier("UInt"), "kotlin")
|
||||
open val uLong = irBuiltIns.findClass(Name.identifier("ULong"), "kotlin")
|
||||
val uIntProgression = progressionOrNull("UIntProgression")
|
||||
val uLongProgression = progressionOrNull("ULongProgression")
|
||||
val uIntRange = progressionOrNull("UIntRange")
|
||||
val uLongRange = progressionOrNull("ULongRange")
|
||||
val sequence = getClassOrNull(Name.identifier("Sequence"), "kotlin", "sequences")
|
||||
val sequence = irBuiltIns.findClass(Name.identifier("Sequence"), "kotlin", "sequences")
|
||||
|
||||
val charProgression = progression("CharProgression")
|
||||
val intProgression = progression("IntProgression")
|
||||
@@ -121,46 +100,26 @@ open class BuiltinSymbolsBase(protected val irBuiltIns: IrBuiltIns, protected va
|
||||
|
||||
val closedRange = progression("ClosedRange")
|
||||
|
||||
val getProgressionLastElementByReturnType = builtInsPackage("kotlin", "internal")
|
||||
.getContributedFunctions(Name.identifier("getProgressionLastElement"), NoLookupLocation.FROM_BACKEND)
|
||||
.filter { it.containingDeclaration !is BuiltInsPackageFragment }
|
||||
.map { d ->
|
||||
val klass = d.returnType?.constructor?.declarationDescriptor?.let { symbolTable.referenceClassifier(it) }
|
||||
val function = symbolTable.referenceSimpleFunction(d)
|
||||
klass to function
|
||||
}.toMap()
|
||||
open val getProgressionLastElementByReturnType: Map<IrClassifierSymbol?, IrSimpleFunctionSymbol>
|
||||
get() = irBuiltIns.getProgressionLastElementByReturnType
|
||||
|
||||
val toUIntByExtensionReceiver = builtInsPackage("kotlin").getContributedFunctions(
|
||||
Name.identifier("toUInt"),
|
||||
NoLookupLocation.FROM_BACKEND
|
||||
).filter { it.containingDeclaration !is BuiltInsPackageFragment && it.extensionReceiverParameter != null }
|
||||
.map {
|
||||
val klass = symbolTable.referenceClassifier(it.extensionReceiverParameter!!.type.constructor.declarationDescriptor!!)
|
||||
val function = symbolTable.referenceSimpleFunction(it)
|
||||
klass to function
|
||||
}.toMap()
|
||||
val toUIntByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
get() = irBuiltIns.toUIntByExtensionReceiver
|
||||
|
||||
val toULongByExtensionReceiver = builtInsPackage("kotlin").getContributedFunctions(
|
||||
Name.identifier("toULong"),
|
||||
NoLookupLocation.FROM_BACKEND
|
||||
).filter { it.containingDeclaration !is BuiltInsPackageFragment && it.extensionReceiverParameter != null }
|
||||
.map {
|
||||
val klass = symbolTable.referenceClassifier(it.extensionReceiverParameter!!.type.constructor.declarationDescriptor!!)
|
||||
val function = symbolTable.referenceSimpleFunction(it)
|
||||
klass to function
|
||||
}.toMap()
|
||||
val toULongByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
get() = irBuiltIns.toULongByExtensionReceiver
|
||||
|
||||
val any = symbolTable.referenceClass(builtIns.any)
|
||||
val unit = symbolTable.referenceClass(builtIns.unit)
|
||||
val any get() = irBuiltIns.anyClass
|
||||
val unit get() = irBuiltIns.unitClass
|
||||
|
||||
val char = symbolTable.referenceClass(builtIns.char)
|
||||
val char get() = irBuiltIns.charClass
|
||||
|
||||
val byte = symbolTable.referenceClass(builtIns.byte)
|
||||
val short = symbolTable.referenceClass(builtIns.short)
|
||||
val int = symbolTable.referenceClass(builtIns.int)
|
||||
val long = symbolTable.referenceClass(builtIns.long)
|
||||
val float = symbolTable.referenceClass(builtIns.float)
|
||||
val double = symbolTable.referenceClass(builtIns.double)
|
||||
val byte get() = irBuiltIns.byteClass
|
||||
val short get() = irBuiltIns.shortClass
|
||||
val int get() = irBuiltIns.intClass
|
||||
val long get() = irBuiltIns.longClass
|
||||
val float get() = irBuiltIns.floatClass
|
||||
val double get() = irBuiltIns.doubleClass
|
||||
|
||||
val integerClasses = listOf(byte, short, int, long)
|
||||
|
||||
@@ -168,41 +127,19 @@ open class BuiltinSymbolsBase(protected val irBuiltIns: IrBuiltIns, protected va
|
||||
listOfNotNull(byte, short, int, long, char, uByte, uShort, uInt, uLong).map { it.defaultType }
|
||||
}
|
||||
|
||||
val arrayOf = getSimpleFunction(Name.identifier("arrayOf")) {
|
||||
it.extensionReceiverParameter == null && it.dispatchReceiverParameter == null && it.valueParameters.size == 1 &&
|
||||
it.valueParameters[0].isVararg
|
||||
}
|
||||
val arrayOf: IrSimpleFunctionSymbol get() = irBuiltIns.arrayOf
|
||||
val arrayOfNulls: IrSimpleFunctionSymbol get() = irBuiltIns.arrayOfNulls
|
||||
|
||||
val primitiveArrayOfByType = PrimitiveType.values().associate { type ->
|
||||
val function = getSimpleFunction(Name.identifier(type.name.toLowerCaseAsciiOnly() + "ArrayOf")) {
|
||||
it.extensionReceiverParameter == null && it.dispatchReceiverParameter == null && it.valueParameters.size == 1 &&
|
||||
it.valueParameters[0].isVararg
|
||||
}
|
||||
type to function
|
||||
}
|
||||
val array get() = irBuiltIns.arrayClass
|
||||
|
||||
val arrayOfNulls = getSimpleFunction(Name.identifier("arrayOfNulls")) {
|
||||
it.extensionReceiverParameter == null && it.dispatchReceiverParameter == null && it.valueParameters.size == 1 &&
|
||||
KotlinBuiltIns.isInt(it.valueParameters[0].type)
|
||||
}
|
||||
|
||||
val array = symbolTable.referenceClass(builtIns.array)
|
||||
|
||||
private fun primitiveArrayClass(type: PrimitiveType) =
|
||||
symbolTable.referenceClass(builtIns.getPrimitiveArrayClassDescriptor(type))
|
||||
|
||||
private fun unsignedArrayClass(unsignedType: UnsignedType) =
|
||||
builtIns.builtInsModule.findClassAcrossModuleDependencies(unsignedType.arrayClassId)
|
||||
?.let { symbolTable.referenceClass(it) }
|
||||
|
||||
val byteArray = primitiveArrayClass(PrimitiveType.BYTE)
|
||||
val charArray = primitiveArrayClass(PrimitiveType.CHAR)
|
||||
val shortArray = primitiveArrayClass(PrimitiveType.SHORT)
|
||||
val intArray = primitiveArrayClass(PrimitiveType.INT)
|
||||
val longArray = primitiveArrayClass(PrimitiveType.LONG)
|
||||
val floatArray = primitiveArrayClass(PrimitiveType.FLOAT)
|
||||
val doubleArray = primitiveArrayClass(PrimitiveType.DOUBLE)
|
||||
val booleanArray = primitiveArrayClass(PrimitiveType.BOOLEAN)
|
||||
val byteArray get() = irBuiltIns.byteArray
|
||||
val charArray get() = irBuiltIns.charArray
|
||||
val shortArray get() = irBuiltIns.shortArray
|
||||
val intArray get() = irBuiltIns.intArray
|
||||
val longArray get() = irBuiltIns.longArray
|
||||
val floatArray get() = irBuiltIns.floatArray
|
||||
val doubleArray get() = irBuiltIns.doubleArray
|
||||
val booleanArray get() = irBuiltIns.booleanArray
|
||||
|
||||
val byteArrayType get() = byteArray.owner.defaultType
|
||||
val charArrayType get() = charArray.owner.defaultType
|
||||
@@ -213,93 +150,50 @@ open class BuiltinSymbolsBase(protected val irBuiltIns: IrBuiltIns, protected va
|
||||
val doubleArrayType get() = doubleArray.owner.defaultType
|
||||
val booleanArrayType get() = booleanArray.owner.defaultType
|
||||
|
||||
val unsignedArrays = UnsignedType.values().mapNotNull { unsignedType ->
|
||||
unsignedArrayClass(unsignedType)?.let { unsignedType to it }
|
||||
}.toMap()
|
||||
val primitiveArrays get() = irBuiltIns.primitiveArrays
|
||||
val primitiveArraysToPrimitiveTypes get() = irBuiltIns.primitiveArraysToPrimitiveTypes
|
||||
val unsignedArrays get() = irBuiltIns.unsignedArrays
|
||||
|
||||
val arrays = primitiveArrays + unsignedArrays + array
|
||||
|
||||
val primitiveArrays = PrimitiveType.values().associate { it to primitiveArrayClass(it) }
|
||||
|
||||
val arrays = primitiveArrays.values + unsignedArrays.values + array
|
||||
|
||||
val collection = symbolTable.referenceClass(builtIns.collection)
|
||||
val set = symbolTable.referenceClass(builtIns.set)
|
||||
val list = symbolTable.referenceClass(builtIns.list)
|
||||
val map = symbolTable.referenceClass(builtIns.map)
|
||||
val mapEntry = symbolTable.referenceClass(builtIns.mapEntry)
|
||||
val iterable = symbolTable.referenceClass(builtIns.iterable)
|
||||
val listIterator = symbolTable.referenceClass(builtIns.listIterator)
|
||||
val mutableCollection = symbolTable.referenceClass(builtIns.mutableCollection)
|
||||
val mutableSet = symbolTable.referenceClass(builtIns.mutableSet)
|
||||
val mutableList = symbolTable.referenceClass(builtIns.mutableList)
|
||||
val mutableMap = symbolTable.referenceClass(builtIns.mutableMap)
|
||||
val mutableMapEntry = symbolTable.referenceClass(builtIns.mutableMapEntry)
|
||||
val mutableIterable = symbolTable.referenceClass(builtIns.mutableIterable)
|
||||
val mutableIterator = symbolTable.referenceClass(builtIns.mutableIterator)
|
||||
val mutableListIterator = symbolTable.referenceClass(builtIns.mutableListIterator)
|
||||
val comparable = symbolTable.referenceClass(builtIns.comparable)
|
||||
val collection get() = irBuiltIns.collectionClass
|
||||
val set get() = irBuiltIns.setClass
|
||||
val list get() = irBuiltIns.listClass
|
||||
val map get() = irBuiltIns.mapClass
|
||||
val mapEntry get() = irBuiltIns.mapEntryClass
|
||||
val iterable get() = irBuiltIns.iterableClass
|
||||
val listIterator get() = irBuiltIns.listIteratorClass
|
||||
val mutableCollection get() = irBuiltIns.mutableCollectionClass
|
||||
val mutableSet get() = irBuiltIns.mutableSetClass
|
||||
val mutableList get() = irBuiltIns.mutableListClass
|
||||
val mutableMap get() = irBuiltIns.mutableMapClass
|
||||
val mutableMapEntry get() = irBuiltIns.mutableMapEntryClass
|
||||
val mutableIterable get() = irBuiltIns.mutableIterableClass
|
||||
val mutableIterator get() = irBuiltIns.mutableIteratorClass
|
||||
val mutableListIterator get() = irBuiltIns.mutableListIteratorClass
|
||||
val comparable get() = irBuiltIns.comparableClass
|
||||
|
||||
private val binaryOperatorCache = mutableMapOf<Triple<Name, IrType, IrType>, IrSimpleFunctionSymbol>()
|
||||
|
||||
fun getBinaryOperator(name: Name, lhsType: IrType, rhsType: IrType): IrSimpleFunctionSymbol {
|
||||
require(lhsType is IrSimpleType) { "Expected IrSimpleType in getBinaryOperator, got $lhsType" }
|
||||
val classifier = lhsType.classifier
|
||||
require(classifier is IrClassSymbol && classifier.isBound) {
|
||||
"Expected a bound IrClassSymbol for lhsType in getBinaryOperator, got $classifier"
|
||||
}
|
||||
val key = Triple(name, lhsType, rhsType)
|
||||
return binaryOperatorCache.getOrPut(key) {
|
||||
classifier.functions.single {
|
||||
val function = it.owner
|
||||
function.name == name && function.valueParameters.size == 1 && function.valueParameters[0].type == rhsType
|
||||
}
|
||||
}
|
||||
}
|
||||
fun getBinaryOperator(name: Name, lhsType: IrType, rhsType: IrType): IrSimpleFunctionSymbol =
|
||||
irBuiltIns.getBinaryOperator(name, lhsType, rhsType)
|
||||
|
||||
private val unaryOperatorCache = mutableMapOf<Pair<Name, IrType>, IrSimpleFunctionSymbol>()
|
||||
fun getUnaryOperator(name: Name, receiverType: IrType): IrSimpleFunctionSymbol = irBuiltIns.getUnaryOperator(name, receiverType)
|
||||
|
||||
fun getUnaryOperator(name: Name, receiverType: IrType): IrSimpleFunctionSymbol {
|
||||
require(receiverType is IrSimpleType) { "Expected IrSimpleType in getBinaryOperator, got $receiverType" }
|
||||
val classifier = receiverType.classifier
|
||||
require(classifier is IrClassSymbol && classifier.isBound) {
|
||||
"Expected a bound IrClassSymbol for receiverType in getBinaryOperator, got $classifier"
|
||||
}
|
||||
val key = Pair(name, receiverType)
|
||||
return unaryOperatorCache.getOrPut(key) {
|
||||
classifier.functions.single {
|
||||
val function = it.owner
|
||||
function.name == name && function.valueParameters.isEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
open fun functionN(n: Int): IrClassSymbol = irBuiltIns.functionN(n).symbol
|
||||
open fun suspendFunctionN(n: Int): IrClassSymbol = irBuiltIns.suspendFunctionN(n).symbol
|
||||
|
||||
open fun functionN(n: Int): IrClassSymbol = irBuiltIns.function(n)
|
||||
open fun suspendFunctionN(n: Int): IrClassSymbol = irBuiltIns.suspendFunction(n)
|
||||
fun kproperty0(): IrClassSymbol = irBuiltIns.kProperty0Class
|
||||
fun kproperty1(): IrClassSymbol = irBuiltIns.kProperty1Class
|
||||
fun kproperty2(): IrClassSymbol = irBuiltIns.kProperty2Class
|
||||
|
||||
fun kproperty0(): IrClassSymbol = symbolTable.referenceClass(builtIns.kProperty0)
|
||||
fun kproperty1(): IrClassSymbol = symbolTable.referenceClass(builtIns.kProperty1)
|
||||
fun kproperty2(): IrClassSymbol = symbolTable.referenceClass(builtIns.kProperty2)
|
||||
fun kmutableproperty0(): IrClassSymbol = irBuiltIns.kMutableProperty0Class
|
||||
fun kmutableproperty1(): IrClassSymbol = irBuiltIns.kMutableProperty1Class
|
||||
fun kmutableproperty2(): IrClassSymbol = irBuiltIns.kMutableProperty2Class
|
||||
|
||||
fun kmutableproperty0(): IrClassSymbol = symbolTable.referenceClass(builtIns.kMutableProperty0)
|
||||
fun kmutableproperty1(): IrClassSymbol = symbolTable.referenceClass(builtIns.kMutableProperty1)
|
||||
fun kmutableproperty2(): IrClassSymbol = symbolTable.referenceClass(builtIns.kMutableProperty2)
|
||||
|
||||
val extensionToString = getSimpleFunction(Name.identifier("toString")) {
|
||||
it.dispatchReceiverParameter == null && it.extensionReceiverParameter != null &&
|
||||
KotlinBuiltIns.isNullableAny(it.extensionReceiverParameter!!.type) && it.valueParameters.size == 0
|
||||
}
|
||||
|
||||
val stringPlus = getSimpleFunction(Name.identifier("plus")) {
|
||||
it.dispatchReceiverParameter == null && it.extensionReceiverParameter != null &&
|
||||
KotlinBuiltIns.isStringOrNullableString(it.extensionReceiverParameter!!.type) && it.valueParameters.size == 1 &&
|
||||
KotlinBuiltIns.isNullableAny(it.valueParameters.first().type)
|
||||
}
|
||||
}
|
||||
|
||||
// Some symbols below are used in kotlin-native, so they can't be private
|
||||
@Suppress("MemberVisibilityCanBePrivate", "PropertyName")
|
||||
abstract class Symbols<out T : CommonBackendContext>(val context: T, irBuiltIns: IrBuiltIns, symbolTable: SymbolTable) :
|
||||
BuiltinSymbolsBase(irBuiltIns, context.builtIns, symbolTable) {
|
||||
val extensionToString: IrSimpleFunctionSymbol get() = irBuiltIns.extensionToString
|
||||
val stringPlus: IrSimpleFunctionSymbol get() = irBuiltIns.stringPlus
|
||||
|
||||
abstract val throwNullPointerException: IrSimpleFunctionSymbol
|
||||
abstract val throwTypeCastException: IrSimpleFunctionSymbol
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addConstructor
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildReceiverParameter
|
||||
|
||||
+1
-1
@@ -5,9 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.lower
|
||||
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrStringConcatenationImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
|
||||
+1
-1
@@ -8,12 +8,12 @@ package org.jetbrains.kotlin.backend.common.lower
|
||||
import org.jetbrains.kotlin.backend.common.BackendContext
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
|
||||
+1
-1
@@ -16,12 +16,12 @@ import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrGetValue
|
||||
import org.jetbrains.kotlin.ir.expressions.IrTypeOperator
|
||||
|
||||
+26
-22
@@ -9,13 +9,17 @@ import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.ir.BuiltInOperatorNames
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrStringConcatenationImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.getPrimitiveType
|
||||
import org.jetbrains.kotlin.ir.types.isStringClassType
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
import org.jetbrains.kotlin.ir.util.isUnsigned
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
@@ -71,29 +75,29 @@ class FoldConstantLowering(
|
||||
|
||||
init {
|
||||
// IrBuiltins
|
||||
registerBuiltinBinaryOp(DOUBLE, IrBuiltIns.OperatorNames.LESS) { a, b -> a < b }
|
||||
registerBuiltinBinaryOp(DOUBLE, IrBuiltIns.OperatorNames.LESS_OR_EQUAL) { a, b -> a <= b }
|
||||
registerBuiltinBinaryOp(DOUBLE, IrBuiltIns.OperatorNames.GREATER) { a, b -> a > b }
|
||||
registerBuiltinBinaryOp(DOUBLE, IrBuiltIns.OperatorNames.GREATER_OR_EQUAL) { a, b -> a >= b }
|
||||
registerBuiltinBinaryOp(DOUBLE, IrBuiltIns.OperatorNames.IEEE754_EQUALS) { a, b -> a == b }
|
||||
registerBuiltinBinaryOp(DOUBLE, BuiltInOperatorNames.LESS) { a, b -> a < b }
|
||||
registerBuiltinBinaryOp(DOUBLE, BuiltInOperatorNames.LESS_OR_EQUAL) { a, b -> a <= b }
|
||||
registerBuiltinBinaryOp(DOUBLE, BuiltInOperatorNames.GREATER) { a, b -> a > b }
|
||||
registerBuiltinBinaryOp(DOUBLE, BuiltInOperatorNames.GREATER_OR_EQUAL) { a, b -> a >= b }
|
||||
registerBuiltinBinaryOp(DOUBLE, BuiltInOperatorNames.IEEE754_EQUALS) { a, b -> a == b }
|
||||
|
||||
registerBuiltinBinaryOp(FLOAT, IrBuiltIns.OperatorNames.LESS) { a, b -> a < b }
|
||||
registerBuiltinBinaryOp(FLOAT, IrBuiltIns.OperatorNames.LESS_OR_EQUAL) { a, b -> a <= b }
|
||||
registerBuiltinBinaryOp(FLOAT, IrBuiltIns.OperatorNames.GREATER) { a, b -> a > b }
|
||||
registerBuiltinBinaryOp(FLOAT, IrBuiltIns.OperatorNames.GREATER_OR_EQUAL) { a, b -> a >= b }
|
||||
registerBuiltinBinaryOp(FLOAT, IrBuiltIns.OperatorNames.IEEE754_EQUALS) { a, b -> a == b }
|
||||
registerBuiltinBinaryOp(FLOAT, BuiltInOperatorNames.LESS) { a, b -> a < b }
|
||||
registerBuiltinBinaryOp(FLOAT, BuiltInOperatorNames.LESS_OR_EQUAL) { a, b -> a <= b }
|
||||
registerBuiltinBinaryOp(FLOAT, BuiltInOperatorNames.GREATER) { a, b -> a > b }
|
||||
registerBuiltinBinaryOp(FLOAT, BuiltInOperatorNames.GREATER_OR_EQUAL) { a, b -> a >= b }
|
||||
registerBuiltinBinaryOp(FLOAT, BuiltInOperatorNames.IEEE754_EQUALS) { a, b -> a == b }
|
||||
|
||||
registerBuiltinBinaryOp(INT, IrBuiltIns.OperatorNames.LESS) { a, b -> a < b }
|
||||
registerBuiltinBinaryOp(INT, IrBuiltIns.OperatorNames.LESS_OR_EQUAL) { a, b -> a <= b }
|
||||
registerBuiltinBinaryOp(INT, IrBuiltIns.OperatorNames.GREATER) { a, b -> a > b }
|
||||
registerBuiltinBinaryOp(INT, IrBuiltIns.OperatorNames.GREATER_OR_EQUAL) { a, b -> a >= b }
|
||||
registerBuiltinBinaryOp(INT, IrBuiltIns.OperatorNames.EQEQ) { a, b -> a == b }
|
||||
registerBuiltinBinaryOp(INT, BuiltInOperatorNames.LESS) { a, b -> a < b }
|
||||
registerBuiltinBinaryOp(INT, BuiltInOperatorNames.LESS_OR_EQUAL) { a, b -> a <= b }
|
||||
registerBuiltinBinaryOp(INT, BuiltInOperatorNames.GREATER) { a, b -> a > b }
|
||||
registerBuiltinBinaryOp(INT, BuiltInOperatorNames.GREATER_OR_EQUAL) { a, b -> a >= b }
|
||||
registerBuiltinBinaryOp(INT, BuiltInOperatorNames.EQEQ) { a, b -> a == b }
|
||||
|
||||
registerBuiltinBinaryOp(LONG, IrBuiltIns.OperatorNames.LESS) { a, b -> a < b }
|
||||
registerBuiltinBinaryOp(LONG, IrBuiltIns.OperatorNames.LESS_OR_EQUAL) { a, b -> a <= b }
|
||||
registerBuiltinBinaryOp(LONG, IrBuiltIns.OperatorNames.GREATER) { a, b -> a > b }
|
||||
registerBuiltinBinaryOp(LONG, IrBuiltIns.OperatorNames.GREATER_OR_EQUAL) { a, b -> a >= b }
|
||||
registerBuiltinBinaryOp(LONG, IrBuiltIns.OperatorNames.EQEQ) { a, b -> a == b }
|
||||
registerBuiltinBinaryOp(LONG, BuiltInOperatorNames.LESS) { a, b -> a < b }
|
||||
registerBuiltinBinaryOp(LONG, BuiltInOperatorNames.LESS_OR_EQUAL) { a, b -> a <= b }
|
||||
registerBuiltinBinaryOp(LONG, BuiltInOperatorNames.GREATER) { a, b -> a > b }
|
||||
registerBuiltinBinaryOp(LONG, BuiltInOperatorNames.GREATER_OR_EQUAL) { a, b -> a >= b }
|
||||
registerBuiltinBinaryOp(LONG, BuiltInOperatorNames.EQEQ) { a, b -> a == b }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user