Add toString, hashCode and equals primitives methods in ir builtin map

This commit is contained in:
Ivan Kylchik
2020-02-29 20:19:32 +03:00
parent 00366197f8
commit 2310a04e4e
2 changed files with 33 additions and 2 deletions
@@ -21,8 +21,11 @@ import org.jetbrains.kotlin.backend.common.interpreter.stack.*
/** This file is generated by org.jetbrains.kotlin.backend.common.interpreter.builtins.GenerateBuiltInsMap.generateMap(). DO NOT MODIFY MANUALLY */
val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
unaryOperation<Boolean>("hashCode", "Boolean") { a -> a.hashCode() },
unaryOperation<Boolean>("not", "Boolean") { a -> a.not() },
unaryOperation<Boolean>("toString", "Boolean") { a -> a.toString() },
unaryOperation<Char>("dec", "Char") { a -> a.dec() },
unaryOperation<Char>("hashCode", "Char") { a -> a.hashCode() },
unaryOperation<Char>("inc", "Char") { a -> a.inc() },
unaryOperation<Char>("toByte", "Char") { a -> a.toByte() },
unaryOperation<Char>("toChar", "Char") { a -> a.toChar() },
@@ -31,7 +34,9 @@ val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
unaryOperation<Char>("toInt", "Char") { a -> a.toInt() },
unaryOperation<Char>("toLong", "Char") { a -> a.toLong() },
unaryOperation<Char>("toShort", "Char") { a -> a.toShort() },
unaryOperation<Char>("toString", "Char") { a -> a.toString() },
unaryOperation<Byte>("dec", "Byte") { a -> a.dec() },
unaryOperation<Byte>("hashCode", "Byte") { a -> a.hashCode() },
unaryOperation<Byte>("inc", "Byte") { a -> a.inc() },
unaryOperation<Byte>("toByte", "Byte") { a -> a.toByte() },
unaryOperation<Byte>("toChar", "Byte") { a -> a.toChar() },
@@ -40,9 +45,11 @@ val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
unaryOperation<Byte>("toInt", "Byte") { a -> a.toInt() },
unaryOperation<Byte>("toLong", "Byte") { a -> a.toLong() },
unaryOperation<Byte>("toShort", "Byte") { a -> a.toShort() },
unaryOperation<Byte>("toString", "Byte") { a -> a.toString() },
unaryOperation<Byte>("unaryMinus", "Byte") { a -> a.unaryMinus() },
unaryOperation<Byte>("unaryPlus", "Byte") { a -> a.unaryPlus() },
unaryOperation<Short>("dec", "Short") { a -> a.dec() },
unaryOperation<Short>("hashCode", "Short") { a -> a.hashCode() },
unaryOperation<Short>("inc", "Short") { a -> a.inc() },
unaryOperation<Short>("toByte", "Short") { a -> a.toByte() },
unaryOperation<Short>("toChar", "Short") { a -> a.toChar() },
@@ -51,9 +58,11 @@ val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
unaryOperation<Short>("toInt", "Short") { a -> a.toInt() },
unaryOperation<Short>("toLong", "Short") { a -> a.toLong() },
unaryOperation<Short>("toShort", "Short") { a -> a.toShort() },
unaryOperation<Short>("toString", "Short") { a -> a.toString() },
unaryOperation<Short>("unaryMinus", "Short") { a -> a.unaryMinus() },
unaryOperation<Short>("unaryPlus", "Short") { a -> a.unaryPlus() },
unaryOperation<Int>("dec", "Int") { a -> a.dec() },
unaryOperation<Int>("hashCode", "Int") { a -> a.hashCode() },
unaryOperation<Int>("inc", "Int") { a -> a.inc() },
unaryOperation<Int>("inv", "Int") { a -> a.inv() },
unaryOperation<Int>("toByte", "Int") { a -> a.toByte() },
@@ -63,9 +72,11 @@ val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
unaryOperation<Int>("toInt", "Int") { a -> a.toInt() },
unaryOperation<Int>("toLong", "Int") { a -> a.toLong() },
unaryOperation<Int>("toShort", "Int") { a -> a.toShort() },
unaryOperation<Int>("toString", "Int") { a -> a.toString() },
unaryOperation<Int>("unaryMinus", "Int") { a -> a.unaryMinus() },
unaryOperation<Int>("unaryPlus", "Int") { a -> a.unaryPlus() },
unaryOperation<Float>("dec", "Float") { a -> a.dec() },
unaryOperation<Float>("hashCode", "Float") { a -> a.hashCode() },
unaryOperation<Float>("inc", "Float") { a -> a.inc() },
unaryOperation<Float>("toByte", "Float") { a -> a.toByte() },
unaryOperation<Float>("toChar", "Float") { a -> a.toChar() },
@@ -74,9 +85,11 @@ val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
unaryOperation<Float>("toInt", "Float") { a -> a.toInt() },
unaryOperation<Float>("toLong", "Float") { a -> a.toLong() },
unaryOperation<Float>("toShort", "Float") { a -> a.toShort() },
unaryOperation<Float>("toString", "Float") { a -> a.toString() },
unaryOperation<Float>("unaryMinus", "Float") { a -> a.unaryMinus() },
unaryOperation<Float>("unaryPlus", "Float") { a -> a.unaryPlus() },
unaryOperation<Long>("dec", "Long") { a -> a.dec() },
unaryOperation<Long>("hashCode", "Long") { a -> a.hashCode() },
unaryOperation<Long>("inc", "Long") { a -> a.inc() },
unaryOperation<Long>("inv", "Long") { a -> a.inv() },
unaryOperation<Long>("toByte", "Long") { a -> a.toByte() },
@@ -86,9 +99,11 @@ val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
unaryOperation<Long>("toInt", "Long") { a -> a.toInt() },
unaryOperation<Long>("toLong", "Long") { a -> a.toLong() },
unaryOperation<Long>("toShort", "Long") { a -> a.toShort() },
unaryOperation<Long>("toString", "Long") { a -> a.toString() },
unaryOperation<Long>("unaryMinus", "Long") { a -> a.unaryMinus() },
unaryOperation<Long>("unaryPlus", "Long") { a -> a.unaryPlus() },
unaryOperation<Double>("dec", "Double") { a -> a.dec() },
unaryOperation<Double>("hashCode", "Double") { a -> a.hashCode() },
unaryOperation<Double>("inc", "Double") { a -> a.inc() },
unaryOperation<Double>("toByte", "Double") { a -> a.toByte() },
unaryOperation<Double>("toChar", "Double") { a -> a.toChar() },
@@ -97,6 +112,7 @@ val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
unaryOperation<Double>("toInt", "Double") { a -> a.toInt() },
unaryOperation<Double>("toLong", "Double") { a -> a.toLong() },
unaryOperation<Double>("toShort", "Double") { a -> a.toShort() },
unaryOperation<Double>("toString", "Double") { a -> a.toString() },
unaryOperation<Double>("unaryMinus", "Double") { a -> a.unaryMinus() },
unaryOperation<Double>("unaryPlus", "Double") { a -> a.unaryPlus() },
unaryOperation<String>("length", "String") { a -> a.length },
@@ -128,9 +144,11 @@ val unaryFunctions = mapOf<CompileTimeFunction, Function1<Any?, Any?>>(
val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any?>>(
binaryOperation<Boolean, Boolean>("and", "Boolean", "Boolean") { a, b -> a.and(b) },
binaryOperation<Boolean, Boolean>("compareTo", "Boolean", "Boolean") { a, b -> a.compareTo(b) },
binaryOperation<Boolean, Any?>("equals", "Boolean", "Any?") { a, b -> a.equals(b) },
binaryOperation<Boolean, Boolean>("or", "Boolean", "Boolean") { a, b -> a.or(b) },
binaryOperation<Boolean, Boolean>("xor", "Boolean", "Boolean") { a, b -> a.xor(b) },
binaryOperation<Char, Char>("compareTo", "Char", "Char") { a, b -> a.compareTo(b) },
binaryOperation<Char, Any?>("equals", "Char", "Any?") { a, b -> a.equals(b) },
binaryOperation<Char, Char>("minus", "Char", "Char") { a, b -> a.minus(b) },
binaryOperation<Char, Int>("minus", "Char", "Int") { a, b -> a.minus(b) },
binaryOperation<Char, Int>("plus", "Char", "Int") { a, b -> a.plus(b) },
@@ -147,6 +165,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any?>>(
binaryOperation<Byte, Int>("div", "Byte", "Int") { a, b -> a.div(b) },
binaryOperation<Byte, Long>("div", "Byte", "Long") { a, b -> a.div(b) },
binaryOperation<Byte, Short>("div", "Byte", "Short") { a, b -> a.div(b) },
binaryOperation<Byte, Any?>("equals", "Byte", "Any?") { a, b -> a.equals(b) },
binaryOperation<Byte, Byte>("minus", "Byte", "Byte") { a, b -> a.minus(b) },
binaryOperation<Byte, Double>("minus", "Byte", "Double") { a, b -> a.minus(b) },
binaryOperation<Byte, Float>("minus", "Byte", "Float") { a, b -> a.minus(b) },
@@ -187,6 +206,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any?>>(
binaryOperation<Short, Int>("div", "Short", "Int") { a, b -> a.div(b) },
binaryOperation<Short, Long>("div", "Short", "Long") { a, b -> a.div(b) },
binaryOperation<Short, Short>("div", "Short", "Short") { a, b -> a.div(b) },
binaryOperation<Short, Any?>("equals", "Short", "Any?") { a, b -> a.equals(b) },
binaryOperation<Short, Byte>("minus", "Short", "Byte") { a, b -> a.minus(b) },
binaryOperation<Short, Double>("minus", "Short", "Double") { a, b -> a.minus(b) },
binaryOperation<Short, Float>("minus", "Short", "Float") { a, b -> a.minus(b) },
@@ -228,6 +248,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any?>>(
binaryOperation<Int, Int>("div", "Int", "Int") { a, b -> a.div(b) },
binaryOperation<Int, Long>("div", "Int", "Long") { a, b -> a.div(b) },
binaryOperation<Int, Short>("div", "Int", "Short") { a, b -> a.div(b) },
binaryOperation<Int, Any?>("equals", "Int", "Any?") { a, b -> a.equals(b) },
binaryOperation<Int, Byte>("minus", "Int", "Byte") { a, b -> a.minus(b) },
binaryOperation<Int, Double>("minus", "Int", "Double") { a, b -> a.minus(b) },
binaryOperation<Int, Float>("minus", "Int", "Float") { a, b -> a.minus(b) },
@@ -273,6 +294,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any?>>(
binaryOperation<Float, Int>("div", "Float", "Int") { a, b -> a.div(b) },
binaryOperation<Float, Long>("div", "Float", "Long") { a, b -> a.div(b) },
binaryOperation<Float, Short>("div", "Float", "Short") { a, b -> a.div(b) },
binaryOperation<Float, Any?>("equals", "Float", "Any?") { a, b -> a.equals(b) },
binaryOperation<Float, Byte>("minus", "Float", "Byte") { a, b -> a.minus(b) },
binaryOperation<Float, Double>("minus", "Float", "Double") { a, b -> a.minus(b) },
binaryOperation<Float, Float>("minus", "Float", "Float") { a, b -> a.minus(b) },
@@ -310,6 +332,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any?>>(
binaryOperation<Long, Int>("div", "Long", "Int") { a, b -> a.div(b) },
binaryOperation<Long, Long>("div", "Long", "Long") { a, b -> a.div(b) },
binaryOperation<Long, Short>("div", "Long", "Short") { a, b -> a.div(b) },
binaryOperation<Long, Any?>("equals", "Long", "Any?") { a, b -> a.equals(b) },
binaryOperation<Long, Byte>("minus", "Long", "Byte") { a, b -> a.minus(b) },
binaryOperation<Long, Double>("minus", "Long", "Double") { a, b -> a.minus(b) },
binaryOperation<Long, Float>("minus", "Long", "Float") { a, b -> a.minus(b) },
@@ -355,6 +378,7 @@ val binaryFunctions = mapOf<CompileTimeFunction, Function2<Any?, Any?, Any?>>(
binaryOperation<Double, Int>("div", "Double", "Int") { a, b -> a.div(b) },
binaryOperation<Double, Long>("div", "Double", "Long") { a, b -> a.div(b) },
binaryOperation<Double, Short>("div", "Double", "Short") { a, b -> a.div(b) },
binaryOperation<Double, Any?>("equals", "Double", "Any?") { a, b -> a.equals(b) },
binaryOperation<Double, Byte>("minus", "Double", "Byte") { a, b -> a.minus(b) },
binaryOperation<Double, Double>("minus", "Double", "Double") { a, b -> a.minus(b) },
binaryOperation<Double, Float>("minus", "Double", "Float") { a, b -> a.minus(b) },
+9 -2
View File
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.generators.evaluate
import org.jetbrains.kotlin.backend.common.interpreter.builtins.compileTimeAnnotation
import org.jetbrains.kotlin.backend.jvm.serialization.JvmIdSignatureDescriptor
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.PrimitiveType
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.LanguageVersion
@@ -88,8 +89,14 @@ private fun getOperationMap(argumentsCount: Int): MutableMap<CallableDescriptor,
val arrays = PrimitiveType.values().map { builtIns.getPrimitiveArrayClassDescriptor(it) } + builtIns.array
fun CallableDescriptor.isCompileTime(classDescriptor: ClassDescriptor): Boolean {
return (this as? FunctionDescriptor)?.kind != CallableMemberDescriptor.Kind.FAKE_OVERRIDE &&
(this.annotations.hasAnnotation(compileTimeAnnotation) || classDescriptor.annotations.hasAnnotation(compileTimeAnnotation))
val thisIsCompileTime = this.annotations.hasAnnotation(compileTimeAnnotation)
val classIsCompileTime = classDescriptor.annotations.hasAnnotation(compileTimeAnnotation)
val isPrimitive = KotlinBuiltIns.isPrimitiveClass(classDescriptor)
val isFakeOverridden = (this as? FunctionDescriptor)?.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE
return when {
isPrimitive -> thisIsCompileTime || classIsCompileTime
else -> !isFakeOverridden && (thisIsCompileTime || classIsCompileTime)
}
}
for (classDescriptor in allPrimitiveTypes + builtIns.string + arrays + builtIns.any) {