[FIR2IR] Create builtin IR class for @IntrinsicConstEvaluation manually if it is missing in stdlib
^KT-59151
This commit is contained in:
committed by
Space Team
parent
3f2e996803
commit
250b94d5dd
@@ -11,9 +11,7 @@ import org.jetbrains.kotlin.KtPsiSourceFileLinesMapping
|
||||
import org.jetbrains.kotlin.KtSourceFileLinesMappingFromLineStartOffsets
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendErrors
|
||||
import org.jetbrains.kotlin.backend.common.sourceElement
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
@@ -577,7 +575,6 @@ class Fir2IrConverter(
|
||||
components.annotationsFromPluginRegistrar = Fir2IrAnnotationsFromPluginRegistrar(components)
|
||||
|
||||
fir2IrExtensions.registerDeclarations(commonMemberStorage.symbolTable)
|
||||
irBuiltIns.initialize()
|
||||
|
||||
val irModuleFragment = IrModuleFragmentImpl(moduleDescriptor, irBuiltIns)
|
||||
|
||||
|
||||
@@ -53,8 +53,6 @@ class IrBuiltInsOverFir(
|
||||
private val moduleDescriptor: FirModuleDescriptor,
|
||||
irMangler: KotlinMangler.IrMangler
|
||||
) : IrBuiltIns() {
|
||||
private var initialized: Boolean = false
|
||||
|
||||
private val session: FirSession
|
||||
get() = components.session
|
||||
|
||||
@@ -65,7 +63,10 @@ class IrBuiltInsOverFir(
|
||||
|
||||
private val kotlinPackage = StandardClassIds.BASE_KOTLIN_PACKAGE
|
||||
|
||||
override val operatorsPackageFragment = createPackage(KOTLIN_INTERNAL_IR_FQN)
|
||||
override val kotlinInternalPackageFragment: IrExternalPackageFragment = createPackage(StandardClassIds.BASE_INTERNAL_PACKAGE)
|
||||
private val kotlinInternalIrPackageFragment: IrExternalPackageFragment = createPackage(StandardClassIds.BASE_INTERNAL_IR_PACKAGE)
|
||||
override val operatorsPackageFragment: IrExternalPackageFragment
|
||||
get() = kotlinInternalIrPackageFragment
|
||||
|
||||
private val irSignatureBuilder = PublicIdSignatureComputer(irMangler)
|
||||
|
||||
@@ -127,7 +128,11 @@ class IrBuiltInsOverFir(
|
||||
override val stringClass: IrClassSymbol by lazy { loadClass(StandardClassIds.String) }
|
||||
override val stringType: IrType get() = stringClass.defaultTypeWithoutArguments
|
||||
|
||||
internal val intrinsicConst by lazy { loadClass(StandardClassIds.Annotations.IntrinsicConstEvaluation) }
|
||||
internal val intrinsicConst by lazy {
|
||||
// Old versions of stdlib may not contain @IntrinsicConstEvaluation (AV < 1.7),
|
||||
// so in this case we should create annotation class manually
|
||||
/*loadClassSafe(StandardClassIds.Annotations.IntrinsicConstEvaluation) ?: */createIntrinsicConstEvaluationClass().symbol
|
||||
}
|
||||
|
||||
private val intrinsicConstAnnotation: IrConstructorCall by lazy {
|
||||
val constructor = intrinsicConst.constructors.single()
|
||||
@@ -242,18 +247,18 @@ class IrBuiltInsOverFir(
|
||||
override val ieee754equalsFunByOperandType: MutableMap<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
get() = _ieee754equalsFunByOperandType
|
||||
|
||||
override lateinit var eqeqeqSymbol: IrSimpleFunctionSymbol private set
|
||||
override lateinit var eqeqSymbol: IrSimpleFunctionSymbol private set
|
||||
override lateinit var throwCceSymbol: IrSimpleFunctionSymbol private set
|
||||
override lateinit var throwIseSymbol: IrSimpleFunctionSymbol private set
|
||||
override lateinit var andandSymbol: IrSimpleFunctionSymbol private set
|
||||
override lateinit var ororSymbol: IrSimpleFunctionSymbol private set
|
||||
override lateinit var noWhenBranchMatchedExceptionSymbol: IrSimpleFunctionSymbol private set
|
||||
override lateinit var illegalArgumentExceptionSymbol: IrSimpleFunctionSymbol private set
|
||||
override lateinit var dataClassArrayMemberHashCodeSymbol: IrSimpleFunctionSymbol private set
|
||||
override lateinit var dataClassArrayMemberToStringSymbol: IrSimpleFunctionSymbol private set
|
||||
override val eqeqeqSymbol: IrSimpleFunctionSymbol
|
||||
override val eqeqSymbol: IrSimpleFunctionSymbol
|
||||
override val throwCceSymbol: IrSimpleFunctionSymbol
|
||||
override val throwIseSymbol: IrSimpleFunctionSymbol
|
||||
override val andandSymbol: IrSimpleFunctionSymbol
|
||||
override val ororSymbol: IrSimpleFunctionSymbol
|
||||
override val noWhenBranchMatchedExceptionSymbol: IrSimpleFunctionSymbol
|
||||
override val illegalArgumentExceptionSymbol: IrSimpleFunctionSymbol
|
||||
override val dataClassArrayMemberHashCodeSymbol: IrSimpleFunctionSymbol
|
||||
override val dataClassArrayMemberToStringSymbol: IrSimpleFunctionSymbol
|
||||
|
||||
override lateinit var checkNotNullSymbol: IrSimpleFunctionSymbol private set
|
||||
override val checkNotNullSymbol: IrSimpleFunctionSymbol
|
||||
override val arrayOfNulls: IrSimpleFunctionSymbol by lazy {
|
||||
val firSymbol = symbolProvider
|
||||
.getTopLevelFunctionSymbols(kotlinPackage, Name.identifier("arrayOfNulls")).first {
|
||||
@@ -265,15 +270,13 @@ class IrBuiltInsOverFir(
|
||||
override val linkageErrorSymbol: IrSimpleFunctionSymbol
|
||||
get() = TODO("Not yet implemented")
|
||||
|
||||
override lateinit var lessFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
||||
override lateinit var lessOrEqualFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
||||
override lateinit var greaterOrEqualFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
||||
override lateinit var greaterFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
||||
override val lessFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
override val lessOrEqualFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
override val greaterOrEqualFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
override val greaterFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||
|
||||
internal fun initialize() {
|
||||
if (initialized) return
|
||||
initialized = true
|
||||
with(this.operatorsPackageFragment) {
|
||||
init {
|
||||
with(this.kotlinInternalIrPackageFragment) {
|
||||
|
||||
fun addBuiltinOperatorSymbol(
|
||||
name: String,
|
||||
@@ -504,12 +507,12 @@ class IrBuiltInsOverFir(
|
||||
findProperties(packageFqName, name)
|
||||
|
||||
override fun findClass(name: Name, vararg packageNameSegments: String): IrClassSymbol? =
|
||||
referenceClassByFqname(FqName.fromSegments(packageNameSegments.asList()), name)
|
||||
loadClassSafe(FqName.fromSegments(packageNameSegments.asList()), name)
|
||||
|
||||
override fun findClass(name: Name, packageFqName: FqName): IrClassSymbol? =
|
||||
referenceClassByFqname(packageFqName, name)
|
||||
loadClassSafe(packageFqName, name)
|
||||
|
||||
private fun referenceClassByFqname(packageName: FqName, identifier: Name): IrClassSymbol? {
|
||||
private fun loadClassSafe(packageName: FqName, identifier: Name): IrClassSymbol? {
|
||||
return loadClassSafe(ClassId(packageName, identifier))
|
||||
}
|
||||
|
||||
@@ -534,7 +537,7 @@ class IrBuiltInsOverFir(
|
||||
|
||||
// ---------------
|
||||
|
||||
private fun referenceClassByFqname(topLevelFqName: FqName): IrClassSymbol? {
|
||||
private fun loadClassSafe(topLevelFqName: FqName): IrClassSymbol? {
|
||||
return loadClassSafe(ClassId.topLevel(topLevelFqName))
|
||||
}
|
||||
|
||||
@@ -551,7 +554,7 @@ class IrBuiltInsOverFir(
|
||||
private fun IrType.getMaybeBuiltinClass(): IrClass? {
|
||||
val lhsClassFqName = classFqName!!
|
||||
return baseIrTypes.find { it.classFqName == lhsClassFqName }?.getClass()
|
||||
?: referenceClassByFqname(lhsClassFqName)?.owner
|
||||
?: loadClassSafe(lhsClassFqName)?.owner
|
||||
}
|
||||
|
||||
private fun createPackage(fqName: FqName): IrExternalPackageFragment =
|
||||
|
||||
+2
-14
@@ -19,8 +19,6 @@ import org.jetbrains.kotlin.ir.BuiltInOperatorNames
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addConstructor
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
|
||||
@@ -79,7 +77,7 @@ class IrBuiltInsOverDescriptors(
|
||||
private val builtInsModule = builtIns.builtInsModule
|
||||
|
||||
private val kotlinInternalPackage = StandardClassIds.BASE_INTERNAL_PACKAGE
|
||||
private val kotlinInternalIrPackage = IrExternalPackageFragmentImpl.createEmptyExternalPackageFragment(builtInsModule, kotlinInternalPackage)
|
||||
override val kotlinInternalPackageFragment = IrExternalPackageFragmentImpl.createEmptyExternalPackageFragment(builtInsModule, kotlinInternalPackage)
|
||||
|
||||
private val packageFragmentDescriptor = IrBuiltinsPackageFragmentDescriptorImpl(builtInsModule, KOTLIN_INTERNAL_IR_FQN)
|
||||
|
||||
@@ -294,17 +292,7 @@ class IrBuiltInsOverDescriptors(
|
||||
override val anyClass = builtIns.any.toIrSymbol()
|
||||
override val anyNType = anyType.makeNullable()
|
||||
|
||||
private val intrinsicConstAnnotationFqName = kotlinInternalPackage.child(Name.identifier("IntrinsicConstEvaluation"))
|
||||
private val intrinsicConstClass = irFactory.buildClass {
|
||||
name = intrinsicConstAnnotationFqName.shortName()
|
||||
kind = ClassKind.ANNOTATION_CLASS
|
||||
modality = Modality.FINAL
|
||||
}.apply {
|
||||
parent = kotlinInternalIrPackage
|
||||
createImplicitParameterDeclarationWithWrappedDescriptor()
|
||||
addConstructor() { isPrimary = true }
|
||||
addFakeOverrides(IrTypeSystemContextImpl(this@IrBuiltInsOverDescriptors))
|
||||
}
|
||||
private val intrinsicConstClass = createIntrinsicConstEvaluationClass()
|
||||
private val intrinsicConstType = intrinsicConstClass.defaultType
|
||||
private val intrinsicConstConstructor = intrinsicConstClass.primaryConstructor as IrConstructor
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ package org.jetbrains.kotlin.ir
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.builtins.UnsignedType
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addConstructor
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.buildClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOriginImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
|
||||
@@ -17,8 +21,12 @@ import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
|
||||
import org.jetbrains.kotlin.ir.util.addFakeOverrides
|
||||
import org.jetbrains.kotlin.ir.util.createImplicitParameterDeclarationWithWrappedDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
|
||||
/**
|
||||
* Symbols for builtins that are available without any context and are not specific to any backend
|
||||
@@ -190,6 +198,20 @@ abstract class IrBuiltIns {
|
||||
abstract fun getUnaryOperator(name: Name, receiverType: IrType): IrSimpleFunctionSymbol
|
||||
|
||||
abstract val operatorsPackageFragment: IrExternalPackageFragment
|
||||
abstract val kotlinInternalPackageFragment: IrExternalPackageFragment
|
||||
|
||||
protected fun createIntrinsicConstEvaluationClass(): IrClass {
|
||||
return irFactory.buildClass {
|
||||
name = StandardClassIds.Annotations.IntrinsicConstEvaluation.shortClassName
|
||||
kind = ClassKind.ANNOTATION_CLASS
|
||||
modality = Modality.FINAL
|
||||
}.apply {
|
||||
parent = kotlinInternalPackageFragment
|
||||
createImplicitParameterDeclarationWithWrappedDescriptor()
|
||||
addConstructor { isPrimary = true }
|
||||
addFakeOverrides(IrTypeSystemContextImpl(this@IrBuiltIns))
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val KOTLIN_INTERNAL_IR_FQN = FqName("kotlin.internal.ir")
|
||||
|
||||
Reference in New Issue
Block a user