-
-
Notifications
You must be signed in to change notification settings - Fork 287
Coverage on 2.12 might have issues #1056
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
Comments
I'm checking on this issue. I compared However the same differences are already visible in 2.12's d1.jar contains:
2.11's d1.jar contains:
The instrumented jars are similar in that they contain instrumented class files respectively. And, most importantly, it's not the case, that the code from |
Going further... I found this: https://users.scala-lang.org/t/has-a-loop-recurs-comprehension-been-considered-for-scala/4787/21 "It was desugared this way in Scala 2.11 and earlier. Scala 2.12 uses low-level Java 8 constructs for creating lightweight lambdas, but they have the same semantics as anonymous inner classes shown above." I think the issue is about the compilation of lightweight lambdas. The example in https://www.scala-lang.org/news/2.12.0/ "Scala and Java 8 interop is also improved for functional code, as methods that take functions can easily be called in both directions using lambda syntax. The FunctionN classes in Scala’s standard library are now Single Abstract Method (SAM) types, and all SAM types are treated uniformly – from type checking through code generation. No class file is generated for a lambda; invokedynamic is used instead." (highlighting by me) |
Maybe there is an issue with Jacoco? https://stackoverflow.com/questions/45674950/jacoco-need-special-handling-fro-lambdas Also in Jacoco release notes a similar issue was mentioned: https://www.jacoco.org/jacoco/trunk/doc/changes.html
However, I see, that most problably Bazel now uses Jacoco 0.8.3. |
I believe this is a bug on Jacoco. Looking at the implementation of the synthetic Lambda fix in Jacoco (https://github.com/jacoco/jacoco/pull/232/files) it seems there is a filter on lambda names, that they have to start with I've added a Java example (from jacoco/jacoco#885 (comment)) to my rules_scala repo, and coverage for the lambdas there is properly detected. Then, I tried decompiling the code for For Scala: Includes: Clearly this method's name is not starting with "lambda$", but rather "$anonfun$". For Java: Includes: This method's name starts with "lambda$". So I'd claim, that Jacoco is prepared for how the Java compiler names the lambdas, but it isn't prepared for how the Scala 2.12 compiler names the lambdas, and then those get ignored in the coverage. |
Current master of Jacoco seems to have support for Scala lambdas: This was fixed in jacoco/jacoco#912 and then later improved in jacoco/jacoco#922. Both changes are part of 0.8.5 release of Jacoco (Bazel still uses Jacoco 0.8.3). |
Nice! |
I'm having hard time to try out this new Jacoco version, so it's simply theory I wrote about, before I'd have some hard proof that indeed this new Jacoco version works. I tried to replace the Jacoco version to 0.8.5 locally (in Bazel), but I haven't been successful (or the 0.8.5 version also does not work - but I doubt that). |
I tried outside of Bazel... Inspiration is coming from jacoco/jacoco#885 (comment). Modified
Steps:
I'd suggest to create an issue on Bazel (or whereever else necessary) to upgrade to Jacoco 0.8.5 (at least to fix this bug for Scala). |
I think now we know what happened. Summary: Scala 2.12 changes class generation comparing to Scala 2.11, and it uses Java bytecode for native lambdas, but their names in the bytecode are different from Java conventional naming. We'd need to upgrade Jacoco version in Bazel to get this fixed. |
Thanks! |
In Bazel itself Jacoco version is in:
In
And surely that's not all, because changing the above did not suffice for me. I'm not sure we could override all of these from rules_scala. I believe Bazel should have a single setting for Jacoco, as many languages use it, e.g. not only Scala, but Java and Kotlin too. |
CC: @iirina, what do you think, is there any other way to fix this issue, than upgrading Jacoco in Bazel to 0.8.5? |
Opened an issue on Bazel to upgrade Jacoco to 0.8.5: bazelbuild/bazel#11674 |
Thanks, well done!
…On Tue, Jun 30, 2020 at 9:03 AM Gergely Fábián ***@***.***> wrote:
Opened an issue on Bazel to upgrade Jacoco to 0.8.5:
bazelbuild/bazel#11674 <bazelbuild/bazel#11674>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1056 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKQQF3JLI4ORR2K2BKJW2TRZF52JANCNFSM4N4DN2NQ>
.
--
*Ittai Zeidman*
40 Hanamal street, Tel Aviv, Israel
<http://www.wix.com>
|
I have the workaround for this issue. It can be fixed by using jacocorunner property of java_toolchain. Example project: https://github.com/gergelyfabian/bazel-scala-example/tree/jacoco_coverage_fix Steps so far:
For me this workaround is ok until Bazel gets Jacoco upgraded officially. There is a question though, how should we approach jacocorunner in |
If anyone is interested, a loosely related topic... I created a PR on Jacoco to improve Scala case class code coverage: jacoco/jacoco#1136. |
Issue is vague because we're not really sure what happened.
When running our coverage test on 2.12 we found that the coverage file changed.
When we compared the files we saw significant changes which we can't explain for now.
This is an issue to track progress of understanding whether this is a bug or just different class generation between 2.11 and 2.12
See #1054 for more details.
The text was updated successfully, but these errors were encountered: