[IR] Update inheritors of SymbolTable which override some descriptor-related methods

This commit is contained in:
Dmitriy Novozhilov
2023-07-11 12:25:59 +03:00
committed by Space Team
parent 8ad202eb8b
commit 4ec65ace1c
5 changed files with 148 additions and 102 deletions
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.IrFactory
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.util.DescriptorSymbolTableExtension
import org.jetbrains.kotlin.ir.util.IdSignatureComposer
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.psi2ir.descriptors.IrBuiltInsOverDescriptors
@@ -44,28 +45,34 @@ class SymbolTableWithBuiltInsDeduplication(
}
}
/**
* Gets or creates the [IrClassSymbol] for [descriptor], or for the built-in descriptor with the same name if [descriptor] is a
* duplicate built-in.
*
* Note that not all built-in symbols may have been bound or created by the time [irBuiltIns] has been bound. However, [referenceClass]
* will create a symbol in such a case (via `super.referenceClass`) and [org.jetbrains.kotlin.ir.util.DeclarationStubGenerator] will
* create a stub for the symbol if [referenceClass] was invoked from the stub generator.
*/
@ObsoleteDescriptorBasedAPI
override fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol {
val irBuiltIns = this.irBuiltIns ?: return super.descriptorExtension.referenceClass(descriptor)
override fun createDescriptorExtension(): DescriptorSymbolTableExtension {
return Extension()
}
// We need to find out whether `descriptor` is possibly a built-in symbol before it's actually retrieved to break recursion as
// `irBuiltIns.findClass` uses `referenceClass` recursively.
val builtInDescriptor = irBuiltIns.findBuiltInClassDescriptor(descriptor)
if (builtInDescriptor != null) {
// We need to delegate to the supertype implementation here to break recursion. `findBuiltInClassDescriptor` will return
// `descriptor` even if `descriptor` was found via `findBuiltInClassDescriptor`.
return super.descriptorExtension.referenceClass(builtInDescriptor)
private inner class Extension : DescriptorSymbolTableExtension(this) {
/**
* Gets or creates the [IrClassSymbol] for [descriptor], or for the built-in descriptor with the same name if [descriptor] is a
* duplicate built-in.
*
* Note that not all built-in symbols may have been bound or created by the time [irBuiltIns] has been bound. However, [referenceClass]
* will create a symbol in such a case (via `super.referenceClass`) and [org.jetbrains.kotlin.ir.util.DeclarationStubGenerator] will
* create a stub for the symbol if [referenceClass] was invoked from the stub generator.
*/
@ObsoleteDescriptorBasedAPI
override fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol {
val irBuiltIns = this@SymbolTableWithBuiltInsDeduplication.irBuiltIns ?: return super.referenceClass(descriptor)
// We need to find out whether `descriptor` is possibly a built-in symbol before it's actually retrieved to break recursion as
// `irBuiltIns.findClass` uses `referenceClass` recursively.
val builtInDescriptor = irBuiltIns.findBuiltInClassDescriptor(descriptor)
if (builtInDescriptor != null) {
// We need to delegate to the supertype implementation here to break recursion. `findBuiltInClassDescriptor` will return
// `descriptor` even if `descriptor` was found via `findBuiltInClassDescriptor`.
return super.referenceClass(builtInDescriptor)
}
return super.referenceClass(descriptor)
}
return super.descriptorExtension.referenceClass(descriptor)
}
private fun IrBuiltInsOverDescriptors.findBuiltInClassDescriptor(descriptor: ClassDescriptor): ClassDescriptor? {