[IR] Support const optimizations for JS backend

This commit is contained in:
Ivan Kylchik
2023-05-29 00:19:47 +02:00
committed by Space Team
parent abbafc0b2a
commit d3d28783c5
22 changed files with 292 additions and 32 deletions
@@ -1,6 +1,7 @@
// !LANGUAGE: +IntrinsicConstEvaluation
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: JS_IR
// IGNORE_BACKEND_K1: JVM_IR, JS_IR, JS_IR_ES6
// WITH_STDLIB
fun <T> T.id() = this
@@ -1,6 +1,7 @@
// !LANGUAGE: +IntrinsicConstEvaluation
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: JS_IR
// IGNORE_BACKEND_K1: JVM_IR, JS_IR, JS_IR_ES6
// WITH_STDLIB
fun <T> T.id() = this
@@ -1,6 +1,7 @@
// !LANGUAGE: +IntrinsicConstEvaluation
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: JS_IR
// IGNORE_BACKEND_K1: JVM_IR, JS_IR, JS_IR_ES6
fun <T> T.id() = this
enum class EnumClass {
@@ -1,5 +1,6 @@
// !LANGUAGE: +IntrinsicConstEvaluation
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: JS_IR
fun <T> T.id() = this
@@ -1,5 +1,7 @@
// !LANGUAGE: +IntrinsicConstEvaluation
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: JS_IR
fun <T> T.id() = this
const val trueVal = <!EVALUATED("true")!>true<!>
@@ -1,6 +1,8 @@
// !LANGUAGE: +IntrinsicConstEvaluation
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: JS_IR
// IGNORE_BACKEND_K1: JVM_IR, JS_IR, JS_IR_ES6
fun <T> T.id() = this
class A(val OK: Int, val somePropertyWithLongName: String) {
@@ -1,15 +1,18 @@
// !LANGUAGE: +IntrinsicConstEvaluation
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: JS_IR
// WITH_STDLIB
fun <T> T.id() = this
fun someSideEffect(value: Any?) = {}
class A {
val a = ""
fun b() = ""
init {
println("A init")
someSideEffect("A init")
}
fun test() {
@@ -1,6 +1,7 @@
// !LANGUAGE: +IntrinsicConstEvaluation
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: JVM_IR
// TARGET_BACKEND: JS_IR
// IGNORE_BACKEND_K1: JVM_IR, JS_IR, JS_IR_ES6
// FILE: 1.kt
@@ -1,5 +1,7 @@
// !LANGUAGE: +IntrinsicConstEvaluation
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: JS_IR
var result = "Fail"
object O {
@@ -1,7 +1,6 @@
// TARGET_BACKEND: JS_IR
// IGNORE_BACKEND_K1: JS_IR, JS_IR_ES6
// IGNORE_BACKEND_K2: JS_IR, JS_IR_ES6
// TODO enable for K2 when const lowering is applied for js
fun <T> T.id() = this
const val toStringDouble1 = 1.0.<!EVALUATED("1")!>toString()<!>
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: JS_IR
annotation class Key(val value: String)
object Messanger {
@@ -1,5 +1,5 @@
// TARGET_BACKEND: JVM_IR
// TODO enable for JS, Native when const lowering is applied in corresponding backends
// TARGET_BACKEND: JS_IR
// WITH_STDLIB
object Test {
@@ -1,5 +1,5 @@
// TARGET_BACKEND: JVM_IR
// TODO enable for JS, Native when const lowering is applied in corresponding backends
// TARGET_BACKEND: JS_IR
object Test
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JVM_IR
// TARGET_BACKEND: JS_IR
// This test is needed to check that IrCompileTimeChecker will not fail trying to find and analyze correct toString method
object Obj {