[K/N][IR][optmz] Global analysis for top-level initializers
The analysis' goal is to remove redundant calls to initializers
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) {
|
||||
if (x <= 0) return
|
||||
bar(x)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
inline fun foo(x: Int) {
|
||||
if (x <= 0) return
|
||||
bar(x)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val x = computeX()
|
||||
|
||||
private fun computeX() = 42
|
||||
|
||||
fun baz1() { }
|
||||
|
||||
fun baz2() { }
|
||||
|
||||
// FILE: main.kt
|
||||
fun bar(x: Int) = if (x == 0) error("") else x
|
||||
|
||||
fun foo(x: Int) {
|
||||
try {
|
||||
bar(x)
|
||||
baz1()
|
||||
} catch (t: Throwable) { }
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(x)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = computeY()
|
||||
|
||||
private fun computeY() = 42
|
||||
|
||||
fun baz1() { }
|
||||
|
||||
fun baz2() { }
|
||||
|
||||
// FILE: main.kt
|
||||
fun bar(x: Int) = if (x == 0) error("") else x
|
||||
|
||||
fun foo(x: Int) {
|
||||
try {
|
||||
bar(x)
|
||||
baz1()
|
||||
} catch (t: Throwable) {
|
||||
println(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) = when {
|
||||
x > 0 -> 42
|
||||
bar(x) -> 117
|
||||
else -> -1
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(123)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) {
|
||||
if (x > 0) bar(x)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(-1)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) {
|
||||
var i = 0
|
||||
while (i < x) {
|
||||
bar(i)
|
||||
++i
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) {
|
||||
var i = 0
|
||||
do {
|
||||
if (i == x) break
|
||||
++i
|
||||
} while (bar(i))
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(y)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
// FILE: lib.kt
|
||||
val y = getY()
|
||||
|
||||
private fun getY() = 42
|
||||
|
||||
fun bar(x: Int) = x == 0
|
||||
|
||||
// FILE: main.kt
|
||||
fun foo(x: Int) {
|
||||
var i = 0
|
||||
do {
|
||||
++i
|
||||
if (i > 0) continue
|
||||
bar(i)
|
||||
} while (i < x)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(0)
|
||||
println(y)
|
||||
}
|
||||
Reference in New Issue
Block a user