diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/CfaUtils.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/CfaUtils.kt index c11c3c21fc8..ce21e657581 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/CfaUtils.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/CfaUtils.kt @@ -112,7 +112,7 @@ class PropertyInitializationInfoCollector(private val localProperties: Set, K : Any, V : Any> ControlFlowGraph.collectDataForNode( direction: TraverseDirection, initialInfo: I, - visitor: ControlFlowGraphVisitor> + visitor: ControlFlowGraphVisitor>> ): Map, I> { val nodeMap = LinkedHashMap, I>() val startNode = getEnterNode(direction) @@ -53,56 +51,6 @@ fun , K : Any, V : Any> ControlFlowGraph.collectDat } private fun , K : Any, V : Any> ControlFlowGraph.collectDataForNodeInternal( - direction: TraverseDirection, - initialInfo: I, - visitor: ControlFlowGraphVisitor>, - nodeMap: MutableMap, I>, - changed: MutableMap, Boolean> -) { - val nodes = getNodesInOrder(direction) - for (node in nodes) { - if (direction == TraverseDirection.Backward && node is CFGNodeWithCfgOwner<*>) { - node.subGraphs.forEach { it.collectDataForNodeInternal(direction, initialInfo, visitor, nodeMap, changed) } - } - val previousNodes = when (direction) { - TraverseDirection.Forward -> node.previousCfgNodes - TraverseDirection.Backward -> node.followingCfgNodes - } - val previousData = previousNodes.mapNotNull { nodeMap[it] } - val data = nodeMap[node] - val newData = node.accept(visitor, previousData) - val hasChanged = newData != data - changed[node] = hasChanged - if (hasChanged) { - nodeMap[node] = newData - } - if (direction == TraverseDirection.Forward && node is CFGNodeWithCfgOwner<*>) { - node.subGraphs.forEach { it.collectDataForNodeInternal(direction, initialInfo, visitor, nodeMap, changed) } - } - } -} - -// ---------------------- Path-sensitive data collection ----------------------- - -// TODO: Once migration is done, get rid of "PathAware" from util names -fun , K : Any, V : Any> ControlFlowGraph.collectPathAwareDataForNode( - direction: TraverseDirection, - initialInfo: I, - visitor: ControlFlowGraphVisitor>> -): Map, I> { - val nodeMap = LinkedHashMap, I>() - val startNode = getEnterNode(direction) - nodeMap[startNode] = initialInfo - - val changed = mutableMapOf, Boolean>() - do { - collectPathAwareDataForNodeInternal(direction, initialInfo, visitor, nodeMap, changed) - } while (changed.any { it.value }) - - return nodeMap -} - -private fun , K : Any, V : Any> ControlFlowGraph.collectPathAwareDataForNodeInternal( direction: TraverseDirection, initialInfo: I, visitor: ControlFlowGraphVisitor>>, @@ -112,7 +60,7 @@ private fun , K : Any, V : Any> ControlFlowGraph.co val nodes = getNodesInOrder(direction) for (node in nodes) { if (direction == TraverseDirection.Backward && node is CFGNodeWithCfgOwner<*>) { - node.subGraphs.forEach { it.collectPathAwareDataForNodeInternal(direction, initialInfo, visitor, nodeMap, changed) } + node.subGraphs.forEach { it.collectDataForNodeInternal(direction, initialInfo, visitor, nodeMap, changed) } } val previousNodes = when (direction) { TraverseDirection.Forward -> node.previousCfgNodes @@ -136,7 +84,7 @@ private fun , K : Any, V : Any> ControlFlowGraph.co nodeMap[node] = newData } if (direction == TraverseDirection.Forward && node is CFGNodeWithCfgOwner<*>) { - node.subGraphs.forEach { it.collectPathAwareDataForNodeInternal(direction, initialInfo, visitor, nodeMap, changed) } + node.subGraphs.forEach { it.collectDataForNodeInternal(direction, initialInfo, visitor, nodeMap, changed) } } } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirCallsEffectAnalyzer.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirCallsEffectAnalyzer.kt index 656fed1d504..d2cec5c9d10 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirCallsEffectAnalyzer.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/cfa/FirCallsEffectAnalyzer.kt @@ -80,7 +80,7 @@ object FirCallsEffectAnalyzer : FirControlFlowChecker() { } } - val invocationData = graph.collectPathAwareDataForNode( + val invocationData = graph.collectDataForNode( TraverseDirection.Forward, PathAwareLambdaInvocationInfo.EMPTY, InvocationDataCollector(functionalTypeEffects.keys.filterTo(mutableSetOf()) { it !in leakedSymbols }) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt index 2aa5022b6a5..f60f9936b1f 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/UnusedChecker.kt @@ -151,7 +151,7 @@ object UnusedChecker : FirControlFlowChecker() { private val localProperties: Set ) : ControlFlowGraphVisitor>>() { fun getData(graph: ControlFlowGraph): Map, PathAwareVariableStatusInfo> { - return graph.collectPathAwareDataForNode(TraverseDirection.Backward, PathAwareVariableStatusInfo.EMPTY, this) + return graph.collectDataForNode(TraverseDirection.Backward, PathAwareVariableStatusInfo.EMPTY, this) } override fun visitNode(