[Native] Support evaluation of const intrinsics for K2

#KT-56023
#KT-55469 Fixed
This commit is contained in:
Ivan Kylchik
2023-02-03 14:53:15 +01:00
committed by Space Team
parent 5d5582d201
commit e981b1f958
34 changed files with 264 additions and 60 deletions
@@ -1,6 +1,3 @@
// KT-55469
// IGNORE_BACKEND_K2: NATIVE
fun equals1(a: Double, b: Double) = a.equals(b)
fun box(): String {
@@ -1,5 +1,3 @@
// KT-55469
// IGNORE_BACKEND_K2: NATIVE
// WITH_STDLIB
fun foo(): Array<Boolean> {
return arrayOf(
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_K2: NATIVE
// WITH_STDLIB
const val a = "INT " + 0x8fffffffU
@@ -1,6 +1,3 @@
// KT-55469
// IGNORE_BACKEND_K2: NATIVE
fun equals1(a: Double, b: Double) = a.equals(b)
fun equals2(a: Double?, b: Double?) = a!!.equals(b!!)
@@ -1,4 +1,7 @@
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: NATIVE
// `Boolean.equals(Boolean)` will not be evaluated in K1
// IGNORE_BACKEND_K1: NATIVE
const val trueVal = true
const val falseVal = false
@@ -1,5 +1,6 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM_IR, NATIVE
const val minusOneVal = (-1).toByte()
const val oneVal = 1.toByte()
@@ -1,4 +1,7 @@
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: NATIVE
// `Char.equals(Char)` will not be evaluated in K1
// IGNORE_BACKEND_K1: NATIVE
// WITH_STDLIB
const val oneVal = '1'
@@ -1,5 +1,6 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM_IR, NATIVE
const val minusOneVal = -1.0
const val oneVal = 1.0
@@ -1,6 +1,6 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// IGNORE_FIR_DIAGNOSTICS
// IGNORE_BACKEND_K1: JVM_IR
// !DIAGNOSTICS: -UNINITIALIZED_ENUM_ENTRY
enum class TestEnum(val testNaming: String) {
@@ -1,5 +1,6 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM_IR, NATIVE
const val minusOneVal = -1.0f
const val oneVal = 1.0f
@@ -1,6 +1,7 @@
// !LANGUAGE: +IntrinsicConstEvaluation
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM_IR, NATIVE
const val flag = true
const val value = 10
@@ -1,5 +1,6 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM_IR, NATIVE
const val minusOneVal = -1
const val oneVal = 1
@@ -1,5 +1,6 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM_IR, NATIVE
const val minusOneVal = -1L
const val oneVal = 1L
@@ -1,5 +1,6 @@
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: NATIVE
// IGNORE_BACKEND_K1: JVM_IR, NATIVE
const val minusOneVal = (-1).toShort()
const val oneVal = 1.toShort()
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: NATIVE
// WITH_STDLIB
const val code = '1'.code
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: NATIVE
const val someStr = "123"
const val otherStr = "other"
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: NATIVE
// WITH_STDLIB
const val byteVal: UByte = 1u
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: NATIVE
object K : Code("K")
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: NATIVE
// WITH_STDLIB
object Test {
@@ -1,6 +1,4 @@
// KT-3517 Can't call .equals() on a boolean
// KT-55469
// IGNORE_BACKEND_K2: NATIVE
fun box(): String {
val a = false
@@ -1,8 +1,3 @@
// KT-56023
// JS_IR: InterpreterError: Unsupported number of arguments for invocation as builtin function: four
// NATIVE: in mode -Pkotlin.internal.native.test.mode=TWO_STAGE_MULTI_MODULE (default test mode), test fails as below
// InterpreterError: Unsupported number of arguments for invocation as builtin function: four
// in mode -Pkotlin.internal.native.test.mode=ONE_STAGE_MULTI_MODULE, test passes
// IGNORE_BACKEND_K2: NATIVE, JS_IR
// MODULE: lib
@@ -1,7 +1,3 @@
// KT-56023
// JS_IR: IllegalStateException: CONST_VAL_WITH_NON_CONST_INITIALIZER: Const 'val' initializer should be a constant value at (7,18) in /lib.kt
// NATIVE: test fails as below in both modes -Pkotlin.internal.native.test.mode=TWO_STAGE_MULTI_MODULE, -Pkotlin.internal.native.test.mode=ONE_STAGE_MULTI_MODULE
// error: const 'val' initializer should be a constant value
// IGNORE_BACKEND_K2: NATIVE, JS_IR
// MODULE: lib