diff options
author | Morten Krogh-Jespersen <mkroghj@google.com> | 2021-03-19 10:45:32 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-03-19 10:45:32 +0000 |
commit | f11988fda551249589b35ebad1afc81f42fedab9 (patch) | |
tree | 53d731c42822e3b29d7fd5c92e9822c5b6611613 | |
parent | 615610ecaa8a6443f9ecbf59b997d91ae93b4602 (diff) | |
parent | 9e1edd29998612e82e8d3609ede664be555836a9 (diff) | |
download | r8-f11988fda551249589b35ebad1afc81f42fedab9.tar.gz |
Add reproduction for repackaging picking merged and pruned class am: 9e1edd2999
Original change: undetermined
Change-Id: I17a8ecfc34c41ddc4bb4f6b7643e5800b9b90fba
3 files changed, 122 insertions, 2 deletions
diff --git a/src/main/java/com/android/tools/r8/graph/DirectMappedDexApplication.java b/src/main/java/com/android/tools/r8/graph/DirectMappedDexApplication.java index 0f7b951c8..ceac26a9f 100644 --- a/src/main/java/com/android/tools/r8/graph/DirectMappedDexApplication.java +++ b/src/main/java/com/android/tools/r8/graph/DirectMappedDexApplication.java @@ -143,7 +143,8 @@ public class DirectMappedDexApplication extends DexApplication { if (definitionFor(type) == null && definitionFor(renamed) != null) { continue; } - assert definitionFor(type).type == renamed || definitionFor(renamed) != null; + assert definitionFor(type).type == renamed || definitionFor(renamed) != null + : "The lens and app is inconsistent"; } } return true; diff --git a/src/test/java/com/android/tools/r8/classmerging/horizontal/MergeWithRepackageNameCollissionTest.java b/src/test/java/com/android/tools/r8/classmerging/horizontal/MergeWithRepackageNameCollissionTest.java new file mode 100644 index 000000000..7f7e655b9 --- /dev/null +++ b/src/test/java/com/android/tools/r8/classmerging/horizontal/MergeWithRepackageNameCollissionTest.java @@ -0,0 +1,111 @@ +// Copyright (c) 2021, 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.classmerging.horizontal; + +import static org.hamcrest.CoreMatchers.containsString; + +import com.android.tools.r8.CompilationFailedException; +import com.android.tools.r8.NeverInline; +import com.android.tools.r8.NoHorizontalClassMerging; +import com.android.tools.r8.TestParameters; +import com.android.tools.r8.TestParametersCollection; +import com.google.common.collect.ImmutableList; +import java.util.Collection; +import org.junit.Test; +import org.junit.runners.Parameterized; + +public class MergeWithRepackageNameCollissionTest extends HorizontalClassMergingTestBase { + + @Parameterized.Parameters(name = "{0}") + public static TestParametersCollection data() { + return getTestParameters().withDexRuntimes().withAllApiLevels().build(); + } + + public MergeWithRepackageNameCollissionTest(TestParameters parameters) { + super(parameters); + } + + @Test(expected = CompilationFailedException.class) + public void testR8() throws Exception { + testForR8(parameters.getBackend()) + .addProgramClassFileData(getProgramFileData()) + .addProgramClasses(I.class, Runner.class) + .addKeepMainRule(Main.class) + .addKeepClassAndMembersRules(I.class, Runner.class) + .setMinApi(parameters.getApiLevel()) + .enableNoHorizontalClassMergingAnnotations() + .enableInliningAnnotations() + .compileWithExpectedDiagnostics( + diagnostics -> { + // TODO(b/183111898): Should not fail. + diagnostics.assertErrorMessageThatMatches( + containsString("The lens and app is inconsistent")); + }); + } + + private Collection<byte[]> getProgramFileData() throws Exception { + return ImmutableList.of( + transformer(A.class).setClassDescriptor("La/a;").transform(), + transformer(B.class).setClassDescriptor("Lb/a;").setSuper("La/a;").transform(), + transformer(D.class).setClassDescriptor("Lc/a;").transform(), + transformer(Main.class) + .replaceClassDescriptorInMethodInstructions(descriptor(A.class), "La/a;") + .replaceClassDescriptorInMethodInstructions(descriptor(B.class), "Lb/a;") + .replaceClassDescriptorInMethodInstructions(descriptor(D.class), "Lc/a;") + .transform()); + } + + public static /* will be: a.a */ class A { + + @NeverInline + public static void foo() { + System.out.println("A::foo"); + } + } + + // a.a will be merged into b.a and thereby produce a mapping from a.a -> b.a in our lens. + public static /* will be: b.a */ class B extends A {} + + // c.a will be repackaged to a.a + @NoHorizontalClassMerging + public static /* will be: c.a */ class D { + + @NeverInline + public static void baz() { + System.out.println("C::baz"); + } + } + + public interface I { + + void run(); + } + + public static class Runner { + + @NeverInline + static void callI(I i) { + i.run(); + } + } + + public static class Main { + + public static void main(String[] args) { + D.baz(); + callFoo(null); + Runner.callI( + () -> { + System.out.println("Hello World"); + }); + } + + public static void callFoo(Object obj) { + if (obj != null) { + B.foo(); + } + } + } +} diff --git a/src/test/java/com/android/tools/r8/utils/codeinspector/HorizontallyMergedClassesInspector.java b/src/test/java/com/android/tools/r8/utils/codeinspector/HorizontallyMergedClassesInspector.java index 91fb00298..e6fa54811 100644 --- a/src/test/java/com/android/tools/r8/utils/codeinspector/HorizontallyMergedClassesInspector.java +++ b/src/test/java/com/android/tools/r8/utils/codeinspector/HorizontallyMergedClassesInspector.java @@ -4,7 +4,6 @@ package com.android.tools.r8.utils.codeinspector; -import static com.android.tools.r8.TestBase.toDexType; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -72,11 +71,20 @@ public class HorizontallyMergedClassesInspector { return this; } + public HorizontallyMergedClassesInspector assertClassesMerged(Class<?>... classes) { + return assertClassesMerged(Arrays.asList(classes)); + } + public HorizontallyMergedClassesInspector assertClassesMerged(Collection<Class<?>> classes) { return assertTypesMerged(classes.stream().map(this::toDexType).collect(Collectors.toList())); } public HorizontallyMergedClassesInspector assertClassReferencesMerged( + ClassReference... classReferences) { + return assertClassReferencesMerged(Arrays.asList(classReferences)); + } + + public HorizontallyMergedClassesInspector assertClassReferencesMerged( Collection<ClassReference> classReferences) { return assertTypesMerged( classReferences.stream().map(this::toDexType).collect(Collectors.toList())); |