Remove special handling of proto builders in definitionFor()

Bug: 149363884
Change-Id: I3c012fef9dc944f1b1f387aeede109cee4edd8a4
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 275b882..989ae9a 100644
--- a/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
+++ b/src/main/java/com/android/tools/r8/shaking/AppInfoWithLiveness.java
@@ -543,8 +543,6 @@
             || TwrCloseResourceRewriter.isUtilityClassDescriptor(type)
             // TODO(b/150736225): Not sure how to remove these.
             || DesugaredLibraryAPIConverter.isVivifiedType(type)
-            // TODO(b/149363884): Handle references to dead proto builders.
-            || type.toDescriptorString().endsWith("$Builder;")
         : "Failed lookup of non-missing type: " + type;
     return definition;
   }
diff --git a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
index 8a54cca..8d6df10 100644
--- a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
+++ b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
@@ -237,7 +237,7 @@
   private final Set<DexType> missingTypes = Sets.newIdentityHashSet();
 
   /** Set of proto types that were found to be dead during the first round of tree shaking. */
-  private Set<DexType> initialDeadProtoTypes;
+  private Set<DexType> initialDeadProtoTypes = Sets.newIdentityHashSet();
 
   /** Set of types that were found to be missing during the first round of tree shaking. */
   private Set<DexType> initialMissingTypes;
@@ -1841,7 +1841,7 @@
   private void reportMissingClass(DexType clazz) {
     assert !mode.isFinalTreeShaking()
             || appView.dexItemFactory().isPossiblyCompilerSynthesizedType(clazz)
-            || (initialDeadProtoTypes != null && initialDeadProtoTypes.contains(clazz))
+            || initialDeadProtoTypes.contains(clazz)
             || initialMissingTypes.contains(clazz)
         : "Unexpected missing class `" + clazz.toSourceString() + "`";
     boolean newReport = missingTypes.add(clazz);
@@ -2847,6 +2847,10 @@
 
     // Compute the set of dead proto types.
     deadProtoTypeCandidates.removeIf(this::isTypeLive);
+    Set<DexType> deadProtoTypes =
+        SetUtils.newIdentityHashSet(deadProtoTypeCandidates.size() + initialDeadProtoTypes.size());
+    deadProtoTypeCandidates.forEach(deadProtoType -> deadProtoTypes.add(deadProtoType.type));
+    deadProtoTypes.addAll(initialDeadProtoTypes);
 
     // Remove the temporary mappings that have been inserted into the field access info collection
     // and verify that the mapping is then one-to-one.
@@ -2891,7 +2895,7 @@
     AppInfoWithLiveness appInfoWithLiveness =
         new AppInfoWithLiveness(
             app,
-            SetUtils.mapIdentityHashSet(deadProtoTypeCandidates, DexProgramClass::getType),
+            deadProtoTypes,
             mode.isFinalTreeShaking()
                 ? Sets.union(initialMissingTypes, missingTypes)
                 : missingTypes,