[IR] Rename IrSymbolInternals to UnsafeDuringIrConstructionAPI

The new name more precisely describes the meaning of this opt-int
This commit is contained in:
Dmitriy Novozhilov
2023-10-23 17:11:58 +03:00
committed by Space Team
parent 38ebe60e9f
commit fb8bf19091
59 changed files with 146 additions and 151 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" { projectDefault() }
+1 -1
View File
@@ -19,7 +19,7 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" { projectDefault() }
+1 -1
View File
@@ -12,7 +12,7 @@ dependencies {
compileOnly(commonDependency("org.jetbrains.intellij.deps:asm-all"))
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" {
@@ -10,7 +10,7 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" {
@@ -13,7 +13,7 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" {
@@ -11,7 +11,7 @@ dependencies {
compileOnly(commonDependency("org.jetbrains.intellij.deps:trove4j"))
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" {
+1 -1
View File
@@ -19,7 +19,7 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" { projectDefault() }
+1 -1
View File
@@ -8,7 +8,7 @@ dependencies {
compileOnly(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" { projectDefault() }
+1 -1
View File
@@ -10,7 +10,7 @@ dependencies {
api(project(":compiler:ir.tree"))
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" { projectDefault() }
+1 -1
View File
@@ -16,4 +16,4 @@ sourceSets {
"main" { projectDefault() }
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
+1 -1
View File
@@ -11,7 +11,7 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
optInToObsoleteDescriptorBasedAPI()
sourceSets {
+1 -1
View File
@@ -18,7 +18,7 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" {
@@ -8,7 +8,7 @@
package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.ir.symbols.IrSymbolInternals
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
/**
* A non-leaf IR tree element.
@@ -22,6 +22,6 @@ interface IrDeclarationContainer : IrDeclarationParent {
* before IR for all sources is built (because fake-overrides of lazy classes may depend on
* declaration of source classes, e.g. for java source classes)
*/
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val declarations: MutableList<IrDeclaration>
}
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbolInternals
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.name.Name
@@ -48,7 +48,7 @@ open class IrClassImpl(
override var thisReceiver: IrValueParameter? = null
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
override val declarations: MutableList<IrDeclaration> = ArrayList()
override var typeParameters: List<IrTypeParameter> = emptyList()
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment
import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbolInternals
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.symbols.impl.IrExternalPackageFragmentSymbolImpl
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
@@ -52,7 +52,7 @@ class IrExternalPackageFragmentImpl(
override val moduleDescriptor: ModuleDescriptor
get() = packageFragmentDescriptor.containingDeclaration
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
override val declarations: MutableList<IrDeclaration> = ArrayList()
@OptIn(ObsoleteDescriptorBasedAPI::class)
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.MetadataSource
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbolInternals
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.symbols.impl.IrFileSymbolImpl
import org.jetbrains.kotlin.name.FqName
@@ -80,7 +80,7 @@ class IrFileImpl(
packageFragmentDescriptor.containingDeclaration
}
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
override val declarations: MutableList<IrDeclaration> = ArrayList()
override var annotations: List<IrConstructorCall> = emptyList()
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbolInternals
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.*
@@ -56,7 +56,7 @@ class IrLazyClass(
}
}
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
override val declarations: MutableList<IrDeclaration> by lazyVar(stubGenerator.lock) {
ArrayList<IrDeclaration>().also {
typeTranslator.buildWithScope(this) {
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.expressions.typeParametersCount
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbolInternals
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.allTypeParameters
import org.jetbrains.kotlin.ir.util.initializeParameterArguments
@@ -55,7 +55,7 @@ class IrDelegatingConstructorCallImpl(
valueArgumentsCount: Int = symbol.descriptor.valueParameters.size + symbol.descriptor.contextReceiverParameters.size
) = IrDelegatingConstructorCallImpl(startOffset, endOffset, type, symbol, typeArgumentsCount, valueArgumentsCount)
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
fun fromSymbolOwner(
startOffset: Int,
endOffset: Int,
@@ -30,11 +30,10 @@ import org.jetbrains.kotlin.types.model.TypeConstructorMarker
import org.jetbrains.kotlin.types.model.TypeParameterMarker
/**
* Usage of [IrSymbol.owner] can be unsafe in some context (like in fir2ir), where not all symbols can be bound),
* so it should be used with care
* Usage of marked API can be unsafe at the stage when IR for the whole module is not built yet (specifically in fir2ir)
*/
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
annotation class IrSymbolInternals
annotation class UnsafeDuringIrConstructionAPI
/**
* A special object that can be used to refer to [IrDeclaration]s and some other entities from IR nodes.
@@ -66,7 +65,7 @@ interface IrSymbol : DeclarationSymbolMarker {
* **A:** Because we most often need to access a symbol's owner in lowerings, which happen after linkage, at which point all symbols
* should be already bound. Declaring this property nullable would make working with it more difficult most of the time.
*/
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val owner: IrSymbolOwner
/**
@@ -126,7 +125,7 @@ val IrSymbol.isPublicApi: Boolean
* Only leaf interfaces in the symbol hierarchy inherit from this interface.
*/
interface IrBindableSymbol<out Descriptor : DeclarationDescriptor, Owner : IrSymbolOwner> : IrSymbol {
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
override val owner: Owner
@ObsoleteDescriptorBasedAPI
@@ -230,7 +229,7 @@ sealed interface IrValueSymbol : IrSymbol {
@ObsoleteDescriptorBasedAPI
override val descriptor: ValueDescriptor
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
override val owner: IrValueDeclaration
}
@@ -253,7 +252,7 @@ sealed interface IrReturnTargetSymbol : IrSymbol {
@ObsoleteDescriptorBasedAPI
override val descriptor: FunctionDescriptor
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
override val owner: IrReturnTarget
}
@@ -263,7 +262,7 @@ sealed interface IrReturnTargetSymbol : IrSymbol {
* @see IrFunctionReference
*/
sealed interface IrFunctionSymbol : IrReturnTargetSymbol, FunctionSymbolMarker {
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
override val owner: IrFunction
}
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbolInternals
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
@@ -33,7 +33,7 @@ object IrErrorClassImpl : IrClassImpl(
get() = shouldNotBeCalled()
set(_) {}
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
override val declarations: MutableList<IrDeclaration>
get() = shouldNotBeCalled()
override val symbol: IrFileSymbol
@@ -186,7 +186,7 @@ val IrDeclaration.fileEntry: IrFileEntry
}
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
fun IrClass.companionObject(): IrClass? =
this.declarations.singleOrNull { it is IrClass && it.isCompanion } as IrClass?
@@ -285,7 +285,7 @@ class NaiveSourceBasedFileEntryImpl(
}
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
private fun IrClass.getPropertyDeclaration(name: String): IrProperty? {
val properties = declarations.filterIsInstanceAnd<IrProperty> { it.name.asString() == name }
if (properties.size > 1) {
@@ -301,24 +301,24 @@ fun IrClass.getSimpleFunction(name: String): IrSimpleFunctionSymbol? =
findDeclaration<IrSimpleFunction> { it.name.asString() == name }?.symbol
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
fun IrClass.getPropertyGetter(name: String): IrSimpleFunctionSymbol? =
getPropertyDeclaration(name)?.getter?.symbol
?: getSimpleFunction("<get-$name>").also { assert(it?.owner?.correspondingPropertySymbol?.owner?.name?.asString() == name) }
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
fun IrClass.getPropertySetter(name: String): IrSimpleFunctionSymbol? =
getPropertyDeclaration(name)?.setter?.symbol
?: getSimpleFunction("<set-$name>").also { assert(it?.owner?.correspondingPropertySymbol?.owner?.name?.asString() == name) }
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
fun IrClassSymbol.getSimpleFunction(name: String): IrSimpleFunctionSymbol? = owner.getSimpleFunction(name)
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
fun IrClassSymbol.getPropertyGetter(name: String): IrSimpleFunctionSymbol? = owner.getPropertyGetter(name)
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
fun IrClassSymbol.getPropertySetter(name: String): IrSimpleFunctionSymbol? = owner.getPropertySetter(name)
fun filterOutAnnotations(fqName: FqName, annotations: List<IrConstructorCall>): List<IrConstructorCall> {
@@ -222,12 +222,12 @@ val IrProperty.isSimpleProperty: Boolean
}
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val IrClass.functions: Sequence<IrSimpleFunction>
get() = declarations.asSequence().filterIsInstance<IrSimpleFunction>()
// This declaration accesses IrBasedSymbol.owner, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val IrClass.superClass: IrClass?
get() = superTypes
.firstOrNull { !it.isInterface() && !it.isAny() }
@@ -235,47 +235,47 @@ val IrClass.superClass: IrClass?
?.owner
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val IrClassSymbol.functions: Sequence<IrSimpleFunctionSymbol>
get() = owner.functions.map { it.symbol }
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val IrClass.constructors: Sequence<IrConstructor>
get() = declarations.asSequence().filterIsInstance<IrConstructor>()
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val IrClass.defaultConstructor: IrConstructor?
get() = constructors.firstOrNull { ctor -> ctor.valueParameters.all { it.defaultValue != null } }
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val IrClassSymbol.constructors: Sequence<IrConstructorSymbol>
get() = owner.constructors.map { it.symbol }
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val IrClass.fields: Sequence<IrField>
get() = declarations.asSequence().filterIsInstance<IrField>()
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val IrClassSymbol.fields: Sequence<IrFieldSymbol>
get() = owner.fields.map { it.symbol }
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val IrClass.primaryConstructor: IrConstructor?
get() = this.declarations.singleOrNull { it is IrConstructor && it.isPrimary } as IrConstructor?
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val IrClass.invokeFun: IrSimpleFunction?
get() = declarations.filterIsInstance<IrSimpleFunction>().singleOrNull { it.name.asString() == "invoke" }
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
val IrDeclarationContainer.properties: Sequence<IrProperty>
get() = declarations.asSequence().filterIsInstance<IrProperty>()
@@ -466,7 +466,7 @@ fun IrFunction.isExternalOrInheritedFromExternal(): Boolean {
}
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
inline fun <reified T : IrDeclaration> IrDeclarationContainer.findDeclaration(predicate: (T) -> Boolean): T? =
declarations.find { it is T && predicate(it) } as? T
@@ -1190,7 +1190,7 @@ fun IrFunction.isMethodOfAny(): Boolean =
}
// This declaration accesses IrDeclarationContainer.declarations, which is marked with this opt-in
@IrSymbolInternals
@UnsafeDuringIrConstructionAPI
fun IrDeclarationContainer.simpleFunctions() = declarations.flatMap {
when (it) {
is IrSimpleFunction -> listOf(it)
@@ -351,7 +351,7 @@ object IrTree : AbstractTreeBuilder() {
declaration of source classes, e.g. for java source classes)
""".trimIndent()
generationCallback = {
addAnnotation(ClassName("org.jetbrains.kotlin.ir.symbols", "IrSymbolInternals"))
addAnnotation(ClassName("org.jetbrains.kotlin.ir.symbols", "UnsafeDuringIrConstructionAPI"))
}
}
}
@@ -16,7 +16,7 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
optInToObsoleteDescriptorBasedAPI()
sourceSets {
@@ -15,7 +15,7 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" { projectDefault() }
@@ -12,7 +12,7 @@ dependencies {
api(project(":compiler:frontend.java"))
}
optInToIrSymbolInternals()
optInToUnsafeDuringIrConstructionAPI()
sourceSets {
"main" {