From 08aeed3b4627f150a353facd56a0403f3571ff64 Mon Sep 17 00:00:00 2001 From: Georgy Bronnikov Date: Mon, 2 Dec 2019 16:39:20 +0300 Subject: [PATCH] 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. --- .../org/jetbrains/kotlin/backend/common/ir/Ir.kt | 13 +++++-------- .../kotlin/ir/backend/js/JsIrBackendContext.kt | 2 +- .../kotlin/backend/jvm/JvmBackendContext.kt | 5 ++--- .../org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt | 2 +- .../jetbrains/kotlin/backend/wasm/WasmSymbols.kt | 4 ++-- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt index 73c6c297f0b..73d215a2359 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Ir.kt @@ -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(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(val context: T, symbolTable: ReferenceSymbolTable) : +abstract class Symbols(val context: T, symbolTable: SymbolTable) : BuiltinSymbolsBase(context.builtIns, symbolTable) { abstract val ThrowNullPointerException: IrFunctionSymbol abstract val ThrowNoWhenBranchMatchedException: IrFunctionSymbol diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt index 35362cefb89..ef67fb1ab69 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsIrBackendContext.kt @@ -161,7 +161,7 @@ class JsIrBackendContext( fun getOperatorByName(name: Name, type: IrSimpleType) = operatorMap[name]?.get(type.classifier) override val ir = object : Ir(this, irModuleFragment) { - override val symbols = object : Symbols(this@JsIrBackendContext, symbolTable.lazyWrapper) { + override val symbols = object : Symbols(this@JsIrBackendContext, symbolTable) { override val ThrowNullPointerException = symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))).single()) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt index f3781d6d096..e66e62a6232 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendContext.kt @@ -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(this, irModuleFragment) { override val symbols = JvmSymbols(this@JvmBackendContext, symbolTable) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt index 1d3be9fe7ff..a7c66c3c235 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSymbols.kt @@ -31,7 +31,7 @@ import org.jetbrains.kotlin.types.Variance class JvmSymbols( context: JvmBackendContext, - private val symbolTable: ReferenceSymbolTable + private val symbolTable: SymbolTable ) : Symbols(context, symbolTable) { private val storageManager = LockBasedStorageManager(this::class.java.simpleName) private val kotlinPackage: IrPackageFragment = createPackage(FqName("kotlin")) diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt index f864aac6bad..244ddfe9978 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt @@ -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(context, symbolTable) { override val ThrowNullPointerException