https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

daphillips

01/26/2023, 10:16 PM
Has anybody played around (and had issues) with
-Xdebug
in kotlin 1.8? I've been getting
java.lang.VerifyError: Bad local variable type
errors whenever I turn it on in my project. I haven't been able to create a minimal reproducible example yet, but it seems to happen around
scope.launch
or
channel.send
calls...
e

ephemient

01/26/2023, 10:28 PM
the verifier should tell you which class and method failed, right? if you dump the bytecode it might have a hint as to what went wrong
d

daphillips

01/26/2023, 10:35 PM
That's a good point. I've looked at bit at what the verifier mentions, but haven't gotten to the bytecode level yet. That's probably a good thing to look into
Blindly poking around at the code though leads to the very interesting discovery that it always seems to be
Type top (current frame, locals[5]) is not assignable to reference type
, but at different locations depending on how I manipulate the stack. With the peculiar part being that it's always the 5th-indexed local variable... more to investigate
n

Norbi

01/27/2023, 1:46 PM
I've just run into the same error 😞
Copy code
java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    ...-W5ldpIw(Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @707: iload
  Reason:
    Type 'java/util/concurrent/locks/Lock' (current frame, locals[9]) is not assignable to integer
Without
-Xdebug
the error goes away...
d

daphillips

01/27/2023, 10:23 PM
@Norbi I was able to get a minimal reproducible example. I'm still uncertain as to what the cause is, but I at least have enough now to submit a bug report
for the curious, this was the smallest I was able to make it:
Copy code
fun main() = runBlocking {
    Path("/tmp")

    withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
        println("hello world!")
    }
}
e

ephemient

01/27/2023, 10:43 PM
huh. that's interesting, it's failing in the code generated for the very first state, I can't tell why it's producing that load though
definitely worth filing a YouTrack issue over this
d

daphillips

01/27/2023, 11:08 PM
The really interesting part is replacing
Path()
with
Paths.get()
seems to fix the issue? So I wonder if it's something related to how kotlin inlines
Path()
to target platforms? ¯\_(ツ)_/¯
e

ephemient

01/28/2023, 12:36 AM
experimenting with the definition of
<http://kotlin.io|kotlin.io>.path.Path
, this generates OK bytecode:
Copy code
inline fun Path(path: String): Path = Paths.get(path)
while this generates broken bytecode:
Copy code
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@kotlin.internal.InlineOnly
inline fun Path(path: String): Path = Paths.get(path)
when used in the above reproducer
minimized the example more:
Copy code
import kotlin.coroutines.*

@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@kotlin.internal.InlineOnly
inline fun f(a: Int): Int = a

fun main() {
    suspend {
        f(0)
        suspendCoroutine<Unit> {}
    }
}
d

daphillips

01/28/2023, 12:51 AM
Interesting find. I'll make sure to add it in my ticket writeup
9 Views