Status Update
Comments
ag...@google.com <ag...@google.com> #2
Hi Sebastian
You are right that R8 is doing the same desugaring of default interface methods as D8. Can you provide a bit more information on what you are seeing? Which version of D8/R8 are you using? Are you invoking D8/R8 from the command line or are you using a build system? If you are using it from the command-line, can you give an example of the command-line that you are using? With R8 you should use one invocation with all the class files as input in one go to build the final dex. Could it be that you end up merging things together where parts of it has been built with desugaring and the other part has not? If you can provide a reproduction either here on the bug or privately to
Thanks, Mads
pr...@gmail.com <pr...@gmail.com> #3
I build R8/D8 from source, it should be just a few commits behind master. I needed to apply a minimal patch to avoid a NPE, because R8 should process a java.lang.Object class, you can find it here:
I wanted to contribute it back, but my CLA wasn't processed yet. But I also don't think that the patch is related to the behavior I noticed.
What I do is that I have 3 jars that I want to dex. When I do it with d8 all works fine (command line can be seen in the reproducer). When I just switch d8 with r8 it fails with the exception mentioned in my first message, but as far as I understand it at the dexing point.
I appended a reproducer, but it includes the used jars from my project, therefor it is pretty large. If a minimal reproducer is needed I can try to provide one in the next days.
In the reproducer there are two shell scripts, that should show the issue I'm facing. When executing the d8 script all does fine, when executing the r8 script it fails with the exception mentioned above.
Kind regards,
Sebastian
ag...@google.com <ag...@google.com> #4
Having java.lang.Object
in your inputs is not really a supported use-case for R8. What is your use case here? Are you building some kind of custom Android system image? If you are building a regular Android app, you should usually not put java.*
types in your APK and they will never be used anyway. The system will take the java.lang.Object
from the bootclasspath and not the one in your app.
That said, it is indeed interesting that the desugaring goes wrong here. Filtering out all the java/android classes in the input and adding android.jar as --lib input and running R8 with assertions enabled, here is the stack trace:
Error: java.lang.AssertionError
Compilation failed with an internal error.
Exception in thread "main" java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
at com.android.tools.r8.utils.ExceptionUtils.withMainProgramHandler(ExceptionUtils.java:189)
at com.android.tools.r8.R8.main(R8.java:1125)
at com.android.tools.r8.SwissArmyKnife.main(SwissArmyKnife.java:63)
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
at Version.fakeStackEntry(Version_main.java:0)
at com.android.tools.r8.utils.ExceptionUtils.failWithFakeEntry(ExceptionUtils.java:139)
at com.android.tools.r8.utils.ExceptionUtils.failCompilation(ExceptionUtils.java:89)
at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:83)
at com.android.tools.r8.utils.ExceptionUtils.withR8CompilationHandler(ExceptionUtils.java:69)
at com.android.tools.r8.R8.run(R8.java:1109)
at com.android.tools.r8.R8.lambda$main$26(R8.java:1125)
at com.android.tools.r8.utils.ExceptionUtils.withMainProgramHandler(ExceptionUtils.java:186)
... 2 more
Caused by: java.lang.AssertionError
at com.android.tools.r8.utils.collections.DexClassAndMethodSetBase.add(DexClassAndMethodSetBase.java:38)
at com.android.tools.r8.shaking.Enqueuer.addToPendingDesugaring(Enqueuer.java:3839)
at com.android.tools.r8.shaking.Enqueuer.traceNonDesugaredCode(Enqueuer.java:4609)
at com.android.tools.r8.shaking.Enqueuer.markMethodAsLive(Enqueuer.java:4553)
at com.android.tools.r8.shaking.EnqueuerWorklist$MarkMethodLiveAction.run(EnqueuerWorklist.java:166)
at com.android.tools.r8.shaking.Enqueuer.trace(Enqueuer.java:4213)
at com.android.tools.r8.shaking.Enqueuer.traceApplication(Enqueuer.java:3496)
at com.android.tools.r8.R8.runEnqueuer(R8.java:1015)
at com.android.tools.r8.R8.run(R8.java:372)
at com.android.tools.r8.R8.run(R8.java:258)
at com.android.tools.r8.R8.lambda$run$25(R8.java:1110)
at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:80)
... 6 more
We should have a look at that and figure out what is going on there.
pr...@gmail.com <pr...@gmail.com> #5
Thanks for looking into this!
mk...@google.com <mk...@google.com> #6
D8 is compiling java to be desugared such that it can run on ART. Desugared output from D8 is never ment to be consumed by a java compiler and dependending on the min-api level (which is an android level api level) it may or may not desugar default methods.
When compiling R8 with a class file output the output is ment to be consumed by a java compiler and R8, I believe, will not consider a min-api. It will assume that the version used for javac compilation is the same for running/addition compilation and will therefore not desugar default methods.
There is no correspondance between min-api and class file versions. If you really want to persue this direction I would recommend using D8 to produce output for an api-level you consider being sufficient for java 7 and then use R8 on it. I believe that should work.
pr...@gmail.com <pr...@gmail.com> #7
I use R8/D8 to produce dex files as output and the dex files will be than compiled with a dex2oat compiler (to use it later on iOS). I use 21 as min api level which should desugar the default methods. This is working when using D8 for producing dex files (see my reproducer). When I now just switch the d8 execution with the r8 execution (+proguard config), the desugaring fails for default methods(see reproducer). Everything else (lambdas, Buffer 9+ Api etc.) will be correctly backported/desugared, the same way just d8 does. Both dex outputs, from d8 and r8 (when no default interface needs to be desugared) leads to a sucessful launch of the app, therefor the general approach is working!
As also the other person analysed, the exception has nothing to do with the java/android classes used in the jar, since the same behavior occures without them. It is only that I can't run r8 on the jar in the reproducer. I would consider this a bug in R8, or am I wrong?
ze...@google.com <ze...@google.com>
ze...@google.com <ze...@google.com> #8
Thank you for the report and for including a reproduction! This is an R8 bug which is subtly caused by having two (or more) keep rules that target an interface method that is defined as a default method on a super-interface. R8 then incorrectly generates multiple bridges. We should have a fix up shortly and I'll post back.
Regarding compiling with java.lang.Object, while R8 does not explicitly support that, there is no reason we should fail on it. I'll update the places that fail based on the reproduction project too.
ap...@google.com <ap...@google.com> #9
Branch: main
commit b14927241155613d1aa8de398494d84fdec68f55
Author: Ian Zerny <zerny@google.com>
Date: Tue Apr 19 14:38:06 2022
Regression test for insertion of multiple interface bridges.
Bug:
Change-Id: I7591d8c02847a8908397a8a7966875b40dcd0fc1
M src/main/java/com/android/tools/r8/shaking/Enqueuer.java
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
A src/test/java/com/android/tools/r8/shaking/interfacebridge/MultipleRulesRegression228791247Test.java
M src/main/java/com/android/tools/r8/optimize/argumentpropagation/utils/DepthFirstTopDownClassHierarchyTraversal.java
ap...@google.com <ap...@google.com> #10
Branch: main
commit f3628f7a1f18b25b04d25342da87985e3e573ee0
Author: Ian Zerny <zerny@google.com>
Date: Wed Apr 20 08:09:32 2022
Maintain canonical interface bridges.
Bug:
Change-Id: I81e2d06133c15a57c0547c66313cc7fdddafe1cc
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
M src/test/java/com/android/tools/r8/shaking/methods/interfaces/MultipleRulesRegression228791247Test.java
ze...@google.com <ze...@google.com> #11
The reproduction in
We need to check the presence of this issue on our release branches so keeping this open until resolved on branches.
ap...@google.com <ap...@google.com> #12
Branch: 3.2
commit d883e9f3f238a0f9c9c9e3ec7ae3edd8be415bf9
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 11:12:10 2022
Version 3.2.57
Bug:
Change-Id: I134b9f021a6f8d1637d1a79c004ae0aa7a9ae434
M src/main/java/com/android/tools/r8/Version.java
ap...@google.com <ap...@google.com> #13
Branch: 3.2
commit bc81e378b114b907afb0f5b75a4aa19421cd8541
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 11:11:02 2022
Maintain canonical interface bridges.
Bug:
Change-Id: I81e2d06133c15a57c0547c66313cc7fdddafe1cc
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
M src/test/java/com/android/tools/r8/shaking/methods/interfaces/MultipleRulesRegression228791247Test.java
ap...@google.com <ap...@google.com> #14
Branch: 3.2
commit 19a4c33e710e4add60553f40c13afa1070f9bfab
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 11:08:43 2022
Regression test for insertion of multiple interface bridges.
Bug:
Change-Id: I7591d8c02847a8908397a8a7966875b40dcd0fc1
M src/main/java/com/android/tools/r8/shaking/Enqueuer.java
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
A src/test/java/com/android/tools/r8/shaking/interfacebridge/MultipleRulesRegression228791247Test.java
M src/main/java/com/android/tools/r8/optimize/argumentpropagation/utils/DepthFirstTopDownClassHierarchyTraversal.java
ap...@google.com <ap...@google.com> #15
Branch: 3.1
commit 58b10fa7a87dd760a3a8dab1b9b3467ef0f25c22
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 11:29:47 2022
Version 3.1.72
Bug:
Change-Id: Ib8e3ff51d53a856b8c9b7cfdbba8a68890f795f2
M src/main/java/com/android/tools/r8/Version.java
ap...@google.com <ap...@google.com> #16
Branch: 3.1
commit 7fb677412dfba1863e05eb2a74088ccd22d59942
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 11:28:35 2022
Maintain canonical interface bridges.
Bug:
Change-Id: I81e2d06133c15a57c0547c66313cc7fdddafe1cc
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
M src/test/java/com/android/tools/r8/shaking/methods/interfaces/MultipleRulesRegression228791247Test.java
ap...@google.com <ap...@google.com> #17
Branch: 3.1
commit e939877e9a6c3c0537e08cddcbef06f87bcdb4b5
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 11:18:16 2022
Regression test for insertion of multiple interface bridges.
Bug:
Change-Id: I7591d8c02847a8908397a8a7966875b40dcd0fc1
M src/main/java/com/android/tools/r8/shaking/Enqueuer.java
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
A src/test/java/com/android/tools/r8/shaking/interfacebridge/MultipleRulesRegression228791247Test.java
M src/main/java/com/android/tools/r8/optimize/argumentpropagation/utils/DepthFirstTopDownClassHierarchyTraversal.java
ap...@google.com <ap...@google.com> #18
Branch: 3.3
commit 312b16c970407cac05ee598180021714ea5d2e79
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 09:53:58 2022
Version 3.3.30
Bug:
Change-Id: I1ecdd5f31da25ce88c6e6fd4f2240cee3435e814
M src/main/java/com/android/tools/r8/Version.java
ap...@google.com <ap...@google.com> #19
Branch: 3.3
commit a93207ef765f5cb22814c5d4d5e0b3b4e7228e2d
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 09:52:07 2022
Maintain canonical interface bridges.
Bug:
Change-Id: I81e2d06133c15a57c0547c66313cc7fdddafe1cc
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
M src/test/java/com/android/tools/r8/shaking/methods/interfaces/MultipleRulesRegression228791247Test.java
ap...@google.com <ap...@google.com> #20
Branch: 3.3
commit e75e0e5696ba55c160fc1fe05d98f28542ee17f4
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 09:06:53 2022
Regression test for insertion of multiple interface bridges.
Bug:
Change-Id: I7591d8c02847a8908397a8a7966875b40dcd0fc1
M src/main/java/com/android/tools/r8/shaking/Enqueuer.java
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
A src/test/java/com/android/tools/r8/shaking/interfacebridge/MultipleRulesRegression228791247Test.java
M src/main/java/com/android/tools/r8/optimize/argumentpropagation/utils/DepthFirstTopDownClassHierarchyTraversal.java
ap...@google.com <ap...@google.com> #21
Branch: 3.2
commit bc81e378b114b907afb0f5b75a4aa19421cd8541
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 11:11:02 2022
Maintain canonical interface bridges.
Bug:
Change-Id: I81e2d06133c15a57c0547c66313cc7fdddafe1cc
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
M src/test/java/com/android/tools/r8/shaking/methods/interfaces/MultipleRulesRegression228791247Test.java
ap...@google.com <ap...@google.com> #22
Branch: 3.2
commit 19a4c33e710e4add60553f40c13afa1070f9bfab
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 11:08:43 2022
Regression test for insertion of multiple interface bridges.
Bug:
Change-Id: I7591d8c02847a8908397a8a7966875b40dcd0fc1
M src/main/java/com/android/tools/r8/shaking/Enqueuer.java
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
A src/test/java/com/android/tools/r8/shaking/interfacebridge/MultipleRulesRegression228791247Test.java
M src/main/java/com/android/tools/r8/optimize/argumentpropagation/utils/DepthFirstTopDownClassHierarchyTraversal.java
ap...@google.com <ap...@google.com> #23
Branch: 3.3
commit a93207ef765f5cb22814c5d4d5e0b3b4e7228e2d
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 09:52:07 2022
Maintain canonical interface bridges.
Bug:
Change-Id: I81e2d06133c15a57c0547c66313cc7fdddafe1cc
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
M src/test/java/com/android/tools/r8/shaking/methods/interfaces/MultipleRulesRegression228791247Test.java
ap...@google.com <ap...@google.com> #24
Branch: 3.3
commit e75e0e5696ba55c160fc1fe05d98f28542ee17f4
Author: Ian Zerny <zerny@google.com>
Date: Thu Apr 21 09:06:53 2022
Regression test for insertion of multiple interface bridges.
Bug:
Change-Id: I7591d8c02847a8908397a8a7966875b40dcd0fc1
M src/main/java/com/android/tools/r8/shaking/Enqueuer.java
M src/main/java/com/android/tools/r8/shaking/RootSetUtils.java
A src/test/java/com/android/tools/r8/shaking/interfacebridge/MultipleRulesRegression228791247Test.java
M src/main/java/com/android/tools/r8/optimize/argumentpropagation/utils/DepthFirstTopDownClassHierarchyTraversal.java
pr...@gmail.com <pr...@gmail.com> #25
I wasn't able to test it on a running application of mine yet, because of another issue, but it probably should work fine!
ze...@google.com <ze...@google.com> #26
Thanks for confirming and again for taking the time to report the issue! The fix has now been included on release branches back to 3.1
Description
Description has been deleted.