Skip to content

Commit 511dec2

Browse files
committed
minor + docs
Signed-off-by: Evgeniy Moiseenko <[email protected]>
1 parent ef6c280 commit 511dec2

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/TraceReporter.kt

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -427,21 +427,10 @@ private fun isSyntheticFieldAccess(methodName: String): Boolean =
427427
methodName.contains("access\$get") || methodName.contains("access\$set")
428428

429429
/**
430-
* Merges fun$default(...) calls.
431-
* Kotlin functions with default values are represented as two nested calls in the stack trace.
432-
* For example:
433-
* ```
434-
* A.calLMe$default(A#1, 3, null, 2, null) at A.operation(A.kt:23)
435-
* A.callMe(3, "Hey") at A.callMe$default(A.kt:27)
436-
* ```
437-
*
438-
* This function collapses such pairs in the provided [callStackTrace]:
430+
* Merges two consecutive calls in the stack trace into one call if they form a compressible pair,
431+
* see [isCompressiblePair] for details.
439432
*
440-
* ```
441-
* A.callMe(3, "Hey") at A.operation(A.kt:23)
442-
* ```
443-
*
444-
* Since each tracePoint itself contains a [callStackTrace] of it's own,
433+
* Since each tracePoint itself contains a [callStackTrace] of its own,
445434
* we need to recursively traverse each point.
446435
*/
447436
private fun compressCallStackTrace(
@@ -471,9 +460,8 @@ private fun compressCallStackTrace(
471460
break
472461
}
473462

474-
// Check if current and next are a "default" or "access" combo
475-
if (isDefaultPair(currentElement.tracePoint.methodName, nextElement.tracePoint.methodName)
476-
|| isAccessPair(currentElement.tracePoint.methodName, nextElement.tracePoint.methodName)) {
463+
// Check if current and next are compressible
464+
if (isCompressiblePair(currentElement.tracePoint.methodName, nextElement.tracePoint.methodName)) {
477465
// Combine fields of next and current, and store in current
478466
currentElement.tracePoint.methodName = nextElement.tracePoint.methodName
479467
currentElement.tracePoint.parameters = nextElement.tracePoint.parameters
@@ -509,22 +497,50 @@ private fun actorNodeResultRepresentation(result: Result?, failure: LincheckFail
509497
}
510498
}
511499

500+
private fun isCompressiblePair(currentName: String, nextName: String): Boolean =
501+
isDefaultPair(currentName, nextName) || isAccessPair(currentName, nextName)
502+
512503
/**
513-
* Default pair example:
504+
* Used by [compressCallStackTrace] to merge `fun$default(...)` calls.
505+
*
506+
* Kotlin functions with default values are represented as two nested calls in the stack trace.
507+
*
508+
* For example:
509+
*
514510
* ```
515511
* A.calLMe$default(A#1, 3, null, 2, null) at A.operation(A.kt:23)
516-
* A.callMe(3, "Hey") at A.callMe$default(A.kt:27)
517-
*```
512+
* A.callMe(3, "Hey") at A.callMe$default(A.kt:27)
513+
* ```
514+
*
515+
* will be collapsed into:
516+
*
517+
* ```
518+
* A.callMe(3, "Hey") at A.operation(A.kt:23)
519+
* ```
520+
*
518521
*/
519522
private fun isDefaultPair(currentName: String, nextName: String): Boolean =
520523
currentName == "${nextName}\$default"
521524

522525
/**
523-
* Access pair example:
526+
* Used by [compressCallStackTrace] to merge `.access$` calls.
527+
*
528+
* The `.access$` methods are generated by the Kotlin compiler to access otherwise inaccessible members
529+
* (e.g., private) from lambdas, inner classes, etc.
530+
*
531+
* For example:
532+
*
524533
* ```
525534
* A.access$callMe() at A.operation(A.kt:N)
526-
* A.callMe() at A.callMe$default(A.kt:N)
527-
*```
535+
* A.callMe() at A.access$callMe(A.kt:N)
536+
* ```
537+
*
538+
* will be collapsed into:
539+
*
540+
* ```
541+
* A.callMe() at A.operation(A.kt:N)
542+
* ```
543+
*
528544
*/
529545
private fun isAccessPair(currentName: String, nextName: String): Boolean =
530546
currentName == "access$${nextName}"

0 commit comments

Comments
 (0)