KT-27936 Generate InnerClasses attributes
This commit is contained in:
committed by
teamcity
parent
4a8eec8166
commit
18e61315f4
+11
-15
@@ -49,12 +49,12 @@ import org.jetbrains.org.objectweb.asm.TypeReference
|
||||
import java.lang.annotation.RetentionPolicy
|
||||
|
||||
abstract class AnnotationCodegen(
|
||||
private val innerClassConsumer: InnerClassConsumer,
|
||||
private val context: JvmBackendContext,
|
||||
private val classCodegen: ClassCodegen,
|
||||
private val skipNullabilityAnnotations: Boolean = false
|
||||
) {
|
||||
private val typeMapper = context.typeMapper
|
||||
private val methodSignatureMapper = context.methodSignatureMapper
|
||||
private val context = classCodegen.context
|
||||
private val typeMapper = classCodegen.typeMapper
|
||||
private val methodSignatureMapper = classCodegen.methodSignatureMapper
|
||||
|
||||
/**
|
||||
* @param returnType can be null if not applicable (e.g. [annotated] is a class)
|
||||
@@ -195,7 +195,7 @@ abstract class AnnotationCodegen(
|
||||
// (Otherwise we would've resolved the entry to the actual annotation class.)
|
||||
if (annotationClass.isOptionalAnnotationClass) return null
|
||||
|
||||
innerClassConsumer.addInnerClassInfoFromAnnotation(annotationClass)
|
||||
classCodegen.addInnerClassInfo(annotationClass)
|
||||
|
||||
val asmTypeDescriptor = typeMapper.mapType(annotation.type).descriptor
|
||||
val annotationVisitor =
|
||||
@@ -249,7 +249,7 @@ abstract class AnnotationCodegen(
|
||||
val annotationClassType = callee.returnType
|
||||
val internalAnnName = typeMapper.mapType(annotationClassType).descriptor
|
||||
val visitor = annotationVisitor.visitAnnotation(name, internalAnnName)
|
||||
annotationClassType.classOrNull?.owner?.let(innerClassConsumer::addInnerClassInfoFromAnnotation)
|
||||
annotationClassType.classOrNull?.owner?.let(classCodegen::addInnerClassInfo)
|
||||
genAnnotationArguments(value, visitor)
|
||||
visitor.visitEnd()
|
||||
}
|
||||
@@ -259,7 +259,7 @@ abstract class AnnotationCodegen(
|
||||
is IrGetEnumValue -> {
|
||||
val enumEntry = value.symbol.owner
|
||||
val enumClass = enumEntry.parentAsClass
|
||||
innerClassConsumer.addInnerClassInfoFromAnnotation(enumClass)
|
||||
classCodegen.addInnerClassInfo(enumClass)
|
||||
annotationVisitor.visitEnum(name, typeMapper.mapClass(enumClass).descriptor, enumEntry.name.asString())
|
||||
}
|
||||
is IrVararg -> { // array constructor
|
||||
@@ -271,7 +271,7 @@ abstract class AnnotationCodegen(
|
||||
}
|
||||
is IrClassReference -> {
|
||||
val classType = value.classType
|
||||
classType.classOrNull?.owner?.let(innerClassConsumer::addInnerClassInfoFromAnnotation)
|
||||
classType.classOrNull?.owner?.let(classCodegen::addInnerClassInfo)
|
||||
val mappedType =
|
||||
if (classType.isInlineClassType()) typeMapper.mapClass(classType.erasedUpperBound)
|
||||
else typeMapper.mapType(classType)
|
||||
@@ -294,7 +294,7 @@ abstract class AnnotationCodegen(
|
||||
) {
|
||||
if (context.state.target != JVM_1_6) {
|
||||
typeParameterContainer.typeParameters.forEachIndexed { index, typeParameter ->
|
||||
object : AnnotationCodegen(classCodegen, context, true) {
|
||||
object : AnnotationCodegen(classCodegen, true) {
|
||||
override fun visitAnnotation(descr: String, visible: Boolean): AnnotationVisitor {
|
||||
|
||||
return visitor(
|
||||
@@ -318,7 +318,7 @@ abstract class AnnotationCodegen(
|
||||
typeParameter.superTypes.forEach { superType ->
|
||||
val isClassOrTypeParameter = !superType.isInterface() && !superType.isAnnotation()
|
||||
val superIndex = if (isClassOrTypeParameter) 0 else superInterfaceIndex++
|
||||
object : AnnotationCodegen(classCodegen, context, true) {
|
||||
object : AnnotationCodegen(classCodegen, true) {
|
||||
override fun visitAnnotation(descr: String, visible: Boolean): AnnotationVisitor {
|
||||
throw RuntimeException(
|
||||
"Error during generation: only type annotations should be presented on type parameters bounds: " +
|
||||
@@ -406,7 +406,7 @@ abstract class AnnotationCodegen(
|
||||
return
|
||||
}
|
||||
val infos: Iterable<TypePathInfo<IrConstructorCall>> =
|
||||
IrTypeAnnotationCollector(context.typeMapper.typeSystem).collectTypeAnnotations(type)
|
||||
IrTypeAnnotationCollector(classCodegen.typeMapper.typeSystem).collectTypeAnnotations(type)
|
||||
for (info in infos) {
|
||||
for (annotation in info.annotations) {
|
||||
genAnnotation(annotation, info.path, true)
|
||||
@@ -435,10 +435,6 @@ abstract class AnnotationCodegen(
|
||||
|
||||
}
|
||||
|
||||
interface InnerClassConsumer {
|
||||
fun addInnerClassInfoFromAnnotation(innerClass: IrClass)
|
||||
}
|
||||
|
||||
private fun isBareTypeParameterWithNullableUpperBound(type: IrType): Boolean {
|
||||
return type.classifierOrNull?.owner is IrTypeParameter && !type.isMarkedNullable() && type.isNullable()
|
||||
}
|
||||
|
||||
+50
-27
@@ -11,13 +11,17 @@ import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.MultifileFacadeFileEntry
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.*
|
||||
import org.jetbrains.kotlin.backend.jvm.mapping.IrTypeMapper
|
||||
import org.jetbrains.kotlin.backend.jvm.mapping.MethodSignatureMapper
|
||||
import org.jetbrains.kotlin.backend.jvm.mapping.mapClass
|
||||
import org.jetbrains.kotlin.backend.jvm.mapping.mapType
|
||||
import org.jetbrains.kotlin.backend.jvm.metadata.MetadataSerializer
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap.mapKotlinToJava
|
||||
import org.jetbrains.kotlin.codegen.DescriptorAsmUtil
|
||||
import org.jetbrains.kotlin.codegen.VersionIndependentOpcodes
|
||||
import org.jetbrains.kotlin.codegen.addRecordComponent
|
||||
import org.jetbrains.kotlin.codegen.inline.*
|
||||
import org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter
|
||||
import org.jetbrains.kotlin.codegen.writeKotlinMetadata
|
||||
import org.jetbrains.kotlin.config.JvmAnalysisFlags
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
@@ -35,14 +39,14 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrSetFieldImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
|
||||
import org.jetbrains.kotlin.load.kotlin.internalName
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.BitEncoding
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.JvmNames.JVM_RECORD_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.name.JvmNames.JVM_SYNTHETIC_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.name.JvmNames.TRANSIENT_ANNOTATION_FQ_NAME
|
||||
@@ -64,7 +68,7 @@ class ClassCodegen private constructor(
|
||||
val irClass: IrClass,
|
||||
val context: JvmBackendContext,
|
||||
private val parentFunction: IrFunction?,
|
||||
) : InnerClassConsumer {
|
||||
) {
|
||||
// We need to avoid recursive calls to getOrCreate() from within the constructor to prevent lockups
|
||||
// in ConcurrentHashMap context.classCodegens.
|
||||
private val parentClassCodegen by lazy {
|
||||
@@ -78,13 +82,29 @@ class ClassCodegen private constructor(
|
||||
}
|
||||
|
||||
private val state get() = context.state
|
||||
private val typeMapper get() = context.typeMapper
|
||||
|
||||
// TODO: the order of entries in this set depends on the order in which methods are generated; this means it is unstable
|
||||
// under incremental compilation, as calls to `inline fun`s declared in this class cause them to be generated out of order.
|
||||
private val innerClasses = linkedSetOf<IrClass>()
|
||||
|
||||
val typeMapper = object : IrTypeMapper(context) {
|
||||
override fun mapType(type: IrType, mode: TypeMappingMode, sw: JvmSignatureWriter?): Type {
|
||||
var t = type
|
||||
while (t.isArray()) {
|
||||
t = t.getArrayElementType(context.irBuiltIns)
|
||||
}
|
||||
t.classOrNull?.owner?.let(::addInnerClassInfo)
|
||||
return super.mapType(type, mode, sw)
|
||||
}
|
||||
}
|
||||
|
||||
val methodSignatureMapper = MethodSignatureMapper(context, typeMapper)
|
||||
|
||||
val type: Type = typeMapper.mapClass(irClass)
|
||||
|
||||
val reifiedTypeParametersUsages = ReifiedTypeParametersUsages()
|
||||
|
||||
private val jvmSignatureClashDetector = JvmSignatureClashDetector(irClass, type, context)
|
||||
private val jvmSignatureClashDetector = JvmSignatureClashDetector(this)
|
||||
|
||||
private val classOrigin = irClass.descriptorOrigin
|
||||
|
||||
@@ -105,10 +125,6 @@ class ClassCodegen private constructor(
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: the order of entries in this set depends on the order in which methods are generated; this means it is unstable
|
||||
// under incremental compilation, as calls to `inline fun`s declared in this class cause them to be generated out of order.
|
||||
private val innerClasses = linkedSetOf<IrClass>()
|
||||
|
||||
// TODO: the names produced by generators in this map depend on the order in which methods are generated; see above.
|
||||
private val regeneratedObjectNameGenerators = mutableMapOf<String, NameGenerator>()
|
||||
|
||||
@@ -166,7 +182,7 @@ class ClassCodegen private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
object : AnnotationCodegen(this@ClassCodegen, context) {
|
||||
object : AnnotationCodegen(this@ClassCodegen) {
|
||||
override fun visitAnnotation(descr: String, visible: Boolean): AnnotationVisitor {
|
||||
return visitor.visitor.visitAnnotation(descr, visible)
|
||||
}
|
||||
@@ -184,8 +200,6 @@ class ClassCodegen private constructor(
|
||||
|
||||
generateKotlinMetadataAnnotation()
|
||||
|
||||
generateInnerAndOuterClasses()
|
||||
|
||||
if (withinInline || !smap.isTrivial) {
|
||||
visitor.visitSMAP(smap, !context.state.languageVersionSettings.supportsFeature(LanguageFeature.CorrectSourceMappingSyntax))
|
||||
} else {
|
||||
@@ -196,6 +210,8 @@ class ClassCodegen private constructor(
|
||||
|
||||
addReifiedParametersFromSignature()
|
||||
|
||||
generateInnerAndOuterClasses()
|
||||
|
||||
visitor.done()
|
||||
jvmSignatureClashDetector.reportErrors(classOrigin)
|
||||
}
|
||||
@@ -345,7 +361,7 @@ class ClassCodegen private constructor(
|
||||
val fieldType = typeMapper.mapType(field)
|
||||
val fieldSignature =
|
||||
if (field.origin == IrDeclarationOrigin.PROPERTY_DELEGATE) null
|
||||
else context.methodSignatureMapper.mapFieldSignature(field)
|
||||
else methodSignatureMapper.mapFieldSignature(field)
|
||||
val fieldName = field.name.asString()
|
||||
val flags = field.computeFieldFlags(context, state.languageVersionSettings)
|
||||
val fv = visitor.newField(
|
||||
@@ -359,7 +375,7 @@ class ClassCodegen private constructor(
|
||||
val skipNullabilityAnnotations =
|
||||
flags and (Opcodes.ACC_SYNTHETIC or Opcodes.ACC_ENUM) != 0 ||
|
||||
(field.origin == IrDeclarationOrigin.FIELD_FOR_OBJECT_INSTANCE && irClass.isSyntheticSingleton)
|
||||
object : AnnotationCodegen(this@ClassCodegen, context, skipNullabilityAnnotations) {
|
||||
object : AnnotationCodegen(this@ClassCodegen, skipNullabilityAnnotations) {
|
||||
override fun visitAnnotation(descr: String, visible: Boolean): AnnotationVisitor {
|
||||
return fv.visitAnnotation(descr, visible)
|
||||
}
|
||||
@@ -474,28 +490,38 @@ class ClassCodegen private constructor(
|
||||
?: error("Class in a non-static initializer found, but container has no constructors: ${containerClass.render()}")
|
||||
} else parentFunction
|
||||
if (enclosingFunction != null || irClass.isAnonymousInnerClass) {
|
||||
val method = enclosingFunction?.let(context.methodSignatureMapper::mapAsmMethod)?.takeIf { it.name != "<clinit>" }
|
||||
val method = enclosingFunction?.let(methodSignatureMapper::mapAsmMethod)?.takeIf { it.name != "<clinit>" }
|
||||
visitor.visitOuterClass(parentClassCodegen!!.type.internalName, method?.name, method?.descriptor)
|
||||
}
|
||||
}
|
||||
|
||||
for (klass in innerClasses) {
|
||||
val innerClass = typeMapper.classInternalName(klass)
|
||||
val innerJavaClassId = klass.mapToJava()
|
||||
val innerClass = innerJavaClassId?.internalName ?: typeMapper.classInternalName(klass)
|
||||
val outerClass =
|
||||
if (klass.isSamWrapper || klass.isAnnotationImplementation || klass.attributeOwnerId in context.isEnclosedInConstructor)
|
||||
null
|
||||
else {
|
||||
when (val parent = klass.parent) {
|
||||
is IrClass -> typeMapper.classInternalName(parent)
|
||||
is IrClass -> {
|
||||
val outerJavaClassId = parent.mapToJava()
|
||||
if (innerJavaClassId?.packageFqName != outerJavaClassId?.packageFqName) {
|
||||
continue
|
||||
}
|
||||
outerJavaClassId?.internalName ?: typeMapper.classInternalName(parent)
|
||||
}
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
val innerName = if (klass.isAnonymousInnerClass) null else klass.name.asString()
|
||||
val innerName = if (klass.isAnonymousInnerClass) null else innerJavaClassId?.shortClassName?.asString() ?: klass.name.asString()
|
||||
val accessFlags = klass.calculateInnerClassAccessFlags(context)
|
||||
visitor.visitInnerClass(innerClass, outerClass, innerName, accessFlags)
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrClass.mapToJava(): ClassId? = fqNameWhenAvailable?.toUnsafe()?.let(::mapKotlinToJava)
|
||||
|
||||
private val IrClass.isAnonymousInnerClass: Boolean
|
||||
get() = isSamWrapper || name.isSpecial || isAnnotationImplementation // NB '<Continuation>' is treated as anonymous inner class here
|
||||
|
||||
@@ -508,13 +534,10 @@ class ClassCodegen private constructor(
|
||||
private val IrClass.isAnnotationImplementation: Boolean
|
||||
get() = origin == ANNOTATION_IMPLEMENTATION
|
||||
|
||||
override fun addInnerClassInfoFromAnnotation(innerClass: IrClass) {
|
||||
// It's necessary for proper recovering of classId by plain string JVM descriptor when loading annotations
|
||||
// See FileBasedKotlinClass.convertAnnotationVisitor
|
||||
generateSequence<IrDeclaration>(innerClass) { it.parent as? IrDeclaration }.takeWhile { !it.isTopLevelDeclaration }.forEach {
|
||||
if (it is IrClass) {
|
||||
innerClasses.add(it)
|
||||
}
|
||||
fun addInnerClassInfo(innerClass: IrClass) {
|
||||
var c = innerClass
|
||||
while (!c.isTopLevelDeclaration && innerClasses.add(c)) {
|
||||
c = c.parentClassOrNull ?: break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -150,8 +150,8 @@ class ExpressionCodegen(
|
||||
get() = generateSequence(irFunction) { context.enclosingMethodOverride[it] }.last()
|
||||
|
||||
val context = classCodegen.context
|
||||
val typeMapper = context.typeMapper
|
||||
val methodSignatureMapper = context.methodSignatureMapper
|
||||
val typeMapper = classCodegen.typeMapper
|
||||
val methodSignatureMapper = classCodegen.methodSignatureMapper
|
||||
|
||||
val state = context.state
|
||||
|
||||
@@ -1479,7 +1479,7 @@ class ExpressionCodegen(
|
||||
|
||||
val reifiedTypeInliner = ReifiedTypeInliner(
|
||||
mappings,
|
||||
IrInlineIntrinsicsSupport(context, typeMapper, element, irFunction.fileParent),
|
||||
IrInlineIntrinsicsSupport(classCodegen, element, irFunction.fileParent),
|
||||
context.typeSystem,
|
||||
state.languageVersionSettings,
|
||||
state.unifiedNullChecks,
|
||||
|
||||
+11
-13
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.backend.jvm.codegen
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.lower.BOUND_RECEIVER_PARAMETER
|
||||
import org.jetbrains.kotlin.backend.common.lower.BOUND_VALUE_PARAMETER
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.*
|
||||
import org.jetbrains.kotlin.backend.jvm.mapping.mapType
|
||||
@@ -48,7 +47,7 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg
|
||||
}
|
||||
|
||||
private fun doGenerate(reifiedTypeParameters: ReifiedTypeParametersUsages): SMAPAndMethodNode {
|
||||
val signature = context.methodSignatureMapper.mapSignatureWithGeneric(irFunction)
|
||||
val signature = classCodegen.methodSignatureMapper.mapSignatureWithGeneric(irFunction)
|
||||
val flags = irFunction.calculateMethodFlags()
|
||||
val isSynthetic = flags.and(Opcodes.ACC_SYNTHETIC) != 0
|
||||
val methodNode = MethodNode(
|
||||
@@ -72,7 +71,7 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg
|
||||
|
||||
if (irFunction.origin !in methodOriginsWithoutAnnotations) {
|
||||
val skipNullabilityAnnotations = flags and Opcodes.ACC_PRIVATE != 0 || flags and Opcodes.ACC_SYNTHETIC != 0
|
||||
object : AnnotationCodegen(classCodegen, context, skipNullabilityAnnotations) {
|
||||
object : AnnotationCodegen(classCodegen, skipNullabilityAnnotations) {
|
||||
override fun visitAnnotation(descr: String, visible: Boolean): AnnotationVisitor {
|
||||
return methodVisitor.visitAnnotation(descr, visible)
|
||||
}
|
||||
@@ -95,7 +94,7 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg
|
||||
}
|
||||
|
||||
if (shouldGenerateAnnotationsOnValueParameters()) {
|
||||
generateParameterAnnotations(irFunction, methodVisitor, signature, classCodegen, context, skipNullabilityAnnotations)
|
||||
generateParameterAnnotations(irFunction, methodVisitor, signature, classCodegen, skipNullabilityAnnotations)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,13 +213,13 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg
|
||||
// @Throws(vararg exceptionClasses: KClass<out Throwable>)
|
||||
val exceptionClasses = function.getAnnotation(JVM_THROWS_ANNOTATION_FQ_NAME)?.getValueArgument(0) ?: return null
|
||||
return (exceptionClasses as IrVararg).elements.map { exceptionClass ->
|
||||
context.typeMapper.mapType((exceptionClass as IrClassReference).classType).internalName
|
||||
classCodegen.typeMapper.mapType((exceptionClass as IrClassReference).classType).internalName
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateAnnotationDefaultValueIfNeeded(methodVisitor: MethodVisitor) {
|
||||
getAnnotationDefaultValueExpression()?.let { defaultValueExpression ->
|
||||
val annotationCodegen = object : AnnotationCodegen(classCodegen, context) {
|
||||
val annotationCodegen = object : AnnotationCodegen(classCodegen) {
|
||||
override fun visitAnnotation(descr: String, visible: Boolean): AnnotationVisitor {
|
||||
return methodVisitor.visitAnnotationDefault()
|
||||
}
|
||||
@@ -247,18 +246,18 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg
|
||||
val frameMap = IrFrameMap()
|
||||
val receiver = if (this is IrConstructor) parentAsClass.thisReceiver else dispatchReceiverParameter
|
||||
receiver?.let {
|
||||
frameMap.enter(it, context.typeMapper.mapTypeAsDeclaration(it.type))
|
||||
frameMap.enter(it, classCodegen.typeMapper.mapTypeAsDeclaration(it.type))
|
||||
}
|
||||
val contextReceivers = valueParameters.subList(0, contextReceiverParametersCount)
|
||||
for (contextReceiver in contextReceivers) {
|
||||
frameMap.enter(contextReceiver, context.typeMapper.mapType(contextReceiver.type))
|
||||
frameMap.enter(contextReceiver, classCodegen.typeMapper.mapType(contextReceiver.type))
|
||||
}
|
||||
extensionReceiverParameter?.let {
|
||||
frameMap.enter(it, context.typeMapper.mapType(it))
|
||||
frameMap.enter(it, classCodegen.typeMapper.mapType(it))
|
||||
}
|
||||
val regularParameters = valueParameters.subList(contextReceiverParametersCount, valueParameters.size)
|
||||
for (parameter in regularParameters) {
|
||||
frameMap.enter(parameter, context.typeMapper.mapType(parameter.type))
|
||||
frameMap.enter(parameter, classCodegen.typeMapper.mapType(parameter.type))
|
||||
}
|
||||
return frameMap
|
||||
}
|
||||
@@ -268,8 +267,7 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg
|
||||
irFunction: IrFunction,
|
||||
mv: MethodVisitor,
|
||||
jvmSignature: JvmMethodSignature,
|
||||
innerClassConsumer: InnerClassConsumer,
|
||||
context: JvmBackendContext,
|
||||
classCodegen: ClassCodegen,
|
||||
skipNullabilityAnnotations: Boolean = false
|
||||
) {
|
||||
val iterator = irFunction.valueParameters.iterator()
|
||||
@@ -286,7 +284,7 @@ class FunctionCodegen(private val irFunction: IrFunction, private val classCodeg
|
||||
}
|
||||
|
||||
if (annotated != null && !kind.isSkippedInGenericSignature && !annotated.isSyntheticMarkerParameter()) {
|
||||
object : AnnotationCodegen(innerClassConsumer, context, skipNullabilityAnnotations) {
|
||||
object : AnnotationCodegen(classCodegen, skipNullabilityAnnotations) {
|
||||
override fun visitAnnotation(descr: String, visible: Boolean): AnnotationVisitor {
|
||||
return mv.visitParameterAnnotation(
|
||||
i - syntheticParameterCount,
|
||||
|
||||
+8
-11
@@ -5,11 +5,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.codegen
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.intrinsics.SignatureString
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.getCallableReferenceOwnerKClassType
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.getCallableReferenceTopLevelFlag
|
||||
import org.jetbrains.kotlin.backend.jvm.mapping.IrTypeMapper
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.inline.ReifiedTypeInliner
|
||||
@@ -35,16 +33,15 @@ import org.jetbrains.org.objectweb.asm.Type.VOID_TYPE
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
|
||||
class IrInlineIntrinsicsSupport(
|
||||
private val context: JvmBackendContext,
|
||||
private val typeMapper: IrTypeMapper,
|
||||
private val classCodegen: ClassCodegen,
|
||||
private val reportErrorsOn: IrExpression,
|
||||
private val containingFile: IrFile,
|
||||
) : ReifiedTypeInliner.IntrinsicsSupport<IrType> {
|
||||
override val state: GenerationState
|
||||
get() = context.state
|
||||
get() = classCodegen.context.state
|
||||
|
||||
override fun putClassInstance(v: InstructionAdapter, type: IrType) {
|
||||
ExpressionCodegen.generateClassInstance(v, type, typeMapper, wrapPrimitives = false)
|
||||
ExpressionCodegen.generateClassInstance(v, type, classCodegen.typeMapper, wrapPrimitives = false)
|
||||
}
|
||||
|
||||
override fun generateTypeParameterContainer(v: InstructionAdapter, typeParameter: TypeParameterMarker) {
|
||||
@@ -53,7 +50,7 @@ class IrInlineIntrinsicsSupport(
|
||||
when (val parent = typeParameter.owner.parent) {
|
||||
is IrClass -> putClassInstance(v, parent.defaultType).also { AsmUtil.wrapJavaClassIntoKClass(v) }
|
||||
is IrSimpleFunction -> {
|
||||
check(context.state.generateOptimizedCallableReferenceSuperClasses) {
|
||||
check(classCodegen.context.state.generateOptimizedCallableReferenceSuperClasses) {
|
||||
"typeOf() of a non-reified type parameter is only allowed if optimized callable references are enabled.\n" +
|
||||
"Please make sure API version is set to 1.4, and -Xno-optimized-callable-references is NOT used.\n" +
|
||||
"Container: $parent"
|
||||
@@ -93,10 +90,10 @@ class IrInlineIntrinsicsSupport(
|
||||
if (withArity) {
|
||||
v.iconst(function.allParametersCount)
|
||||
}
|
||||
putClassInstance(v, declaration.parent.getCallableReferenceOwnerKClassType(context))
|
||||
putClassInstance(v, declaration.parent.getCallableReferenceOwnerKClassType(classCodegen.context))
|
||||
v.aconst(declaration.name.asString())
|
||||
// TODO: generate correct signature for functions and property accessors which have inline class types in the signature.
|
||||
SignatureString.generateSignatureString(v, function, context)
|
||||
SignatureString.generateSignatureString(v, function, classCodegen)
|
||||
v.iconst(declaration.getCallableReferenceTopLevelFlag())
|
||||
val parameterTypes =
|
||||
(if (withArity) listOf(INT_TYPE) else emptyList()) +
|
||||
@@ -116,11 +113,11 @@ class IrInlineIntrinsicsSupport(
|
||||
override fun toKotlinType(type: IrType): KotlinType = type.toIrBasedKotlinType()
|
||||
|
||||
override fun reportSuspendTypeUnsupported() {
|
||||
context.ktDiagnosticReporter.at(reportErrorsOn, containingFile).report(JvmBackendErrors.TYPEOF_SUSPEND_TYPE)
|
||||
classCodegen.context.ktDiagnosticReporter.at(reportErrorsOn, containingFile).report(JvmBackendErrors.TYPEOF_SUSPEND_TYPE)
|
||||
}
|
||||
|
||||
override fun reportNonReifiedTypeParameterWithRecursiveBoundUnsupported(typeParameterName: Name) {
|
||||
context.ktDiagnosticReporter.at(reportErrorsOn, containingFile)
|
||||
classCodegen.context.ktDiagnosticReporter.at(reportErrorsOn, containingFile)
|
||||
.report(JvmBackendErrors.TYPEOF_NON_REIFIED_TYPE_PARAMETER_WITH_RECURSIVE_BOUND, typeParameterName.asString())
|
||||
}
|
||||
}
|
||||
|
||||
+9
-13
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.backend.jvm.codegen
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.lower.ANNOTATION_IMPLEMENTATION
|
||||
import org.jetbrains.kotlin.backend.common.psi.PsiSourceManager
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory1
|
||||
@@ -17,12 +16,9 @@ import org.jetbrains.kotlin.ir.util.file
|
||||
import org.jetbrains.kotlin.ir.util.isFakeOverride
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.*
|
||||
import org.jetbrains.kotlin.utils.SmartSet
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
class JvmSignatureClashDetector(
|
||||
private val irClass: IrClass,
|
||||
private val type: Type,
|
||||
private val context: JvmBackendContext
|
||||
private val classCodegen: ClassCodegen
|
||||
) {
|
||||
private val methodsBySignature = LinkedHashMap<RawSignature, MutableSet<IrFunction>>()
|
||||
private val fieldsBySignature = LinkedHashMap<RawSignature, MutableSet<IrField>>()
|
||||
@@ -46,7 +42,7 @@ class JvmSignatureClashDetector(
|
||||
}
|
||||
|
||||
private fun mapRawSignature(irFunction: IrFunction): RawSignature {
|
||||
val jvmSignature = context.methodSignatureMapper.mapSignatureSkipGeneric(irFunction)
|
||||
val jvmSignature = classCodegen.methodSignatureMapper.mapSignatureSkipGeneric(irFunction)
|
||||
return RawSignature(jvmSignature.asmMethod.name, jvmSignature.asmMethod.descriptor, MemberKind.METHOD)
|
||||
}
|
||||
|
||||
@@ -88,10 +84,10 @@ class JvmSignatureClashDetector(
|
||||
|
||||
when {
|
||||
realMethodsCount == 0 && (fakeOverridesCount > 1 || specialOverridesCount > 1) ->
|
||||
if (irClass.origin != JvmLoweredDeclarationOrigin.DEFAULT_IMPLS) {
|
||||
if (classCodegen.irClass.origin != JvmLoweredDeclarationOrigin.DEFAULT_IMPLS) {
|
||||
reportJvmSignatureClash(
|
||||
JvmBackendErrors.CONFLICTING_INHERITED_JVM_DECLARATIONS,
|
||||
listOf(irClass),
|
||||
listOf(classCodegen.irClass),
|
||||
conflictingJvmDeclarationsData
|
||||
)
|
||||
}
|
||||
@@ -99,7 +95,7 @@ class JvmSignatureClashDetector(
|
||||
fakeOverridesCount == 0 && specialOverridesCount == 0 -> {
|
||||
// In IFoo$DefaultImpls we should report errors only if there are private methods among conflicting ones
|
||||
// (otherwise such errors would be reported twice: once for IFoo and once for IFoo$DefaultImpls).
|
||||
if (irClass.origin != JvmLoweredDeclarationOrigin.DEFAULT_IMPLS ||
|
||||
if (classCodegen.irClass.origin != JvmLoweredDeclarationOrigin.DEFAULT_IMPLS ||
|
||||
methods.any { DescriptorVisibilities.isPrivate(it.visibility) }
|
||||
) {
|
||||
reportJvmSignatureClash(
|
||||
@@ -111,7 +107,7 @@ class JvmSignatureClashDetector(
|
||||
}
|
||||
|
||||
else ->
|
||||
if (irClass.origin != JvmLoweredDeclarationOrigin.DEFAULT_IMPLS) {
|
||||
if (classCodegen.irClass.origin != JvmLoweredDeclarationOrigin.DEFAULT_IMPLS) {
|
||||
reportJvmSignatureClash(
|
||||
JvmBackendErrors.ACCIDENTAL_OVERRIDE,
|
||||
methods.filter { !it.isFakeOverride && !it.isSpecialOverride() },
|
||||
@@ -128,7 +124,7 @@ class JvmSignatureClashDetector(
|
||||
val methods = knownMethods.filter { !it.isFakeOverride && !it.isSpecialOverride() }
|
||||
if (methods.isEmpty()) continue
|
||||
val conflictingJvmDeclarationsData = ConflictingJvmDeclarationsData(
|
||||
type.internalName, classOrigin, predefinedSignature,
|
||||
classCodegen.type.internalName, classOrigin, predefinedSignature,
|
||||
methods.map { it.getJvmDeclarationOrigin() } + JvmDeclarationOrigin(JvmDeclarationOriginKind.OTHER, null, null)
|
||||
)
|
||||
reportJvmSignatureClash(JvmBackendErrors.ACCIDENTAL_OVERRIDE, methods, conflictingJvmDeclarationsData)
|
||||
@@ -149,7 +145,7 @@ class JvmSignatureClashDetector(
|
||||
conflictingJvmDeclarationsData: ConflictingJvmDeclarationsData
|
||||
) {
|
||||
irDeclarations.mapNotNullTo(LinkedHashSet()) { irDeclaration ->
|
||||
context.ktDiagnosticReporter.atFirstValidFrom(irDeclaration, irClass, containingIrFile = irDeclaration.file)
|
||||
classCodegen.context.ktDiagnosticReporter.atFirstValidFrom(irDeclaration, classCodegen.irClass, containingIrFile = irDeclaration.file)
|
||||
}.forEach {
|
||||
it.report(diagnosticFactory1, conflictingJvmDeclarationsData)
|
||||
}
|
||||
@@ -161,7 +157,7 @@ class JvmSignatureClashDetector(
|
||||
methods: Collection<IrDeclaration>
|
||||
): ConflictingJvmDeclarationsData =
|
||||
ConflictingJvmDeclarationsData(
|
||||
type.internalName,
|
||||
classCodegen.type.internalName,
|
||||
classOrigin,
|
||||
rawSignature,
|
||||
methods.map { it.getJvmDeclarationOrigin() }
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ fun JvmBackendContext.getSourceMapper(declaration: IrClass): SourceMapper {
|
||||
return SourceMapper(
|
||||
SourceInfo(
|
||||
sourceFileName,
|
||||
typeMapper.mapClass(declaration).internalName,
|
||||
defaultTypeMapper.mapClass(declaration).internalName,
|
||||
endLineNumber + 1
|
||||
)
|
||||
)
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.mapping.mapClass
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
@@ -27,10 +27,10 @@ object ArrayIterator : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction {
|
||||
val owner = context.typeMapper.mapClass(expression.symbol.owner.parentAsClass)
|
||||
return IrIntrinsicFunction.create(expression, signature, context, owner) {
|
||||
val owner = classCodegen.typeMapper.mapClass(expression.symbol.owner.parentAsClass)
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen, owner) {
|
||||
val methodSignature = "(${owner.descriptor})${signature.returnType.descriptor}"
|
||||
val intrinsicOwner =
|
||||
if (AsmUtil.isPrimitive(owner.elementType))
|
||||
|
||||
+3
-4
@@ -16,15 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
|
||||
object ArraySize : IntrinsicMethod() {
|
||||
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, context) {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen) {
|
||||
it.arraylength()
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil.numberFunctionOperandType
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
@@ -34,7 +34,7 @@ class BinaryOp(private val opcode: Int) : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction {
|
||||
val returnType = signature.returnType
|
||||
val intermediateResultType = numberFunctionOperandType(returnType)
|
||||
@@ -44,7 +44,7 @@ class BinaryOp(private val opcode: Int) : IntrinsicMethod() {
|
||||
listOf(Type.CHAR_TYPE, signature.valueParameters[0].asmType)
|
||||
}
|
||||
|
||||
return IrIntrinsicFunction.create(expression, signature, context, argTypes) {
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen, argTypes) {
|
||||
it.visitInsn(returnType.getOpcode(opcode))
|
||||
StackValue.coerce(intermediateResultType, returnType, it)
|
||||
}
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
@@ -31,15 +31,15 @@ object Clone : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction {
|
||||
val isSuperCall = expression is IrCall && expression.superQualifierSymbol != null
|
||||
val opcode = if (isSuperCall) Opcodes.INVOKESPECIAL else Opcodes.INVOKEVIRTUAL
|
||||
val newSignature = signature.newReturnType(AsmTypes.OBJECT_TYPE)
|
||||
val argTypes0 = expression.argTypes(context)
|
||||
val argTypes0 = expression.argTypes(classCodegen)
|
||||
// Don't upcast receiver to java.lang.Cloneable, since 'clone' is protected in java.lang.Object.
|
||||
val argTypes = if (isSuperCall || argTypes0[0] == CLONEABLE_TYPE) listOf(AsmTypes.OBJECT_TYPE) else argTypes0
|
||||
return IrIntrinsicFunction.create(expression, newSignature, context, argTypes) { mv ->
|
||||
return IrIntrinsicFunction.create(expression, newSignature, classCodegen, argTypes) { mv ->
|
||||
mv.visitMethodInsn(opcode, "java/lang/Object", "clone", "()Ljava/lang/Object;", false)
|
||||
}
|
||||
}
|
||||
|
||||
+6
-7
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmSymbols
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.*
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.isSmartcastFromHigherThanNullable
|
||||
@@ -40,7 +39,7 @@ import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
|
||||
object CompareTo : IntrinsicMethod() {
|
||||
private fun genInvoke(type: Type?, v: InstructionAdapter, context: JvmBackendContext) {
|
||||
private fun genInvoke(type: Type?, v: InstructionAdapter, classCodegen: ClassCodegen) {
|
||||
when (type) {
|
||||
Type.CHAR_TYPE, Type.BYTE_TYPE, Type.SHORT_TYPE, Type.INT_TYPE ->
|
||||
v.invokestatic(JvmSymbols.INTRINSICS_CLASS_NAME, "compare", "(II)I", false)
|
||||
@@ -50,7 +49,7 @@ object CompareTo : IntrinsicMethod() {
|
||||
Type.BOOLEAN_TYPE -> {
|
||||
// We could support it for JVM target 1.6, but it's prohibited now anyway (except for stdlib, which doesn't have such code),
|
||||
// so throwing an exception instead.
|
||||
check(context.state.target >= JvmTarget.JVM_1_8) {
|
||||
check(classCodegen.context.state.target >= JvmTarget.JVM_1_8) {
|
||||
"Cannot generate boolean comparison for JVM target 1.6"
|
||||
}
|
||||
v.invokestatic("java/lang/Boolean", "compare", "(ZZ)I", false)
|
||||
@@ -62,16 +61,16 @@ object CompareTo : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction {
|
||||
val callee = expression.symbol.owner
|
||||
val calleeParameter = callee.dispatchReceiverParameter ?: callee.extensionReceiverParameter!!
|
||||
val parameterType = comparisonOperandType(
|
||||
context.typeMapper.mapType(calleeParameter.type),
|
||||
classCodegen.typeMapper.mapType(calleeParameter.type),
|
||||
signature.valueParameters.single().asmType,
|
||||
)
|
||||
return IrIntrinsicFunction.create(expression, signature, context, listOf(parameterType, parameterType)) {
|
||||
genInvoke(parameterType, it, context)
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen, listOf(parameterType, parameterType)) {
|
||||
genInvoke(parameterType, it, classCodegen)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-6
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.*
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.isSmartcastFromHigherThanNullable
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.receiverAndArgs
|
||||
@@ -155,12 +154,12 @@ class Ieee754Equals(val operandType: Type) : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction {
|
||||
class Ieee754AreEqual(
|
||||
val left: Type,
|
||||
val right: Type
|
||||
) : IrIntrinsicFunction(expression, signature, context, listOf(left, right)) {
|
||||
) : IrIntrinsicFunction(expression, signature, classCodegen, listOf(left, right)) {
|
||||
override fun genInvokeInstruction(v: InstructionAdapter) {
|
||||
v.invokestatic(
|
||||
IntrinsicMethods.INTRINSICS_CLASS_NAME, "areEqual",
|
||||
@@ -185,15 +184,15 @@ class Ieee754Equals(val operandType: Type) : IntrinsicMethod() {
|
||||
val arg1isNullable = arg1Type.isNullable()
|
||||
|
||||
val useNonIEEE754Comparison =
|
||||
!context.state.languageVersionSettings.supportsFeature(LanguageFeature.ProperIeee754Comparisons)
|
||||
&& (arg0.isSmartcastFromHigherThanNullable(context) || arg1.isSmartcastFromHigherThanNullable(context))
|
||||
!classCodegen.context.state.languageVersionSettings.supportsFeature(LanguageFeature.ProperIeee754Comparisons)
|
||||
&& (arg0.isSmartcastFromHigherThanNullable(classCodegen.context) || arg1.isSmartcastFromHigherThanNullable(classCodegen.context))
|
||||
|
||||
return when {
|
||||
useNonIEEE754Comparison ->
|
||||
Ieee754AreEqual(AsmTypes.OBJECT_TYPE, AsmTypes.OBJECT_TYPE)
|
||||
|
||||
!arg0isNullable && !arg1isNullable ->
|
||||
object : IrIntrinsicFunction(expression, signature, context, listOf(operandType, operandType)) {
|
||||
object : IrIntrinsicFunction(expression, signature, classCodegen, listOf(operandType, operandType)) {
|
||||
override fun genInvokeInstruction(v: InstructionAdapter) {
|
||||
StackValue.cmp(KtTokens.EQEQ, operandType, StackValue.onStack(operandType), StackValue.onStack(operandType))
|
||||
.put(Type.BOOLEAN_TYPE, v)
|
||||
|
||||
+3
-3
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.codegen.DescriptorAsmUtil.genIncrement
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
|
||||
class Increment(private val myDelta: Int) : IntrinsicMethod() {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, context) {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen) {
|
||||
genIncrement(signature.returnType, myDelta, it)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-17
@@ -6,14 +6,8 @@
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.IntrinsicMarker
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.MaterialValue
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.PromisedValue
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.commons.Method
|
||||
@@ -22,27 +16,19 @@ abstract class IntrinsicMethod : IntrinsicMarker {
|
||||
open fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction = TODO("implement toCallable() or invoke() of $this")
|
||||
|
||||
open fun invoke(expression: IrFunctionAccessExpression, codegen: ExpressionCodegen, data: BlockInfo): PromisedValue? =
|
||||
with(codegen) {
|
||||
val descriptor = methodSignatureMapper.mapSignatureSkipGeneric(expression.symbol.owner)
|
||||
val stackValue = toCallable(expression, descriptor, context).invoke(mv, codegen, data, expression)
|
||||
val stackValue = toCallable(expression, descriptor, codegen.classCodegen).invoke(mv, codegen, data, expression)
|
||||
stackValue.put(mv)
|
||||
return MaterialValue(this, stackValue.type, expression.type)
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
fun calcReceiverType(call: IrMemberAccessExpression<*>, context: JvmBackendContext): Type {
|
||||
return context.typeMapper.mapType(call.dispatchReceiver?.type ?: call.extensionReceiver!!.type)
|
||||
}
|
||||
|
||||
fun expressionType(expression: IrExpression, context: JvmBackendContext): Type {
|
||||
return context.typeMapper.mapType(expression.type)
|
||||
}
|
||||
|
||||
fun JvmMethodSignature.newReturnType(type: Type): JvmMethodSignature {
|
||||
val newMethod = with(asmMethod) {
|
||||
Method(name, type, argumentTypes)
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
@@ -14,7 +14,7 @@ object IntrinsicShouldHaveBeenLowered : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction {
|
||||
error("Intrinsic should have been lowered: '${expression.symbol.owner.render()}'")
|
||||
}
|
||||
|
||||
+3
-4
@@ -16,19 +16,18 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil.numberFunctionOperandType
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
object Inv : IntrinsicMethod() {
|
||||
/*TODO new this type*/
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen): IrIntrinsicFunction {
|
||||
val returnType = signature.returnType
|
||||
val type = numberFunctionOperandType(returnType)
|
||||
return IrIntrinsicFunction.create(expression, signature, context, type) {
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen, type) {
|
||||
if (returnType == Type.LONG_TYPE) {
|
||||
it.lconst(-1)
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ object IrDataClassArrayMemberHashCode : IntrinsicMethod() {
|
||||
override fun invoke(expression: IrFunctionAccessExpression, codegen: ExpressionCodegen, data: BlockInfo): PromisedValue? =
|
||||
with(codegen) {
|
||||
val arrayType = expression.getValueArgument(0)!!.type
|
||||
val asmArrayType = context.typeMapper.mapType(arrayType)
|
||||
val asmArrayType = codegen.typeMapper.mapType(arrayType)
|
||||
gen(expression.getValueArgument(0)!!, asmArrayType, arrayType, data)
|
||||
val hashCodeArgumentDescriptor = if (arrayType.isPrimitiveArray()) asmArrayType.descriptor else "[Ljava/lang/Object;"
|
||||
mv.invokestatic("java/util/Arrays", "hashCode", "($hashCodeArgumentDescriptor)I", false)
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ object IrDataClassArrayMemberToString : IntrinsicMethod() {
|
||||
override fun invoke(expression: IrFunctionAccessExpression, codegen: ExpressionCodegen, data: BlockInfo): PromisedValue? =
|
||||
with(codegen) {
|
||||
val arrayType = expression.getValueArgument(0)!!.type
|
||||
val asmArrayType = context.typeMapper.mapType(arrayType)
|
||||
val asmArrayType = codegen.typeMapper.mapType(arrayType)
|
||||
gen(expression.getValueArgument(0)!!, asmArrayType, arrayType, data)
|
||||
val toStringArgumentDescriptor = if (arrayType.isPrimitiveArray()) asmArrayType.descriptor else "[Ljava/lang/Object;"
|
||||
mv.invokestatic("java/util/Arrays", "toString", "($toStringArgumentDescriptor)Ljava/lang/String;", false)
|
||||
|
||||
+3
-3
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
@@ -32,9 +32,9 @@ object IrIllegalArgumentException : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction {
|
||||
return object : IrIntrinsicFunction(expression, signature, context, listOf(JAVA_STRING_TYPE)) {
|
||||
return object : IrIntrinsicFunction(expression, signature, classCodegen, listOf(JAVA_STRING_TYPE)) {
|
||||
override fun genInvokeInstruction(v: InstructionAdapter) {
|
||||
v.invokespecial(
|
||||
exceptionTypeDescriptor.internalName,
|
||||
|
||||
+14
-14
@@ -5,8 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.mapping.mapClass
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
@@ -27,8 +27,8 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
open class IrIntrinsicFunction(
|
||||
val expression: IrFunctionAccessExpression,
|
||||
val signature: JvmMethodSignature,
|
||||
val context: JvmBackendContext,
|
||||
val argsTypes: List<Type> = expression.argTypes(context)
|
||||
val classCodegen: ClassCodegen,
|
||||
val argsTypes: List<Type> = expression.argTypes(classCodegen)
|
||||
) : Callable {
|
||||
override val owner: Type
|
||||
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
|
||||
@@ -110,11 +110,11 @@ open class IrIntrinsicFunction(
|
||||
fun create(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext,
|
||||
argsTypes: List<Type> = expression.argTypes(context),
|
||||
classCodegen: ClassCodegen,
|
||||
argsTypes: List<Type> = expression.argTypes(classCodegen),
|
||||
invokeInstruction: IrIntrinsicFunction.(InstructionAdapter) -> Unit
|
||||
): IrIntrinsicFunction {
|
||||
return object : IrIntrinsicFunction(expression, signature, context, argsTypes) {
|
||||
return object : IrIntrinsicFunction(expression, signature, classCodegen, argsTypes) {
|
||||
|
||||
override fun genInvokeInstruction(v: InstructionAdapter) = invokeInstruction(v)
|
||||
}
|
||||
@@ -122,11 +122,11 @@ open class IrIntrinsicFunction(
|
||||
|
||||
fun createWithResult(
|
||||
expression: IrFunctionAccessExpression, signature: JvmMethodSignature,
|
||||
context: JvmBackendContext,
|
||||
argsTypes: List<Type> = expression.argTypes(context),
|
||||
classCodegen: ClassCodegen,
|
||||
argsTypes: List<Type> = expression.argTypes(classCodegen ),
|
||||
invokeInstruction: IrIntrinsicFunction.(InstructionAdapter) -> Type
|
||||
): IrIntrinsicFunction {
|
||||
return object : IrIntrinsicFunction(expression, signature, context, argsTypes) {
|
||||
return object : IrIntrinsicFunction(expression, signature, classCodegen, argsTypes) {
|
||||
|
||||
override fun genInvokeInstructionWithResult(v: InstructionAdapter) = invokeInstruction(v)
|
||||
}
|
||||
@@ -135,21 +135,21 @@ open class IrIntrinsicFunction(
|
||||
fun create(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext,
|
||||
classCodegen: ClassCodegen,
|
||||
type: Type,
|
||||
invokeInstruction: IrIntrinsicFunction.(InstructionAdapter) -> Unit
|
||||
): IrIntrinsicFunction {
|
||||
return create(expression, signature, context, listOf(type), invokeInstruction)
|
||||
return create(expression, signature, classCodegen, listOf(type), invokeInstruction)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun IrFunctionAccessExpression.argTypes(context: JvmBackendContext): ArrayList<Type> {
|
||||
fun IrFunctionAccessExpression.argTypes(classCodegen: ClassCodegen): ArrayList<Type> {
|
||||
val callee = symbol.owner
|
||||
val signature = context.methodSignatureMapper.mapSignatureSkipGeneric(callee)
|
||||
val signature = classCodegen.methodSignatureMapper.mapSignatureSkipGeneric(callee)
|
||||
return arrayListOf<Type>().apply {
|
||||
if (dispatchReceiver != null) {
|
||||
add(context.typeMapper.mapClass(callee.parentAsClass))
|
||||
add(classCodegen.typeMapper.mapClass(callee.parentAsClass))
|
||||
}
|
||||
addAll(signature.asmMethod.argumentTypes)
|
||||
}
|
||||
|
||||
+3
-4
@@ -16,15 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil.genThrow
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
|
||||
object IrNoWhenBranchMatchedException : IntrinsicMethod() {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, context) {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen) {
|
||||
genThrow(it, "kotlin/NoWhenBranchMatchedException", null)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.types.typeWith
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
@@ -14,9 +14,9 @@ object IsArrayOf : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
): IrIntrinsicFunction = IrIntrinsicFunction.create(expression, signature, context) { v ->
|
||||
val arrayType = context.irBuiltIns.arrayClass.typeWith(expression.getTypeArgument(0)!!)
|
||||
v.instanceOf(context.typeMapper.mapType(arrayType))
|
||||
classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction = IrIntrinsicFunction.create(expression, signature, classCodegen) { v ->
|
||||
val arrayType = classCodegen.context.irBuiltIns.arrayClass.typeWith(expression.getTypeArgument(0)!!)
|
||||
v.instanceOf(classCodegen.typeMapper.mapType(arrayType))
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -16,25 +16,24 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.COLLECTIONS_PACKAGE_FQ_NAME
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.fileClasses.internalNameWithoutInnerClasses
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
|
||||
object IteratorNext : IntrinsicMethod() {
|
||||
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen): IrIntrinsicFunction {
|
||||
// If the array element type is unboxed primitive, do not unbox. Otherwise AsmUtil.unbox throws exception
|
||||
val type = if (AsmUtil.isBoxedPrimitiveType(signature.returnType)) AsmUtil.unboxType(signature.returnType) else signature.returnType
|
||||
val newSignature = signature.newReturnType(type)
|
||||
val primitiveClassName = getKotlinPrimitiveClassName(type)
|
||||
return IrIntrinsicFunction.create(expression, newSignature, context, getPrimitiveIteratorType(primitiveClassName)) {
|
||||
return IrIntrinsicFunction.create(expression, newSignature, classCodegen, getPrimitiveIteratorType(primitiveClassName)) {
|
||||
it.invokevirtual(
|
||||
getPrimitiveIteratorType(primitiveClassName).internalName,
|
||||
"next${primitiveClassName.asString()}",
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ object JvmInvokeDynamic : IntrinsicMethod() {
|
||||
}
|
||||
|
||||
private fun generateMethodHandle(irRawFunctionReference: IrRawFunctionReference, codegen: ExpressionCodegen): Handle =
|
||||
codegen.context.methodSignatureMapper.mapToMethodHandle(irRawFunctionReference.symbol.owner)
|
||||
codegen.methodSignatureMapper.mapToMethodHandle(irRawFunctionReference.symbol.owner)
|
||||
|
||||
private fun evalOriginalMethodType(irCall: IrCall, codegen: ExpressionCodegen): Type {
|
||||
val irRawFunRef = irCall.getValueArgument(0) as? IrRawFunctionReference
|
||||
|
||||
+3
-4
@@ -16,9 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||
@@ -33,8 +32,8 @@ class MonitorInstruction private constructor(private val opcode: Int) : Intrinsi
|
||||
}
|
||||
|
||||
/*TODO void return type*/
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, context, OBJECT_TYPE) {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen, OBJECT_TYPE) {
|
||||
it.visitInsn(opcode)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -16,16 +16,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
|
||||
object NumberCast : IntrinsicMethod() {
|
||||
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, context) {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen) {
|
||||
StackValue.coerce(argsTypes[0], signature.returnType, it)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -5,21 +5,21 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
|
||||
object RangeTo : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext
|
||||
expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction {
|
||||
val argType = mapRangeTypeToPrimitiveType(signature.returnType)
|
||||
return object : IrIntrinsicFunction(expression, signature, context, listOf(argType) + signature.valueParameters.map { argType }) {
|
||||
return object : IrIntrinsicFunction(expression, signature, classCodegen, listOf(argType) + signature.valueParameters.map { argType }) {
|
||||
override fun genInvokeInstruction(v: InstructionAdapter) {
|
||||
v.invokespecial(
|
||||
signature.returnType.internalName,
|
||||
|
||||
+4
-4
@@ -5,17 +5,17 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
|
||||
object RangeUntil : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext
|
||||
expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction {
|
||||
return object : IrIntrinsicFunction(expression, signature, context) {
|
||||
return object : IrIntrinsicFunction(expression, signature, classCodegen) {
|
||||
override fun genInvokeInstruction(v: InstructionAdapter) {
|
||||
v.invokestatic(
|
||||
"kotlin/ranges/RangesKt", "until",
|
||||
|
||||
+5
-9
@@ -5,11 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.MaterialValue
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.PromisedValue
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
@@ -26,16 +22,16 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
object SignatureString : IntrinsicMethod() {
|
||||
override fun invoke(expression: IrFunctionAccessExpression, codegen: ExpressionCodegen, data: BlockInfo): PromisedValue {
|
||||
val function = (expression.getValueArgument(0) as IrFunctionReference).symbol.owner
|
||||
generateSignatureString(codegen.mv, function, codegen.context)
|
||||
generateSignatureString(codegen.mv, function, codegen.classCodegen)
|
||||
return MaterialValue(codegen, AsmTypes.JAVA_STRING_TYPE, codegen.context.irBuiltIns.stringType)
|
||||
}
|
||||
|
||||
internal fun generateSignatureString(v: InstructionAdapter, function: IrFunction, context: JvmBackendContext) {
|
||||
internal fun generateSignatureString(v: InstructionAdapter, function: IrFunction, codegen: ClassCodegen) {
|
||||
var resolved = if (function is IrSimpleFunction) function.collectRealOverrides().first() else function
|
||||
if (resolved.isSuspend) {
|
||||
resolved = context.suspendFunctionOriginalToView[resolved] ?: resolved
|
||||
resolved = codegen.context.suspendFunctionOriginalToView[resolved] ?: resolved
|
||||
}
|
||||
val method = context.methodSignatureMapper.mapAsmMethod(resolved)
|
||||
val method = codegen.methodSignatureMapper.mapAsmMethod(resolved)
|
||||
val descriptor = method.name + method.descriptor
|
||||
v.aconst(descriptor)
|
||||
}
|
||||
|
||||
+3
-4
@@ -16,14 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
|
||||
object StringGetChar : IntrinsicMethod() {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, context) {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen) {
|
||||
it.invokevirtual("java/lang/String", "charAt", "(I)C", false)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
@@ -17,9 +17,9 @@ object StringPlus : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction =
|
||||
IrIntrinsicFunction.create(expression, signature, context, listOf(AsmTypes.JAVA_STRING_TYPE, AsmTypes.OBJECT_TYPE)) {
|
||||
IrIntrinsicFunction.create(expression, signature, classCodegen, listOf(AsmTypes.JAVA_STRING_TYPE, AsmTypes.OBJECT_TYPE)) {
|
||||
it.invokestatic(
|
||||
IntrinsicMethods.INTRINSICS_CLASS_NAME,
|
||||
"stringPlus",
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.Type
|
||||
@@ -14,10 +14,10 @@ object ThrowKotlinNothingValueException : IntrinsicMethod() {
|
||||
override fun toCallable(
|
||||
expression: IrFunctionAccessExpression,
|
||||
signature: JvmMethodSignature,
|
||||
context: JvmBackendContext
|
||||
classCodegen: ClassCodegen
|
||||
): IrIntrinsicFunction =
|
||||
IrIntrinsicFunction.create(expression, signature, context) { mv ->
|
||||
if (context.state.useKotlinNothingValueException) {
|
||||
IrIntrinsicFunction.create(expression, signature, classCodegen) { mv ->
|
||||
if (classCodegen.context.state.useKotlinNothingValueException) {
|
||||
mv.anew(Type.getObjectType("kotlin/KotlinNothingValueException"))
|
||||
mv.dup()
|
||||
mv.invokespecial("kotlin/KotlinNothingValueException", "<init>", "()V", false)
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ object TypeOf : IntrinsicMethod() {
|
||||
if (putReifiedOperationMarkerIfTypeIsReifiedParameter(type, ReifiedTypeInliner.OperationKind.TYPE_OF)) {
|
||||
mv.aconst(null) // see ReifiedTypeInliner.processTypeOf
|
||||
} else {
|
||||
val support = IrInlineIntrinsicsSupport(context, typeMapper, expression, codegen.irFunction.fileParent)
|
||||
val support = IrInlineIntrinsicsSupport(codegen.classCodegen, expression, codegen.irFunction.fileParent)
|
||||
typeMapper.typeSystem.generateTypeOf(mv, type, support)
|
||||
}
|
||||
expression.onStack
|
||||
|
||||
+3
-5
@@ -16,17 +16,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil.numberFunctionOperandType
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
|
||||
object UnaryMinus : IntrinsicMethod() {
|
||||
/*TODO return type*/
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, context) {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen) {
|
||||
it.neg(numberFunctionOperandType(signature.returnType))
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -16,14 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
|
||||
object UnaryPlus : IntrinsicMethod() {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, context) {
|
||||
override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, classCodegen: ClassCodegen): IrIntrinsicFunction {
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user