Only rewrite dynamicMethod() of proto messages if shrinking or minifying
Change-Id: Idb59ec4a0dbaa74f6e5446d0f2c4886ddda702cd
diff --git a/src/main/java/com/android/tools/r8/R8.java b/src/main/java/com/android/tools/r8/R8.java
index d65fbc2..5742bb6 100644
--- a/src/main/java/com/android/tools/r8/R8.java
+++ b/src/main/java/com/android/tools/r8/R8.java
@@ -698,29 +698,26 @@
} finally {
timing.end();
}
- }
- if (appView.options().isProtoShrinkingEnabled()) {
- // TODO(b/112437944): IRConverter.<init>() asserts that liveness information is available in
- // AppView. This is not the case if both shrinking and minification is disabled, because we
- // skip the second round of tree shaking in that case.
- IRConverter converter = new IRConverter(appView, timing, null, mainDexClasses);
+ if (appView.options().isProtoShrinkingEnabled()) {
+ IRConverter converter = new IRConverter(appView, timing, null, mainDexClasses);
- // If proto shrinking is enabled, we need to reprocess every dynamicMethod(). This ensures
- // that proto fields that have been removed by the second round of tree shaking are also
- // removed from the proto schemas in the bytecode.
- // TODO(b/112437944): Avoid iterating the entire application to post-process every
- // dynamicMethod() method.
- appView.withGeneratedMessageLiteShrinker(
- shrinker -> shrinker.postOptimizeDynamicMethods(converter));
+ // If proto shrinking is enabled, we need to reprocess every dynamicMethod(). This ensures
+ // that proto fields that have been removed by the second round of tree shaking are also
+ // removed from the proto schemas in the bytecode.
+ // TODO(b/112437944): Avoid iterating the entire application to post-process every
+ // dynamicMethod() method.
+ appView.withGeneratedMessageLiteShrinker(
+ shrinker -> shrinker.postOptimizeDynamicMethods(converter));
- // If proto shrinking is enabled, we need to post-process every findLiteExtensionByNumber()
- // method. This ensures that there are no references to dead extensions that have been
- // removed by the second round of tree shaking.
- // TODO(b/112437944): Avoid iterating the entire application to post-process every
- // findLiteExtensionByNumber() method.
- appView.withGeneratedExtensionRegistryShrinker(
- shrinker -> shrinker.postOptimizeGeneratedExtensionRegistry(converter));
+ // If proto shrinking is enabled, we need to post-process every
+ // findLiteExtensionByNumber() method. This ensures that there are no references to dead
+ // extensions that have been removed by the second round of tree shaking.
+ // TODO(b/112437944): Avoid iterating the entire application to post-process every
+ // findLiteExtensionByNumber() method.
+ appView.withGeneratedExtensionRegistryShrinker(
+ shrinker -> shrinker.postOptimizeGeneratedExtensionRegistry(converter));
+ }
}
// Add automatic main dex classes to an eventual manual list of classes.