Skip to content

Commit

Permalink
IR: remove IrDeserializer.IrLinkerExtension
Browse files Browse the repository at this point in the history
There are no implementations of this extension in known plugins, and the
commits which introduced it (5eae262, a095909) do not have any
links to issues.

It looks like it was only used from the removed android-extensions
plugin:

2fdb194#diff-1da466955b70d7f36f0e94aec4d8b8226b63de6dbb41fcf222c9e5d08fbc8006L54
  • Loading branch information
udalov authored and Space Team committed Dec 6, 2024
1 parent bc69bf8 commit c2122db
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,11 @@ fun generateIrForKlibSerialization(
messageCollector::checkNoUnboundSymbols
)
val psi2IrContext = psi2Ir.createGeneratorContext(analysisResult.moduleDescriptor, analysisResult.bindingContext, symbolTable)
val irBuiltIns = psi2IrContext.irBuiltIns

val feContext = psi2IrContext.run {
JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns)
}
val stubGenerator = DeclarationStubGeneratorImpl(
psi2IrContext.moduleDescriptor,
symbolTable,
irBuiltIns,
psi2IrContext.irBuiltIns,
DescriptorByIdSignatureFinderImpl(psi2IrContext.moduleDescriptor, JsManglerDesc),
)
val irLinker = JsIrLinker(
Expand All @@ -87,7 +83,6 @@ fun generateIrForKlibSerialization(
builtIns = psi2IrContext.irBuiltIns,
messageCollector = messageCollector
),
feContext,
ICData(icData.map { it.irData!! }, containsErrorCode = false),
stubGenerator = stubGenerator
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ package org.jetbrains.kotlin.backend.common.extensions
import org.jetbrains.kotlin.backend.common.LoweringContext
import org.jetbrains.kotlin.extensions.ProjectExtensionDescriptor
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.linkage.IrDeserializer

interface IrGenerationExtension : IrDeserializer.IrLinkerExtension {
interface IrGenerationExtension {
companion object :
ProjectExtensionDescriptor<IrGenerationExtension>(
"org.jetbrains.kotlin.irGenerationExtension", IrGenerationExtension::class.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ internal class JsIrLinkerLoader(
builtIns = irBuiltIns,
messageCollector = messageCollector
),
translationPluginContext = null,
friendModules = mapOf(mainLibrary.uniqueName to mainModuleFriends.map { it.uniqueName })
)
return LinkerContext(symbolTable, typeTranslator, irBuiltIns, linker)
Expand Down Expand Up @@ -213,7 +212,7 @@ internal class JsIrLinkerLoader(
val (_, stdlibFragment) = findStdlib(mainFragment, irModules)
linkerContext.loadFunctionInterfacesIntoStdlib(stdlibFragment)

linkerContext.linker.init(null, emptyList())
linkerContext.linker.init(null)

if (!loadAllIr) {
for ((loadingLibFile, loadingSrcFiles) in modifiedFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContextImpl
import org.jetbrains.kotlin.backend.common.ir.isJvmBuiltin
import org.jetbrains.kotlin.backend.common.ir.isBytecodeGenerationSuppressed
import org.jetbrains.kotlin.backend.common.ir.isJvmBuiltin
import org.jetbrains.kotlin.backend.common.linkage.issues.checkNoUnboundSymbols
import org.jetbrains.kotlin.backend.common.serialization.DescriptorByIdSignatureFinderImpl
import org.jetbrains.kotlin.backend.jvm.codegen.EnumEntriesIntrinsicMappingsCacheImpl
Expand All @@ -36,7 +36,6 @@ import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmDescriptorMangler
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrLinker
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.MetadataSource
Expand All @@ -45,9 +44,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
import org.jetbrains.kotlin.ir.linkage.IrProvider
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.ir.util.TypeTranslator
import org.jetbrains.kotlin.library.metadata.DeserializedKlibModuleOrigin
import org.jetbrains.kotlin.library.metadata.KlibModuleOrigin
import org.jetbrains.kotlin.metadata.jvm.JvmModuleProtoBuf
Expand Down Expand Up @@ -174,22 +171,11 @@ open class JvmIrCodegenFactory(
DescriptorByIdSignatureFinderImpl(psi2irContext.moduleDescriptor, mangler),
jvmGeneratorExtensions
)
val frontEndContext = object : TranslationPluginContext {
override val moduleDescriptor: ModuleDescriptor
get() = psi2irContext.moduleDescriptor
override val symbolTable: ReferenceSymbolTable
get() = symbolTable
override val typeTranslator: TypeTranslator
get() = psi2irContext.typeTranslator
override val irBuiltIns: IrBuiltIns
get() = psi2irContext.irBuiltIns
}
val irLinker = JvmIrLinker(
psi2irContext.moduleDescriptor,
messageCollector,
JvmIrTypeSystemContext(psi2irContext.irBuiltIns),
symbolTable,
frontEndContext,
stubGenerator,
mangler,
enableIdSignatures,
Expand Down Expand Up @@ -247,14 +233,7 @@ open class JvmIrCodegenFactory(
symbolTable.referenceUndiscoveredExpectSymbols(input.files, input.bindingContext)
}

val irModuleFragment =
psi2ir.generateModuleFragment(
psi2irContext,
input.files,
irProviders,
pluginExtensions,
fragmentInfo = evaluatorFragmentInfoForPsi2Ir
)
val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, input.files, irProviders, evaluatorFragmentInfoForPsi2Ir)

irLinker.postProcess(inOrAfterLinkageStep = true)
irLinker.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class Psi2IrTranslator(
context: GeneratorContext,
ktFiles: Collection<KtFile>,
irProviders: List<IrProvider>,
linkerExtensions: Collection<IrDeserializer.IrLinkerExtension>,
fragmentInfo: EvaluatorFragmentInfo? = null
): IrModuleFragment {

Expand All @@ -94,7 +93,7 @@ class Psi2IrTranslator(
val irModule = moduleGenerator.generateModuleFragment(ktFiles)

val deserializers = irProviders.filterIsInstance<IrDeserializer>()
deserializers.forEach { it.init(irModule, linkerExtensions) }
deserializers.forEach { it.init(irModule) }

moduleGenerator.generateUnboundSymbolsAsDependencies(irProviders)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,20 @@

package org.jetbrains.kotlin.ir.linkage

import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.name.Name

interface IrDeserializer : IrProvider {

interface IrLinkerExtension {
fun resolveSymbol(symbol: IrSymbol, context: TranslationPluginContext): IrDeclaration? = null
}

enum class TopLevelSymbolKind {
FUNCTION_SYMBOL,
CLASS_SYMBOL,
PROPERTY_SYMBOL,
TYPEALIAS_SYMBOL;
}

fun init(moduleFragment: IrModuleFragment?, extensions: Collection<IrLinkerExtension>) {}
fun init(moduleFragment: IrModuleFragment?) {}
fun resolveBySignatureInModule(signature: IdSignature, kind: TopLevelSymbolKind, moduleName: Name): IrSymbol

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ import org.jetbrains.kotlin.backend.common.overrides.FileLocalAwareLinker
import org.jetbrains.kotlin.backend.common.overrides.IrLinkerFakeOverrideProvider
import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrFunctionReference
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
import org.jetbrains.kotlin.ir.linkage.IrDeserializer
import org.jetbrains.kotlin.ir.symbols.*
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.symbols.isPublicApi
import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.ir.util.file
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.library.KotlinLibrary
Expand All @@ -46,12 +49,8 @@ abstract class KotlinIrLinker(

abstract val fakeOverrideBuilder: IrLinkerFakeOverrideProvider

abstract val translationPluginContext: TranslationPluginContext?

private val triedToDeserializeDeclarationForSymbol = hashSetOf<IrSymbol>()

private lateinit var linkerExtensions: Collection<IrDeserializer.IrLinkerExtension>

open val partialLinkageSupport: PartialLinkageSupportForLinker get() = PartialLinkageSupportForLinker.DISABLED

open val returnUnboundSymbolsIfSignatureNotFound: Boolean
Expand Down Expand Up @@ -125,24 +124,6 @@ abstract class KotlinIrLinker(

protected open fun platformSpecificSymbol(symbol: IrSymbol): Boolean = false

private fun tryResolveCustomDeclaration(symbol: IrSymbol): IrDeclaration? {
val descriptor = if (symbol.hasDescriptor) symbol.descriptor else return null
if (descriptor is CallableMemberDescriptor) {
if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
// skip fake overrides
return null
}
}

return translationPluginContext?.let { ctx ->
linkerExtensions.firstNotNullOfOrNull {
it.resolveSymbol(symbol, ctx)
}?.also {
require(symbol.owner == it)
}
}
}

override fun getDeclaration(symbol: IrSymbol): IrDeclaration? =
deserializeOrResolveDeclaration(symbol, false)

Expand All @@ -155,9 +136,7 @@ abstract class KotlinIrLinker(

if (!symbol.isBound) {
try {
findDeserializedDeclarationForSymbol(symbol)
?: tryResolveCustomDeclaration(symbol)
?: return null
findDeserializedDeclarationForSymbol(symbol) ?: return null
} catch (e: IrSymbolTypeMismatchException) {
SymbolTypeMismatch(e, deserializersForModules.values, userVisibleIrModulesSupport).raiseIssue(messageCollector)
}
Expand Down Expand Up @@ -195,8 +174,7 @@ abstract class KotlinIrLinker(
protected open fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
CurrentModuleDeserializer(moduleFragment, dependencies)

override fun init(moduleFragment: IrModuleFragment?, extensions: Collection<IrDeserializer.IrLinkerExtension>) {
linkerExtensions = extensions
override fun init(moduleFragment: IrModuleFragment?) {
if (moduleFragment != null) {
val currentModuleDependencies = moduleFragment.descriptor.allDependencyModules.map {
resolveModuleDeserializer(it, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ fun getIrModuleInfoForKlib(
builtIns = irBuiltIns,
messageCollector = messageCollector
),
translationPluginContext = null,
icData = null,
friendModules = friendModules
)
Expand All @@ -271,7 +270,7 @@ fun getIrModuleInfoForKlib(

val moduleFragment = deserializedModuleFragments.last()

irLinker.init(null, emptyList())
irLinker.init(null)
ExternalDependenciesGenerator(symbolTable, listOf(irLinker)).generateUnboundSymbolsAsDependencies()
irLinker.postProcess(inOrAfterLinkageStep = true)

Expand Down Expand Up @@ -300,10 +299,6 @@ fun getIrModuleInfoForSourceFiles(
mapping: (KotlinLibrary) -> ModuleDescriptor
): IrModuleInfo {
val irBuiltIns = psi2IrContext.irBuiltIns
val feContext = psi2IrContext.run {
JsIrLinker.JsFePluginContext(moduleDescriptor, symbolTable, typeTranslator, irBuiltIns)
}

val irLinker = JsIrLinker(
currentModule = psi2IrContext.moduleDescriptor,
messageCollector = messageCollector,
Expand All @@ -314,7 +309,6 @@ fun getIrModuleInfoForSourceFiles(
builtIns = irBuiltIns,
messageCollector = messageCollector
),
translationPluginContext = feContext,
icData = null,
friendModules = friendModules,
)
Expand Down Expand Up @@ -384,7 +378,6 @@ fun GeneratorContext.generateModuleFragmentWithPlugins(
stubGenerator: DeclarationStubGenerator? = null
): Pair<IrModuleFragment, IrPluginContext> {
val psi2Ir = Psi2IrTranslator(languageVersionSettings, configuration, messageCollector::checkNoUnboundSymbols)
val extensions = IrGenerationExtension.getInstances(project)

// plugin context should be instantiated before postprocessing steps
val pluginContext = IrPluginContextImpl(
Expand All @@ -397,27 +390,19 @@ fun GeneratorContext.generateModuleFragmentWithPlugins(
linker = irLinker,
messageCollector
)
if (extensions.isNotEmpty()) {
for (extension in extensions) {
psi2Ir.addPostprocessingStep { module ->
val old = stubGenerator?.unboundSymbolGeneration
try {
stubGenerator?.unboundSymbolGeneration = true
extension.generate(module, pluginContext)
} finally {
stubGenerator?.unboundSymbolGeneration = old!!
}
for (extension in IrGenerationExtension.getInstances(project)) {
psi2Ir.addPostprocessingStep { module ->
val old = stubGenerator?.unboundSymbolGeneration
try {
stubGenerator?.unboundSymbolGeneration = true
extension.generate(module, pluginContext)
} finally {
stubGenerator?.unboundSymbolGeneration = old!!
}
}

}

return psi2Ir.generateModuleFragment(
this,
files,
listOf(stubGenerator ?: irLinker),
extensions
) to pluginContext
return psi2Ir.generateModuleFragment(this, files, listOf(stubGenerator ?: irLinker)) to pluginContext
}

private fun createBuiltIns(storageManager: StorageManager) = object : KotlinBuiltIns(storageManager) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import org.jetbrains.kotlin.backend.common.serialization.*
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.library.IrLibrary
import org.jetbrains.kotlin.library.KotlinAbiVersion
import org.jetbrains.kotlin.library.KotlinLibrary
Expand All @@ -25,7 +26,6 @@ import org.jetbrains.kotlin.utils.memoryOptimizedMap
class JsIrLinker(
private val currentModule: ModuleDescriptor?, messageCollector: MessageCollector, builtIns: IrBuiltIns, symbolTable: SymbolTable,
override val partialLinkageSupport: PartialLinkageSupportForLinker,
override val translationPluginContext: TranslationPluginContext?,
private val icData: ICData? = null,
friendModules: Map<String, Collection<String>> = emptyMap(),
private val stubGenerator: DeclarationStubGenerator? = null
Expand Down Expand Up @@ -105,11 +105,4 @@ class JsIrLinker(
fun getDeserializedFilesInKlibOrder(fragment: IrModuleFragment): List<IrFile> {
return deserializedFilesInKlibOrder[fragment] ?: emptyList()
}

class JsFePluginContext(
override val moduleDescriptor: ModuleDescriptor,
override val symbolTable: ReferenceSymbolTable,
override val typeTranslator: TypeTranslator,
override val irBuiltIns: IrBuiltIns,
) : TranslationPluginContext
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolD
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrField
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
Expand All @@ -38,7 +37,6 @@ class JvmIrLinker(
messageCollector: MessageCollector,
typeSystem: IrTypeSystemContext,
symbolTable: SymbolTable,
override val translationPluginContext: TranslationPluginContext?,
private val stubGenerator: DeclarationStubGenerator,
private val manglerDesc: JvmDescriptorMangler,
private val enableIdSignatures: Boolean,
Expand Down
Loading

0 comments on commit c2122db

Please sign in to comment.