Account for lambda call sites in argument propagation

Bug: b/366932318
Change-Id: I7d6378034d4bf7e607badbe266653e273fdcd14a
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/LambdaDescriptor.java b/src/main/java/com/android/tools/r8/ir/desugar/LambdaDescriptor.java
index e3cbc07..4d0f768 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/LambdaDescriptor.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/LambdaDescriptor.java
@@ -153,10 +153,13 @@
         if (target == null) {
             target = appInfo.lookupDirectTarget(method, context, appView, appInfo);
         }
-        assert target == null
-            || (implHandle.type.isInvokeInstance() && isInstanceMethod(target))
-            || (implHandle.type.isInvokeDirect() && isPrivateInstanceMethod(target))
-            || (implHandle.type.isInvokeDirect() && isPublicizedInstanceMethod(target));
+          assert target == null
+              // TODO(b/366932318): We should disallow staticizing of methods called from lambdas
+              //  or update the implHandle accordingly.
+              || (implHandle.type.isInvokeInstance()
+                  && (isInstanceMethod(target) || target.getAccessFlags().isStatic()))
+              || (implHandle.type.isInvokeDirect() && isPrivateInstanceMethod(target))
+              || (implHandle.type.isInvokeDirect() && isPublicizedInstanceMethod(target));
         return target;
       }
 
diff --git a/src/main/java/com/android/tools/r8/optimize/argumentpropagation/ArgumentPropagatorMethodReprocessingEnqueuer.java b/src/main/java/com/android/tools/r8/optimize/argumentpropagation/ArgumentPropagatorMethodReprocessingEnqueuer.java
index 287de23..2bdebd2 100644
--- a/src/main/java/com/android/tools/r8/optimize/argumentpropagation/ArgumentPropagatorMethodReprocessingEnqueuer.java
+++ b/src/main/java/com/android/tools/r8/optimize/argumentpropagation/ArgumentPropagatorMethodReprocessingEnqueuer.java
@@ -7,6 +7,7 @@
 import com.android.tools.r8.graph.AppView;
 import com.android.tools.r8.graph.Code;
 import com.android.tools.r8.graph.DefaultUseRegistryWithResult;
+import com.android.tools.r8.graph.DexCallSite;
 import com.android.tools.r8.graph.DexEncodedMethod;
 import com.android.tools.r8.graph.DexField;
 import com.android.tools.r8.graph.DexMethod;
@@ -25,6 +26,7 @@
 import com.android.tools.r8.ir.conversion.IRConverter;
 import com.android.tools.r8.ir.conversion.IRToLirFinalizer;
 import com.android.tools.r8.ir.conversion.PostMethodProcessor;
+import com.android.tools.r8.ir.desugar.LambdaDescriptor;
 import com.android.tools.r8.ir.optimize.AffectedValues;
 import com.android.tools.r8.ir.optimize.info.CallSiteOptimizationInfo;
 import com.android.tools.r8.lightir.LirCode;
@@ -318,6 +320,30 @@
     }
 
     @Override
+    public void registerCallSite(DexCallSite callSite) {
+      LambdaDescriptor descriptor =
+          LambdaDescriptor.tryInfer(callSite, appView, appViewWithLiveness.appInfo(), getContext());
+      if (descriptor == null || descriptor.interfaces.isEmpty()) {
+        return;
+      }
+      ProgramMethod resolvedMainMethod =
+          appViewWithLiveness
+              .appInfo()
+              .resolveMethodOnInterface(descriptor.interfaces.get(0), descriptor.getMainMethod())
+              .getResolvedProgramMethod();
+      if (resolvedMainMethod == null) {
+        return;
+      }
+      DexMethod rewrittenMainMethod =
+          graphLens.getNextMethodSignature(resolvedMainMethod.getReference());
+      if (rewrittenMainMethod.isNotIdenticalTo(resolvedMainMethod.getReference())) {
+        markAffected();
+      } else {
+        assert !graphLens.hasPrototypeChanges(rewrittenMainMethod);
+      }
+    }
+
+    @Override
     public void registerInstanceFieldRead(DexField field) {
       registerFieldAccess(field);
     }
diff --git a/src/main/java/com/android/tools/r8/optimize/argumentpropagation/ArgumentPropagatorProgramOptimizer.java b/src/main/java/com/android/tools/r8/optimize/argumentpropagation/ArgumentPropagatorProgramOptimizer.java
index b7a13df..1c973c4 100644
--- a/src/main/java/com/android/tools/r8/optimize/argumentpropagation/ArgumentPropagatorProgramOptimizer.java
+++ b/src/main/java/com/android/tools/r8/optimize/argumentpropagation/ArgumentPropagatorProgramOptimizer.java
@@ -782,7 +782,7 @@
 
       // We need to find a new name for this method, since the signature is already occupied.
       // TODO(b/190154391): Instead of generating a new name, we could also try permuting the order
-      // of parameters.
+      //  of parameters.
       IntBox suffix =
           newMethodSignatureSuffixes.computeIfAbsent(
               methodSignatureWithParametersRemoved, ignoreKey(IntBox::new));