Reland "Add library retargeting classes into retarget package"
This reverts commit a913e035e76f4403c54232b26effd63212aaf90e.
Change-Id: Ifd8fa265578a7cb567e4593b0a05a26e29b54088
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryRetargeter.java b/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryRetargeter.java
index 3dc74ac..1bda095 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryRetargeter.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/DesugaredLibraryRetargeter.java
@@ -43,6 +43,7 @@
import com.android.tools.r8.ir.code.InvokeStatic;
import com.android.tools.r8.ir.conversion.IRConverter;
import com.android.tools.r8.origin.SynthesizedOrigin;
+import com.android.tools.r8.utils.InternalOptions;
import com.android.tools.r8.utils.StringDiagnostic;
import com.android.tools.r8.utils.WorkList;
import com.android.tools.r8.utils.collections.DexClassAndMethodSet;
@@ -64,6 +65,7 @@
public class DesugaredLibraryRetargeter {
+ private static final String RETARGET_PACKAGE = "retarget/";
public static final String DESUGAR_LIB_RETARGET_CLASS_NAME_PREFIX =
"$r8$retargetLibraryMember$virtualDispatch";
@@ -76,14 +78,27 @@
// Non final virtual library methods requiring generation of emulated dispatch.
private final DexClassAndMethodSet emulatedDispatchMethods = DexClassAndMethodSet.create();
+ private final String packageAndClassDescriptorPrefix;
+
public DesugaredLibraryRetargeter(AppView<?> appView) {
this.appView = appView;
+ packageAndClassDescriptorPrefix =
+ getRetargetPackageAndClassPrefixDescriptor(appView.options().desugaredLibraryConfiguration);
if (appView.options().desugaredLibraryConfiguration.getRetargetCoreLibMember().isEmpty()) {
return;
}
new RetargetingSetup().setUpRetargeting();
}
+ public static boolean isRetargetType(DexType type, InternalOptions options) {
+ if (options.desugaredLibraryConfiguration == null) {
+ return false;
+ }
+ return type.toDescriptorString()
+ .startsWith(
+ getRetargetPackageAndClassPrefixDescriptor(options.desugaredLibraryConfiguration));
+ }
+
public static void checkForAssumedLibraryTypes(AppView<?> appView) {
Map<DexString, Map<DexType, DexType>> retargetCoreLibMember =
appView.options().desugaredLibraryConfiguration.getRetargetCoreLibMember();
@@ -668,14 +683,17 @@
return dispatchTypeFor(method, "dispatchHolder");
}
+ private static String getRetargetPackageAndClassPrefixDescriptor(
+ DesugaredLibraryConfiguration config) {
+ return "L"
+ + config.getSynthesizedLibraryClassesPackagePrefix()
+ + RETARGET_PACKAGE
+ + DESUGAR_LIB_RETARGET_CLASS_NAME_PREFIX;
+ }
+
private DexType dispatchTypeFor(DexClassAndMethod method, String suffix) {
String descriptor =
- "L"
- + appView
- .options()
- .desugaredLibraryConfiguration
- .getSynthesizedLibraryClassesPackagePrefix()
- + DESUGAR_LIB_RETARGET_CLASS_NAME_PREFIX
+ packageAndClassDescriptorPrefix
+ '$'
+ method.getHolderType().getName()
+ '$'
diff --git a/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java b/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
index 6b316f7..7443af8 100644
--- a/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
+++ b/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
@@ -45,6 +45,7 @@
import com.android.tools.r8.ir.analysis.type.ClassTypeElement;
import com.android.tools.r8.ir.code.Invoke.Type;
import com.android.tools.r8.ir.desugar.DesugaredLibraryAPIConverter;
+import com.android.tools.r8.ir.desugar.DesugaredLibraryRetargeter;
import com.android.tools.r8.ir.desugar.InterfaceMethodRewriter;
import com.android.tools.r8.ir.desugar.LambdaDescriptor;
import com.android.tools.r8.ir.desugar.TwrCloseResourceRewriter;
@@ -470,8 +471,8 @@
// TODO(b/150693139): Remove these exceptions once fixed.
|| InterfaceMethodRewriter.isCompanionClassType(type)
|| InterfaceMethodRewriter.isEmulatedLibraryClassType(type)
- || type.toDescriptorString().startsWith("Lj$/$r8$retargetLibraryMember$")
|| TwrCloseResourceRewriter.isUtilityClassDescriptor(type)
+ || DesugaredLibraryRetargeter.isRetargetType(type, options())
// TODO(b/150736225): Not sure how to remove these.
|| DesugaredLibraryAPIConverter.isVivifiedType(type)
: "Failed lookup of non-missing type: " + type;