Add temporary experimental flag
Bug: 202686322
Change-Id: I33ca3a4abe65c1ec639d03a124fc6f5410f93a1b
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryConfiguration.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryConfiguration.java
index 84e3558..326b3c9 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryConfiguration.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryConfiguration.java
@@ -57,6 +57,7 @@
private final Map<DexType, DexType> backportCoreLibraryMember;
private final Map<DexType, DexType> customConversions;
private final List<Pair<DexType, DexString>> dontRewriteInvocation;
+ private final Set<DexType> dontRetargetLibMember;
private final List<String> extraKeepRules;
private final Set<DexType> wrapperConversions;
private final PrefixRewritingMapper prefixRewritingMapper;
@@ -81,6 +82,7 @@
ImmutableMap.of(),
ImmutableSet.of(),
ImmutableList.of(),
+ ImmutableSet.of(),
ImmutableList.of(),
new DesugarPrefixRewritingMapper(prefix, options.itemFactory, true));
}
@@ -100,6 +102,7 @@
ImmutableMap.of(),
ImmutableSet.of(),
ImmutableList.of(),
+ ImmutableSet.of(),
ImmutableList.of(),
PrefixRewritingMapper.empty()) {
@@ -129,6 +132,7 @@
Map<DexType, DexType> customConversions,
Set<DexType> wrapperConversions,
List<Pair<DexType, DexString>> dontRewriteInvocation,
+ Set<DexType> dontRetargetLibMember,
List<String> extraKeepRules,
PrefixRewritingMapper prefixRewritingMapper) {
this.requiredCompilationAPILevel = requiredCompilationAPILevel;
@@ -144,6 +148,7 @@
this.customConversions = customConversions;
this.wrapperConversions = wrapperConversions;
this.dontRewriteInvocation = dontRewriteInvocation;
+ this.dontRetargetLibMember = dontRetargetLibMember;
this.extraKeepRules = extraKeepRules;
this.prefixRewritingMapper = prefixRewritingMapper;
}
@@ -233,6 +238,10 @@
return dontRewriteInvocation;
}
+ public Set<DexType> getDontRetargetLibMember() {
+ return dontRetargetLibMember;
+ }
+
public List<String> getExtraKeepRules() {
return extraKeepRules;
}
@@ -262,6 +271,8 @@
private Map<DexType, DexType> customConversions = new IdentityHashMap<>();
private Set<DexType> wrapperConversions = Sets.newIdentityHashSet();
private List<Pair<DexType, DexString>> dontRewriteInvocation = new ArrayList<>();
+ private Set<DexType> dontRetargetLibMember = Sets.newIdentityHashSet();
+ ;
private List<String> extraKeepRules = Collections.emptyList();
private boolean supportAllCallbacksFromLibrary = FALL_BACK_SUPPORT_ALL_CALLBACKS_FROM_LIBRARY;
@@ -395,6 +406,11 @@
return this;
}
+ public Builder addDontRetargetLibMember(String dontRetargetLibMember) {
+ this.dontRetargetLibMember.add(stringClassToDexType(dontRetargetLibMember));
+ return this;
+ }
+
private int sharpIndex(String typeAndSelector, String descr) {
int index = typeAndSelector.lastIndexOf('#');
if (index <= 0 || index >= typeAndSelector.length() - 1) {
@@ -428,6 +444,7 @@
ImmutableMap.copyOf(customConversions),
ImmutableSet.copyOf(wrapperConversions),
ImmutableList.copyOf(dontRewriteInvocation),
+ ImmutableSet.copyOf(dontRetargetLibMember),
ImmutableList.copyOf(extraKeepRules),
rewritePrefix.isEmpty()
? PrefixRewritingMapper.empty()
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryConfigurationParser.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryConfigurationParser.java
index 9b0862e..f8b69f6 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryConfigurationParser.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryConfigurationParser.java
@@ -45,6 +45,7 @@
static final String RETARGET_LIB_MEMBER_KEY = "retarget_lib_member";
static final String EMULATE_INTERFACE_KEY = "emulate_interface";
static final String DONT_REWRITE_KEY = "dont_rewrite";
+ static final String DONT_RETARGET_LIB_MEMBER_KEY = "dont_retarget_lib_member";
static final String BACKPORT_KEY = "backport";
static final String SHRINKER_CONFIG_KEY = "shrinker_config";
static final String SUPPORT_ALL_CALLBACKS_FROM_LIBRARY_KEY = "support_all_callbacks_from_library";
@@ -222,5 +223,11 @@
configurationBuilder.addDontRewriteInvocation(rewrite.getAsString());
}
}
+ if (jsonFlagSet.has(DONT_RETARGET_LIB_MEMBER_KEY)) {
+ JsonArray dontRetarget = jsonFlagSet.get(DONT_RETARGET_LIB_MEMBER_KEY).getAsJsonArray();
+ for (JsonElement rewrite : dontRetarget) {
+ configurationBuilder.addDontRetargetLibMember(rewrite.getAsString());
+ }
+ }
}
}
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryRetargeterPostProcessor.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryRetargeterPostProcessor.java
index c268bfd..1a2adfb 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryRetargeterPostProcessor.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/DesugaredLibraryRetargeterPostProcessor.java
@@ -121,6 +121,13 @@
// The class has already been desugared.
continue;
}
+ if (appView
+ .options()
+ .desugaredLibraryConfiguration
+ .getDontRetargetLibMember()
+ .contains(clazz.getType())) {
+ continue;
+ }
clazz.addExtraInterfaces(
Collections.singletonList(new ClassTypeSignature(newInterface.type)));
eventConsumer.acceptInterfaceInjection(clazz, newInterface);