Cleanup Symbols and JvmIr.JvmSymbols
This commit is contained in:
@@ -39,6 +39,8 @@ abstract class Ir<out T : CommonBackendContext>(val context: T, val irModule: Ir
|
|||||||
open fun shouldGenerateHandlerParameterForDefaultBodyFun() = false
|
open fun shouldGenerateHandlerParameterForDefaultBodyFun() = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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, private val symbolTable: ReferenceSymbolTable) {
|
abstract class Symbols<out T : CommonBackendContext>(val context: T, private val symbolTable: ReferenceSymbolTable) {
|
||||||
|
|
||||||
protected val builtIns
|
protected val builtIns
|
||||||
@@ -48,24 +50,12 @@ abstract class Symbols<out T : CommonBackendContext>(val context: T, private val
|
|||||||
context.builtIns.builtInsModule.getPackage(FqName.fromSegments(listOf(*packageNameSegments))).memberScope
|
context.builtIns.builtInsModule.getPackage(FqName.fromSegments(listOf(*packageNameSegments))).memberScope
|
||||||
|
|
||||||
|
|
||||||
// This hack allows to disable related symbol instantiation in descendants
|
|
||||||
// TODO move relevant symbols to non-common code
|
|
||||||
open fun calc(initializer: () -> IrClassSymbol): IrClassSymbol {
|
|
||||||
return initializer()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this table to reference external dependencies.
|
* Use this table to reference external dependencies.
|
||||||
*/
|
*/
|
||||||
open val externalSymbolTable: ReferenceSymbolTable
|
open val externalSymbolTable: ReferenceSymbolTable
|
||||||
get() = symbolTable
|
get() = symbolTable
|
||||||
|
|
||||||
// val refClass = calc { symbolTable.referenceClass(context.getInternalClass("Ref")) }
|
|
||||||
|
|
||||||
//abstract val areEqualByValue: List<IrFunctionSymbol>
|
|
||||||
|
|
||||||
abstract val areEqual: IrFunctionSymbol
|
|
||||||
|
|
||||||
abstract val ThrowNullPointerException: IrFunctionSymbol
|
abstract val ThrowNullPointerException: IrFunctionSymbol
|
||||||
abstract val ThrowNoWhenBranchMatchedException: IrFunctionSymbol
|
abstract val ThrowNoWhenBranchMatchedException: IrFunctionSymbol
|
||||||
abstract val ThrowTypeCastException: IrFunctionSymbol
|
abstract val ThrowTypeCastException: IrFunctionSymbol
|
||||||
@@ -96,11 +86,6 @@ abstract class Symbols<out T : CommonBackendContext>(val context: T, private val
|
|||||||
val progressionClasses = listOf(charProgression, intProgression, longProgression)
|
val progressionClasses = listOf(charProgression, intProgression, longProgression)
|
||||||
val progressionClassesTypes = progressionClasses.map { it.descriptor.defaultType }.toSet()
|
val progressionClassesTypes = progressionClasses.map { it.descriptor.defaultType }.toSet()
|
||||||
|
|
||||||
// val checkProgressionStep = context.getInternalFunctions("checkProgressionStep")
|
|
||||||
// .map { Pair(it.returnType, symbolTable.referenceSimpleFunction(it)) }.toMap()
|
|
||||||
// val getProgressionLast = context.getInternalFunctions("getProgressionLast")
|
|
||||||
// .map { Pair(it.returnType, symbolTable.referenceSimpleFunction(it)) }.toMap()
|
|
||||||
|
|
||||||
val defaultConstructorMarker = symbolTable.referenceClass(context.getInternalClass("DefaultConstructorMarker"))
|
val defaultConstructorMarker = symbolTable.referenceClass(context.getInternalClass("DefaultConstructorMarker"))
|
||||||
|
|
||||||
val any = symbolTable.referenceClass(builtIns.any)
|
val any = symbolTable.referenceClass(builtIns.any)
|
||||||
@@ -158,39 +143,18 @@ abstract class Symbols<out T : CommonBackendContext>(val context: T, private val
|
|||||||
.firstOrNull {
|
.firstOrNull {
|
||||||
it.valueParameters.isEmpty()
|
it.valueParameters.isEmpty()
|
||||||
&& (it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor as? ClassDescriptor)?.defaultType == type
|
&& (it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor as? ClassDescriptor)?.defaultType == type
|
||||||
}
|
} ?: throw Error(type.toString())
|
||||||
?: throw Error(type.toString())
|
|
||||||
return symbolTable.referenceSimpleFunction(descriptor)
|
return symbolTable.referenceSimpleFunction(descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract val copyRangeTo: Map<ClassDescriptor, IrSimpleFunctionSymbol>
|
abstract val copyRangeTo: Map<ClassDescriptor, IrSimpleFunctionSymbol>
|
||||||
|
|
||||||
// val valuesForEnum = symbolTable.referenceSimpleFunction(
|
|
||||||
// context.getInternalFunctions("valuesForEnum").single())
|
|
||||||
//
|
|
||||||
// val valueOfForEnum = symbolTable.referenceSimpleFunction(
|
|
||||||
// context.getInternalFunctions("valueOfForEnum").single())
|
|
||||||
|
|
||||||
// val getContinuation = symbolTable.referenceSimpleFunction(
|
|
||||||
// context.getInternalFunctions("getContinuation").single())
|
|
||||||
|
|
||||||
abstract val coroutineImpl: IrClassSymbol
|
abstract val coroutineImpl: IrClassSymbol
|
||||||
|
|
||||||
abstract val coroutineSuspendedGetter: IrSimpleFunctionSymbol
|
abstract val coroutineSuspendedGetter: IrSimpleFunctionSymbol
|
||||||
|
|
||||||
fun getFunction(parameterCount: Int) = symbolTable.referenceClass(context.builtIns.getFunction(parameterCount))
|
|
||||||
|
|
||||||
val functionReference = calc { symbolTable.referenceClass(context.getInternalClass("FunctionReference")) }
|
|
||||||
|
|
||||||
fun getFunction(name: Name, receiverType: KotlinType, vararg argTypes: KotlinType) =
|
|
||||||
symbolTable.referenceFunction(receiverType.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_BACKEND)
|
|
||||||
.first {
|
|
||||||
var i = 0
|
|
||||||
it.valueParameters.size == argTypes.size && it.valueParameters.all { type -> type == argTypes[i++] }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
private val binaryOperatorCache = mutableMapOf<Triple<Name, KotlinType, KotlinType>, IrFunctionSymbol>()
|
private val binaryOperatorCache = mutableMapOf<Triple<Name, KotlinType, KotlinType>, IrFunctionSymbol>()
|
||||||
|
|
||||||
fun getBinaryOperator(name: Name, lhsType: KotlinType, rhsType: KotlinType): IrFunctionSymbol {
|
fun getBinaryOperator(name: Name, lhsType: KotlinType, rhsType: KotlinType): IrFunctionSymbol {
|
||||||
val key = Triple(name, lhsType, rhsType)
|
val key = Triple(name, lhsType, rhsType)
|
||||||
var result = binaryOperatorCache[key]
|
var result = binaryOperatorCache[key]
|
||||||
@@ -204,6 +168,7 @@ abstract class Symbols<out T : CommonBackendContext>(val context: T, private val
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val unaryOperatorCache = mutableMapOf<Pair<Name, KotlinType>, IrFunctionSymbol>()
|
private val unaryOperatorCache = mutableMapOf<Pair<Name, KotlinType>, IrFunctionSymbol>()
|
||||||
|
|
||||||
fun getUnaryOperator(name: Name, receiverType: KotlinType): IrFunctionSymbol {
|
fun getUnaryOperator(name: Name, receiverType: KotlinType): IrFunctionSymbol {
|
||||||
val key = name to receiverType
|
val key = name to receiverType
|
||||||
var result = unaryOperatorCache[key]
|
var result = unaryOperatorCache[key]
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.ir.backend.js.utils.OperatorNames
|
|||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
|
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
@@ -147,20 +146,6 @@ class JsIrBackendContext(
|
|||||||
|
|
||||||
override val ir = object : Ir<CommonBackendContext>(this, irModuleFragment) {
|
override val ir = object : Ir<CommonBackendContext>(this, irModuleFragment) {
|
||||||
override val symbols = object : Symbols<CommonBackendContext>(this@JsIrBackendContext, symbolTable.lazyWrapper) {
|
override val symbols = object : Symbols<CommonBackendContext>(this@JsIrBackendContext, symbolTable.lazyWrapper) {
|
||||||
|
|
||||||
override fun calc(initializer: () -> IrClassSymbol): IrClassSymbol {
|
|
||||||
val v = lazy { initializer() }
|
|
||||||
return object : IrClassSymbol {
|
|
||||||
override val owner: IrClass get() = v.value.owner
|
|
||||||
override val isBound: Boolean get() = v.value.isBound
|
|
||||||
override fun bind(owner: IrClass) = v.value.bind(owner)
|
|
||||||
override val descriptor: ClassDescriptor get() = v.value.descriptor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override val areEqual
|
|
||||||
get () = TODO("not implemented")
|
|
||||||
|
|
||||||
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())
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,10 @@ import org.jetbrains.kotlin.backend.common.ir.Symbols
|
|||||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmDeclarationFactory
|
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmDeclarationFactory
|
||||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmSharedVariablesManager
|
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmSharedVariablesManager
|
||||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.NotFoundClasses
|
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
@@ -29,7 +27,6 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
|
||||||
|
|
||||||
class JvmBackendContext(
|
class JvmBackendContext(
|
||||||
val state: GenerationState,
|
val state: GenerationState,
|
||||||
@@ -41,9 +38,6 @@ class JvmBackendContext(
|
|||||||
override val declarationFactory: JvmDeclarationFactory = JvmDeclarationFactory(state)
|
override val declarationFactory: JvmDeclarationFactory = JvmDeclarationFactory(state)
|
||||||
override val sharedVariablesManager = JvmSharedVariablesManager(state.module, builtIns, irBuiltIns)
|
override val sharedVariablesManager = JvmSharedVariablesManager(state.module, builtIns, irBuiltIns)
|
||||||
|
|
||||||
// TODO: inject a correct StorageManager instance, or store NotFoundClasses inside ModuleDescriptor
|
|
||||||
internal val reflectionTypes = ReflectionTypes(state.module, NotFoundClasses(LockBasedStorageManager.NO_LOCKS, state.module))
|
|
||||||
|
|
||||||
override val ir = JvmIr(irModuleFragment, symbolTable)
|
override val ir = JvmIr(irModuleFragment, symbolTable)
|
||||||
|
|
||||||
val phaseConfig = PhaseConfig(jvmPhases, state.configuration)
|
val phaseConfig = PhaseConfig(jvmPhases, state.configuration)
|
||||||
@@ -107,34 +101,20 @@ class JvmBackendContext(
|
|||||||
override val symbols = JvmSymbols()
|
override val symbols = JvmSymbols()
|
||||||
|
|
||||||
inner class JvmSymbols : Symbols<JvmBackendContext>(this@JvmBackendContext, symbolTable.lazyWrapper) {
|
inner class JvmSymbols : Symbols<JvmBackendContext>(this@JvmBackendContext, symbolTable.lazyWrapper) {
|
||||||
|
override val ThrowNullPointerException: IrSimpleFunctionSymbol
|
||||||
|
get() = symbolTable.referenceSimpleFunction(context.getInternalFunctions("ThrowNullPointerException").single())
|
||||||
|
|
||||||
override val areEqual
|
override val ThrowNoWhenBranchMatchedException: IrSimpleFunctionSymbol
|
||||||
get () = symbolTable.referenceSimpleFunction(context.getInternalFunctions("areEqual").single())
|
get() = symbolTable.referenceSimpleFunction(context.getInternalFunctions("ThrowNoWhenBranchMatchedException").single())
|
||||||
|
|
||||||
override val ThrowNullPointerException
|
override val ThrowTypeCastException: IrSimpleFunctionSymbol
|
||||||
get () = symbolTable.referenceSimpleFunction(
|
get() = symbolTable.referenceSimpleFunction(context.getInternalFunctions("ThrowTypeCastException").single())
|
||||||
context.getInternalFunctions("ThrowNullPointerException").single()
|
|
||||||
)
|
|
||||||
|
|
||||||
override val ThrowNoWhenBranchMatchedException
|
override val ThrowUninitializedPropertyAccessException: IrSimpleFunctionSymbol =
|
||||||
get () = symbolTable.referenceSimpleFunction(
|
symbolTable.referenceSimpleFunction(context.getInternalFunctions("ThrowUninitializedPropertyAccessException").single())
|
||||||
context.getInternalFunctions("ThrowNoWhenBranchMatchedException").single()
|
|
||||||
)
|
|
||||||
|
|
||||||
override val ThrowTypeCastException
|
override val stringBuilder: IrClassSymbol
|
||||||
get () = symbolTable.referenceSimpleFunction(
|
get() = symbolTable.referenceClass(context.getClass(FqName("java.lang.StringBuilder")))
|
||||||
context.getInternalFunctions("ThrowTypeCastException").single()
|
|
||||||
)
|
|
||||||
|
|
||||||
override val ThrowUninitializedPropertyAccessException =
|
|
||||||
symbolTable.referenceSimpleFunction(
|
|
||||||
context.getInternalFunctions("ThrowUninitializedPropertyAccessException").single()
|
|
||||||
)
|
|
||||||
|
|
||||||
override val stringBuilder
|
|
||||||
get() = symbolTable.referenceClass(
|
|
||||||
context.getClass(FqName("java.lang.StringBuilder"))
|
|
||||||
)
|
|
||||||
|
|
||||||
override val copyRangeTo: Map<ClassDescriptor, IrSimpleFunctionSymbol>
|
override val copyRangeTo: Map<ClassDescriptor, IrSimpleFunctionSymbol>
|
||||||
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
|
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
|
||||||
@@ -143,12 +123,16 @@ class JvmBackendContext(
|
|||||||
override val coroutineSuspendedGetter: IrSimpleFunctionSymbol
|
override val coroutineSuspendedGetter: IrSimpleFunctionSymbol
|
||||||
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
|
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
|
||||||
|
|
||||||
val lambdaClass = calc { symbolTable.referenceClass(context.getInternalClass("Lambda")) }
|
val lambdaClass: IrClassSymbol =
|
||||||
|
symbolTable.referenceClass(context.getInternalClass("Lambda"))
|
||||||
|
|
||||||
fun getKFunction(parameterCount: Int) = symbolTable.referenceClass(reflectionTypes.getKFunction(parameterCount))
|
val functionReference: IrClassSymbol =
|
||||||
|
symbolTable.referenceClass(context.getInternalClass("FunctionReference"))
|
||||||
|
|
||||||
|
fun getFunction(parameterCount: Int): IrClassSymbol =
|
||||||
|
symbolTable.referenceClass(context.builtIns.getFunction(parameterCount))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true
|
override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user