Rewrite InvokeToPrivateRewriter to use DesugaringDescription
Fixes: b/270144889
Change-Id: Ic748fdc24232023b8268c99e2e6b7278cb3f33f2
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/InvokeToPrivateRewriter.java b/src/main/java/com/android/tools/r8/ir/desugar/InvokeToPrivateRewriter.java
index 65f23dc..7bef7e4 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/InvokeToPrivateRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/InvokeToPrivateRewriter.java
@@ -6,13 +6,10 @@
import com.android.tools.r8.cf.code.CfInstruction;
import com.android.tools.r8.cf.code.CfInvoke;
-import com.android.tools.r8.contexts.CompilationContext.MethodProcessingContext;
import com.android.tools.r8.graph.DexEncodedMethod;
-import com.android.tools.r8.graph.DexItemFactory;
import com.android.tools.r8.graph.DexMethod;
import com.android.tools.r8.graph.ProgramMethod;
import com.google.common.collect.ImmutableList;
-import java.util.Collection;
import org.objectweb.asm.Opcodes;
/**
@@ -28,33 +25,26 @@
public class InvokeToPrivateRewriter implements CfInstructionDesugaring {
@Override
- public Collection<CfInstruction> desugarInstruction(
- CfInstruction instruction,
- FreshLocalProvider freshLocalProvider,
- LocalStackAllocator localStackAllocator,
- CfInstructionDesugaringEventConsumer eventConsumer,
- ProgramMethod context,
- MethodProcessingContext methodProcessingContext,
- CfInstructionDesugaringCollection desugaringCollection,
- DexItemFactory dexItemFactory) {
+ public DesugarDescription compute(CfInstruction instruction, ProgramMethod context) {
if (!instruction.isInvokeVirtual() && !instruction.isInvokeInterface()) {
- return null;
+ return DesugarDescription.nothing();
}
CfInvoke invoke = instruction.asInvoke();
DexMethod method = invoke.getMethod();
DexEncodedMethod privateMethod = privateMethodInvokedOnSelf(invoke, context);
if (privateMethod == null) {
- return null;
+ return DesugarDescription.nothing();
}
- return ImmutableList.of(new CfInvoke(Opcodes.INVOKESPECIAL, method, invoke.isInterface()));
- }
-
- @Override
- public boolean needsDesugaring(CfInstruction instruction, ProgramMethod context) {
- if (!instruction.isInvokeVirtual() && !instruction.isInvokeInterface()) {
- return false;
- }
- return isInvokingPrivateMethodOnSelf(instruction.asInvoke(), context);
+ return DesugarDescription.builder()
+ .setDesugarRewrite(
+ (freshLocalProvider,
+ localStackAllocator,
+ eventConsumer,
+ ignore, // context
+ methodProcessingContext,
+ dexItemFactory) ->
+ ImmutableList.of(new CfInvoke(Opcodes.INVOKESPECIAL, method, invoke.isInterface())))
+ .build();
}
private DexEncodedMethod privateMethodInvokedOnSelf(CfInvoke invoke, ProgramMethod context) {
@@ -69,8 +59,4 @@
}
return null;
}
-
- private boolean isInvokingPrivateMethodOnSelf(CfInvoke invoke, ProgramMethod context) {
- return privateMethodInvokedOnSelf(invoke, context) != null;
- }
}