IR: Move unsigned classes loading from builtins back to symbols
see #KT-47540 for the motivation
This commit is contained in:
committed by
TeamCityServer
parent
808f5148f3
commit
51dc829aae
@@ -497,21 +497,33 @@ class IrBuiltInsOverFir(
|
||||
|
||||
override val arrayOf: IrSimpleFunctionSymbol get() = kotlinBuiltinFunctions.arrayOf
|
||||
|
||||
override val toUIntByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> by lazy {
|
||||
findFunctions(kotlinPackage, Name.identifier("toUInt")).mapNotNull { fn ->
|
||||
fn.owner.extensionReceiverParameter?.type?.classifierOrNull?.let { klass ->
|
||||
klass to fn
|
||||
private fun <T: Any> getFunctionsByKey(
|
||||
name: Name,
|
||||
vararg packageNameSegments: String,
|
||||
makeKey: (IrSimpleFunctionSymbol) -> T?
|
||||
): Map<T, IrSimpleFunctionSymbol> {
|
||||
val result = mutableMapOf<T, IrSimpleFunctionSymbol>()
|
||||
for (fn in findFunctions(name, *packageNameSegments)) {
|
||||
makeKey(fn)?.let { key ->
|
||||
result[key] = fn
|
||||
}
|
||||
}.toMap()
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override val toULongByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> by lazy {
|
||||
findFunctions(kotlinPackage, Name.identifier("toULong")).mapNotNull { fn ->
|
||||
fn.owner.extensionReceiverParameter?.type?.classifierOrNull?.let { klass ->
|
||||
klass to fn
|
||||
}
|
||||
}.toMap()
|
||||
}
|
||||
override fun getNonBuiltInFunctionsByExtensionReceiver(
|
||||
name: Name, vararg packageNameSegments: String
|
||||
): Map<IrClassifierSymbol, IrSimpleFunctionSymbol> =
|
||||
getFunctionsByKey(name, *packageNameSegments) { fn ->
|
||||
fn.owner.extensionReceiverParameter?.type?.classifierOrNull
|
||||
}
|
||||
|
||||
override fun getNonBuiltinFunctionsByReturnType(
|
||||
name: Name, vararg packageNameSegments: String
|
||||
): Map<IrClassifierSymbol, IrSimpleFunctionSymbol> =
|
||||
getFunctionsByKey(name, *packageNameSegments) { fn ->
|
||||
fn.owner.returnType.classOrNull
|
||||
}
|
||||
|
||||
private val functionNMap = mutableMapOf<Int, IrClass>()
|
||||
private val kFunctionNMap = mutableMapOf<Int, IrClass>()
|
||||
@@ -579,12 +591,6 @@ class IrBuiltInsOverFir(
|
||||
}.symbol
|
||||
}
|
||||
|
||||
override val getProgressionLastElementByReturnType: Map<IrClassifierSymbol?, IrSimpleFunctionSymbol> by lazy {
|
||||
findFunctions(kotlinPackage.child(Name.identifier("internal")), Name.identifier("getProgressionLastElement")).mapNotNull { fn ->
|
||||
fn.owner.returnType.classOrNull?.let { it to fn }
|
||||
}.toMap()
|
||||
}
|
||||
|
||||
// ---------------
|
||||
|
||||
class BuiltInClassValue(
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.backend.common.lower.LocalDeclarationsLowering
|
||||
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.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
@@ -96,14 +95,14 @@ open class BuiltinSymbolsBase(val irBuiltIns: IrBuiltIns, private val symbolTabl
|
||||
|
||||
val closedRange = progression("ClosedRange")
|
||||
|
||||
open val getProgressionLastElementByReturnType: Map<IrClassifierSymbol?, IrSimpleFunctionSymbol>
|
||||
get() = irBuiltIns.getProgressionLastElementByReturnType
|
||||
open val getProgressionLastElementByReturnType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> =
|
||||
irBuiltIns.getNonBuiltinFunctionsByReturnType(Name.identifier("getProgressionLastElement"), "kotlin", "internal")
|
||||
|
||||
val toUIntByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
get() = irBuiltIns.toUIntByExtensionReceiver
|
||||
val toUIntByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> =
|
||||
irBuiltIns.getNonBuiltInFunctionsByExtensionReceiver(Name.identifier("toUInt"), "kotlin")
|
||||
|
||||
val toULongByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
get() = irBuiltIns.toULongByExtensionReceiver
|
||||
val toULongByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> =
|
||||
irBuiltIns.getNonBuiltInFunctionsByExtensionReceiver(Name.identifier("toULong"), "kotlin")
|
||||
|
||||
val any get() = irBuiltIns.anyClass
|
||||
val unit get() = irBuiltIns.unitClass
|
||||
|
||||
@@ -574,7 +574,7 @@ class JvmSymbols(
|
||||
}
|
||||
}
|
||||
|
||||
override val getProgressionLastElementByReturnType: Map<IrClassifierSymbol?, IrSimpleFunctionSymbol> by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
override val getProgressionLastElementByReturnType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
progressionUtilClasses.flatMap { klass ->
|
||||
klass.functions.filter {
|
||||
it.owner.name.identifier == "getProgressionLastElement"
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -146,8 +147,13 @@ abstract class IrBuiltIns {
|
||||
abstract val arrayOf: IrSimpleFunctionSymbol
|
||||
abstract val arrayOfNulls: IrSimpleFunctionSymbol
|
||||
|
||||
abstract val toUIntByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
abstract val toULongByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
abstract fun getNonBuiltInFunctionsByExtensionReceiver(
|
||||
name: Name, vararg packageNameSegments: String
|
||||
): Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
|
||||
abstract fun getNonBuiltinFunctionsByReturnType(
|
||||
name: Name, vararg packageNameSegments: String
|
||||
): Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
|
||||
abstract fun functionN(arity: Int, declarator: SymbolTable.((IrClassSymbol) -> IrClass) -> IrClass): IrClass
|
||||
abstract fun kFunctionN(arity: Int, declarator: SymbolTable.((IrClassSymbol) -> IrClass) -> IrClass): IrClass
|
||||
@@ -169,8 +175,6 @@ abstract class IrBuiltIns {
|
||||
abstract fun getBinaryOperator(name: Name, lhsType: IrType, rhsType: IrType): IrSimpleFunctionSymbol
|
||||
abstract fun getUnaryOperator(name: Name, receiverType: IrType): IrSimpleFunctionSymbol
|
||||
|
||||
abstract val getProgressionLastElementByReturnType: Map<IrClassifierSymbol?, IrSimpleFunctionSymbol>
|
||||
|
||||
abstract val operatorsPackageFragment: IrExternalPackageFragment
|
||||
|
||||
companion object {
|
||||
|
||||
+31
-34
@@ -345,12 +345,11 @@ class IrBuiltInsOverDescriptors(
|
||||
override val primitiveArrayElementTypes = primitiveArraysToPrimitiveTypes.mapValues { primitiveTypeToIrType[it.value] }
|
||||
override val primitiveArrayForType = primitiveArrayElementTypes.asSequence().associate { it.value to it.key }
|
||||
|
||||
override val unsignedTypesToUnsignedArrays: Map<UnsignedType, IrClassSymbol> by lazy {
|
||||
override val unsignedTypesToUnsignedArrays: Map<UnsignedType, IrClassSymbol> =
|
||||
UnsignedType.values().mapNotNull { unsignedType ->
|
||||
val array = builtIns.builtInsModule.findClassAcrossModuleDependencies(unsignedType.arrayClassId)?.toIrSymbol()
|
||||
if (array == null) null else unsignedType to array
|
||||
}.toMap()
|
||||
}
|
||||
|
||||
override val lessFunByOperandType = primitiveIrTypesWithComparisons.defineComparisonOperatorForEachIrType(BuiltInOperatorNames.LESS)
|
||||
override val lessOrEqualFunByOperandType = primitiveIrTypesWithComparisons.defineComparisonOperatorForEachIrType(BuiltInOperatorNames.LESS_OR_EQUAL)
|
||||
@@ -469,27 +468,37 @@ class IrBuiltInsOverDescriptors(
|
||||
}
|
||||
}
|
||||
|
||||
override val toUIntByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> =
|
||||
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()
|
||||
private fun <T: Any> getFunctionsByKey(
|
||||
name: Name,
|
||||
vararg packageNameSegments: String,
|
||||
makeKey: (SimpleFunctionDescriptor) -> T?
|
||||
): Map<T, IrSimpleFunctionSymbol> {
|
||||
val result = mutableMapOf<T, IrSimpleFunctionSymbol>()
|
||||
for (d in builtInsPackage(*packageNameSegments).getContributedFunctions(name, NoLookupLocation.FROM_BACKEND)) {
|
||||
makeKey(d)?.let { key ->
|
||||
result[key] = symbolTable.referenceSimpleFunction(d)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
override val toULongByExtensionReceiver: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> =
|
||||
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()
|
||||
override fun getNonBuiltInFunctionsByExtensionReceiver(
|
||||
name: Name, vararg packageNameSegments: String
|
||||
): Map<IrClassifierSymbol, IrSimpleFunctionSymbol> =
|
||||
getFunctionsByKey(name, *packageNameSegments) {
|
||||
if (it.containingDeclaration !is BuiltInsPackageFragment && it.extensionReceiverParameter != null) {
|
||||
symbolTable.referenceClassifier(it.extensionReceiverParameter!!.type.constructor.declarationDescriptor!!)
|
||||
} else null
|
||||
}
|
||||
|
||||
override fun getNonBuiltinFunctionsByReturnType(
|
||||
name: Name, vararg packageNameSegments: String
|
||||
): Map<IrClassifierSymbol, IrSimpleFunctionSymbol> =
|
||||
getFunctionsByKey(Name.identifier("getProgressionLastElement"), *packageNameSegments) { d ->
|
||||
if (d.containingDeclaration !is BuiltInsPackageFragment) {
|
||||
d.returnType?.constructor?.declarationDescriptor?.let { symbolTable.referenceClassifier(it) }
|
||||
} else null
|
||||
}
|
||||
|
||||
override val extensionToString: IrSimpleFunctionSymbol = findFunctions(Name.identifier("toString"), "kotlin").first {
|
||||
val descriptor = it.descriptor
|
||||
@@ -523,18 +532,6 @@ class IrBuiltInsOverDescriptors(
|
||||
override fun kFunctionN(arity: Int): IrClass = functionFactory.kFunctionN(arity)
|
||||
override fun suspendFunctionN(arity: Int): IrClass = functionFactory.suspendFunctionN(arity)
|
||||
override fun kSuspendFunctionN(arity: Int): IrClass = functionFactory.kSuspendFunctionN(arity)
|
||||
|
||||
override val getProgressionLastElementByReturnType: Map<IrClassifierSymbol?, IrSimpleFunctionSymbol> by lazy {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun MemberScope.findFirstFunction(name: String, predicate: (CallableMemberDescriptor) -> Boolean) =
|
||||
|
||||
Reference in New Issue
Block a user