Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Conversation

@poseidon-mysugr
Copy link

No description provided.

@poseidon-mysugr poseidon-mysugr changed the base branch from myMaster to master November 17, 2021 14:12
@poseidon-mysugr poseidon-mysugr force-pushed the feature/tailOptimizedSuspendFunsReturnUnit branch from a22b3e6 to 4759c3f Compare November 17, 2021 14:21
Copy link

@ChristopherKoellner ChristopherKoellner left a comment

Choose a reason for hiding this comment

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

Could you also attach the bytecode to this pull request?
Others than that LGTM!

@poseidon-mysugr
Copy link
Author

This function ignores some uncoverable instructions and branchs of suspend funs:

    suspend fun example(b: Boolean) {
        if (b)
            suspendingFunction()
        else
            suspendingFunction()
    }

produces the following bytecode:

   L0
    ILOAD 1
    IFEQ L1
   L2
    ALOAD 0
    ALOAD 2
    INVOKEVIRTUAL suspendingFunction (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
>   DUP
>   INVOKESTATIC kotlin/coroutines/intrinsics/IntrinsicsKt.getCOROUTINE_SUSPENDED ()Ljava/lang/Object;
>   IF_ACMPNE L3
>   ARETURN
>  L3
>   POP
    GOTO L4
   L1
    ALOAD 0
    ALOAD 2
    INVOKEVIRTUAL suspendingFunction (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
>   DUP
>   INVOKESTATIC kotlin/coroutines/intrinsics/IntrinsicsKt.getCOROUTINE_SUSPENDED ()Ljava/lang/Object;
>   IF_ACMPNE L5
>   ARETURN
>  L5
>   POP
   L4
>   GETSTATIC kotlin/Unit.INSTANCE : Lkotlin/Unit;
>   ARETURN

Here, the first two blocks marked with > need to be ignored, as they are only executed if the coroutine function call (suspendingFunction) actually does suspend, in which case the COROUTINE_SUSPENDED marker is passed on. The last block at the bottom in turn cannot be covered if the suspendingFunction never suspends.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants