mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
This change improves the debugging experience around local functions on the IR backend. The changes include moving old checkLocalVariablesTable (cLVT) tests to the new stepping/local variable infrastructure in order to refine the tests and further define the behavior of the two JVM backends, and their differences. The primary ported test case is cLVT/localFun.kt that documents the discrepancy in implementation strategy for local functions on the two backends. The old backend implements local functions as lambdas assigned to a local variable while the IR backend lifts them out as static funtions on the surrounding class. The discrepancies and their consequences are documented in bytecodeListing, idea-stepping, localVariableTable and debugStepping tests. The only _code change_ is disabling the captured variable name mangling for captured variables on the IR backend. Captured variables are passed as arguments to the static function, so in the debugger, they really just are local variables. For them to show properly in the debugger and be detectable by evaluate expression, they simply need no mangling. Finally, this change cleans 3 redundant cLVT tests, copyFunction.kt and destructuringInlineLambda.kt and destructuringInFor.kt, that are all covered in the new suite. The stepping behavior needs to be made precise around for loops, but that is an entirely seperate issue.
54 lines
1.6 KiB
Kotlin
Vendored
54 lines
1.6 KiB
Kotlin
Vendored
|
|
|
|
//FILE: test.kt
|
|
fun foo() {
|
|
val x = 1
|
|
fun bar() {
|
|
val y = x
|
|
}
|
|
bar()
|
|
}
|
|
|
|
fun box() {
|
|
foo()
|
|
}
|
|
|
|
// Local functions are compiled to private static functions on the class
|
|
// containing the local funtion. This has a number of consequences observable
|
|
// from a debugging perspective, for this test specifically:
|
|
// - local functions do not figure in the LVT of the outer function, as they
|
|
// are not instantiated.
|
|
// - the _declaration_ of the local function does not figure in the byte code
|
|
// of the outer function and hence, has no line number
|
|
// - captures are treated differently, according to the implementation
|
|
// strategy: on the IR, captures are passed as arguments to the static
|
|
// function, on the old backend, they are added to fields on the lambda
|
|
// object. Hence, for debugging purposes, captures are "just"
|
|
// variables local to the function, and hence need no name mangling to
|
|
// properly figure in the debugger.
|
|
|
|
// LOCAL VARIABLES
|
|
// test.kt:13 box:
|
|
// test.kt:5 foo:
|
|
|
|
// LOCAL VARIABLES JVM
|
|
// test.kt:6 foo: x:int=1:int
|
|
|
|
// LOCAL VARIABLES JVM
|
|
// test.kt:9 foo: x:int=1:int, $fun$bar$1:TestKt$foo$1=TestKt$foo$1
|
|
// LOCAL VARIABLES JVM_IR
|
|
// test.kt:9 foo: x:int=1:int
|
|
|
|
// LOCAL VARIABLES JVM
|
|
// test.kt:7 invoke:
|
|
// test.kt:8 invoke: y:int=1:int
|
|
// LOCAL VARIABLES JVM_IR
|
|
// test.kt:7 foo$bar: x:int=1:int
|
|
// test.kt:8 foo$bar: x:int=1:int, y:int=1:int
|
|
|
|
// LOCAL VARIABLES JVM
|
|
// test.kt:10 foo: x:int=1:int, $fun$bar$1:TestKt$foo$1=TestKt$foo$1
|
|
// test.kt:14 box:
|
|
// LOCAL VARIABLES JVM_IR
|
|
// test.kt:10 foo: x:int=1:int
|
|
// test.kt:14 box: |