JVM IR: Turn static callable references into singletons

This commit is contained in:
Steven Schäfer
2020-03-05 11:35:51 +01:00
committed by Dmitry Petrov
parent ac5c255c20
commit bb5a639153
9 changed files with 196 additions and 10 deletions

View File

@@ -0,0 +1,22 @@
// TARGET_BACKEND: JVM
var capturedRef: ((Int) -> Int)? = null
fun ref(x: Int) = x
fun updateCapturedRef(): Boolean {
val r = ::ref
if (capturedRef == null) {
capturedRef = r
} else if (capturedRef !== r) {
return false
}
return true
}
fun box(): String {
updateCapturedRef()
if (!updateCapturedRef())
return "FAIL"
return "OK"
}