Skip to content

Conversation

@Godin
Copy link
Member

@Godin Godin commented Apr 4, 2025

Given src/Utils.kt

suspend fun suspendingFunction(): String = ""
suspend fun suspendingFunctionReturningInlineValueClass(): InlineValueClass = InlineValueClass("")
@JvmInline
value class InlineValueClass(val value: String)
fun beforeSuspensionPoint() = Any()
fun afterSuspensionPoint(a: Any, b: Any) = Unit

compilation of src/Example.kt

import kotlinx.coroutines.runBlocking

fun example() =
    runBlocking {
        afterSuspensionPoint(
            beforeSuspensionPoint(),
            suspendingFunction()
        )
    }

differs from compilation of src/Example.kt

import kotlinx.coroutines.runBlocking

fun example() =
    runBlocking {
        afterSuspensionPoint(
            beforeSuspensionPoint(),
            suspendingFunctionReturningInlineValueClass()
        )
    }

as

index 274d343..1df493e 100644
--- 1/1.txt
+++ 2/2.txt
@@ -66,7 +66,7 @@ final class ExampleKt$example$1 extends kotlin/coroutines/jvm/internal/SuspendLa
     ALOAD 0
     ICONST_1
     PUTFIELD ExampleKt$example$1.label : I
-    INVOKESTATIC UtilsKt.suspendingFunctionReturningInlineValueClass (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
+    INVOKESTATIC UtilsKt.suspendingFunction (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
     DUP
     ALOAD 3
     IF_ACMPNE L7
@@ -82,15 +82,10 @@ final class ExampleKt$example$1 extends kotlin/coroutines/jvm/internal/SuspendLa
     ALOAD 1
     INVOKESTATIC kotlin/ResultKt.throwOnFailure (Ljava/lang/Object;)V
     ALOAD 1
-    CHECKCAST InlineValueClass
-    INVOKEVIRTUAL InlineValueClass.unbox-impl ()Ljava/lang/String;
    L7
-    LINENUMBER 7 L7
    FRAME FULL [ExampleKt$example$1 java/lang/Object java/lang/Object java/lang/Object] [java/lang/Object]
     ALOAD 2
     SWAP
-    CHECKCAST java/lang/String
-    INVOKESTATIC InlineValueClass.box-impl (Ljava/lang/String;)LInlineValueClass;
    L9
     LINENUMBER 5 L9
     INVOKESTATIC UtilsKt.afterSuspensionPoint (Ljava/lang/Object;Ljava/lang/Object;)V

and

nextIs(Opcodes.ALOAD);
nextIsThrowOnFailure();
nextIs(Opcodes.ALOAD);
if (cursor != null && skipNonOpcodes(cursor
.getNext()) == continuationAfterLoadedResult) {

does not handle

    CHECKCAST InlineValueClass
    INVOKEVIRTUAL InlineValueClass.unbox-impl ()Ljava/lang/String;

JetBrains/kotlin@ccc5b7a


See #1868 (comment) and #1868 (comment)

@Godin Godin self-assigned this Apr 4, 2025
@Godin Godin added this to Filtering Apr 4, 2025
@github-project-automation github-project-automation bot moved this to Awaiting triage in Filtering Apr 4, 2025
@Godin Godin moved this from Awaiting triage to In Progress in Filtering Apr 4, 2025
@Godin Godin added this to the 0.8.14 milestone Apr 4, 2025
@Godin Godin force-pushed the kotlin_suspending_function_returning_inline_value_class branch from 674fd39 to 7caa090 Compare September 19, 2025 19:05
@Godin Godin changed the title Improve KotlinCoroutineFilter KotlinCoroutineFilter should filter suspension points that return inline value classes Sep 19, 2025
@Godin Godin marked this pull request as ready for review September 19, 2025 19:48
@Godin Godin requested a review from leveretka September 19, 2025 19:48
Copy link
Collaborator

@leveretka leveretka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Comment on lines 148 to -167
}

for (AbstractInsnNode j = i; j != null; j = j.getNext()) {
cursor = j;
nextIs(Opcodes.ALOAD);
nextIsThrowOnFailure();

nextIs(Opcodes.ALOAD);
if (cursor != null && skipNonOpcodes(cursor
.getNext()) == continuationAfterLoadedResult) {
ignore.add(i);
ignore.add(cursor);
suspensionPoint++;
break;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, the simplified logic here still detects desired generated code, so no need to have a very precise matcher here

@Godin Godin merged commit fd2b323 into jacoco:master Sep 22, 2025
36 checks passed
@Godin Godin deleted the kotlin_suspending_function_returning_inline_value_class branch September 22, 2025 21:39
@github-project-automation github-project-automation bot moved this from In Progress to Done in Filtering Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants