Skip to content

Improvement of generation logic in K2 #75

Closed
@ForteScarlet

Description

@ForteScarlet

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) })
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions