Devirtualization fails to eliminate boxing in function reference context

^KT-49847 Fixed

Merge-request: KT-MR-6460
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
This commit is contained in:
Vladimir Sukharev
2022-07-12 08:26:27 +00:00
committed by Space
parent 5013988dbb
commit fd52f475cb
19 changed files with 289 additions and 8 deletions
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2022 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.
*/
fun plus1(x: Int) = x + 1
// CHECK: define void @"kfun:#main(){}"()
// CHECK-NOT: Int-box
// CHECK-NOT: Int-unbox
// CHECK: ret void
fun main() {
val ref = ::plus1
var y = 0
repeat(100000) {
y += ref(it) // Should be devirtualized and invoked without boxing/unboxing (`Int-box`/`Int-unbox`)
}
if (y > 999999)
println("y > 999999")
}