Fix generation of checkcast instructions for inline classes

Normalize LHS and RHS types to use only boxed ones and then let bytecode
 optmizer reduce redundant boxing
This commit is contained in:
Mikhail Zarechenskiy
2018-07-04 15:31:23 +03:00
parent 8eb7eab535
commit 4f490ac264
9 changed files with 117 additions and 1 deletions
@@ -0,0 +1,30 @@
// !LANGUAGE: +InlineClasses
// FILE: util.kt
inline class AsAny<T>(val x: Any?)
inline class AsInt(val x: Int)
// FILE: Reference.kt
fun <T, R> transform(a: AsAny<T>): AsAny<R> = a as AsAny<R>
fun <T, R> transformNullable(a: AsAny<T>?): AsAny<R> = a as AsAny<R> // unbox
fun <T, R> transformToNullable(a: AsAny<T>): AsAny<R>? = a as AsAny<R> // box
fun <T, R> transformToNullableTarget(a: AsAny<T>): AsAny<R>? = a as AsAny<R>? // box
fun <T, R> transformNullableToNullableTarget(a: AsAny<T>?): AsAny<R>? = a as AsAny<R>?
// FILE: Primitive.kt
fun transform(a: AsInt): AsInt = a as AsInt
fun transformNullable(a: AsInt?): AsInt = a as AsInt // unbox
fun transformToNullable(a: AsInt): AsInt? = a as AsInt // box
fun transformToNullableTarget(a: AsInt): AsInt? = a as AsInt? // box
fun transformNullableToNullableTarget(a: AsInt?): AsInt? = a as AsInt?
// @ReferenceKt.class:
// 2 INVOKESTATIC AsAny\$Erased.box
// 1 INVOKEVIRTUAL AsAny.unbox
// @PrimitiveKt.class:
// 2 INVOKESTATIC AsInt\$Erased.box
// 1 INVOKEVIRTUAL AsInt.unbox