JVM IR: remove MethodSignatureMapper.mapImplementationOwner
This commit is contained in:
+9
-10
@@ -438,23 +438,24 @@ class ExpressionCodegen(
|
||||
}
|
||||
|
||||
override fun visitFieldAccess(expression: IrFieldAccessExpression, data: BlockInfo): PromisedValue {
|
||||
expression.symbol.owner.constantValue()?.let {
|
||||
val callee = expression.symbol.owner
|
||||
callee.constantValue()?.let {
|
||||
// Handling const reads before codegen is important for constant folding.
|
||||
assert(expression is IrSetField) { "read of const val ${expression.symbol.owner.name} not inlined by ConstLowering" }
|
||||
assert(expression is IrSetField) { "read of const val ${callee.name} not inlined by ConstLowering" }
|
||||
// This can only be the field's initializer; JVM implementations are required
|
||||
// to generate those for ConstantValue-marked fields automatically, so this is redundant.
|
||||
return defaultValue(expression.type)
|
||||
}
|
||||
|
||||
val realField = expression.symbol.owner.resolveFakeOverride()!!
|
||||
val realField = callee.resolveFakeOverride()!!
|
||||
val fieldType = typeMapper.mapType(realField.type)
|
||||
val ownerType = methodSignatureMapper.mapImplementationOwner(expression.symbol.owner).internalName
|
||||
val ownerType = typeMapper.mapClass(callee.parentAsClass).internalName
|
||||
val fieldName = realField.name.asString()
|
||||
val isStatic = expression.receiver == null
|
||||
expression.markLineNumber(startOffset = true)
|
||||
expression.receiver?.accept(this, data)?.materialize()
|
||||
return if (expression is IrSetField) {
|
||||
expression.value.accept(this, data).coerce(fieldType, expression.symbol.owner.type).materialize()
|
||||
expression.value.accept(this, data).coerce(fieldType, callee.type).materialize()
|
||||
when {
|
||||
isStatic -> mv.putstatic(ownerType, fieldName, fieldType.descriptor)
|
||||
else -> mv.putfield(ownerType, fieldName, fieldType.descriptor)
|
||||
@@ -462,12 +463,10 @@ class ExpressionCodegen(
|
||||
defaultValue(expression.type)
|
||||
} else {
|
||||
when {
|
||||
isStatic ->
|
||||
mv.getstatic(ownerType, fieldName, fieldType.descriptor)
|
||||
else ->
|
||||
mv.getfield(ownerType, fieldName, fieldType.descriptor)
|
||||
isStatic -> mv.getstatic(ownerType, fieldName, fieldType.descriptor)
|
||||
else -> mv.getfield(ownerType, fieldName, fieldType.descriptor)
|
||||
}
|
||||
MaterialValue(this, fieldType, expression.symbol.owner.type).coerce(expression.type)
|
||||
MaterialValue(this, fieldType, callee.type).coerce(expression.type)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-3
@@ -41,9 +41,6 @@ class MethodSignatureMapper(context: JvmBackendContext) {
|
||||
fun mapAnnotationParameterName(field: IrField): String =
|
||||
kotlinTypeMapper.mapAnnotationParameterName(field.descriptor)
|
||||
|
||||
fun mapImplementationOwner(irDeclaration: IrDeclaration): Type =
|
||||
kotlinTypeMapper.mapImplementationOwner(irDeclaration.descriptor)
|
||||
|
||||
fun mapReturnType(irField: IrField): Type =
|
||||
kotlinTypeMapper.mapReturnType(irField.descriptor)
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@ import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil.numberFunctionOperandType
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.types.isChar
|
||||
import org.jetbrains.kotlin.ir.util.defaultType
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -33,10 +36,9 @@ class BinaryOp(private val opcode: Int) : IntrinsicMethod() {
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
): IrIntrinsicFunction {
|
||||
val owner = context.methodSignatureMapper.mapImplementationOwner(expression.symbol.owner)
|
||||
val returnType = signature.returnType
|
||||
val intermediateResultType = numberFunctionOperandType(returnType)
|
||||
val argTypes = if (owner != Type.CHAR_TYPE) {
|
||||
val argTypes = if (!expression.symbol.owner.parentAsClass.defaultType.isChar()) {
|
||||
listOf(intermediateResultType, if (shift()) Type.INT_TYPE else intermediateResultType)
|
||||
} else {
|
||||
listOf(Type.CHAR_TYPE, signature.valueParameters[0].asmType)
|
||||
|
||||
Reference in New Issue
Block a user