FIR CFA: properly visit subgraphs in checkers
Interpretation: a graph A is a subgraph of B if information available at nodes of A depends on the paths taken in B. For example, local classes are subgraphs of a graph in which they are declared, and members of those classes are subgraphs of the local class itself - because these members can reference captured values. Consequences: * if graph G is a subgraph of node N, then G is a subgraph of N's owner; * `ControlFlowAnalysisDiagnosticComponent` will only visit root graphs; * `graph.traverse` will ignore subgraph boundaries, as if all subgraphs are inlined into one huge root graph; * if a control flow checker needs information from a declaration to which a graph is attached, it must look at subgraphs explicitly. For example, consider the `callsInPlace` checker. When a function has a `callsInPlace` contract and a local declaration, the checker must visit that local declaration to ensure it does not capture the allegedly called-in-place argument - hence `graph.traverse` will look at the nodes. However, the local declaration can also be a function with its own `callsInPlace` contracts, so the checker should also run for it in isolation. If that sounds quadratic, that's because unfortunately it is.
This commit is contained in:
+2
@@ -433,6 +433,7 @@ class ControlFlowGraphBuilder {
|
||||
} ?: continue
|
||||
|
||||
createPartOfClassInitializationNode(declaration as FirControlFlowGraphOwner).also {
|
||||
currentGraph.addSubGraph(graph)
|
||||
addEdge(node, it, preferredKind = EdgeKind.CfgForward)
|
||||
addEdge(it, graph.enterNode, preferredKind = EdgeKind.CfgForward)
|
||||
node = graph.exitNode
|
||||
@@ -537,6 +538,7 @@ class ControlFlowGraphBuilder {
|
||||
if (functionGraph != null && functionGraph.owner == null) {
|
||||
addEdge(node, functionGraph.enterNode, preferredKind = EdgeKind.CfgForward)
|
||||
node.addSubGraph(functionGraph)
|
||||
currentGraph.addSubGraph(functionGraph)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user