Version 1.6.54

Cherry pick: Add test for adding mapped members from parent interfaces
to classes
CL: https://r8-review.googlesource.com/46443

Cherry pick: Fix mapping of members in indirect interfaces
https://r8-review.googlesource.com/46444

Bug: 144151805
Change-Id: Iefdcd2ec42b03b209756e982f24b3437ca3aaa9e
diff --git a/src/main/java/com/android/tools/r8/Version.java b/src/main/java/com/android/tools/r8/Version.java
index 8d6cfe6..1044086 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.53";
+  public static final String LABEL = "1.6.54";
 
   private Version() {
   }
diff --git a/src/main/java/com/android/tools/r8/naming/ProguardMapMinifier.java b/src/main/java/com/android/tools/r8/naming/ProguardMapMinifier.java
index 47a8d3f..c16d718 100644
--- a/src/main/java/com/android/tools/r8/naming/ProguardMapMinifier.java
+++ b/src/main/java/com/android/tools/r8/naming/ProguardMapMinifier.java
@@ -252,11 +252,10 @@
       DexType type, Map<DexReference, MemberNaming> nonPrivateMembers, DexType[] interfaces) {
     for (DexType iface : interfaces) {
       ClassNamingForMapApplier interfaceNaming = seedMapper.getClassNaming(iface);
-      if (interfaceNaming == null) {
-        continue;
+      if (interfaceNaming != null) {
+        interfaceNaming.forAllMemberNaming(
+            memberNaming -> addMemberNamings(type, memberNaming, nonPrivateMembers, true));
       }
-      interfaceNaming.forAllMemberNaming(
-          memberNaming -> addMemberNamings(type, memberNaming, nonPrivateMembers, true));
       DexClass ifaceClass = appView.definitionFor(iface);
       if (ifaceClass != null) {
         addNonPrivateInterfaceMappings(type, nonPrivateMembers, ifaceClass.interfaces.values);
diff --git a/src/test/java/com/android/tools/r8/naming/applymapping/ApplyMappingExtendEmptyInterfaceTest.java b/src/test/java/com/android/tools/r8/naming/applymapping/ApplyMappingExtendEmptyInterfaceTest.java
new file mode 100644
index 0000000..e16307b
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/naming/applymapping/ApplyMappingExtendEmptyInterfaceTest.java
@@ -0,0 +1,118 @@
+// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.naming.applymapping;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.R8TestCompileResult;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import java.io.IOException;
+import java.util.concurrent.ExecutionException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+// This is a reproduction of b/144151805.
+@RunWith(Parameterized.class)
+public class ApplyMappingExtendEmptyInterfaceTest extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().build();
+  }
+
+  public ApplyMappingExtendEmptyInterfaceTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void testRuntime() throws ExecutionException, CompilationFailedException, IOException {
+    testForRuntime(parameters)
+        .addProgramClasses(
+            TestI.class,
+            TestA.class,
+            Main.class,
+            LibI.class,
+            LibI2.class,
+            LibI3.class,
+            Runner.class)
+        .run(parameters.getRuntime(), Main.class)
+        .assertSuccessWithOutputLines("injectTestA", "injectObject");
+  }
+
+  @Test
+  public void testInheritLibraryInterface()
+      throws CompilationFailedException, IOException, ExecutionException {
+    final R8TestCompileResult libCompileResult =
+        testForR8(parameters.getBackend())
+            .addProgramClasses(LibI.class, LibI2.class, LibI3.class, Runner.class)
+            .addKeepClassAndMembersRules(Runner.class)
+            .addKeepClassAndMembersRulesWithAllowObfuscation(LibI.class, LibI2.class, LibI3.class)
+            .setMinApi(parameters.getApiLevel())
+            .compile();
+    testForR8(parameters.getBackend())
+        .addProgramClasses(TestI.class, TestA.class, Main.class)
+        .addClasspathClasses(LibI.class, LibI2.class, LibI3.class, Runner.class)
+        .addKeepAllClassesRule()
+        .addApplyMapping(libCompileResult.getProguardMap())
+        .addRunClasspathFiles(libCompileResult.writeToZip())
+        .setMinApi(parameters.getApiLevel())
+        .run(parameters.getRuntime(), Main.class)
+        .assertSuccessWithOutputLines("injectTestA", "injectObject");
+  }
+
+  public interface LibI {
+    void inject(Object object);
+  }
+
+  public interface LibI2 extends LibI {}
+
+  // Add an additional interface on top of LibI2 to ensure a class naming is generated here.
+  public interface LibI3 extends LibI2 {
+    void foo();
+  }
+
+  public static class Runner {
+
+    public static void foo(LibI libI) {
+      libI.inject(libI);
+    }
+  }
+
+  public interface TestI extends LibI3 {
+    void inject(TestA testA);
+  }
+
+  public static class TestA implements TestI {
+
+    @Override
+    public void inject(Object object) {
+      System.out.println("injectObject");
+    }
+
+    @Override
+    public void inject(TestA testA) {
+      System.out.println("injectTestA");
+    }
+
+    @Override
+    public void foo() {
+      throw new RuntimeException("Should never be called");
+    }
+  }
+
+  public static class Main {
+
+    public static void main(String[] args) {
+      final TestA testA = new TestA();
+      testA.inject(testA);
+      Runner.foo(testA);
+    }
+  }
+}
diff --git a/src/test/java/com/android/tools/r8/naming/applymapping/ApplyMappingExtendInterfaceTest.java b/src/test/java/com/android/tools/r8/naming/applymapping/ApplyMappingExtendInterfaceTest.java
new file mode 100644
index 0000000..c70d49c
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/naming/applymapping/ApplyMappingExtendInterfaceTest.java
@@ -0,0 +1,99 @@
+// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.naming.applymapping;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.R8TestCompileResult;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import java.io.IOException;
+import java.util.concurrent.ExecutionException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+// This is a reproduction of b/144151805.
+@RunWith(Parameterized.class)
+public class ApplyMappingExtendInterfaceTest extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().build();
+  }
+
+  public ApplyMappingExtendInterfaceTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void testRuntime() throws ExecutionException, CompilationFailedException, IOException {
+    testForRuntime(parameters)
+        .addProgramClasses(TestI.class, TestA.class, Main.class, LibI.class, Runner.class)
+        .run(parameters.getRuntime(), Main.class)
+        .assertSuccessWithOutputLines("injectTestA", "injectObject");
+  }
+
+  @Test
+  public void testInheritLibraryInterface()
+      throws CompilationFailedException, IOException, ExecutionException {
+    final R8TestCompileResult libCompileResult =
+        testForR8(parameters.getBackend())
+            .addProgramClasses(LibI.class, Runner.class)
+            .addKeepClassAndMembersRules(Runner.class)
+            .addKeepClassAndMembersRulesWithAllowObfuscation(LibI.class)
+            .setMinApi(parameters.getApiLevel())
+            .compile();
+    testForR8(parameters.getBackend())
+        .addProgramClasses(TestI.class, TestA.class, Main.class)
+        .addClasspathClasses(LibI.class, Runner.class)
+        .addKeepAllClassesRule()
+        .addApplyMapping(libCompileResult.getProguardMap())
+        .addRunClasspathFiles(libCompileResult.writeToZip())
+        .setMinApi(parameters.getApiLevel())
+        .run(parameters.getRuntime(), Main.class)
+        .assertSuccessWithOutputLines("injectTestA", "injectObject");
+  }
+
+  public interface LibI {
+    void inject(Object object);
+  }
+
+  public static class Runner {
+
+    public static void foo(LibI libI) {
+      libI.inject(libI);
+    }
+  }
+
+  public interface TestI extends LibI {
+    void inject(TestA testA);
+  }
+
+  public static class TestA implements TestI {
+
+    @Override
+    public void inject(Object object) {
+      System.out.println("injectObject");
+    }
+
+    @Override
+    public void inject(TestA testA) {
+      System.out.println("injectTestA");
+    }
+  }
+
+  public static class Main {
+
+    public static void main(String[] args) {
+      final TestA testA = new TestA();
+      testA.inject(testA);
+      Runner.foo(testA);
+    }
+  }
+}