IR: do not use lazyWrapper for Ir.Symbols
The reason for switching from lazyWrapper to SymbolTable itself is that (at least in JS_IR) some of those lazily created structures could later be deserialized, which created conflicts.
This commit is contained in:
@@ -19,10 +19,7 @@ import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
|||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||||
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
|
||||||
import org.jetbrains.kotlin.ir.util.getPackageFragment
|
|
||||||
import org.jetbrains.kotlin.ir.util.referenceFunction
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||||
@@ -47,7 +44,7 @@ abstract class Ir<out T : CommonBackendContext>(val context: T, val irModule: Ir
|
|||||||
/**
|
/**
|
||||||
* Symbols for builtins that are available without any context and are not specific to any backend
|
* Symbols for builtins that are available without any context and are not specific to any backend
|
||||||
*/
|
*/
|
||||||
open class BuiltinSymbolsBase(protected val builtIns: KotlinBuiltIns, private val symbolTable: ReferenceSymbolTable) {
|
open class BuiltinSymbolsBase(protected val builtIns: KotlinBuiltIns, private val symbolTable: SymbolTable) {
|
||||||
protected fun builtInsPackage(vararg packageNameSegments: String) =
|
protected fun builtInsPackage(vararg packageNameSegments: String) =
|
||||||
builtIns.builtInsModule.getPackage(FqName.fromSegments(listOf(*packageNameSegments))).memberScope
|
builtIns.builtInsModule.getPackage(FqName.fromSegments(listOf(*packageNameSegments))).memberScope
|
||||||
|
|
||||||
@@ -201,8 +198,8 @@ open class BuiltinSymbolsBase(protected val builtIns: KotlinBuiltIns, private va
|
|||||||
val intAnd = getBinaryOperator(OperatorNameConventions.AND, builtIns.intType, builtIns.intType)
|
val intAnd = getBinaryOperator(OperatorNameConventions.AND, builtIns.intType, builtIns.intType)
|
||||||
val intPlusInt = getBinaryOperator(OperatorNameConventions.PLUS, builtIns.intType, builtIns.intType)
|
val intPlusInt = getBinaryOperator(OperatorNameConventions.PLUS, builtIns.intType, builtIns.intType)
|
||||||
|
|
||||||
open fun functionN(n: Int): IrClassSymbol = symbolTable.referenceClass(builtIns.getFunction(n))
|
open fun functionN(n: Int): IrClassSymbol = symbolTable.lazyWrapper.referenceClass(builtIns.getFunction(n))
|
||||||
open fun suspendFunctionN(n: Int): IrClassSymbol = symbolTable.referenceClass(builtIns.getSuspendFunction(n))
|
open fun suspendFunctionN(n: Int): IrClassSymbol = symbolTable.lazyWrapper.referenceClass(builtIns.getSuspendFunction(n))
|
||||||
|
|
||||||
fun kproperty0(): IrClassSymbol = symbolTable.referenceClass(builtIns.kProperty0)
|
fun kproperty0(): IrClassSymbol = symbolTable.referenceClass(builtIns.kProperty0)
|
||||||
fun kproperty1(): IrClassSymbol = symbolTable.referenceClass(builtIns.kProperty1)
|
fun kproperty1(): IrClassSymbol = symbolTable.referenceClass(builtIns.kProperty1)
|
||||||
@@ -226,7 +223,7 @@ open class BuiltinSymbolsBase(protected val builtIns: KotlinBuiltIns, private va
|
|||||||
|
|
||||||
// Some symbols below are used in kotlin-native, so they can't be private
|
// Some symbols below are used in kotlin-native, so they can't be private
|
||||||
@Suppress("MemberVisibilityCanBePrivate", "PropertyName")
|
@Suppress("MemberVisibilityCanBePrivate", "PropertyName")
|
||||||
abstract class Symbols<out T : CommonBackendContext>(val context: T, symbolTable: ReferenceSymbolTable) :
|
abstract class Symbols<out T : CommonBackendContext>(val context: T, symbolTable: SymbolTable) :
|
||||||
BuiltinSymbolsBase(context.builtIns, symbolTable) {
|
BuiltinSymbolsBase(context.builtIns, symbolTable) {
|
||||||
abstract val ThrowNullPointerException: IrFunctionSymbol
|
abstract val ThrowNullPointerException: IrFunctionSymbol
|
||||||
abstract val ThrowNoWhenBranchMatchedException: IrFunctionSymbol
|
abstract val ThrowNoWhenBranchMatchedException: IrFunctionSymbol
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ class JsIrBackendContext(
|
|||||||
fun getOperatorByName(name: Name, type: IrSimpleType) = operatorMap[name]?.get(type.classifier)
|
fun getOperatorByName(name: Name, type: IrSimpleType) = operatorMap[name]?.get(type.classifier)
|
||||||
|
|
||||||
override val ir = object : Ir<JsIrBackendContext>(this, irModuleFragment) {
|
override val ir = object : Ir<JsIrBackendContext>(this, irModuleFragment) {
|
||||||
override val symbols = object : Symbols<JsIrBackendContext>(this@JsIrBackendContext, symbolTable.lazyWrapper) {
|
override val symbols = object : Symbols<JsIrBackendContext>(this@JsIrBackendContext, symbolTable) {
|
||||||
override val ThrowNullPointerException =
|
override val ThrowNullPointerException =
|
||||||
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))).single())
|
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))).single())
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class JvmBackendContext(
|
|||||||
val psiSourceManager: PsiSourceManager,
|
val psiSourceManager: PsiSourceManager,
|
||||||
override val irBuiltIns: IrBuiltIns,
|
override val irBuiltIns: IrBuiltIns,
|
||||||
irModuleFragment: IrModuleFragment,
|
irModuleFragment: IrModuleFragment,
|
||||||
symbolTable: SymbolTable,
|
private val symbolTable: SymbolTable,
|
||||||
val phaseConfig: PhaseConfig,
|
val phaseConfig: PhaseConfig,
|
||||||
// If the JVM fqname of a class differs from what is implied by its parent, e.g. if it's a file class
|
// If the JVM fqname of a class differs from what is implied by its parent, e.g. if it's a file class
|
||||||
// annotated with @JvmPackageName, the correct name is recorded here.
|
// annotated with @JvmPackageName, the correct name is recorded here.
|
||||||
@@ -64,7 +64,6 @@ class JvmBackendContext(
|
|||||||
override val declarationFactory: JvmDeclarationFactory = JvmDeclarationFactory(methodSignatureMapper)
|
override val declarationFactory: JvmDeclarationFactory = JvmDeclarationFactory(methodSignatureMapper)
|
||||||
override val sharedVariablesManager = JvmSharedVariablesManager(state.module, builtIns, irBuiltIns)
|
override val sharedVariablesManager = JvmSharedVariablesManager(state.module, builtIns, irBuiltIns)
|
||||||
|
|
||||||
private val symbolTable = symbolTable.lazyWrapper
|
|
||||||
override val ir = JvmIr(irModuleFragment, this.symbolTable)
|
override val ir = JvmIr(irModuleFragment, this.symbolTable)
|
||||||
|
|
||||||
val irIntrinsics = IrIntrinsicMethods(irBuiltIns, ir.symbols)
|
val irIntrinsics = IrIntrinsicMethods(irBuiltIns, ir.symbols)
|
||||||
@@ -147,7 +146,7 @@ class JvmBackendContext(
|
|||||||
|
|
||||||
inner class JvmIr(
|
inner class JvmIr(
|
||||||
irModuleFragment: IrModuleFragment,
|
irModuleFragment: IrModuleFragment,
|
||||||
symbolTable: ReferenceSymbolTable
|
symbolTable: SymbolTable
|
||||||
) : Ir<JvmBackendContext>(this, irModuleFragment) {
|
) : Ir<JvmBackendContext>(this, irModuleFragment) {
|
||||||
override val symbols = JvmSymbols(this@JvmBackendContext, symbolTable)
|
override val symbols = JvmSymbols(this@JvmBackendContext, symbolTable)
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.types.Variance
|
|||||||
|
|
||||||
class JvmSymbols(
|
class JvmSymbols(
|
||||||
context: JvmBackendContext,
|
context: JvmBackendContext,
|
||||||
private val symbolTable: ReferenceSymbolTable
|
private val symbolTable: SymbolTable
|
||||||
) : Symbols<JvmBackendContext>(context, symbolTable) {
|
) : Symbols<JvmBackendContext>(context, symbolTable) {
|
||||||
private val storageManager = LockBasedStorageManager(this::class.java.simpleName)
|
private val storageManager = LockBasedStorageManager(this::class.java.simpleName)
|
||||||
private val kotlinPackage: IrPackageFragment = createPackage(FqName("kotlin"))
|
private val kotlinPackage: IrPackageFragment = createPackage(FqName("kotlin"))
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
|||||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
|
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.types.SimpleType
|
|||||||
|
|
||||||
class WasmSymbols(
|
class WasmSymbols(
|
||||||
context: WasmBackendContext,
|
context: WasmBackendContext,
|
||||||
private val symbolTable: ReferenceSymbolTable
|
private val symbolTable: SymbolTable
|
||||||
) : Symbols<WasmBackendContext>(context, symbolTable) {
|
) : Symbols<WasmBackendContext>(context, symbolTable) {
|
||||||
|
|
||||||
override val ThrowNullPointerException
|
override val ThrowNullPointerException
|
||||||
|
|||||||
Reference in New Issue
Block a user