FIR CFA: remove CFGNode.outgoingEdges

If it's symmetric with incomingEdges, then what's the point?..
This commit is contained in:
pyos
2022-11-27 22:51:22 +01:00
committed by Dmitriy Novozhilov
parent 7feeb7cd4e
commit fa0ea1504e
10 changed files with 35 additions and 78 deletions
@@ -1128,7 +1128,7 @@ abstract class FirDataFlowAnalyzer(
// In that case `mergeIncomingFlow` will automatically ensure consistency once called on that node.
private fun CFGNode<*>.buildIncomingFlow(): MutableFlow {
val previousFlows = previousNodes.mapNotNull {
val incomingEdgeKind = incomingEdges.getValue(it).kind
val incomingEdgeKind = edgeFrom(it).kind
if (if (isDead) !incomingEdgeKind.usedInDeadDfa else !incomingEdgeKind.usedInDfa) return@mapNotNull null
// `MergePostponedLambdaExitsNode` nodes form a parallel data flow graph. We never compute
// data flow for any of them until reaching a completed call.
@@ -114,7 +114,7 @@ class ControlFlowGraphBuilder {
}
val returnValues = exitNode.previousNodes.mapNotNullTo(mutableSetOf()) {
val edge = exitNode.incomingEdges.getValue(it)
val edge = exitNode.edgeFrom(it)
// * NormalPath: last expression = return value
// * UncaughtExceptionPath: last expression = whatever threw, *not* a return value
// * ReturnPath(this lambda): these go from `finally` blocks, so that's not the return value;
@@ -1009,7 +1009,7 @@ class ControlFlowGraphBuilder {
val exitNode = createFinallyBlockExitNode(enterNode.fir)
popAndAddEdge(exitNode)
val allNormalInputsAreDead = enterNode.previousNodes.all {
val edge = enterNode.incomingEdges.getValue(it)
val edge = enterNode.edgeFrom(it)
edge.kind.isDead || edge.label != NormalPath
}
addEdge(exitNode, tryExitNode, isDead = allNormalInputsAreDead)
@@ -1087,7 +1087,7 @@ class ControlFlowGraphBuilder {
private fun completeFunctionCall(node: FunctionCallNode) {
if (!node.fir.resultType.isNothing) return
val stub = withLevelOfNode(node) { createStubNode() }
val edges = node.followingNodes.map { it to node.outgoingEdges.getValue(it) }
val edges = node.followingNodes.map { it to node.edgeTo(it) }
CFGNode.removeAllOutgoingEdges(node)
CFGNode.addEdge(node, stub, EdgeKind.DeadForward, propagateDeadness = false)
for ((to, edge) in edges) {
@@ -1448,7 +1448,7 @@ class ControlFlowGraphBuilder {
private fun propagateDeadnessForward(node: CFGNode<*>) {
if (!node.isDead) return
for (next in node.followingNodes) {
val kind = node.outgoingEdges.getValue(next).kind
val kind = node.edgeTo(next).kind
if (CFGNode.killEdge(node, next, propagateDeadness = false) && !kind.isBack && kind.usedInCfa) {
next.updateDeadStatus()
propagateDeadnessForward(next)
@@ -122,7 +122,7 @@ class FirControlFlowGraphRenderVisitor(
private fun Printer.renderEdges(graph: ControlFlowGraph) {
for (node in graph.nodes) {
for ((style, group) in node.followingNodes.groupBy { node.outgoingEdges.getValue(it).style }.entries.sortedBy { it.key }) {
for ((style, group) in node.followingNodes.groupBy { node.edgeTo(it).style }.entries.sortedBy { it.key }) {
val mappedGroup = group.map { indices.getValue(it) }.sorted()
print(indices.getValue(node), EDGE, mappedGroup.joinToString(prefix = "{", postfix = "}", separator = " "))
style?.let { printWithNoIndent(" $it") }