Version 1.4.82

Cherry pick: Clear reference type lattice element cache after main dex computation
CL: https://r8-review.googlesource.com/c/r8/+/36900

Cherry pick: Clear reference type lattice elements cache after IR processing
CL: https://r8-review.googlesource.com/c/r8/+/36920

Bug: 130051274
Change-Id: I0ab869f54a2603df872f59d2d9f77dbb9f246013
diff --git a/src/main/java/com/android/tools/r8/R8.java b/src/main/java/com/android/tools/r8/R8.java
index a59fb57..4b23ef3 100644
--- a/src/main/java/com/android/tools/r8/R8.java
+++ b/src/main/java/com/android/tools/r8/R8.java
@@ -414,6 +414,11 @@
         mainDexClasses = new MainDexListBuilder(mainDexBaseClasses, application).run();
       }
 
+      // The class type lattice elements include information about the interfaces that a class
+      // implements. This information can change as a result of vertical class merging, so we need
+      // to clear the cache, so that we will recompute the type lattice elements.
+      appView.dexItemFactory().clearReferenceTypeLatticeElementsCache();
+
       if (appView.appInfo().hasLiveness()) {
         AppView<AppInfoWithLiveness> appViewWithLiveness = appView.withLiveness();
 
@@ -490,6 +495,9 @@
           }
         }
 
+        // None of the optimizations above should lead to the creation of type lattice elements.
+        assert appView.dexItemFactory().verifyNoCachedReferenceTypeLatticeElements();
+
         // Collect switch maps and ordinals maps.
         appViewWithLiveness.setAppInfo(new SwitchMapCollector(appViewWithLiveness, options).run());
         appViewWithLiveness.setAppInfo(
@@ -511,6 +519,9 @@
         timing.end();
       }
 
+      // Clear the reference type lattice element cache to reduce memory pressure.
+      appView.dexItemFactory().clearReferenceTypeLatticeElementsCache();
+
       // At this point all code has been mapped according to the graph lens. We cannot remove the
       // graph lens entirely, though, since it is needed for mapping all field and method signatures
       // back to the original program.
@@ -575,7 +586,6 @@
       if (options.enableTreeShaking || options.enableMinification) {
         timing.begin("Post optimization code stripping");
         try {
-
           GraphConsumer keptGraphConsumer = null;
           WhyAreYouKeepingConsumer whyAreYouKeepingConsumer = null;
           if (options.enableTreeShaking) {
diff --git a/src/main/java/com/android/tools/r8/Version.java b/src/main/java/com/android/tools/r8/Version.java
index eff22da..7b7d977 100644
--- a/src/main/java/com/android/tools/r8/Version.java
+++ b/src/main/java/com/android/tools/r8/Version.java
@@ -11,7 +11,7 @@
 
   // This field is accessed from release scripts using simple pattern matching.
   // Therefore, changing this field could break our release scripts.
-  public static final String LABEL = "1.4.81";
+  public static final String LABEL = "1.4.82";
 
   private Version() {
   }
diff --git a/src/main/java/com/android/tools/r8/graph/DexItemFactory.java b/src/main/java/com/android/tools/r8/graph/DexItemFactory.java
index 8cd38d0..18d7454 100644
--- a/src/main/java/com/android/tools/r8/graph/DexItemFactory.java
+++ b/src/main/java/com/android/tools/r8/graph/DexItemFactory.java
@@ -1031,6 +1031,15 @@
     return method.name == classConstructorMethodName;
   }
 
+  public void clearReferenceTypeLatticeElementsCache() {
+    referenceTypeLatticeElements.clear();
+  }
+
+  public boolean verifyNoCachedReferenceTypeLatticeElements() {
+    assert referenceTypeLatticeElements.isEmpty();
+    return true;
+  }
+
   public ReferenceTypeLatticeElement createReferenceTypeLatticeElement(
       DexType type, boolean isNullable, AppInfo appInfo) {
     ReferenceTypeLatticeElement typeLattice = referenceTypeLatticeElements.get(type);