Only attempt to inline kotlin information if coming from CF

This CL also updates the code that checks for identity of debug
elements because we will insert additional debug events if we can
inline a kotlin function.

Bug: 141817471
Change-Id: I9b0f833310f31940723811b487942b6df81d0da3
diff --git a/src/main/java/com/android/tools/r8/utils/CfLineToMethodMapper.java b/src/main/java/com/android/tools/r8/utils/CfLineToMethodMapper.java
index 7721378..94024ee 100644
--- a/src/main/java/com/android/tools/r8/utils/CfLineToMethodMapper.java
+++ b/src/main/java/com/android/tools/r8/utils/CfLineToMethodMapper.java
@@ -5,6 +5,7 @@
 package com.android.tools.r8.utils;
 
 import com.android.tools.r8.ProgramResource;
+import com.android.tools.r8.ProgramResource.Kind;
 import com.android.tools.r8.ProgramResourceProvider;
 import com.android.tools.r8.ResourceException;
 import it.unimi.dsi.fastutil.ints.Int2ReferenceOpenHashMap;
@@ -38,8 +39,10 @@
     ClassVisitor classVisitor = new ClassVisitor();
     for (ProgramResourceProvider resourceProvider : inputApp.getProgramResourceProviders()) {
       for (ProgramResource programResource : resourceProvider.getProgramResources()) {
-        new ClassReader(StreamUtils.StreamToByteArrayClose(programResource.getByteStream()))
-            .accept(classVisitor, ClassReader.SKIP_FRAMES);
+        if (programResource.getKind() == Kind.CF) {
+          new ClassReader(StreamUtils.StreamToByteArrayClose(programResource.getByteStream()))
+              .accept(classVisitor, ClassReader.SKIP_FRAMES);
+        }
       }
     }
   }
diff --git a/src/main/java/com/android/tools/r8/utils/LineNumberOptimizer.java b/src/main/java/com/android/tools/r8/utils/LineNumberOptimizer.java
index 64c0067..933f4fb 100644
--- a/src/main/java/com/android/tools/r8/utils/LineNumberOptimizer.java
+++ b/src/main/java/com/android/tools/r8/utils/LineNumberOptimizer.java
@@ -546,6 +546,8 @@
     PositionEventEmitter positionEventEmitter =
         new PositionEventEmitter(application.dexItemFactory, method.method, processedEvents);
 
+    Box<Boolean> inlinedOriginalPosition = new Box<>(false);
+
     // Debug event visitor to map line numbers.
     DexDebugEventVisitor visitor =
         new DexDebugPositionState(debugInfo.startLine, method.method) {
@@ -572,8 +574,11 @@
                     getCurrentFile(),
                     getCurrentMethod(),
                     getCurrentCallerPosition());
-            positionEventEmitter.emitPositionEvents(
-                getCurrentPc(), remapAndAdd(position, positionRemapper, mappedPositions));
+            Position currentPosition = remapAndAdd(position, positionRemapper, mappedPositions);
+            if (currentPosition != position) {
+              inlinedOriginalPosition.set(true);
+            }
+            positionEventEmitter.emitPositionEvents(getCurrentPc(), currentPosition);
             emittedPc = getCurrentPc();
           }
 
@@ -629,7 +634,7 @@
 
     // TODO(b/111253214) Remove this as soon as we have external tests testing not only the
     // remapping but whether the non-positional debug events remain intact.
-    if (identityMapping) {
+    if (identityMapping && !inlinedOriginalPosition.get()) {
       assert optimizedDebugInfo.startLine == debugInfo.startLine;
       assert optimizedDebugInfo.events.length == debugInfo.events.length;
       for (int i = 0; i < debugInfo.events.length; ++i) {