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:
committed by
Space Team
parent
de880ce9aa
commit
e1f2b89875
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
// This is what Context collects about IR.
|
// This is what Context collects about IR.
|
||||||
abstract class Ir<out T : CommonBackendContext>(val context: T, val irModule: IrModuleFragment) {
|
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>()
|
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
|
// 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>(
|
abstract class Symbols(
|
||||||
val context: T, irBuiltIns: IrBuiltIns, symbolTable: ReferenceSymbolTable
|
irBuiltIns: IrBuiltIns, symbolTable: ReferenceSymbolTable
|
||||||
) : BuiltinSymbolsBase(irBuiltIns, symbolTable) {
|
) : BuiltinSymbolsBase(irBuiltIns, symbolTable) {
|
||||||
|
|
||||||
abstract val throwNullPointerException: IrSimpleFunctionSymbol
|
abstract val throwNullPointerException: IrSimpleFunctionSymbol
|
||||||
|
|||||||
+2
-2
@@ -355,7 +355,7 @@ private class Transformer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun computeComparisonClass(
|
private fun computeComparisonClass(
|
||||||
symbols: Symbols<CommonBackendContext>,
|
symbols: Symbols,
|
||||||
lowerType: IrType,
|
lowerType: IrType,
|
||||||
upperType: IrType,
|
upperType: IrType,
|
||||||
argumentType: IrType
|
argumentType: IrType
|
||||||
@@ -364,7 +364,7 @@ private class Transformer(
|
|||||||
return leastCommonPrimitiveNumericType(symbols, argumentType, commonBoundType)?.getClass()
|
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 primitive1 = t1.getPrimitiveType()
|
||||||
val primitive2 = t2.getPrimitiveType()
|
val primitive2 = t2.getPrimitiveType()
|
||||||
val unsigned1 = t1.getUnsignedType()
|
val unsigned1 = t1.getUnsignedType()
|
||||||
|
|||||||
+1
-1
@@ -189,7 +189,7 @@ class ProgressionHeaderInfo(
|
|||||||
* The internal induction variable used is an Int.
|
* The internal induction variable used is an Int.
|
||||||
*/
|
*/
|
||||||
class IndexedGetHeaderInfo(
|
class IndexedGetHeaderInfo(
|
||||||
symbols: Symbols<CommonBackendContext>,
|
symbols: Symbols,
|
||||||
first: IrExpression,
|
first: IrExpression,
|
||||||
last: IrExpression,
|
last: IrExpression,
|
||||||
step: IrExpression,
|
step: IrExpression,
|
||||||
|
|||||||
+7
-10
@@ -7,16 +7,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.common.lower.loops
|
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.ir.Symbols
|
||||||
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
|
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.irInt
|
||||||
import org.jetbrains.kotlin.ir.builders.irLong
|
import org.jetbrains.kotlin.ir.builders.irLong
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
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.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.defaultType
|
import org.jetbrains.kotlin.ir.types.defaultType
|
||||||
@@ -38,7 +35,7 @@ sealed class ProgressionType(
|
|||||||
fun IrExpression.asStepType() = castIfNecessary(stepClass)
|
fun IrExpression.asStepType() = castIfNecessary(stepClass)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun fromIrType(irType: IrType, symbols: Symbols<CommonBackendContext>, allowUnsignedBounds: Boolean): ProgressionType? =
|
fun fromIrType(irType: IrType, symbols: Symbols, allowUnsignedBounds: Boolean): ProgressionType? =
|
||||||
when {
|
when {
|
||||||
irType.isSubtypeOfClass(symbols.charProgression) -> CharProgressionType(symbols)
|
irType.isSubtypeOfClass(symbols.charProgression) -> CharProgressionType(symbols)
|
||||||
irType.isSubtypeOfClass(symbols.intProgression) -> IntProgressionType(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(
|
ProgressionType(
|
||||||
elementClass = symbols.int.owner,
|
elementClass = symbols.int.owner,
|
||||||
stepClass = symbols.int.owner,
|
stepClass = symbols.int.owner,
|
||||||
@@ -65,7 +62,7 @@ internal class IntProgressionType(symbols: Symbols<CommonBackendContext>) :
|
|||||||
override fun DeclarationIrBuilder.zeroStepExpression() = irInt(0)
|
override fun DeclarationIrBuilder.zeroStepExpression() = irInt(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class LongProgressionType(symbols: Symbols<CommonBackendContext>) :
|
internal class LongProgressionType(symbols: Symbols) :
|
||||||
ProgressionType(
|
ProgressionType(
|
||||||
elementClass = symbols.long.owner,
|
elementClass = symbols.long.owner,
|
||||||
stepClass = symbols.long.owner,
|
stepClass = symbols.long.owner,
|
||||||
@@ -78,7 +75,7 @@ internal class LongProgressionType(symbols: Symbols<CommonBackendContext>) :
|
|||||||
override fun DeclarationIrBuilder.zeroStepExpression() = irLong(0)
|
override fun DeclarationIrBuilder.zeroStepExpression() = irLong(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CharProgressionType(symbols: Symbols<CommonBackendContext>) :
|
internal class CharProgressionType(symbols: Symbols) :
|
||||||
ProgressionType(
|
ProgressionType(
|
||||||
elementClass = symbols.char.owner,
|
elementClass = symbols.char.owner,
|
||||||
stepClass = symbols.int.owner,
|
stepClass = symbols.int.owner,
|
||||||
@@ -107,7 +104,7 @@ internal class CharProgressionType(symbols: Symbols<CommonBackendContext>) :
|
|||||||
// `to(U)Int/(U)Long()` functions otherwise.
|
// `to(U)Int/(U)Long()` functions otherwise.
|
||||||
|
|
||||||
internal abstract class UnsignedProgressionType(
|
internal abstract class UnsignedProgressionType(
|
||||||
symbols: Symbols<CommonBackendContext>,
|
symbols: Symbols,
|
||||||
elementClass: IrClass,
|
elementClass: IrClass,
|
||||||
stepClass: IrClass,
|
stepClass: IrClass,
|
||||||
minValueAsLong: Long,
|
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(
|
UnsignedProgressionType(
|
||||||
symbols,
|
symbols,
|
||||||
elementClass = if (allowUnsignedBounds) symbols.uInt!!.owner else symbols.int.owner,
|
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)
|
override fun DeclarationIrBuilder.zeroStepExpression() = irInt(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class ULongProgressionType(symbols: Symbols<CommonBackendContext>, allowUnsignedBounds: Boolean) :
|
internal class ULongProgressionType(symbols: Symbols, allowUnsignedBounds: Boolean) :
|
||||||
UnsignedProgressionType(
|
UnsignedProgressionType(
|
||||||
symbols,
|
symbols,
|
||||||
elementClass = if (allowUnsignedBounds) symbols.uLong!!.owner else symbols.long.owner,
|
elementClass = if (allowUnsignedBounds) symbols.uLong!!.owner else symbols.long.owner,
|
||||||
|
|||||||
@@ -199,7 +199,9 @@ class JsIrBackendContext(
|
|||||||
.let { symbolTable.referenceSimpleFunction(it!!) }
|
.let { symbolTable.referenceSimpleFunction(it!!) }
|
||||||
|
|
||||||
override val ir = object : Ir<JsIrBackendContext>(this, irModuleFragment) {
|
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 =
|
override val throwNullPointerException =
|
||||||
symbolTable.referenceSimpleFunction(getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_NPE"))).single())
|
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
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
class JvmSymbols(
|
class JvmSymbols(
|
||||||
context: JvmBackendContext,
|
private val context: JvmBackendContext,
|
||||||
symbolTable: SymbolTable
|
symbolTable: SymbolTable
|
||||||
) : Symbols<JvmBackendContext>(context, context.irBuiltIns, symbolTable) {
|
) : Symbols(context.irBuiltIns, symbolTable) {
|
||||||
private val storageManager = LockBasedStorageManager(this::class.java.simpleName)
|
private val storageManager = LockBasedStorageManager(this::class.java.simpleName)
|
||||||
private val irFactory = context.irFactory
|
private val irFactory = context.irFactory
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -112,7 +112,7 @@ class WasmBackendContext(
|
|||||||
PropertyLazyInitialization(enabled = propertyLazyInitialization, eagerInitialization = wasmSymbols.eagerInitialization)
|
PropertyLazyInitialization(enabled = propertyLazyInitialization, eagerInitialization = wasmSymbols.eagerInitialization)
|
||||||
|
|
||||||
override val ir = object : Ir<WasmBackendContext>(this, irModuleFragment) {
|
override val ir = object : Ir<WasmBackendContext>(this, irModuleFragment) {
|
||||||
override val symbols: Symbols<WasmBackendContext> = wasmSymbols
|
override val symbols: Symbols = wasmSymbols
|
||||||
override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true
|
override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ import java.lang.IllegalArgumentException
|
|||||||
|
|
||||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||||
class WasmSymbols(
|
class WasmSymbols(
|
||||||
context: WasmBackendContext,
|
private val context: WasmBackendContext,
|
||||||
private val symbolTable: SymbolTable
|
private val symbolTable: SymbolTable
|
||||||
) : Symbols<WasmBackendContext>(context, context.irBuiltIns, symbolTable) {
|
) : Symbols(context.irBuiltIns, symbolTable) {
|
||||||
|
|
||||||
private val kotlinTopLevelPackage: PackageViewDescriptor =
|
private val kotlinTopLevelPackage: PackageViewDescriptor =
|
||||||
context.module.getPackage(FqName("kotlin"))
|
context.module.getPackage(FqName("kotlin"))
|
||||||
|
|||||||
+5
-4
@@ -18,11 +18,12 @@ import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
|||||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
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.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.defaultType
|
import org.jetbrains.kotlin.ir.types.defaultType
|
||||||
import org.jetbrains.kotlin.ir.types.typeWith
|
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.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi2ir.descriptors.IrBuiltInsOverDescriptors
|
import org.jetbrains.kotlin.psi2ir.descriptors.IrBuiltInsOverDescriptors
|
||||||
@@ -39,12 +40,12 @@ internal class KonanIr(context: Context, irModule: IrModuleFragment): Ir<Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal class KonanSymbols(
|
internal class KonanSymbols(
|
||||||
context: Context,
|
val context: Context,
|
||||||
private val descriptorsLookup: DescriptorsLookup,
|
private val descriptorsLookup: DescriptorsLookup,
|
||||||
irBuiltIns: IrBuiltIns,
|
irBuiltIns: IrBuiltIns,
|
||||||
private val symbolTable: SymbolTable,
|
private val symbolTable: SymbolTable,
|
||||||
lazySymbolTable: ReferenceSymbolTable
|
lazySymbolTable: ReferenceSymbolTable
|
||||||
): Symbols<Context>(context, irBuiltIns, symbolTable) {
|
): Symbols(irBuiltIns, symbolTable) {
|
||||||
|
|
||||||
val entryPoint = findMainEntryPoint(context)?.let { symbolTable.referenceSimpleFunction(it) }
|
val entryPoint = findMainEntryPoint(context)?.let { symbolTable.referenceSimpleFunction(it) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user