Untie Symbols class from CommonBackendContext

`Symbols.context` property is actually unused. Let's drop
it as it makes harder to create an instance of this class.
This commit is contained in:
Sergey Bogolepov
2022-10-03 14:31:56 +03:00
committed by Space Team
parent de880ce9aa
commit e1f2b89875
9 changed files with 26 additions and 26 deletions
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.name.Name
// This is what Context collects about IR.
abstract class Ir<out T : CommonBackendContext>(val context: T, val irModule: IrModuleFragment) {
abstract val symbols: Symbols<T>
abstract val symbols: Symbols
val defaultParameterDeclarationsCache = mutableMapOf<IrFunction, IrFunction>()
@@ -200,8 +200,8 @@ open class BuiltinSymbolsBase(val irBuiltIns: IrBuiltIns, private val symbolTabl
// 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, irBuiltIns: IrBuiltIns, symbolTable: ReferenceSymbolTable
abstract class Symbols(
irBuiltIns: IrBuiltIns, symbolTable: ReferenceSymbolTable
) : BuiltinSymbolsBase(irBuiltIns, symbolTable) {
abstract val throwNullPointerException: IrSimpleFunctionSymbol
@@ -355,7 +355,7 @@ private class Transformer(
}
private fun computeComparisonClass(
symbols: Symbols<CommonBackendContext>,
symbols: Symbols,
lowerType: IrType,
upperType: IrType,
argumentType: IrType
@@ -364,7 +364,7 @@ private class Transformer(
return leastCommonPrimitiveNumericType(symbols, argumentType, commonBoundType)?.getClass()
}
private fun leastCommonPrimitiveNumericType(symbols: Symbols<CommonBackendContext>, t1: IrType, t2: IrType): IrType? {
private fun leastCommonPrimitiveNumericType(symbols: Symbols, t1: IrType, t2: IrType): IrType? {
val primitive1 = t1.getPrimitiveType()
val primitive2 = t2.getPrimitiveType()
val unsigned1 = t1.getUnsignedType()
@@ -189,7 +189,7 @@ class ProgressionHeaderInfo(
* The internal induction variable used is an Int.
*/
class IndexedGetHeaderInfo(
symbols: Symbols<CommonBackendContext>,
symbols: Symbols,
first: IrExpression,
last: IrExpression,
step: IrExpression,
@@ -7,16 +7,13 @@
package org.jetbrains.kotlin.backend.common.lower.loops
import org.jetbrains.kotlin.backend.common.CommonBackendContext
import org.jetbrains.kotlin.backend.common.ir.Symbols
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
import org.jetbrains.kotlin.ir.builders.irChar
import org.jetbrains.kotlin.ir.builders.irInt
import org.jetbrains.kotlin.ir.builders.irLong
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.defaultType
@@ -38,7 +35,7 @@ sealed class ProgressionType(
fun IrExpression.asStepType() = castIfNecessary(stepClass)
companion object {
fun fromIrType(irType: IrType, symbols: Symbols<CommonBackendContext>, allowUnsignedBounds: Boolean): ProgressionType? =
fun fromIrType(irType: IrType, symbols: Symbols, allowUnsignedBounds: Boolean): ProgressionType? =
when {
irType.isSubtypeOfClass(symbols.charProgression) -> CharProgressionType(symbols)
irType.isSubtypeOfClass(symbols.intProgression) -> IntProgressionType(symbols)
@@ -52,7 +49,7 @@ sealed class ProgressionType(
}
}
internal class IntProgressionType(symbols: Symbols<CommonBackendContext>) :
internal class IntProgressionType(symbols: Symbols) :
ProgressionType(
elementClass = symbols.int.owner,
stepClass = symbols.int.owner,
@@ -65,7 +62,7 @@ internal class IntProgressionType(symbols: Symbols<CommonBackendContext>) :
override fun DeclarationIrBuilder.zeroStepExpression() = irInt(0)
}
internal class LongProgressionType(symbols: Symbols<CommonBackendContext>) :
internal class LongProgressionType(symbols: Symbols) :
ProgressionType(
elementClass = symbols.long.owner,
stepClass = symbols.long.owner,
@@ -78,7 +75,7 @@ internal class LongProgressionType(symbols: Symbols<CommonBackendContext>) :
override fun DeclarationIrBuilder.zeroStepExpression() = irLong(0)
}
internal class CharProgressionType(symbols: Symbols<CommonBackendContext>) :
internal class CharProgressionType(symbols: Symbols) :
ProgressionType(
elementClass = symbols.char.owner,
stepClass = symbols.int.owner,
@@ -107,7 +104,7 @@ internal class CharProgressionType(symbols: Symbols<CommonBackendContext>) :
// `to(U)Int/(U)Long()` functions otherwise.
internal abstract class UnsignedProgressionType(
symbols: Symbols<CommonBackendContext>,
symbols: Symbols,
elementClass: IrClass,
stepClass: IrClass,
minValueAsLong: Long,
@@ -170,7 +167,7 @@ internal abstract class UnsignedProgressionType(
}
}
internal class UIntProgressionType(symbols: Symbols<CommonBackendContext>, allowUnsignedBounds: Boolean) :
internal class UIntProgressionType(symbols: Symbols, allowUnsignedBounds: Boolean) :
UnsignedProgressionType(
symbols,
elementClass = if (allowUnsignedBounds) symbols.uInt!!.owner else symbols.int.owner,
@@ -186,7 +183,7 @@ internal class UIntProgressionType(symbols: Symbols<CommonBackendContext>, allow
override fun DeclarationIrBuilder.zeroStepExpression() = irInt(0)
}
internal class ULongProgressionType(symbols: Symbols<CommonBackendContext>, allowUnsignedBounds: Boolean) :
internal class ULongProgressionType(symbols: Symbols, allowUnsignedBounds: Boolean) :
UnsignedProgressionType(
symbols,
elementClass = if (allowUnsignedBounds) symbols.uLong!!.owner else symbols.long.owner,
@@ -199,7 +199,9 @@ class JsIrBackendContext(
.let { symbolTable.referenceSimpleFunction(it!!) }
override val ir = object : Ir<JsIrBackendContext>(this, irModuleFragment) {
override val symbols = object : Symbols<JsIrBackendContext>(this@JsIrBackendContext, irBuiltIns, symbolTable) {
override val symbols = object : Symbols(irBuiltIns, symbolTable) {
private val context = this@JsIrBackendContext
override val throwNullPointerException =
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))).single())
@@ -42,9 +42,9 @@ import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.Variance
class JvmSymbols(
context: JvmBackendContext,
private val context: JvmBackendContext,
symbolTable: SymbolTable
) : Symbols<JvmBackendContext>(context, context.irBuiltIns, symbolTable) {
) : Symbols(context.irBuiltIns, symbolTable) {
private val storageManager = LockBasedStorageManager(this::class.java.simpleName)
private val irFactory = context.irFactory
@@ -112,7 +112,7 @@ class WasmBackendContext(
PropertyLazyInitialization(enabled = propertyLazyInitialization, eagerInitialization = wasmSymbols.eagerInitialization)
override val ir = object : Ir<WasmBackendContext>(this, irModuleFragment) {
override val symbols: Symbols<WasmBackendContext> = wasmSymbols
override val symbols: Symbols = wasmSymbols
override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true
}
@@ -32,9 +32,9 @@ import java.lang.IllegalArgumentException
@OptIn(ObsoleteDescriptorBasedAPI::class)
class WasmSymbols(
context: WasmBackendContext,
private val context: WasmBackendContext,
private val symbolTable: SymbolTable
) : Symbols<WasmBackendContext>(context, context.irBuiltIns, symbolTable) {
) : Symbols(context.irBuiltIns, symbolTable) {
private val kotlinTopLevelPackage: PackageViewDescriptor =
context.module.getPackage(FqName("kotlin"))
@@ -18,11 +18,12 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.defaultType
import org.jetbrains.kotlin.ir.types.typeWith
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.util.ReferenceSymbolTable
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.ir.util.constructors
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi2ir.descriptors.IrBuiltInsOverDescriptors
@@ -39,12 +40,12 @@ internal class KonanIr(context: Context, irModule: IrModuleFragment): Ir<Context
}
internal class KonanSymbols(
context: Context,
val context: Context,
private val descriptorsLookup: DescriptorsLookup,
irBuiltIns: IrBuiltIns,
private val symbolTable: SymbolTable,
lazySymbolTable: ReferenceSymbolTable
): Symbols<Context>(context, irBuiltIns, symbolTable) {
): Symbols(irBuiltIns, symbolTable) {
val entryPoint = findMainEntryPoint(context)?.let { symbolTable.referenceSimpleFunction(it) }