FIR CFA: do not remove provideDelegate subgraphs when rolling back

The receiver of the provideDelegate call is the same FirExpression as
the delegate itself, so there's only one copy of the nodes in the first
place; trying to remove subgraphs completely detaches objects inside it
from the parent graph, which is not great for checkers.

Note that currently if provideDelegate is not selected, there will be a
stray FunctionCallExit node in the control flow graph. This commit *does
not change that*. It has been there for a while. Don't @ me. I'll try to
fix that. No promises.
This commit is contained in:
pyos
2022-11-28 17:15:56 +01:00
committed by Dmitriy Novozhilov
parent ef2fa01a8d
commit e7e5569539
6 changed files with 43 additions and 96 deletions
@@ -55,15 +55,6 @@ sealed class CFGNode<out E : FirElement>(val owner: ControlFlowGraph, val level:
return true
}
@CfgInternals
fun removeAllIncomingEdges(to: CFGNode<*>) {
for (from in to._previousNodes) {
from._followingNodes.remove(to)
}
to._incomingEdges = null
to._previousNodes.clear()
}
@CfgInternals
fun removeAllOutgoingEdges(from: CFGNode<*>) {
for (to in from._followingNodes) {
@@ -59,16 +59,6 @@ class ControlFlowGraph(val declaration: FirDeclaration?, val name: String, val k
_subGraphs += graph
}
@CfgInternals
fun removeSubGraph(graph: ControlFlowGraph) {
assert(graph.owner == this)
_subGraphs.remove(graph)
graph.owner = null
CFGNode.removeAllIncomingEdges(graph.enterNode)
CFGNode.removeAllOutgoingEdges(graph.exitNode)
}
private fun assertState(state: State) {
assert(this.state == state) {
"This action can not be performed at $this state"