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

Update KotlinCoroutineFilter for Kotlin 1.6 #1283

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Godin
Copy link
Member

@Godin Godin commented Feb 3, 2022

For the following Example.kt

fun example() {
  exec {
    // suspending lambda without suspension points,
    // i.e. without invocations of suspending functions/lambdas
  }
}

fun exec(suspendingLambda: suspend () -> Unit) {}

execution of

kotlin/bin/kotlinc Example.kt -d classes
javap -v -p classes/ExampleKt\$example\$1.class

using Kotlin compiler version 1.5.32 (latest as of today in 1.5 series) produces

  public final java.lang.Object invokeSuspend(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Ljava/lang/Object;
    flags: ACC_PUBLIC, ACC_FINAL
    Code:
      stack=3, locals=3, args_size=2
         0: invokestatic  #36                 // Method kotlin/coroutines/intrinsics/IntrinsicsKt.getCOROUTINE_SUSPENDED:()Ljava/lang/Object;
         3: astore_2
         4: aload_0
         5: getfield      #40                 // Field label:I
         8: tableswitch   { // 0 to 0
                       0: 28
                 default: 36
            }
        28: aload_1
        29: invokestatic  #46                 // Method kotlin/ResultKt.throwOnFailure:(Ljava/lang/Object;)V
        32: getstatic     #52                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
        35: areturn
        36: new           #54                 // class java/lang/IllegalStateException
        39: dup
        40: ldc           #56                 // String call to 'resume' before 'invoke' with coroutine
        42: invokespecial #59                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
        45: athrow

whereas using Kotlin compiler version 1.6.0 produces

  public final java.lang.Object invokeSuspend(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Ljava/lang/Object;
    flags: ACC_PUBLIC, ACC_FINAL
    Code:
      stack=3, locals=2, args_size=2
         0: invokestatic  #36                 // Method kotlin/coroutines/intrinsics/IntrinsicsKt.getCOROUTINE_SUSPENDED:()Ljava/lang/Object;
         3: pop
         4: aload_0
         5: getfield      #40                 // Field label:I
         8: tableswitch   { // 0 to 0
                       0: 28
                 default: 36
            }
        28: aload_1
        29: invokestatic  #46                 // Method kotlin/ResultKt.throwOnFailure:(Ljava/lang/Object;)V
        32: getstatic     #52                 // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
        35: areturn
        36: new           #54                 // class java/lang/IllegalStateException
        39: dup
        40: ldc           #56                 // String call to 'resume' before 'invoke' with coroutine
        42: invokespecial #59                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
        45: athrow

Currently the first one is filtered by KotlinCoroutineFilter, but not the second.

And the diff between them

-      stack=3, locals=3, args_size=2
+      stack=3, locals=2, args_size=2
          0: invokestatic  #36                 // Method kotlin/coroutines/intrinsics/IntrinsicsKt.getCOROUTINE_SUSPENDED:()Ljava/lang/Object;
-         3: astore_2
+         3: pop
          4: aload_0

This relates to the following change in Kotlin compiler - JetBrains/kotlin@f4a1e27


Closes #1258

@Godin Godin self-assigned this Feb 3, 2022
@Godin Godin added this to Awaiting triage in Filtering via automation Feb 3, 2022
@Godin Godin moved this from Awaiting triage to In Progress in Filtering Feb 3, 2022
@Godin Godin added this to Implementation in Current work items via automation Feb 3, 2022
@Godin Godin added this to the 0.8.9 milestone Apr 26, 2022
@Godin Godin modified the milestones: 0.8.9, 0.8.10 Mar 31, 2023
@Godin Godin modified the milestones: 0.8.10, 0.8.11 Apr 24, 2023
@Godin Godin modified the milestones: 0.8.11, 0.8.12 Oct 14, 2023
@Godin Godin removed this from the 0.8.12 milestone Apr 9, 2024
@Godin Godin force-pushed the kotlin_1_6_suspending_lambda_without_suspension_points branch 2 times, most recently from 5b1d09c to 86b594c Compare May 14, 2024 07:43
@Godin Godin added this to the 0.8.13 milestone May 14, 2024
@Godin Godin marked this pull request as ready for review May 14, 2024 09:45
@Godin Godin requested a review from marchof May 14, 2024 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Current work items
  
Implementation
Filtering
  
In Progress
Development

Successfully merging this pull request may close these issues.

None yet

1 participant