mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 00:21:26 +00:00
KT-5248 Don't wrap variable if it is captured only in inlined closures
Remove non-escaping Ref's on bytecode postprocessing pass.
This commit is contained in:
16
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/capturedInChainOfInlineFuns.kt
vendored
Normal file
16
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/capturedInChainOfInlineFuns.kt
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test() {
|
||||
var x = 0
|
||||
run {
|
||||
run {
|
||||
run {
|
||||
++x
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 0 NEW
|
||||
// 0 GETFIELD
|
||||
// 0 PUTFIELD
|
||||
10
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/capturedInInlineOnly.kt
vendored
Normal file
10
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/capturedInInlineOnly.kt
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test() {
|
||||
var x = 0
|
||||
run { ++x }
|
||||
}
|
||||
|
||||
// 0 NEW
|
||||
// 0 GETFIELD
|
||||
// 0 PUTFIELD
|
||||
15
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/capturedInLocalObject.kt
vendored
Normal file
15
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/capturedInLocalObject.kt
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun test() {
|
||||
var x = 0
|
||||
run {
|
||||
val obj = object {
|
||||
fun foo() { ++x }
|
||||
}
|
||||
obj.foo()
|
||||
}
|
||||
}
|
||||
|
||||
// 1 NEW kotlin/jvm/internal/Ref\$IntRef
|
||||
// 2 GETFIELD kotlin/jvm/internal/Ref\$IntRef\.element
|
||||
// 2 PUTFIELD kotlin/jvm/internal/Ref\$IntRef\.element
|
||||
12
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/capturedInNoInlineOnly.kt
vendored
Normal file
12
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/capturedInNoInlineOnly.kt
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun runNoInline(f: () -> Unit) = f()
|
||||
|
||||
fun test() {
|
||||
var x = 0
|
||||
runNoInline { ++x }
|
||||
}
|
||||
|
||||
// 1 NEW kotlin/jvm/internal/Ref\$IntRef
|
||||
// 2 GETFIELD kotlin/jvm/internal/Ref\$IntRef\.element
|
||||
// 2 PUTFIELD kotlin/jvm/internal/Ref\$IntRef\.element
|
||||
@@ -0,0 +1,20 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun runNoInline(f: () -> Unit) = f()
|
||||
|
||||
fun test() {
|
||||
var x = 0
|
||||
run {
|
||||
run {
|
||||
runNoInline {
|
||||
run {
|
||||
++x
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1 NEW kotlin/jvm/internal/Ref\$IntRef
|
||||
// 2 GETFIELD kotlin/jvm/internal/Ref\$IntRef\.element
|
||||
// 2 PUTFIELD kotlin/jvm/internal/Ref\$IntRef\.element
|
||||
25
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/capturedVarsOfSize2.kt
vendored
Normal file
25
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/capturedVarsOfSize2.kt
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
var xl = 0L // Long, size 2
|
||||
var xi = 0 // Int, size 1
|
||||
var xd = 0.0 // Double, size 2
|
||||
|
||||
run {
|
||||
xl++
|
||||
xd += 1.0
|
||||
xi++
|
||||
}
|
||||
|
||||
run {
|
||||
run {
|
||||
xl++
|
||||
xd += 1.0
|
||||
xi++
|
||||
}
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// 0 NEW
|
||||
32
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/sharedSlotsWithCapturedVars.kt
vendored
Normal file
32
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/sharedSlotsWithCapturedVars.kt
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun box(): String {
|
||||
run {
|
||||
run {
|
||||
var x1 = 0
|
||||
run { ++x1 }
|
||||
if (x1 == 0) return "fail"
|
||||
}
|
||||
|
||||
run {
|
||||
var x2 = 0
|
||||
run { x2++ }
|
||||
if (x2 == 0) return "fail"
|
||||
}
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
|
||||
// Shared variable slots (x1, x2):
|
||||
// 5 ILOAD 0
|
||||
// 4 ISTORE 0
|
||||
|
||||
// Temporary variable slots for 'x2++':
|
||||
// 1 ILOAD 1
|
||||
// 1 ISTORE 1
|
||||
|
||||
// 0 NEW
|
||||
// 0 GETFIELD
|
||||
// 0 PUTFIELD
|
||||
14
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/withStackNormalization.kt
vendored
Normal file
14
compiler/testData/codegen/bytecodeText/capturedVarsOptimization/withStackNormalization.kt
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun add(x: Int, y: Int) = x + y
|
||||
|
||||
fun test() {
|
||||
var x = 0
|
||||
run {
|
||||
x += add(1, try { 1 } catch (e: Throwable) { 42 })
|
||||
}
|
||||
}
|
||||
|
||||
// 0 NEW
|
||||
// 0 GETFIELD
|
||||
// 0 PUTFIELD
|
||||
Reference in New Issue
Block a user