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