Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[inliner] parent fix after copy #3465

Merged
merged 1 commit into from
Jun 10, 2020

Conversation

vvlevchenko
Copy link
Contributor

this change fix issue with inlining lambda in inline function which(function) inlined from other library.
E.g.

cat i-lib.kt
class _special_class(val v:Int)
class _special_class1(val v:Int)

class __helper(val v:Int)

inline fun foo(h: __helper): Int {
val sum = h.op {
_special_class(it.v)
}.v
return sum
}

inline fun __helper.op(block:(_special_class1) -> _special_class) = block(_special_class1(v))

cat i-main.kt
fun main() {
val h = __helper(42)
println(foo(h))
}

Here how the incorrect parent affects debug information:

(lldb) target create "program.kexe"
Current executable set to '/Users/minamoto/ws/kotlin-native/program.kexe' (x86_64).
(lldb) command source -s 0 'i-test.lldb'
Executing commands in '/Users/minamoto/ws/kotlin-native/i-test.lldb'.
(lldb) b i-lib.kt:8
Breakpoint 1: where = program.kexe`kfun:#main(){} + 435 [inlined] foo + 98 at i-main.kt:3, address = 0x00000001000540e3
(lldb) r
Process 70550 stopped

  • thread Fix for KT-1334 Class object in "Show Structure View" action #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001000540e3 program.kexe`kfun:#main(){} [inlined] foo at i-lib.kt:9:7
    6 inline fun foo(h: __helper): Int {
    7 val sum = h.op {
    8 _special_class(it.v)
    -> 9 }.v
    ^
    10 return sum
    11 }
    12
    Target 0: (program.kexe) stopped.

the parent of lambda is i-main.kt instead of i-lib.kt, and offsets calculated against wrong file.
Here is behaviour with fix:

(lldb) target create "program.kexe"
Current executable set to '/Users/minamoto/ws/.git-trees/minamoto/debug-info/subprograms-with-missed-scopes/program.kexe' (x86_64).
(lldb) command source -s 0 '/Users/minamoto/ws/kotlin-native/i-test.lldb'
Executing commands in '/Users/minamoto/ws/kotlin-native/i-test.lldb'.
(lldb) b i-lib.kt:8
Breakpoint 1: where = program.kexe`kfun:#main(){} + 337 [inlined] _2 at i-lib.kt:14, address = 0x0000000100054bb1
(lldb) r
Process 70560 stopped

  • thread Fix for KT-1334 Class object in "Show Structure View" action #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100054bb1 program.kexe`kfun:#main(){} [inlined] _2 at i-lib.kt:8:24
    5
    6 inline fun foo(h: __helper): Int {
    7 val sum = h.op {
    -> 8 _special_class(it.v)
    ^
    9 }.v
    10 return sum
    11 }
    Target 0: (program.kexe) stopped.

@vvlevchenko vvlevchenko force-pushed the rr/minamoto/inliner/fix-parent-patching branch from e858361 to 37d884a Compare June 10, 2020 06:52
this change fix issue with inlining lambda in inline function which(function) inlined from other library.
E.g.

> cat i-lib.kt
class _special_class(val v:Int)
class _special_class1(val v:Int)

class __helper(val v:Int)

inline fun foo(h: __helper): Int {
    val sum = h.op {
        _special_class(it.v)
    }.v
    return sum
}

inline fun __helper.op(block:(_special_class1) -> _special_class) = block(_special_class1(v))

> cat i-main.kt
fun main() {
    val h = __helper(42)
    println(foo(h))
}

Here how the incorrect parent affects debug information:

(lldb) target create "program.kexe"
Current executable set to '/Users/minamoto/ws/kotlin-native/program.kexe' (x86_64).
(lldb) command source -s 0 'i-test.lldb'
Executing commands in '/Users/minamoto/ws/kotlin-native/i-test.lldb'.
(lldb) b i-lib.kt:8
Breakpoint 1: where = program.kexe`kfun:#main(){} + 435 [inlined] foo + 98 at i-main.kt:3, address = 0x00000001000540e3
(lldb) r
Process 70550 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001000540e3 program.kexe`kfun:#main(){} [inlined] foo at i-lib.kt:9:7
   6       inline fun foo(h: __helper): Int {
   7           val sum = h.op {
   8               _special_class(it.v)
-> 9           }.v
              ^
   10          return sum
   11      }
   12
Target 0: (program.kexe) stopped.

the parent of lambda is i-main.kt instead of i-lib.kt, and offsets calculated against wrong file.
Here is behaviour with fix:

(lldb) target create "program.kexe"
Current executable set to '/Users/minamoto/ws/.git-trees/minamoto/debug-info/subprograms-with-missed-scopes/program.kexe' (x86_64).
(lldb) command source -s 0 '/Users/minamoto/ws/kotlin-native/i-test.lldb'
Executing commands in '/Users/minamoto/ws/kotlin-native/i-test.lldb'.
(lldb) b i-lib.kt:8
Breakpoint 1: where = program.kexe`kfun:#main(){} + 337 [inlined] <anonymous>_2 at i-lib.kt:14, address = 0x0000000100054bb1
(lldb) r
Process 70560 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100054bb1 program.kexe`kfun:#main(){} [inlined] <anonymous>_2 at i-lib.kt:8:24
   5
   6       inline fun foo(h: __helper): Int {
   7           val sum = h.op {
-> 8               _special_class(it.v)
                               ^
   9           }.v
   10          return sum
   11      }
Target 0: (program.kexe) stopped.
@vvlevchenko vvlevchenko force-pushed the rr/minamoto/inliner/fix-parent-patching branch from 37d884a to 852561c Compare June 10, 2020 07:47
@vvlevchenko vvlevchenko requested a review from homuroll June 10, 2020 07:47
@vvlevchenko vvlevchenko merged commit 25f0e38 into master Jun 10, 2020
@vvlevchenko vvlevchenko deleted the rr/minamoto/inliner/fix-parent-patching branch June 10, 2020 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants