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

New Kotlin IR Compiler Backend breaks generated code filter #1086

Closed
Grisu118 opened this issue Aug 22, 2020 · 6 comments
Closed

New Kotlin IR Compiler Backend breaks generated code filter #1086

Grisu118 opened this issue Aug 22, 2020 · 6 comments

Comments

@Grisu118
Copy link

Jacoco 0.8.2 introduced filtering of generated methods in kotlin (#689).

When I use the kotlin 1.4.0 with the new IR Compiler Backend, the filters do not work. You find below the example from above pull request updated to kotlin 1.4.0. With a comment where you can enable / disable the new compiler backend.

Steps to reproduce

  • JaCoCo version: 0.8.5

  • Operating system: Windows 10

  • Tool integration: Gradle 6.6

  • Complete executable reproducer: example.zip

  • Steps: gradlew clean jacocoTestReport

Expected behaviour

Generated methods are excluded, like with useIR = false
jacoco_kotlin

Actual behaviour

Generated methods are not excluded, with useIR = true
jacoco_kotlin_ir

@Grisu118 Grisu118 added the type: bug 🐛 Something isn't working label Aug 22, 2020
@Godin
Copy link
Member

Godin commented Sep 3, 2020

@Grisu118 if there is a change in the bytecode generated by Kotlin compiler, then why don't you report this to developers of compiler ? 😉 CC @qwwdfsad @Alefas @antonarhipov


For example for DataClass.kt

data class DataClass(var x: Int)

after execution of kotlin-compiler-1.4.0/bin/kotlinc -Xuse-ir DataClass.kt
execution of javap -v -p DataClass.class
shows that generated methods have LineNumberTable

  public int hashCode();
    descriptor: ()I
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: getfield      #13                 // Field x:I
         4: ireturn
      LineNumberTable:
        line 1: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   LDataClass;

which was not the case before and is not the case in the absence of -Xuse-ir,
what breaks #689 implemented by one of compiler developers @goodwinnk at that time


Using our validation tests one can observe other changes in how the Kotlin compiler generates bytecode:

--- c/org.jacoco.core.test.validation.kotlin/pom.xml
+++ w/org.jacoco.core.test.validation.kotlin/pom.xml
@@ -26,7 +26,7 @@

   <properties>
     <bytecode.version>6</bytecode.version>
-    <kotlin.version>1.3.61</kotlin.version>
+    <kotlin.version>1.4.0</kotlin.version>
   </properties>

   <dependencies>
@@ -43,7 +43,7 @@
     <dependency>
       <groupId>org.jetbrains.kotlinx</groupId>
       <artifactId>kotlinx-coroutines-core</artifactId>
-      <version>1.0.1</version>
+      <version>1.3.9</version>
     </dependency>
   </dependencies>

@@ -60,6 +60,11 @@
             <goals>
               <goal>compile</goal>
             </goals>
+            <configuration>
+              <args>
+                <arg>-Xuse-ir</arg>
+              </args>
+            </configuration>
           </execution>
         </executions>
       </plugin>

@Godin Godin added component: core.filters feedback pending Further information is requested labels Sep 3, 2020
@qwwdfsad
Copy link

qwwdfsad commented Sep 3, 2020

I'll investigate it on our side

@qwwdfsad
Copy link

We'll consider it a bug for now: https://youtrack.jetbrains.com/issue/KT-41903

Also, we (again) discussed a potential solution for coverage and bytecode processing tools and decided to experiment with @kotlin.Generated (https://youtrack.jetbrains.com/issue/KT-41906) to have a consistent marker for most of the autogenerated members

@Godin
Copy link
Member

Godin commented Sep 18, 2020

@qwwdfsad first of all thanks a lot! ❤️

We'll consider it a bug for now: https://youtrack.jetbrains.com/issue/KT-41903

As of today title is "JVM IR: do not generate LineNumberTable in auto-generated members of data classes",
however quoting #1086 (comment)

Using our validation tests one can observe other changes in how the Kotlin compiler generates bytecode

😉 for another example for the following DelegatedList.kt that is not about data classes

class DelegatedList : List<Int> by ArrayList()

execution of

kotlin-compiler-1.4.10/bin/kotlinc DelegatedList.kt \
    && javap -v -p DelegatedList.class

shows

  public int getSize();
    descriptor: ()I
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: getfield      #20                 // Field $$delegate_0:Ljava/util/ArrayList;
         4: invokevirtual #30                 // Method java/util/ArrayList.size:()I
         7: ireturn
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   LDelegatedList;

but execution with -Xuse-ir

kotlin-compiler-1.4.10/bin/kotlinc -Xuse-ir DelegatedList.kt \
    && javap -v -p DelegatedList.class

shows that LineNumberTable appears

  public int getSize();
    descriptor: ()I
    flags: ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: getfield      #20                 // Field $$delegate_0:Ljava/util/ArrayList;
         4: invokevirtual #99                 // Method java/util/ArrayList.size:()I
         7: ireturn
      LineNumberTable:
        line 1: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       8     0  this   LDelegatedList;

@qwwdfsad
Copy link

Thanks, it is also being fixed :) https://youtrack.jetbrains.com/issue/KT-41960

@Godin Godin self-assigned this Apr 30, 2021
@Godin Godin added this to Candidates in Current work items via automation Apr 30, 2021
@Godin Godin moved this from Candidates to Implementation in Current work items Apr 30, 2021
@Godin Godin added this to the 0.8.7 milestone Apr 30, 2021
@Godin Godin removed the feedback pending Further information is requested label May 4, 2021
@Godin
Copy link
Member

Godin commented May 4, 2021

After #1162, #1164, #1166, #1172, #1174, #1178 and #1181
our validation tests pass
with Kotlin compiler version 1.5.0 that uses new IR backend
as well as with Kotlin compiler version 1.4.32 with option -Xuse-ir
So I'm closing this ticket.

@Godin Godin closed this as completed May 4, 2021
Current work items automation moved this from Implementation to Done May 4, 2021
@Godin Godin added type: enhancement and removed type: bug 🐛 Something isn't working labels May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants