mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-16 00:21:32 +00:00
Perform bytecode optimisations for inline classes
#KT-23742 Fixed
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// https://youtrack.jetbrains.com/issue/KT-15871
|
||||
|
||||
// FILE: Test.kt
|
||||
@@ -10,8 +12,20 @@ fun getAndCheckInt(a: Int, b: Int) =
|
||||
// 0 Value
|
||||
// 0 areEqual
|
||||
|
||||
// FILE: TestInlined.kt
|
||||
|
||||
fun getAndCheckInlinedInt(a: InlinedInt, b: InlinedInt) =
|
||||
getAndCheck({ a }, { b })
|
||||
|
||||
// @TestInlinedKt.class:
|
||||
// 0 valueOf
|
||||
// 0 Value
|
||||
// 0 areEqual
|
||||
// 0 INVOKESTATIC InlinedInt\$Erased.box
|
||||
// 0 INVOKEVIRTUAL InlinedInt.unbox
|
||||
|
||||
// FILE: Inline.kt
|
||||
inline fun <T> getAndCheck(getFirst: () -> T, getSecond: () -> T) =
|
||||
getFirst() == getSecond()
|
||||
|
||||
|
||||
inline class InlinedInt(val x: Int)
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
// FILE: Test.kt
|
||||
|
||||
inline fun <R, T> foo(x : R, y : R, block : (R) -> T) : T {
|
||||
val a = x is Number
|
||||
@@ -17,7 +20,26 @@ fun bar() {
|
||||
foo(1, 2) { x -> x is Int }
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 valueOf
|
||||
// 0 Value\s\(\)
|
||||
// 2 INSTANCEOF
|
||||
// 1 CHECKCAST
|
||||
|
||||
// FILE: Inline.kt
|
||||
|
||||
inline class InlinedInt(val x: Int)
|
||||
|
||||
// FILE: TestInlined.kt
|
||||
|
||||
fun baz() {
|
||||
foo(InlinedInt(1), InlinedInt(2)) { x -> x is InlinedInt }
|
||||
}
|
||||
|
||||
// @TestInlinedKt.class:
|
||||
// 0 valueOf
|
||||
// 0 Value\s\(\)
|
||||
// 0 INSTANCEOF
|
||||
// 0 CHECKCAST
|
||||
// 0 INVOKESTATIC InlinedInt\$Erased.box
|
||||
// 0 INVOKEVIRTUAL InlinedInt.unbox
|
||||
|
||||
36
compiler/testData/codegen/bytecodeText/boxingOptimization/inlineClassesAndInlinedLambda.kt
vendored
Normal file
36
compiler/testData/codegen/bytecodeText/boxingOptimization/inlineClassesAndInlinedLambda.kt
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
|
||||
// FILE: dependency.kt
|
||||
|
||||
inline class InlinedInt(val internal: Int)
|
||||
inline class InlinedString(val internal: String)
|
||||
|
||||
inline fun <T> foo(callback: () -> T): T {
|
||||
return callback()
|
||||
}
|
||||
|
||||
inline fun bar(callback: () -> InlinedInt): InlinedInt {
|
||||
return callback()
|
||||
}
|
||||
|
||||
inline fun baz(callback: () -> InlinedString): InlinedString {
|
||||
return callback()
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test(i: InlinedInt, s: InlinedString) {
|
||||
foo { i }
|
||||
bar { i }
|
||||
|
||||
foo { s }
|
||||
baz { s }
|
||||
}
|
||||
|
||||
// @TestKt.class:
|
||||
// 0 valueOf
|
||||
// 0 INVOKESTATIC InlinedInt\$Erased.box
|
||||
// 0 INVOKEVIRTUAL InlinedInt.unbox
|
||||
// 0 INVOKESTATIC InlinedString\$Erased.box
|
||||
// 0 INVOKEVIRTUAL InlinedString.unbox
|
||||
Reference in New Issue
Block a user