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:
Georgy Bronnikov
2019-12-02 16:39:20 +03:00
parent b0b04eb4cd
commit 08aeed3b46
5 changed files with 11 additions and 15 deletions
@@ -19,10 +19,7 @@ import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.classOrNull
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
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.ir.util.*
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
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
*/
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) =
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 intPlusInt = getBinaryOperator(OperatorNameConventions.PLUS, builtIns.intType, builtIns.intType)
open fun functionN(n: Int): IrClassSymbol = symbolTable.referenceClass(builtIns.getFunction(n))
open fun suspendFunctionN(n: Int): IrClassSymbol = symbolTable.referenceClass(builtIns.getSuspendFunction(n))
open fun functionN(n: Int): IrClassSymbol = symbolTable.lazyWrapper.referenceClass(builtIns.getFunction(n))
open fun suspendFunctionN(n: Int): IrClassSymbol = symbolTable.lazyWrapper.referenceClass(builtIns.getSuspendFunction(n))
fun kproperty0(): IrClassSymbol = symbolTable.referenceClass(builtIns.kProperty0)
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
@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) {
abstract val ThrowNullPointerException: IrFunctionSymbol
abstract val ThrowNoWhenBranchMatchedException: IrFunctionSymbol
@@ -161,7 +161,7 @@ class JsIrBackendContext(
fun getOperatorByName(name: Name, type: IrSimpleType) = operatorMap[name]?.get(type.classifier)
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 =
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))).single())
@@ -46,7 +46,7 @@ class JvmBackendContext(
val psiSourceManager: PsiSourceManager,
override val irBuiltIns: IrBuiltIns,
irModuleFragment: IrModuleFragment,
symbolTable: SymbolTable,
private val symbolTable: SymbolTable,
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
// annotated with @JvmPackageName, the correct name is recorded here.
@@ -64,7 +64,6 @@ class JvmBackendContext(
override val declarationFactory: JvmDeclarationFactory = JvmDeclarationFactory(methodSignatureMapper)
override val sharedVariablesManager = JvmSharedVariablesManager(state.module, builtIns, irBuiltIns)
private val symbolTable = symbolTable.lazyWrapper
override val ir = JvmIr(irModuleFragment, this.symbolTable)
val irIntrinsics = IrIntrinsicMethods(irBuiltIns, ir.symbols)
@@ -147,7 +146,7 @@ class JvmBackendContext(
inner class JvmIr(
irModuleFragment: IrModuleFragment,
symbolTable: ReferenceSymbolTable
symbolTable: SymbolTable
) : Ir<JvmBackendContext>(this, irModuleFragment) {
override val symbols = JvmSymbols(this@JvmBackendContext, symbolTable)
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.types.Variance
class JvmSymbols(
context: JvmBackendContext,
private val symbolTable: ReferenceSymbolTable
private val symbolTable: SymbolTable
) : Symbols<JvmBackendContext>(context, symbolTable) {
private val storageManager = LockBasedStorageManager(this::class.java.simpleName)
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.IrSimpleFunctionSymbol
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.Name
import org.jetbrains.kotlin.resolve.scopes.MemberScope
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.types.SimpleType
class WasmSymbols(
context: WasmBackendContext,
private val symbolTable: ReferenceSymbolTable
private val symbolTable: SymbolTable
) : Symbols<WasmBackendContext>(context, symbolTable) {
override val ThrowNullPointerException