<@U0B8UEMV1> or anyone that can help rewriting som...
# arrow-meta
r
@pakoito or anyone that can help rewriting some suspension so it works in IR…. We have an issue with Meta, the IR format and some of the stuff we have in the Arrow code base. Seems like IR is not complete even for JVM and does not support certain things we seem to use in Arrow. 1. Type aliases like Validated.Valid / Validated.Invalid declared in the same file that point to an inner class is one of them. This easy to resolve because those type aliases wouldn’t need to be there if Valid and Invalid weren’t nested. I got passed this issue refactoring Valid and Invalid to be top level. 2. suspended anonymous functions like this one fail to find their context:
Copy code
fun <B> bindingFilter(c: suspend MonadFilterSyntax<F>.() -> B): Kind<F, B> {
    val continuation = MonadFilterContinuation<F, B>(this)
    val wrapReturn: suspend MonadFilterSyntax<F>.() -> Kind<F, B> = { just(c()) }
    wrapReturn.startCoroutine(continuation, continuation)
    return continuation.returnedMonad()
  }
In this function IR codegen freaks out with :
{ just(c()) }
getting into this error: https://github.com/JetBrains/kotlin/blob/9c9d2b5ad4ac27a0792d3cf4c62599fb3e09ebbb/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt#L420 Seems like IR is unable to deal with suspended lambdas like this one. While I still have work in the comprehension plugin which will get rid of this problem all together I wonder if there is a way to rewrite that so that is not a suspended lambda.
s
Same issue if you refactor to
suspend { just(c()) }
? Now that suspend is inferred by the lhs
p
in this order I’d try: change lambda to function declared inside the function, private function and use a function reference, and wrapping it on IO.effect or Id.just and then accessing the value directly on startCoroutine
🤔 1