Version 1.6.67

Cherry-pick: Mark default methods as live is a sub-interface is
instantiated.
CL: https://r8-review.googlesource.com/48019

Cherry-pick: Resolve default methods in sub-interfaces
CL: https://r8-review.googlesource.com/48018

Bug: 148447828
Bug: 148168065
Change-Id: Idb24c4661b769f387007072f055c3178c66c27cf
diff --git a/src/main/java/com/android/tools/r8/Version.java b/src/main/java/com/android/tools/r8/Version.java
index 6f2d5c3..5224657 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.6.66";
+  public static final String LABEL = "1.6.67";
 
   private Version() {
   }
diff --git a/src/main/java/com/android/tools/r8/graph/ResolutionResult.java b/src/main/java/com/android/tools/r8/graph/ResolutionResult.java
index 253d014..ae016be 100644
--- a/src/main/java/com/android/tools/r8/graph/ResolutionResult.java
+++ b/src/main/java/com/android/tools/r8/graph/ResolutionResult.java
@@ -83,10 +83,7 @@
       //   }
       //
       DexEncodedMethod singleTarget = asSingleTarget();
-      if (singleTarget.getCode() != null
-          && appInfo.hasAnyInstantiatedLambdas(singleTarget.method.holder)) {
-        result.add(singleTarget);
-      }
+      addIfDefaultMethodWithLambdaInstantiations(appInfo, singleTarget, result);
     }
 
     DexEncodedMethod encodedMethod = asResultOfResolve();
@@ -98,10 +95,8 @@
           }
         };
     // Default methods are looked up when looking at a specific subtype that does not override
-    // them.
-    // Otherwise, we would look up default methods that are actually never used. However, we have
-    // to
-    // add bridge methods, otherwise we can remove a bridge that will be used.
+    // them. Otherwise, we would look up default methods that are actually never used. However, we
+    // have to add bridge methods, otherwise we can remove a bridge that will be used.
     Consumer<DexEncodedMethod> addIfNotAbstractAndBridge =
         m -> {
           if (!m.accessFlags.isAbstract() && m.accessFlags.isBridge()) {
@@ -114,6 +109,9 @@
       DexClass clazz = appInfo.definitionFor(type);
       if (clazz.isInterface()) {
         ResolutionResult targetMethods = appInfo.resolveMethodOnInterface(clazz, method);
+        if (targetMethods.hasSingleTarget()) {
+          addIfDefaultMethodWithLambdaInstantiations(appInfo, targetMethods.asSingleTarget(), result);
+        }
         targetMethods.forEachTarget(addIfNotAbstractAndBridge);
       } else {
         ResolutionResult targetMethods = appInfo.resolveMethodOnClass(clazz, method);
@@ -123,6 +121,18 @@
     return result;
   }
 
+  default void addIfDefaultMethodWithLambdaInstantiations(
+      AppInfoWithSubtyping appInfo, DexEncodedMethod method, Set<DexEncodedMethod> result) {
+    if (method == null) {
+      return;
+    }
+    if (method.hasCode()) {
+      if (appInfo.hasAnyInstantiatedLambdas(method.method.holder)) {
+        result.add(method);
+      }
+    }
+  }
+
   class MultiResult implements ResolutionResult {
 
     private final ImmutableList<DexEncodedMethod> methods;
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 f602541..674db97 100644
--- a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
+++ b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
@@ -1929,6 +1929,7 @@
       return;
     }
 
+    // TODO(mkroghj): Remove pinnedItems check here.
     if (instantiatedTypes.contains(clazz)
         || instantiatedInterfaceTypes.contains(clazz)
         || pinnedItems.contains(clazz.type)) {
@@ -1944,8 +1945,8 @@
         if (currentClass == null || currentClass.lookupVirtualMethod(possibleTarget) != null) {
           continue;
         }
-        // TODO(zerny): Why does not not confer with lambdas and pinned too?
-        if (instantiatedTypes.contains(currentClass)) {
+        if (instantiatedTypes.contains(currentClass)
+            || instantiatedInterfaceTypes.contains(currentClass)) {
           markVirtualMethodAsLive(clazz, encodedPossibleTarget, reason);
           break;
         }