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

Improvement of generation logic in K2 #75

Closed
ForteScarlet opened this issue Jan 19, 2025 · 0 comments · Fixed by #80
Closed

Improvement of generation logic in K2 #75

ForteScarlet opened this issue Jan 19, 2025 · 0 comments · Fixed by #80

Comments

@ForteScarlet
Copy link
Owner

ForteScarlet commented Jan 19, 2025

Perhaps the logic could be generated directly at the fir stage without crossing fir->ir?

Now

Source

interface MyInterface {

    suspend fun run(times: Int): Int

    @JvmBlocking
    fun runBlocking(times: Int): Int
}

FIR

interface MyInterface {
    
    @JvmSynthetic
    suspend fun run(times: Int): Int

    @JvmBlocking
    fun runBlocking(times: Int): Int  // Generated FIR synthetic function
}

IR

interface MyInterface {
    
    @JvmSynthetic
    @TargetMarker(value = "The unique target id for IR to searh it")
    suspend fun run(times: Int): Int

    @JvmBlocking
    fun runBlocking(times: Int): Int = `$runInBlocking$`({ run(times) }, this as? CoroutineScope)
    // Include body in IR
    // 
}

Planned

Source

interface MyInterface {

    suspend fun run(times: Int): Int

    @JvmBlocking
    fun runBlocking(times: Int): Int
}

FIR

interface MyInterface {
    @JvmSynthetic
    suspend fun run(times: Int): Int

    // Generated bridge private inline function for `runBlocking` without body
    @Suppress("NOTHING_TO_INLINE")
    private inline fun __run_runBlocking_suspendTransform_0(noinline block: suspend () -> Int): Int

    // Generated FIR synthetic function with actually body
    fun runBlocking(times: Int): Int = __run_runBlocking_suspendTransform_0({ run(times) })
}

IR

interface MyInterface {

    @JvmSynthetic
    suspend fun run(times: Int): Int

    // Generate body for this bridge function in IR directly, without search
    @JvmSynthetic
    @Suppress("NOTHING_TO_INLINE")
    private inline fun __run_runBlocking_suspendTransform_0(noinline block: suspend () -> Int): Int {
        return `$runInBlocking$`(block, this as? CoroutineScope)
    }

    fun runBlocking(times: Int): Int = __run_runBlocking_suspendTransform_0({ run(times) })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant