JVM: remove most usages of JvmTarget.JVM_1_6
This commit is contained in:
committed by
Space Team
parent
75197d1b86
commit
fb900d2e2a
+39
-43
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.TypeAnnotationCollector
|
||||
import org.jetbrains.kotlin.codegen.TypePathInfo
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.config.JvmTarget.JVM_1_6
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
|
||||
@@ -292,50 +291,48 @@ abstract class AnnotationCodegen(
|
||||
boundType: Int,
|
||||
visitor: (typeRef: Int, typePath: TypePath?, descriptor: String, visible: Boolean) -> AnnotationVisitor
|
||||
) {
|
||||
if (context.state.target != JVM_1_6) {
|
||||
typeParameterContainer.typeParameters.forEachIndexed { index, typeParameter ->
|
||||
object : AnnotationCodegen(classCodegen, true) {
|
||||
override fun visitAnnotation(descr: String, visible: Boolean): AnnotationVisitor {
|
||||
typeParameterContainer.typeParameters.forEachIndexed { index, typeParameter ->
|
||||
object : AnnotationCodegen(classCodegen, true) {
|
||||
override fun visitAnnotation(descr: String, visible: Boolean): AnnotationVisitor {
|
||||
|
||||
return visitor(
|
||||
TypeReference.newTypeParameterReference(referenceType, index).value,
|
||||
null,
|
||||
descr,
|
||||
visible
|
||||
)
|
||||
}
|
||||
return visitor(
|
||||
TypeReference.newTypeParameterReference(referenceType, index).value,
|
||||
null,
|
||||
descr,
|
||||
visible
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitTypeAnnotation(descr: String, path: TypePath?, visible: Boolean): AnnotationVisitor {
|
||||
throw RuntimeException(
|
||||
"Error during generation: type annotation shouldn't be presented on type parameter: " +
|
||||
"${ir2string(typeParameter)} in ${ir2string(typeParameterContainer)}"
|
||||
)
|
||||
}
|
||||
}.genAnnotations(typeParameter, null, null)
|
||||
override fun visitTypeAnnotation(descr: String, path: TypePath?, visible: Boolean): AnnotationVisitor {
|
||||
throw RuntimeException(
|
||||
"Error during generation: type annotation shouldn't be presented on type parameter: " +
|
||||
"${ir2string(typeParameter)} in ${ir2string(typeParameterContainer)}"
|
||||
)
|
||||
}
|
||||
}.genAnnotations(typeParameter, null, null)
|
||||
|
||||
if (context.state.configuration.getBoolean(JVMConfigurationKeys.EMIT_JVM_TYPE_ANNOTATIONS)) {
|
||||
var superInterfaceIndex = 1
|
||||
typeParameter.superTypes.forEach { superType ->
|
||||
val isClassOrTypeParameter = !superType.isInterface() && !superType.isAnnotation()
|
||||
val superIndex = if (isClassOrTypeParameter) 0 else superInterfaceIndex++
|
||||
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: " +
|
||||
"${ir2string(typeParameter)} in ${ir2string(typeParameter)}"
|
||||
)
|
||||
}
|
||||
if (context.state.configuration.getBoolean(JVMConfigurationKeys.EMIT_JVM_TYPE_ANNOTATIONS)) {
|
||||
var superInterfaceIndex = 1
|
||||
typeParameter.superTypes.forEach { superType ->
|
||||
val isClassOrTypeParameter = !superType.isInterface() && !superType.isAnnotation()
|
||||
val superIndex = if (isClassOrTypeParameter) 0 else superInterfaceIndex++
|
||||
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: " +
|
||||
"${ir2string(typeParameter)} in ${ir2string(typeParameter)}"
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitTypeAnnotation(descr: String, path: TypePath?, visible: Boolean): AnnotationVisitor {
|
||||
return visitor(
|
||||
TypeReference.newTypeParameterBoundReference(boundType, index, superIndex).value,
|
||||
path,
|
||||
descr,
|
||||
visible
|
||||
)
|
||||
}
|
||||
}.generateTypeAnnotations(typeParameterContainer, superType)
|
||||
}
|
||||
override fun visitTypeAnnotation(descr: String, path: TypePath?, visible: Boolean): AnnotationVisitor {
|
||||
return visitor(
|
||||
TypeReference.newTypeParameterBoundReference(boundType, index, superIndex).value,
|
||||
path,
|
||||
descr,
|
||||
visible
|
||||
)
|
||||
}
|
||||
}.generateTypeAnnotations(typeParameterContainer, superType)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -401,8 +398,7 @@ abstract class AnnotationCodegen(
|
||||
type: IrType?
|
||||
) {
|
||||
if ((annotated as? IrDeclaration)?.origin == JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR ||
|
||||
type == null || context.state.target === JVM_1_6 ||
|
||||
!context.state.configuration.getBoolean(JVMConfigurationKeys.EMIT_JVM_TYPE_ANNOTATIONS)
|
||||
type == null || !context.state.configuration.getBoolean(JVMConfigurationKeys.EMIT_JVM_TYPE_ANNOTATIONS)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
+3
-11
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.codegen.AsmUtil.comparisonOperandType
|
||||
import org.jetbrains.kotlin.codegen.BranchedValue
|
||||
import org.jetbrains.kotlin.codegen.NumberCompare
|
||||
import org.jetbrains.kotlin.codegen.ObjectCompare
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
||||
@@ -39,21 +38,14 @@ 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, classCodegen: ClassCodegen) {
|
||||
private fun genInvoke(type: Type?, v: InstructionAdapter) {
|
||||
when (type) {
|
||||
Type.CHAR_TYPE, Type.BYTE_TYPE, Type.SHORT_TYPE, Type.INT_TYPE ->
|
||||
v.invokestatic(JvmSymbols.INTRINSICS_CLASS_NAME, "compare", "(II)I", false)
|
||||
Type.LONG_TYPE -> v.invokestatic(JvmSymbols.INTRINSICS_CLASS_NAME, "compare", "(JJ)I", false)
|
||||
Type.FLOAT_TYPE -> v.invokestatic("java/lang/Float", "compare", "(FF)I", false)
|
||||
Type.DOUBLE_TYPE -> v.invokestatic("java/lang/Double", "compare", "(DD)I", false)
|
||||
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(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)
|
||||
}
|
||||
Type.BOOLEAN_TYPE -> v.invokestatic("java/lang/Boolean", "compare", "(ZZ)I", false)
|
||||
else -> throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@@ -70,7 +62,7 @@ object CompareTo : IntrinsicMethod() {
|
||||
signature.valueParameters.single().asmType,
|
||||
)
|
||||
return IrIntrinsicFunction.create(expression, signature, classCodegen, listOf(parameterType, parameterType)) {
|
||||
genInvoke(parameterType, it, classCodegen)
|
||||
genInvoke(parameterType, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.*
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.DescriptorAsmUtil
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
@@ -43,7 +42,7 @@ object HashCode : IntrinsicMethod() {
|
||||
// TODO generate or lower IR for data class / value class 'hashCode'?
|
||||
DescriptorAsmUtil.genHashCode(mv, mv, receiverType, target)
|
||||
}
|
||||
target >= JvmTarget.JVM_1_8 && AsmUtil.isPrimitive(receiverJvmType) -> {
|
||||
AsmUtil.isPrimitive(receiverJvmType) -> {
|
||||
val boxedType = AsmUtil.boxPrimitiveType(receiverJvmType)
|
||||
?: throw AssertionError("Primitive type expected: $receiverJvmType")
|
||||
receiverValue.materializeAt(receiverJvmType, receiverIrType)
|
||||
|
||||
Reference in New Issue
Block a user