Perform bytecode optimisations for inline classes

#KT-23742 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2018-06-15 15:36:47 +03:00
parent 7465289811
commit 01d9be65bc
16 changed files with 204 additions and 71 deletions
@@ -6,7 +6,7 @@ fun f() {
val unull = UInt(1) ?: null
}
// 1 INVOKESTATIC UInt\$Erased.box
// 0 INVOKESTATIC UInt\$Erased.box
// 0 INVOKEVIRTUAL UInt.unbox
// 0 valueOf
@@ -12,8 +12,8 @@ fun test(x: UInt?, y: UInt) {
}
}
// 2 INVOKESTATIC UInt\$Erased.box
// 3 INVOKEVIRTUAL UInt.unbox
// 0 INVOKESTATIC UInt\$Erased.box
// 1 INVOKEVIRTUAL UInt.unbox
// 0 valueOf
// 0 intValue
@@ -9,17 +9,17 @@ fun <T> T.idExtension(): T = this
inline fun <T> T.inlinedIdExtension(): T = this
fun test(f: Foo) {
inlinedId(f) // box
inlinedId(f)
inlinedId(f).idExtension() // box
f.inlinedIdExtension() // box
f.inlinedIdExtension()
val a = inlinedId(f).idExtension() // box unbox
val b = inlinedId(f).inlinedIdExtension() // box unbox
val b = inlinedId(f).inlinedIdExtension()
}
// 5 INVOKESTATIC Foo\$Erased.box
// 2 INVOKEVIRTUAL Foo.unbox
// 2 INVOKESTATIC Foo\$Erased.box
// 1 INVOKEVIRTUAL Foo.unbox
// 0 valueOf
// 0 intValue
@@ -7,39 +7,39 @@ inline class InlineNullableReference(val a: Any?)
fun test1(a: InlineNotNullPrimitive) {
val a0 = a
val a1: Any = a // box
val a2: Any? = a // box
val a1: Any = a
val a2: Any? = a
val a3: InlineNotNullPrimitive = a
val a4: InlineNotNullPrimitive? = a // box
val a4: InlineNotNullPrimitive? = a
}
fun test2(b: InlineNullablePrimitive) {
val b0 = b
val b1: Any = b // box
val b2: Any? = b // box
val b1: Any = b
val b2: Any? = b
val b3: InlineNullablePrimitive = b
val b4: InlineNullablePrimitive? = b // box
val b4: InlineNullablePrimitive? = b
}
fun test3(c: InlineNotNullReference) {
val c0 = c
val c1: Any = c // box
val c2: Any? = c // box
val c1: Any = c
val c2: Any? = c
val c3: InlineNotNullReference = c
val c4: InlineNotNullReference? = c
}
fun test4(d: InlineNullableReference) {
val d0 = d
val d1: Any = d // box
val d2: Any? = d // box
val d1: Any = d
val d2: Any? = d
val d3: InlineNullableReference = d
val d4: InlineNullableReference? = d // box
val d4: InlineNullableReference? = d
}
// 3 INVOKESTATIC InlineNotNullPrimitive\$Erased.box
// 3 INVOKESTATIC InlineNullablePrimitive\$Erased.box
// 2 INVOKESTATIC InlineNotNullReference\$Erased.box
// 3 INVOKESTATIC InlineNullableReference\$Erased.box
// 0 INVOKESTATIC InlineNotNullPrimitive\$Erased.box
// 0 INVOKESTATIC InlineNullablePrimitive\$Erased.box
// 0 INVOKESTATIC InlineNotNullReference\$Erased.box
// 0 INVOKESTATIC InlineNullableReference\$Erased.box
// 0 valueOf
@@ -16,8 +16,8 @@ fun UIntArray.swap(i: Int, j: Int) {
this[j] = this[i].also { this[i] = this[j] }
}
// 2 INVOKEVIRTUAL UInt.unbox
// 1 INVOKESTATIC UInt\$Erased.box
// 0 INVOKEVIRTUAL UInt.unbox
// 0 INVOKESTATIC UInt\$Erased.box
// 0 intValue
// 0 valueOf