Revert "Use Machine desugared library flag where obvious" Revert submission 65698 Reason for revert: bots red Reverted Changes: I2c822452c:Use Machine desugared library flag where obvious Icf25fb1d1:Enabling machine desugared library specification Change-Id: I1e81d3f7373888cd27c297a7372e4c2b942f2f3b
diff --git a/src/main/java/com/android/tools/r8/R8.java b/src/main/java/com/android/tools/r8/R8.java index e57f3e1..b96eaef 100644 --- a/src/main/java/com/android/tools/r8/R8.java +++ b/src/main/java/com/android/tools/r8/R8.java
@@ -310,7 +310,7 @@ if (!options.mainDexKeepRules.isEmpty()) { MainDexListBuilder.checkForAssumedLibraryTypes(appView.appInfo()); } - if (options.machineDesugaredLibrarySpecification.hasRetargeting()) { + if (!options.desugaredLibrarySpecification.getRetargetCoreLibMember().isEmpty()) { DesugaredLibraryRetargeterLibraryTypeSynthesizer.checkForAssumedLibraryTypes(appView); DesugaredLibraryRetargeterLibraryTypeSynthesizer.amendLibraryWithRetargetedMembers(appView); }
diff --git a/src/main/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryKeepRuleGenerator.java b/src/main/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryKeepRuleGenerator.java index 8bdf5a1..a720021 100644 --- a/src/main/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryKeepRuleGenerator.java +++ b/src/main/java/com/android/tools/r8/desugar/desugaredlibrary/DesugaredLibraryKeepRuleGenerator.java
@@ -71,7 +71,7 @@ return false; } return namingLens.hasPrefixRewritingLogic() - || options.machineDesugaredLibrarySpecification.hasEmulatedInterfaces(); + || options.desugaredLibrarySpecification.hasEmulatedLibraryInterfaces(); } private void run() {
diff --git a/src/main/java/com/android/tools/r8/dex/CodeToKeep.java b/src/main/java/com/android/tools/r8/dex/CodeToKeep.java index 3adc951..cc05c31 100644 --- a/src/main/java/com/android/tools/r8/dex/CodeToKeep.java +++ b/src/main/java/com/android/tools/r8/dex/CodeToKeep.java
@@ -25,7 +25,7 @@ static CodeToKeep createCodeToKeep(InternalOptions options, NamingLens namingLens) { if ((!namingLens.hasPrefixRewritingLogic() - && !options.machineDesugaredLibrarySpecification.hasEmulatedInterfaces()) + && !options.desugaredLibrarySpecification.hasEmulatedLibraryInterfaces()) || options.isDesugaredLibraryCompilation() || options.testing.enableExperimentalDesugaredLibraryKeepRuleGenerator) { return new NopCodeToKeep(); @@ -65,7 +65,7 @@ this.namingLens = namingLens; this.options = options; potentialTypesToKeep.addAll( - options.machineDesugaredLibrarySpecification.getEmulatedInterfaceRewrittenTypes()); + options.desugaredLibrarySpecification.getEmulateLibraryInterface().values()); potentialTypesToKeep.addAll( options.desugaredLibrarySpecification.getCustomConversions().values()); } @@ -77,7 +77,7 @@ || type.toDescriptorString() .startsWith( "L" - + options.machineDesugaredLibrarySpecification + + options.desugaredLibrarySpecification .getSynthesizedLibraryClassesPackagePrefix()); }
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/BackportedMethodRewriter.java b/src/main/java/com/android/tools/r8/ir/desugar/BackportedMethodRewriter.java index 0606d2d..49ad698 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/BackportedMethodRewriter.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/BackportedMethodRewriter.java
@@ -128,16 +128,24 @@ DexMethod original = appView.graphLens().getOriginalMethodSignature(method); assert original != null; MethodProvider provider = rewritableMethods.getProvider(original); - // Old versions of desugared library have in the jar file pre-desugared code. This is used - // to undesugar pre-desugared code, then the code is re-desugared with D8/R8. This is - // maintained for legacy only, recent desugared library should not be shipped with - // pre-desugared code. - Map<DexType, DexType> legacyBackport = - appView.options().machineDesugaredLibrarySpecification.getLegacyBackport(); + // TODO(b/150693139): Since the DesugarLibraryRetargeter is run during IR processing while the + // backported method rewriter is run in cf to cf, we need here to compute if the method is + // actually going to be retargeted through desugared library backports, and compute the + // corresponding backported method if so. This can be removed once the DesugarLibraryRetargeter + // has been moved as a cf to cf transformation. if (provider == null && appView.options().isDesugaredLibraryCompilation() - && legacyBackport.containsKey(method.holder)) { - DexType newHolder = legacyBackport.get(method.holder); + && appView + .options() + .desugaredLibrarySpecification + .getBackportCoreLibraryMember() + .containsKey(method.holder)) { + DexType newHolder = + appView + .options() + .desugaredLibrarySpecification + .getBackportCoreLibraryMember() + .get(method.holder); DexMethod backportedMethod = appView.dexItemFactory().createMethod(newHolder, method.proto, method.name); provider = rewritableMethods.getProvider(backportedMethod);
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/CfPostProcessingDesugaringCollection.java b/src/main/java/com/android/tools/r8/ir/desugar/CfPostProcessingDesugaringCollection.java index 1243435..1fd0ad0 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/CfPostProcessingDesugaringCollection.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/CfPostProcessingDesugaringCollection.java
@@ -57,7 +57,7 @@ InterfaceMethodProcessorFacade interfaceMethodProcessorFacade, RetargetingInfo retargetingInfo) { ArrayList<CfPostProcessingDesugaring> desugarings = new ArrayList<>(); - if (appView.options().machineDesugaredLibrarySpecification.hasRetargeting() + if (!appView.options().desugaredLibrarySpecification.getRetargetCoreLibMember().isEmpty() && !appView.options().isDesugaredLibraryCompilation()) { desugarings.add(new DesugaredLibraryRetargeterPostProcessor(appView, retargetingInfo)); }
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/NonEmptyCfInstructionDesugaringCollection.java b/src/main/java/com/android/tools/r8/ir/desugar/NonEmptyCfInstructionDesugaringCollection.java index e55c246..33c69ac 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/NonEmptyCfInstructionDesugaringCollection.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/NonEmptyCfInstructionDesugaringCollection.java
@@ -82,9 +82,9 @@ this.nestBasedAccessDesugaring = NestBasedAccessDesugaring.create(appView); BackportedMethodRewriter backportedMethodRewriter = null; desugaredLibraryRetargeter = - appView.options().machineDesugaredLibrarySpecification.hasRetargeting() - ? new DesugaredLibraryRetargeter(appView) - : null; + appView.options().desugaredLibrarySpecification.getRetargetCoreLibMember().isEmpty() + ? null + : new DesugaredLibraryRetargeter(appView); if (desugaredLibraryRetargeter != null) { desugarings.add(desugaredLibraryRetargeter); }
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/PrefixRewritingMapper.java b/src/main/java/com/android/tools/r8/ir/desugar/PrefixRewritingMapper.java index f8cf00e..7e1b479 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/PrefixRewritingMapper.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/PrefixRewritingMapper.java
@@ -12,7 +12,7 @@ import com.android.tools.r8.graph.DexString; import com.android.tools.r8.graph.DexType; import com.android.tools.r8.ir.desugar.desugaredlibrary.legacyspecification.LegacyDesugaredLibrarySpecification; -import com.android.tools.r8.ir.desugar.desugaredlibrary.machinespecification.MachineDesugaredLibrarySpecification; +import com.android.tools.r8.ir.desugar.desugaredlibrary.machinespecification.MachineRewritingFlags; import com.android.tools.r8.utils.DescriptorUtils; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; @@ -228,10 +228,10 @@ private final Map<DexType, DexType> rewriteDerivedTypeOnly; public MachineDesugarPrefixRewritingMapper( - PrefixRewritingMapper mapper, MachineDesugaredLibrarySpecification specification) { + PrefixRewritingMapper mapper, MachineRewritingFlags flags) { this.mapper = mapper; - this.rewriteType = new ConcurrentHashMap<>(specification.getRewriteType()); - rewriteDerivedTypeOnly = specification.getRewriteDerivedTypeOnly(); + this.rewriteType = new ConcurrentHashMap<>(flags.getRewriteType()); + rewriteDerivedTypeOnly = flags.getRewriteDerivedTypeOnly(); } @Override
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryAPICallbackSynthesizer.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryAPICallbackSynthesizer.java index 9b07615..150e6c4 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryAPICallbackSynthesizer.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryAPICallbackSynthesizer.java
@@ -109,8 +109,8 @@ if (!appView.rewritePrefix.hasRewrittenTypeInSignature(definition.getProto(), appView) || appView .options() - .machineDesugaredLibrarySpecification - .getEmulatedInterfaces() + .desugaredLibrarySpecification + .getEmulateLibraryInterface() .containsKey(method.getHolderType())) { return false; } @@ -127,7 +127,7 @@ return false; } } - if (!appView.options().machineDesugaredLibrarySpecification.supportAllCallbacksFromLibrary() + if (!appView.options().desugaredLibrarySpecification.supportAllCallbacksFromLibrary() && appView.options().isDesugaredLibraryCompilation()) { return false; } @@ -178,7 +178,7 @@ } private boolean shouldGenerateCallbacksForEmulateInterfaceAPIs(DexClass dexClass) { - if (appView.options().machineDesugaredLibrarySpecification.supportAllCallbacksFromLibrary()) { + if (appView.options().desugaredLibrarySpecification.supportAllCallbacksFromLibrary()) { return true; } Map<DexType, DexType> emulateLibraryInterfaces =
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryAPIConverter.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryAPIConverter.java index f234a1b..987dc8d 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryAPIConverter.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryAPIConverter.java
@@ -181,8 +181,8 @@ return interfaceResult != null && appView .options() - .machineDesugaredLibrarySpecification - .getEmulatedInterfaces() + .desugaredLibrarySpecification + .getEmulateLibraryInterface() .containsKey(interfaceResult.getHolderType()); }
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryWrapperSynthesizer.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryWrapperSynthesizer.java index 1e62da6..725d1e9 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryWrapperSynthesizer.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/apiconversion/DesugaredLibraryWrapperSynthesizer.java
@@ -185,11 +185,7 @@ } private boolean canConvert(DexType type) { - return appView - .options() - .machineDesugaredLibrarySpecification - .getCustomConversions() - .containsKey(type) + return appView.options().desugaredLibrarySpecification.getCustomConversions().containsKey(type) || canGenerateWrapper(type); } @@ -550,6 +546,7 @@ return appView .options() .machineDesugaredLibrarySpecification + .getRewritingFlags() .getWrappers() .get(clazz.type); }
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineDesugaredLibrarySpecification.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineDesugaredLibrarySpecification.java index 3f6ab19..9e65398 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineDesugaredLibrarySpecification.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineDesugaredLibrarySpecification.java
@@ -4,15 +4,8 @@ package com.android.tools.r8.ir.desugar.desugaredlibrary.machinespecification; -import com.android.tools.r8.graph.DexMethod; -import com.android.tools.r8.graph.DexString; import com.android.tools.r8.graph.DexType; -import com.android.tools.r8.utils.AndroidApiLevel; -import com.android.tools.r8.utils.Pair; -import java.util.List; import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; public class MachineDesugaredLibrarySpecification { @@ -20,11 +13,6 @@ private final MachineTopLevelFlags topLevelFlags; private final MachineRewritingFlags rewritingFlags; - public static MachineDesugaredLibrarySpecification empty() { - return new MachineDesugaredLibrarySpecification( - false, MachineTopLevelFlags.empty(), MachineRewritingFlags.builder().build()); - } - public static MachineDesugaredLibrarySpecification withOnlyRewriteTypeForTesting( Map<DexType, DexType> rewriteTypeForTesting) { MachineRewritingFlags.Builder builder = MachineRewritingFlags.builder(); @@ -46,83 +34,11 @@ return libraryCompilation; } - public AndroidApiLevel getRequiredCompilationAPILevel() { - return topLevelFlags.getRequiredCompilationAPILevel(); + public MachineTopLevelFlags getTopLevelFlags() { + return topLevelFlags; } - public String getSynthesizedLibraryClassesPackagePrefix() { - return topLevelFlags.getSynthesizedLibraryClassesPackagePrefix(); - } - - public String getIdentifier() { - return topLevelFlags.getIdentifier(); - } - - public String getJsonSource() { - return topLevelFlags.getJsonSource(); - } - - public boolean supportAllCallbacksFromLibrary() { - return topLevelFlags.supportAllCallbacksFromLibrary(); - } - - public List<String> getExtraKeepRules() { - return topLevelFlags.getExtraKeepRules(); - } - - public Map<DexType, DexType> getRewriteType() { - return rewritingFlags.getRewriteType(); - } - - public Map<DexType, DexType> getRewriteDerivedTypeOnly() { - return rewritingFlags.getRewriteDerivedTypeOnly(); - } - - public Map<DexMethod, DexMethod> getStaticRetarget() { - return rewritingFlags.getStaticRetarget(); - } - - public Map<DexMethod, DexMethod> getNonEmulatedVirtualRetarget() { - return rewritingFlags.getNonEmulatedVirtualRetarget(); - } - - public Map<DexMethod, EmulatedDispatchMethodDescriptor> getEmulatedVirtualRetarget() { - return rewritingFlags.getEmulatedVirtualRetarget(); - } - - public void forEachRetargetHolder(Consumer<DexType> consumer) { - rewritingFlags.forEachRetargetHolder(consumer); - } - - public Map<DexType, EmulatedInterfaceDescriptor> getEmulatedInterfaces() { - return rewritingFlags.getEmulatedInterfaces(); - } - - public Set<DexType> getEmulatedInterfaceRewrittenTypes() { - return rewritingFlags.getEmulatedInterfaceRewrittenTypes(); - } - - public Map<DexType, List<DexMethod>> getWrappers() { - return rewritingFlags.getWrappers(); - } - - public Map<DexType, DexType> getLegacyBackport() { - return rewritingFlags.getLegacyBackport(); - } - - public Set<DexType> getDontRetarget() { - return rewritingFlags.getDontRetarget(); - } - - public Map<DexType, Pair<DexType, DexString>> getCustomConversions() { - return rewritingFlags.getCustomConversions(); - } - - public boolean hasRetargeting() { - return rewritingFlags.hasRetargeting(); - } - - public boolean hasEmulatedInterfaces() { - return rewritingFlags.hasEmulatedInterfaces(); + public MachineRewritingFlags getRewritingFlags() { + return rewritingFlags; } }
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineRewritingFlags.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineRewritingFlags.java index c2c281f..a28fdaa 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineRewritingFlags.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineRewritingFlags.java
@@ -11,12 +11,10 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Consumer; public class MachineRewritingFlags { @@ -96,24 +94,10 @@ return emulatedVirtualRetarget; } - public void forEachRetargetHolder(Consumer<DexType> consumer) { - staticRetarget.keySet().forEach(m -> consumer.accept(m.getHolderType())); - nonEmulatedVirtualRetarget.keySet().forEach(m -> consumer.accept(m.getHolderType())); - emulatedVirtualRetarget.keySet().forEach(m -> consumer.accept(m.getHolderType())); - } - public Map<DexType, EmulatedInterfaceDescriptor> getEmulatedInterfaces() { return emulatedInterfaces; } - public Set<DexType> getEmulatedInterfaceRewrittenTypes() { - Set<DexType> rewrittenTypes = Sets.newIdentityHashSet(); - emulatedInterfaces - .values() - .forEach(descriptor -> rewrittenTypes.add(descriptor.getRewrittenType())); - return rewrittenTypes; - } - public Map<DexType, List<DexMethod>> getWrappers() { return wrappers; } @@ -130,16 +114,6 @@ return customConversions; } - public boolean hasRetargeting() { - return !staticRetarget.isEmpty() - || !nonEmulatedVirtualRetarget.isEmpty() - || !emulatedVirtualRetarget.isEmpty(); - } - - public boolean hasEmulatedInterfaces() { - return !emulatedInterfaces.isEmpty(); - } - public static class Builder { Builder() {}
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineTopLevelFlags.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineTopLevelFlags.java index 0c6a88a..57b79fe 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineTopLevelFlags.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/machinespecification/MachineTopLevelFlags.java
@@ -60,7 +60,7 @@ return jsonSource; } - public boolean supportAllCallbacksFromLibrary() { + public boolean isSupportAllCallbacksFromLibrary() { return supportAllCallbacksFromLibrary; }
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeter.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeter.java index 5fcf037..a54cd8d 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeter.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeter.java
@@ -129,8 +129,8 @@ } if (appView .options() - .machineDesugaredLibrarySpecification - .getDontRetarget() + .desugaredLibrarySpecification + .getDontRetargetLibMember() .contains(context.getContextType())) { return NO_REWRITING; }
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeterL8Synthesizer.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeterL8Synthesizer.java index eb28d20..11fcfb7 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeterL8Synthesizer.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeterL8Synthesizer.java
@@ -20,7 +20,7 @@ AppView<?> appView, RetargetingInfo retargetingInfo) { assert appView.options().isDesugaredLibraryCompilation(); if (retargetingInfo == null || retargetingInfo.getEmulatedVirtualRetarget().isEmpty()) { - assert !appView.options().machineDesugaredLibrarySpecification.hasRetargeting(); + assert appView.options().desugaredLibrarySpecification.getRetargetCoreLibMember().isEmpty(); return null; } return new DesugaredLibraryRetargeterL8Synthesizer(appView, retargetingInfo);
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeterLibraryTypeSynthesizer.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeterLibraryTypeSynthesizer.java index bfb423a..bbaa4cf 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeterLibraryTypeSynthesizer.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/DesugaredLibraryRetargeterLibraryTypeSynthesizer.java
@@ -39,16 +39,16 @@ public class DesugaredLibraryRetargeterLibraryTypeSynthesizer { public static void checkForAssumedLibraryTypes(AppView<?> appView) { - appView - .options() - .machineDesugaredLibrarySpecification - .forEachRetargetHolder( - inType -> { - DexClass typeClass = appView.definitionFor(inType); - if (typeClass == null) { - warnMissingRetargetCoreLibraryMember(inType, appView); - } - }); + Map<DexString, Map<DexType, DexType>> retargetCoreLibMember = + appView.options().desugaredLibrarySpecification.getRetargetCoreLibMember(); + for (DexString methodName : retargetCoreLibMember.keySet()) { + for (DexType inType : retargetCoreLibMember.get(methodName).keySet()) { + DexClass typeClass = appView.definitionFor(inType); + if (typeClass == null) { + warnMissingRetargetCoreLibraryMember(inType, appView); + } + } + } } public static void amendLibraryWithRetargetedMembers(AppView<AppInfoWithClassHierarchy> appView) {
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/RetargetingInfo.java b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/RetargetingInfo.java index b7ac366..88a3104 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/RetargetingInfo.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/desugaredlibrary/retargeter/RetargetingInfo.java
@@ -6,7 +6,7 @@ import com.android.tools.r8.graph.AppView; import com.android.tools.r8.graph.DexMethod; import com.android.tools.r8.ir.desugar.desugaredlibrary.machinespecification.EmulatedDispatchMethodDescriptor; -import com.android.tools.r8.ir.desugar.desugaredlibrary.machinespecification.MachineDesugaredLibrarySpecification; +import com.android.tools.r8.ir.desugar.desugaredlibrary.machinespecification.MachineRewritingFlags; import java.util.Map; public class RetargetingInfo { @@ -25,12 +25,12 @@ } public static RetargetingInfo get(AppView<?> appView) { - MachineDesugaredLibrarySpecification specification = - appView.options().machineDesugaredLibrarySpecification; - return new RetargetingInfo( - specification.getStaticRetarget(), - specification.getNonEmulatedVirtualRetarget(), - specification.getEmulatedVirtualRetarget()); + MachineRewritingFlags rewritingFlags = + appView.options().machineDesugaredLibrarySpecification.getRewritingFlags(); + return new RetargetingInfo( + rewritingFlags.getStaticRetarget(), + rewritingFlags.getNonEmulatedVirtualRetarget(), + rewritingFlags.getEmulatedVirtualRetarget()); } public Map<DexMethod, DexMethod> getStaticRetarget() {
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/itf/ClassProcessor.java b/src/main/java/com/android/tools/r8/ir/desugar/itf/ClassProcessor.java index 9543f58..758812e 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/itf/ClassProcessor.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/itf/ClassProcessor.java
@@ -376,11 +376,11 @@ this.dexItemFactory = appView.dexItemFactory(); this.helper = new InterfaceDesugaringSyntheticHelper(appView); needsLibraryInfo = - appView.options().machineDesugaredLibrarySpecification.hasEmulatedInterfaces() + !appView.options().desugaredLibrarySpecification.getEmulateLibraryInterface().isEmpty() || !appView .options() - .machineDesugaredLibrarySpecification - .getEmulatedVirtualRetarget() + .desugaredLibrarySpecification + .getRetargetCoreLibMember() .isEmpty(); this.isLiveMethod = isLiveMethod; } @@ -510,7 +510,7 @@ DexClass iface = appView.definitionFor(emulatedInterface); if (iface != null) { assert iface.isLibraryClass() - || appView.options().machineDesugaredLibrarySpecification.isLibraryCompilation(); + || appView.options().desugaredLibrarySpecification.isLibraryCompilation(); workList.addIfNotSeen(iface.getInterfaces()); } }
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/itf/InterfaceMethodRewriter.java b/src/main/java/com/android/tools/r8/ir/desugar/itf/InterfaceMethodRewriter.java index e769b3a..6740441 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/itf/InterfaceMethodRewriter.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/itf/InterfaceMethodRewriter.java
@@ -156,9 +156,9 @@ } private void initializeEmulatedInterfaceVariables() { - Set<DexType> emulateLibraryInterface = - options.machineDesugaredLibrarySpecification.getEmulatedInterfaces().keySet(); - for (DexType interfaceType : emulateLibraryInterface) { + Map<DexType, DexType> emulateLibraryInterface = + options.desugaredLibrarySpecification.getEmulateLibraryInterface(); + for (DexType interfaceType : emulateLibraryInterface.keySet()) { DexClass emulatedInterfaceClass = appView.definitionFor(interfaceType); if (emulatedInterfaceClass != null) { for (DexEncodedMethod encodedMethod :
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/itf/ProgramEmulatedInterfaceSynthesizer.java b/src/main/java/com/android/tools/r8/ir/desugar/itf/ProgramEmulatedInterfaceSynthesizer.java index a4249a5..1cb43ef 100644 --- a/src/main/java/com/android/tools/r8/ir/desugar/itf/ProgramEmulatedInterfaceSynthesizer.java +++ b/src/main/java/com/android/tools/r8/ir/desugar/itf/ProgramEmulatedInterfaceSynthesizer.java
@@ -65,6 +65,7 @@ appView .options() .machineDesugaredLibrarySpecification + .getRewritingFlags() .getEmulatedInterfaces() .get(emulatedInterface.type); emulatedInterface.forEachProgramVirtualMethodMatching(
diff --git a/src/main/java/com/android/tools/r8/shaking/L8TreePruner.java b/src/main/java/com/android/tools/r8/shaking/L8TreePruner.java index ab0a04d..960ccd5 100644 --- a/src/main/java/com/android/tools/r8/shaking/L8TreePruner.java +++ b/src/main/java/com/android/tools/r8/shaking/L8TreePruner.java
@@ -28,9 +28,9 @@ public L8TreePruner(InternalOptions options) { this.options = options; - backports.addAll(options.machineDesugaredLibrarySpecification.getLegacyBackport().keySet()); + backports.addAll(options.desugaredLibrarySpecification.getBackportCoreLibraryMember().keySet()); emulatedInterfaces.addAll( - options.machineDesugaredLibrarySpecification.getEmulatedInterfaces().keySet()); + options.desugaredLibrarySpecification.getEmulateLibraryInterface().keySet()); } public DexApplication prune(DexApplication app, PrefixRewritingMapper rewritePrefix) {
diff --git a/src/main/java/com/android/tools/r8/utils/InternalOptions.java b/src/main/java/com/android/tools/r8/utils/InternalOptions.java index 610708f..762c2e0 100644 --- a/src/main/java/com/android/tools/r8/utils/InternalOptions.java +++ b/src/main/java/com/android/tools/r8/utils/InternalOptions.java
@@ -397,8 +397,8 @@ if (isGeneratingDex() || desugarState == DesugarState.ON) { marker.setMinApi(getMinApiLevel().getLevel()); } - if (machineDesugaredLibrarySpecification.getIdentifier() != null) { - marker.setDesugaredLibraryIdentifiers(machineDesugaredLibrarySpecification.getIdentifier()); + if (desugaredLibrarySpecification.getIdentifier() != null) { + marker.setDesugaredLibraryIdentifiers(desugaredLibrarySpecification.getIdentifier()); } if (Version.isDevelopmentVersion()) { marker.setSha1(VersionProperties.INSTANCE.getSha()); @@ -445,7 +445,7 @@ } public boolean isDesugaredLibraryCompilation() { - return machineDesugaredLibrarySpecification.isLibraryCompilation(); + return desugaredLibrarySpecification.isLibraryCompilation(); } public boolean isRelocatorCompilation() { @@ -934,20 +934,19 @@ } // Meant to replace desugaredLibrarySpecification, set only from tests at the moment. - public MachineDesugaredLibrarySpecification machineDesugaredLibrarySpecification = - MachineDesugaredLibrarySpecification.empty(); + public MachineDesugaredLibrarySpecification machineDesugaredLibrarySpecification; public PrefixRewritingMapper getPrefixRewritingMapper() { if (machineDesugaredLibrarySpecification != null) { if (desugaredLibrarySpecification.getRewritePrefix().isEmpty()) { - assert machineDesugaredLibrarySpecification.getRewriteType().isEmpty(); + assert machineDesugaredLibrarySpecification.getRewritingFlags().getRewriteType().isEmpty(); return PrefixRewritingMapper.empty(); } return new MachineDesugarPrefixRewritingMapper( // This mapper is used for assertions only (prior behavior is identical to the new one). new DesugarPrefixRewritingMapper( desugaredLibrarySpecification.getRewritePrefix(), dexItemFactory(), true), - machineDesugaredLibrarySpecification); + machineDesugaredLibrarySpecification.getRewritingFlags()); } return desugaredLibrarySpecification.getPrefixRewritingMapper(); }