[IR] Mark IrSymbol.owner with OptIn annotation

^KT-60923 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-08-03 12:33:55 +03:00
committed by Space Team
parent 20da554443
commit 697d0d5638
28 changed files with 70 additions and 7 deletions
@@ -64,6 +64,7 @@ import org.jetbrains.kotlin.ir.descriptors.IrBasedVariableDescriptor
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbolInternals
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.util.classId
import org.jetbrains.kotlin.ir.util.StubGeneratorExtensions
@@ -242,6 +243,7 @@ internal class KtFirCompilerFacility(
irCodeFragmentFiles.forEach { it.acceptVoid(patchingVisitor) }
}
@OptIn(IrSymbolInternals::class)
private fun computeAdditionalCodeFragmentMapping(descriptor: IrBasedDeclarationDescriptor<*>): CodeFragmentCapturedValue? {
val owner = descriptor.owner
@@ -541,6 +543,7 @@ private class IrDeclarationPatchingVisitor(private val mapping: Map<FirDeclarati
super.visitClassReference(expression)
}
@OptIn(IrSymbolInternals::class)
private inline fun <reified T : IrSymbol> patchIfNeeded(irSymbol: T?, patcher: (T) -> Unit) {
if (irSymbol != null) {
val irDeclaration = irSymbol.owner as? IrMetadataSourceOwner ?: return
@@ -551,4 +554,4 @@ private class IrDeclarationPatchingVisitor(private val mapping: Map<FirDeclarati
}
}
}
}
}
+2
View File
@@ -48,6 +48,8 @@ dependencies {
testRuntimeOnly(jpsModelImpl())
}
optInToIrSymbolInternals()
val generationRoot = projectDir.resolve("tests-gen")
sourceSets {
@@ -23,6 +23,8 @@ dependencies {
compileOnly(commonDependency("org.jetbrains.intellij.deps:asm-all"))
}
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
}
@@ -12,6 +12,8 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
"test" {}
+2
View File
@@ -19,6 +19,8 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
"test" {}
+2
View File
@@ -12,6 +12,8 @@ dependencies {
compileOnly(commonDependency("org.jetbrains.intellij.deps:asm-all"))
}
optInToIrSymbolInternals()
sourceSets {
"main" {
projectDefault()
@@ -10,6 +10,8 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
sourceSets {
"main" {
projectDefault()
@@ -13,6 +13,8 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
sourceSets {
"main" {
projectDefault()
@@ -11,6 +11,8 @@ dependencies {
compileOnly(commonDependency("org.jetbrains.intellij.deps:trove4j"))
}
optInToIrSymbolInternals()
sourceSets {
"main" {
projectDefault()
@@ -19,6 +19,8 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
"test" {}
@@ -8,6 +8,8 @@ dependencies {
compileOnly(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
}
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
"test" {}
+2 -1
View File
@@ -10,8 +10,9 @@ dependencies {
api(project(":compiler:ir.tree"))
}
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
"test" {}
}
+2
View File
@@ -11,6 +11,8 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
"test" {}
+2
View File
@@ -18,6 +18,8 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
sourceSets {
"main" {
projectDefault()
@@ -29,6 +29,13 @@ import org.jetbrains.kotlin.mpp.*
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
*/
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
annotation class IrSymbolInternals
/**
* A special object that can be used to refer to [IrDeclaration]s and some other entities from IR nodes.
*
@@ -59,6 +66,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
val owner: IrSymbolOwner
/**
@@ -118,6 +126,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
override val owner: Owner
@ObsoleteDescriptorBasedAPI
@@ -221,6 +230,7 @@ sealed interface IrValueSymbol : IrSymbol {
@ObsoleteDescriptorBasedAPI
override val descriptor: ValueDescriptor
@IrSymbolInternals
override val owner: IrValueDeclaration
}
@@ -243,6 +253,7 @@ sealed interface IrReturnTargetSymbol : IrSymbol {
@ObsoleteDescriptorBasedAPI
override val descriptor: FunctionDescriptor
@IrSymbolInternals
override val owner: IrReturnTarget
}
@@ -252,6 +263,7 @@ sealed interface IrReturnTargetSymbol : IrSymbol {
* @see IrFunctionReference
*/
sealed interface IrFunctionSymbol : IrReturnTargetSymbol, FunctionSymbolMarker {
@IrSymbolInternals
override val owner: IrFunction
}
@@ -16,6 +16,8 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
"test" {}
@@ -39,6 +39,7 @@ dependencies {
}
optInToExperimentalCompilerApi()
optInToIrSymbolInternals()
sourceSets {
"main" { none() }
+1
View File
@@ -85,6 +85,7 @@ dependencies {
}
optInToExperimentalCompilerApi()
optInToIrSymbolInternals()
sourceSets {
"main" { }
@@ -37,6 +37,8 @@ dependencies {
testApi(commonDependency("org.jetbrains.intellij.deps:jdom"))
}
optInToIrSymbolInternals()
sourceSets {
"main" { none() }
"test" { projectDefault() }
@@ -41,6 +41,8 @@ compileCompilerKotlin {
'-Xskip-prerelease-check']
}
TasksKt.optInToIrSymbolInternals(project)
compileCli_bcKotlin {
kotlinOptions.freeCompilerArgs += ['-Xskip-prerelease-check']
}
@@ -50,6 +50,7 @@ dependencies {
}
optInToExperimentalCompilerApi()
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
@@ -156,14 +156,13 @@ dependencies {
}
optInToExperimentalCompilerApi()
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
"test" { projectDefault() }
}
optInToExperimentalCompilerApi()
testsJar()
useD8Plugin()
@@ -45,6 +45,7 @@ dependencies {
}
optInToExperimentalCompilerApi()
optInToIrSymbolInternals()
val generationRoot = projectDir.resolve("tests-gen")
@@ -25,6 +25,8 @@ dependencies {
compileOnly(intellijCore())
}
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
"test" { none() }
@@ -13,6 +13,8 @@ dependencies {
implementation(kotlinStdlib())
}
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
"test" { none() }
@@ -66,6 +66,7 @@ dependencies {
}
optInToExperimentalCompilerApi()
optInToIrSymbolInternals()
sourceSets {
"main" { none() }
@@ -18,6 +18,8 @@ dependencies {
compileOnly(commonDependency("org.jetbrains.intellij.deps:asm-all"))
}
optInToIrSymbolInternals()
sourceSets {
"main" { projectDefault() }
"test" { none() }
@@ -402,11 +402,18 @@ fun Project.confugureFirPluginAnnotationsDependency(testTask: TaskProvider<Test>
}
}
fun Project.optInToExperimentalCompilerApi() {
@Suppress("DEPRECATION")
private fun Project.optInTo(annotationFqName: String) {
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
kotlinOptions {
freeCompilerArgs += "-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi"
freeCompilerArgs += "-opt-in=$annotationFqName"
}
}
}
fun Project.optInToExperimentalCompilerApi() {
optInTo("org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
}
fun Project.optInToIrSymbolInternals() {
optInTo("org.jetbrains.kotlin.ir.symbols.IrSymbolInternals")
}