FIR CFA: rewrite handling of try-catch-finally

The result is the same, but it should now be much clearer what the
shortcomings of the current implementation are.
This commit is contained in:
pyos
2022-11-27 21:27:37 +01:00
committed by Dmitriy Novozhilov
parent a079010fad
commit 069d99c5ea
10 changed files with 390 additions and 466 deletions
@@ -6,8 +6,7 @@
package org.jetbrains.kotlin.fir.resolve.dfa.cfg
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.expressions.FirBreakExpression
import org.jetbrains.kotlin.fir.expressions.FirLoopJump
import org.jetbrains.kotlin.fir.expressions.FirLoop
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
class ControlFlowGraph(val declaration: FirDeclaration?, val name: String, val kind: Kind) {
@@ -146,15 +145,10 @@ object LoopBackPath : EdgeLabel(label = null) {
object UncaughtExceptionPath : EdgeLabel(label = "onUncaughtException")
class LoopPath(
firLoopJump: FirLoopJump
) : EdgeLabel((if (firLoopJump is FirBreakExpression) "break" else "continue") +
(firLoopJump.target.labeledElement.label?.let { "@${it.name}" } ?: ""))
// TODO: Label `return`ing edge with this.
class ReturnPath(
returnTargetSymbol: FirFunctionSymbol<*>
) : EdgeLabel(label = "return@${returnTargetSymbol.callableId}")
data class ReturnPath(val target: FirFunctionSymbol<*>) : EdgeLabel(label = "return@${target.callableId}")
data class LoopBreakPath(val loop: FirLoop) : EdgeLabel(loop.label?.let { "break@${it.name}" } ?: "break")
data class LoopContinuePath(val loop: FirLoop) : EdgeLabel(loop.label?.let { "continue@${it.name}" } ?: "continue")
enum class EdgeKind(
val usedInDfa: Boolean, // propagate flow to alive nodes