Introduce @FirIncompatiblePluginApi

This commit is contained in:
Leonid Startsev
2022-07-22 20:29:46 +02:00
committed by Space
parent 467ff30aac
commit 89329a0e1b
15 changed files with 62 additions and 98 deletions
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.backend
import org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.backend.common.ir.BuiltinSymbolsBase
import org.jetbrains.kotlin.config.LanguageVersionSettings
@@ -39,15 +40,17 @@ class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginCo
}
@ObsoleteDescriptorBasedAPI
@FirIncompatiblePluginAPI
override val moduleDescriptor: ModuleDescriptor
get() = error(ERROR_MESSAGE)
@Suppress("OVERRIDE_DEPRECATION")
@ObsoleteDescriptorBasedAPI
@FirIncompatiblePluginAPI
override val bindingContext: BindingContext
get() = error(ERROR_MESSAGE)
@ObsoleteDescriptorBasedAPI
@FirIncompatiblePluginAPI
override val typeTranslator: TypeTranslator
get() = error(ERROR_MESSAGE)
@@ -139,26 +142,27 @@ class Fir2IrPluginContext(private val components: Fir2IrComponents) : IrPluginCo
}
@Deprecated("Use classId overload instead")
@FirIncompatiblePluginAPI
override fun referenceClass(fqName: FqName): IrClassSymbol? {
error(ERROR_MESSAGE)
}
@FirIncompatiblePluginAPI
override fun referenceTypeAlias(fqName: FqName): IrTypeAliasSymbol? {
error(ERROR_MESSAGE)
}
@Deprecated("Use classId overload instead")
@FirIncompatiblePluginAPI
override fun referenceConstructors(classFqn: FqName): Collection<IrConstructorSymbol> {
error(ERROR_MESSAGE)
}
@Deprecated("Use callableId overload instead")
@FirIncompatiblePluginAPI
override fun referenceFunctions(fqName: FqName): Collection<IrSimpleFunctionSymbol> {
error(ERROR_MESSAGE)
}
@Deprecated("Use callableId overload instead")
@FirIncompatiblePluginAPI
override fun referenceProperties(fqName: FqName): Collection<IrPropertySymbol> {
error(ERROR_MESSAGE)
}
@@ -22,6 +22,15 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.resolve.BindingContext
/**
* Indicates methods and properties that are not available in backend after FIR
*
* Invocation of such methods in IR plugins if frontend was a FIR results in compiler crash.
* It's still possible to use them in IR plugins with old frontend.
*/
@RequiresOptIn("This API is not available after FIR")
annotation class FirIncompatiblePluginAPI(val hint: String = "")
interface IrPluginContext : IrGeneratorContext {
val languageVersionSettings: LanguageVersionSettings
@@ -29,13 +38,13 @@ interface IrPluginContext : IrGeneratorContext {
val moduleDescriptor: ModuleDescriptor
@ObsoleteDescriptorBasedAPI
@Deprecated("", level = DeprecationLevel.ERROR)
@FirIncompatiblePluginAPI
val bindingContext: BindingContext
val symbolTable: ReferenceSymbolTable
@ObsoleteDescriptorBasedAPI
// @Deprecated("", level = DeprecationLevel.ERROR)
@FirIncompatiblePluginAPI
val typeTranslator: TypeTranslator
val symbols: BuiltinSymbolsBase
@@ -51,14 +60,15 @@ interface IrPluginContext : IrGeneratorContext {
fun createDiagnosticReporter(pluginId: String): IrMessageLogger
// The following API is experimental
@Deprecated("Use classId overload instead")
@FirIncompatiblePluginAPI("Use classId overload instead")
fun referenceClass(fqName: FqName): IrClassSymbol?
@FirIncompatiblePluginAPI("Use classId overload instead")
fun referenceTypeAlias(fqName: FqName): IrTypeAliasSymbol?
@Deprecated("Use classId overload instead")
@FirIncompatiblePluginAPI("Use classId overload instead")
fun referenceConstructors(classFqn: FqName): Collection<IrConstructorSymbol>
@Deprecated("Use callableId overload instead")
@FirIncompatiblePluginAPI("Use callableId overload instead")
fun referenceFunctions(fqName: FqName): Collection<IrSimpleFunctionSymbol>
@Deprecated("Use callableId overload instead")
@FirIncompatiblePluginAPI("Use callableId overload instead")
fun referenceProperties(fqName: FqName): Collection<IrPropertySymbol>
// This one is experimental too
@@ -30,11 +30,11 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
open class IrPluginContextImpl constructor(
private val module: ModuleDescriptor,
@Deprecated("", level = DeprecationLevel.ERROR)
@OptIn(ObsoleteDescriptorBasedAPI::class)
@OptIn(ObsoleteDescriptorBasedAPI::class, FirIncompatiblePluginAPI::class)
override val bindingContext: BindingContext,
override val languageVersionSettings: LanguageVersionSettings,
private val st: ReferenceSymbolTable,
@OptIn(ObsoleteDescriptorBasedAPI::class)
@OptIn(ObsoleteDescriptorBasedAPI::class, FirIncompatiblePluginAPI::class)
override val typeTranslator: TypeTranslator,
override val irBuiltIns: IrBuiltIns,
val linker: IrDeserializer,
@@ -98,8 +98,7 @@ open class IrPluginContextImpl constructor(
return symbols
}
@Deprecated("Use classId overload instead")
@OptIn(ObsoleteDescriptorBasedAPI::class)
@OptIn(ObsoleteDescriptorBasedAPI::class, FirIncompatiblePluginAPI::class)
override fun referenceClass(fqName: FqName): IrClassSymbol? {
assert(!fqName.isRoot)
return resolveSymbol(fqName.parent()) { scope ->
@@ -110,7 +109,7 @@ open class IrPluginContextImpl constructor(
}
}
@OptIn(ObsoleteDescriptorBasedAPI::class)
@OptIn(ObsoleteDescriptorBasedAPI::class, FirIncompatiblePluginAPI::class)
override fun referenceTypeAlias(fqName: FqName): IrTypeAliasSymbol? {
assert(!fqName.isRoot)
return resolveSymbol(fqName.parent()) { scope ->
@@ -121,15 +120,14 @@ open class IrPluginContextImpl constructor(
}
}
@Deprecated("Use classId overload instead")
@OptIn(FirIncompatiblePluginAPI::class)
override fun referenceConstructors(classFqn: FqName): Collection<IrConstructorSymbol> {
@Suppress("DEPRECATION")
val classSymbol = referenceClass(classFqn) ?: error("Cannot find class $classFqn")
return classSymbol.owner.declarations.filterIsInstance<IrConstructor>().map { it.symbol }
}
@Deprecated("Use callableId overload instead")
@OptIn(ObsoleteDescriptorBasedAPI::class)
@OptIn(ObsoleteDescriptorBasedAPI::class, FirIncompatiblePluginAPI::class)
override fun referenceFunctions(fqName: FqName): Collection<IrSimpleFunctionSymbol> {
assert(!fqName.isRoot)
return resolveSymbolCollection(fqName.parent()) { scope ->
@@ -138,8 +136,7 @@ open class IrPluginContextImpl constructor(
}
}
@Deprecated("Use callableId overload instead")
@OptIn(ObsoleteDescriptorBasedAPI::class)
@OptIn(ObsoleteDescriptorBasedAPI::class, FirIncompatiblePluginAPI::class)
override fun referenceProperties(fqName: FqName): Collection<IrPropertySymbol> {
assert(!fqName.isRoot)
return resolveSymbolCollection(fqName.parent()) { scope ->
@@ -149,7 +146,6 @@ open class IrPluginContextImpl constructor(
}
override fun referenceClass(classId: ClassId): IrClassSymbol? {
@Suppress("DEPRECATION")
return referenceClass(classId.asSingleFqName())
}
@@ -158,17 +154,14 @@ open class IrPluginContextImpl constructor(
}
override fun referenceConstructors(classId: ClassId): Collection<IrConstructorSymbol> {
@Suppress("DEPRECATION")
return referenceConstructors(classId.asSingleFqName())
}
override fun referenceFunctions(callableId: CallableId): Collection<IrSimpleFunctionSymbol> {
@Suppress("DEPRECATION")
return referenceFunctions(callableId.asSingleFqName())
}
override fun referenceProperties(callableId: CallableId): Collection<IrPropertySymbol> {
@Suppress("DEPRECATION")
return referenceProperties(callableId.asSingleFqName())
}