JVM IR: minor, repurpose JvmBackendContext.getLocalClassInfo to store Type
This commit is contained in:
@@ -35,6 +35,7 @@ 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.jvm.JvmClassName
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||||
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
|
||||||
class JvmBackendContext(
|
class JvmBackendContext(
|
||||||
val state: GenerationState,
|
val state: GenerationState,
|
||||||
@@ -61,15 +62,13 @@ class JvmBackendContext(
|
|||||||
|
|
||||||
val irIntrinsics = IrIntrinsicMethods(irBuiltIns, ir.symbols)
|
val irIntrinsics = IrIntrinsicMethods(irBuiltIns, ir.symbols)
|
||||||
|
|
||||||
internal class LocalClassInfo(val internalName: String)
|
private val localClassType = mutableMapOf<IrAttributeContainer, Type>()
|
||||||
|
|
||||||
private val localClassInfo = mutableMapOf<IrAttributeContainer, LocalClassInfo>()
|
internal fun getLocalClassType(container: IrAttributeContainer): Type? =
|
||||||
|
localClassType[container.attributeOwnerId]
|
||||||
|
|
||||||
internal fun getLocalClassInfo(container: IrAttributeContainer): LocalClassInfo? =
|
internal fun putLocalClassType(container: IrAttributeContainer, value: Type) {
|
||||||
localClassInfo[container.attributeOwnerId]
|
localClassType[container.attributeOwnerId] = value
|
||||||
|
|
||||||
internal fun putLocalClassInfo(container: IrAttributeContainer, value: LocalClassInfo) {
|
|
||||||
localClassInfo[container.attributeOwnerId] = value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val customEnclosingFunction = mutableMapOf<IrAttributeContainer, IrFunction>()
|
internal val customEnclosingFunction = mutableMapOf<IrAttributeContainer, IrFunction>()
|
||||||
|
|||||||
+2
-4
@@ -158,10 +158,8 @@ class IrExpressionLambdaImpl(
|
|||||||
// arguments apart from any other scope's. So long as it's unique, any value is fine.
|
// arguments apart from any other scope's. So long as it's unique, any value is fine.
|
||||||
// This particular string slightly aids in debugging internal compiler errors as it at least
|
// This particular string slightly aids in debugging internal compiler errors as it at least
|
||||||
// points towards the function containing the lambda.
|
// points towards the function containing the lambda.
|
||||||
override val lambdaClassType: Type = Type.getObjectType(
|
override val lambdaClassType: Type =
|
||||||
context.getLocalClassInfo(reference)?.internalName
|
context.getLocalClassType(reference) ?: throw AssertionError("callable reference ${reference.dump()} has no name in context")
|
||||||
?: throw AssertionError("callable reference ${reference.dump()} has no name in context")
|
|
||||||
)
|
|
||||||
|
|
||||||
override val capturedVars: List<CapturedParamDesc> =
|
override val capturedVars: List<CapturedParamDesc> =
|
||||||
reference.getArgumentsWithIr().map { (param, _) ->
|
reference.getArgumentsWithIr().map { (param, _) ->
|
||||||
|
|||||||
+3
-1
@@ -50,8 +50,10 @@ class IrTypeMapper(private val context: JvmBackendContext) : KotlinTypeMapperBas
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun classInternalName(irClass: IrClass): String {
|
fun classInternalName(irClass: IrClass): String {
|
||||||
context.getLocalClassInfo(irClass)?.internalName?.let { return it }
|
context.getLocalClassType(irClass)?.internalName?.let { return it }
|
||||||
|
|
||||||
context.classNameOverride[irClass]?.let { return it.internalName }
|
context.classNameOverride[irClass]?.let { return it.internalName }
|
||||||
|
|
||||||
val className = SpecialNames.safeIdentifier(irClass.name).identifier
|
val className = SpecialNames.safeIdentifier(irClass.name).identifier
|
||||||
val internalName = when (val parent = irClass.parent) {
|
val internalName = when (val parent = irClass.parent) {
|
||||||
is IrPackageFragment -> {
|
is IrPackageFragment -> {
|
||||||
|
|||||||
+1
-1
@@ -35,7 +35,7 @@ class CheckLocalNamesWithOldBackend(private val context: JvmBackendContext) : Fi
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClass(declaration: IrClass) {
|
override fun visitClass(declaration: IrClass) {
|
||||||
val actualName = context.getLocalClassInfo(declaration)?.internalName
|
val actualName = context.getLocalClassType(declaration)?.internalName
|
||||||
if (actualName != null) {
|
if (actualName != null) {
|
||||||
val expectedName = context.state.bindingTrace.get(CodegenBinding.ASM_TYPE, declaration.symbol.descriptor)?.internalName
|
val expectedName = context.state.bindingTrace.get(CodegenBinding.ASM_TYPE, declaration.symbol.descriptor)?.internalName
|
||||||
if (expectedName != null && expectedName != actualName) {
|
if (expectedName != null && expectedName != actualName) {
|
||||||
|
|||||||
+6
-5
@@ -11,13 +11,14 @@ import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
|||||||
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
|
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.IrFunctionReference
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
|
||||||
import org.jetbrains.kotlin.ir.util.isAnonymousObject
|
import org.jetbrains.kotlin.ir.util.isAnonymousObject
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||||
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
|
||||||
val inventNamesForLocalClassesPhase = makeIrFilePhase<JvmBackendContext>(
|
val inventNamesForLocalClassesPhase = makeIrFilePhase<JvmBackendContext>(
|
||||||
{ context -> InventNamesForLocalClasses(context) },
|
{ context -> InventNamesForLocalClasses(context) },
|
||||||
@@ -63,7 +64,7 @@ class InventNamesForLocalClasses(private val context: JvmBackendContext) : FileL
|
|||||||
}
|
}
|
||||||
|
|
||||||
val internalName = inventName(declaration.name, data)
|
val internalName = inventName(declaration.name, data)
|
||||||
context.putLocalClassInfo(declaration, JvmBackendContext.LocalClassInfo(internalName))
|
context.putLocalClassType(declaration, Type.getObjectType(internalName))
|
||||||
|
|
||||||
val newData = data.withName(internalName)
|
val newData = data.withName(internalName)
|
||||||
|
|
||||||
@@ -130,14 +131,14 @@ class InventNamesForLocalClasses(private val context: JvmBackendContext) : FileL
|
|||||||
|
|
||||||
override fun visitFunctionReference(expression: IrFunctionReference, data: Data) {
|
override fun visitFunctionReference(expression: IrFunctionReference, data: Data) {
|
||||||
val internalName = localFunctionNames[expression.symbol] ?: inventName(null, data)
|
val internalName = localFunctionNames[expression.symbol] ?: inventName(null, data)
|
||||||
context.putLocalClassInfo(expression, JvmBackendContext.LocalClassInfo(internalName))
|
context.putLocalClassType(expression, Type.getObjectType(internalName))
|
||||||
|
|
||||||
expression.acceptChildren(this, data)
|
expression.acceptChildren(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitPropertyReference(expression: IrPropertyReference, data: Data) {
|
override fun visitPropertyReference(expression: IrPropertyReference, data: Data) {
|
||||||
val internalName = inventName(null, data)
|
val internalName = inventName(null, data)
|
||||||
context.putLocalClassInfo(expression, JvmBackendContext.LocalClassInfo(internalName))
|
context.putLocalClassType(expression, Type.getObjectType(internalName))
|
||||||
|
|
||||||
expression.acceptChildren(this, data)
|
expression.acceptChildren(this, data)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user