[JVM_IR] Use line number 1 for multifile bridge methods.

This is necessary for the intellij debugger filters to hide
these bridges.

Fixes KT-41961.
This commit is contained in:
Mads Ager
2020-10-13 08:35:25 +02:00
committed by max-kammerer
parent c8a8410fc5
commit dca1f4631c
4 changed files with 17 additions and 10 deletions
@@ -84,15 +84,20 @@ class SourceMapper(val sourceInfo: SourceInfo?) {
val resultMappings: List<FileMapping> val resultMappings: List<FileMapping>
get() = fileMappings.values.toList() get() = fileMappings.values.toList()
companion object {
const val FAKE_FILE_NAME = "fake.kt"
const val FAKE_PATH = "kotlin/jvm/internal/FakeKt"
}
init { init {
sourceInfo?.let { sourceInfo -> sourceInfo?.let { sourceInfo ->
// If 'sourceFileName' is null, this class doesn't have debug information // If 'sourceFileName' is null we are dealing with a synthesized class
// (e.g., multi-file class facade with multiple parts). // (e.g., multi-file class facade with multiple parts). Such classes
sourceInfo.sourceFileName?.let { sourceFileName -> // only have synthetic debug information and we use a fake file name.
// Explicitly map the file to itself -- we'll probably need a lot of lines from it, so this will produce fewer ranges. val sourceFileName = sourceInfo.sourceFileName ?: FAKE_FILE_NAME
getOrRegisterNewSource(sourceFileName, sourceInfo.pathOrCleanFQN) // Explicitly map the file to itself -- we'll probably need a lot of lines from it, so this will produce fewer ranges.
.mapNewInterval(1, 1, sourceInfo.linesInFile) getOrRegisterNewSource(sourceFileName, sourceInfo.pathOrCleanFQN)
} .mapNewInterval(1, 1, sourceInfo.linesInFile)
} }
} }
@@ -110,7 +115,7 @@ class SourceMapper(val sourceInfo: SourceInfo?) {
} }
fun mapSyntheticLineNumber(id: Int): Int { fun mapSyntheticLineNumber(id: Int): Int {
return mapLineNumber(SourcePosition(id, "fake.kt", "kotlin/jvm/internal/FakeKt"), null) return mapLineNumber(SourcePosition(id, FAKE_FILE_NAME, FAKE_PATH), null)
} }
} }
@@ -213,6 +213,10 @@ class ExpressionCodegen(
fun generate() { fun generate() {
mv.visitCode() mv.visitCode()
val startLabel = markNewLabel() val startLabel = markNewLabel()
if (irFunction.origin == JvmLoweredDeclarationOrigin.MULTIFILE_BRIDGE) {
// Multifile bridges need to have line number 1 to be filtered out by the intellij debugging filters.
mv.visitLineNumber(1, startLabel)
}
val info = BlockInfo() val info = BlockInfo()
val body = irFunction.body!! val body = irFunction.body!!
generateNonNullAssertions() generateNonNullAssertions()
@@ -90,7 +90,6 @@ fun JvmBackendContext.getSourceMapper(declaration: IrClass): SourceMapper {
val fileEntry = sourceManager.getFileEntry(declaration.fileParent) val fileEntry = sourceManager.getFileEntry(declaration.fileParent)
// NOTE: apparently inliner requires the source range to cover the // NOTE: apparently inliner requires the source range to cover the
// whole file the class is declared in rather than the class only. // whole file the class is declared in rather than the class only.
// TODO: revise
val endLineNumber = when (fileEntry) { val endLineNumber = when (fileEntry) {
is MultifileFacadeFileEntry -> 0 is MultifileFacadeFileEntry -> 0
else -> fileEntry?.getSourceRangeInfo(0, fileEntry.maxOffset)?.endLineNumber ?: 0 else -> fileEntry?.getSourceRangeInfo(0, fileEntry.maxOffset)?.endLineNumber ?: 0
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
LineBreakpoint created at stepIntoMultiFileFacade.kt:6 LineBreakpoint created at stepIntoMultiFileFacade.kt:6
Run Java Run Java
Connected to the target VM Connected to the target VM