JVM IR: minor, repurpose JvmBackendContext.getLocalClassInfo to store Type

This commit is contained in:
Alexander Udalov
2019-10-31 17:17:04 +01:00
parent 6be9101675
commit 180e718752
5 changed files with 18 additions and 18 deletions
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.org.objectweb.asm.Type
class JvmBackendContext(
val state: GenerationState,
@@ -61,15 +62,13 @@ class JvmBackendContext(
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? =
localClassInfo[container.attributeOwnerId]
internal fun putLocalClassInfo(container: IrAttributeContainer, value: LocalClassInfo) {
localClassInfo[container.attributeOwnerId] = value
internal fun putLocalClassType(container: IrAttributeContainer, value: Type) {
localClassType[container.attributeOwnerId] = value
}
internal val customEnclosingFunction = mutableMapOf<IrAttributeContainer, IrFunction>()
@@ -158,10 +158,8 @@ class IrExpressionLambdaImpl(
// 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
// points towards the function containing the lambda.
override val lambdaClassType: Type = Type.getObjectType(
context.getLocalClassInfo(reference)?.internalName
?: throw AssertionError("callable reference ${reference.dump()} has no name in context")
)
override val lambdaClassType: Type =
context.getLocalClassType(reference) ?: throw AssertionError("callable reference ${reference.dump()} has no name in context")
override val capturedVars: List<CapturedParamDesc> =
reference.getArgumentsWithIr().map { (param, _) ->
@@ -50,8 +50,10 @@ class IrTypeMapper(private val context: JvmBackendContext) : KotlinTypeMapperBas
}
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 }
val className = SpecialNames.safeIdentifier(irClass.name).identifier
val internalName = when (val parent = irClass.parent) {
is IrPackageFragment -> {
@@ -35,7 +35,7 @@ class CheckLocalNamesWithOldBackend(private val context: JvmBackendContext) : Fi
}
override fun visitClass(declaration: IrClass) {
val actualName = context.getLocalClassInfo(declaration)?.internalName
val actualName = context.getLocalClassType(declaration)?.internalName
if (actualName != null) {
val expectedName = context.state.bindingTrace.get(CodegenBinding.ASM_TYPE, declaration.symbol.descriptor)?.internalName
if (expectedName != null && expectedName != actualName) {
@@ -11,13 +11,14 @@ import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
import org.jetbrains.kotlin.ir.IrElement
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.util.fqNameWhenAvailable
import org.jetbrains.kotlin.ir.util.isAnonymousObject
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
import org.jetbrains.org.objectweb.asm.Type
val inventNamesForLocalClassesPhase = makeIrFilePhase<JvmBackendContext>(
{ context -> InventNamesForLocalClasses(context) },
@@ -63,7 +64,7 @@ class InventNamesForLocalClasses(private val context: JvmBackendContext) : FileL
}
val internalName = inventName(declaration.name, data)
context.putLocalClassInfo(declaration, JvmBackendContext.LocalClassInfo(internalName))
context.putLocalClassType(declaration, Type.getObjectType(internalName))
val newData = data.withName(internalName)
@@ -130,14 +131,14 @@ class InventNamesForLocalClasses(private val context: JvmBackendContext) : FileL
override fun visitFunctionReference(expression: IrFunctionReference, data: 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)
}
override fun visitPropertyReference(expression: IrPropertyReference, data: Data) {
val internalName = inventName(null, data)
context.putLocalClassInfo(expression, JvmBackendContext.LocalClassInfo(internalName))
context.putLocalClassType(expression, Type.getObjectType(internalName))
expression.acceptChildren(this, data)
}