Simplify debug metadata: instead of array of same values, store single element

This change is valid, since we want StackTraceElement to be as close
as possible to StackTraceElement of non-coroutine code.
Particularly, if the line is inside inlined function, its className,
functionName and sourceFile are inline site's ones, but lineNumber
is large, which is the way of representing inline function's line
numbers. The rest is handled by the plugin, which allows the user to choose
between inline function body and inline site.
This commit is contained in:
Ilmir Usmanov
2018-08-30 18:00:41 +03:00
parent ad58fdd158
commit cfc10ec061
3 changed files with 7 additions and 11 deletions
@@ -11,7 +11,7 @@ import kotlin.coroutines.Continuation
@SinceKotlin("1.3")
internal annotation class DebugMetadata(
@get:JvmName("f")
val sourceFiles: Array<String>,
val sourceFile: String,
@get:JvmName("l")
val lineNumbers: IntArray,
@get:JvmName("n")
@@ -39,9 +39,8 @@ internal annotation class DebugMetadata(
internal fun BaseContinuationImpl.getStackTraceElementImpl(): StackTraceElement? {
val debugMetadata = getDebugMetadataAnnotation() ?: return null
val label = getLabel()
val fileName = if (label < 0) "" else debugMetadata.sourceFiles[label]
val lineNumber = if (label < 0) -1 else debugMetadata.lineNumbers[label]
return StackTraceElement(debugMetadata.className, debugMetadata.methodName, fileName, lineNumber)
return StackTraceElement(debugMetadata.className, debugMetadata.methodName, debugMetadata.sourceFile, lineNumber)
}
private fun BaseContinuationImpl.getDebugMetadataAnnotation(): DebugMetadata? =
@@ -19,8 +19,8 @@ import kotlin.test.assertEquals
*/
@DebugMetadata(
sourceFiles = ["test.kt", "test1.kt", "test.kt"],
lineNumbers = [10, 2, 11],
sourceFile = "test.kt",
lineNumbers = [10, 122, 11],
indexToLabel = [0, 0, 1, 1, 2],
localNames = ["a", "b", "b", "c", "c"],
spilled = ["L$1", "L$2", "L$1", "L$2", "L$1"],
@@ -49,7 +49,7 @@ class DebugMetadataTest {
assertEquals(listOf("L$1", "a", "L$2", "b"), myContinuation.getSpilledVariableFieldMapping()!!.toList())
myContinuation.label = 2
assertEquals(
StackTraceElement("SomeClass", "testMethod", "test1.kt", 2),
StackTraceElement("SomeClass", "testMethod", "test.kt", 122),
myContinuation.getStackTraceElement()
)
assertEquals(listOf("L$1", "b", "L$2", "c"), myContinuation.getSpilledVariableFieldMapping()!!.toList())