[FIR] Clean data flow context before body resolve of file
This commit is contained in:
@@ -36,6 +36,13 @@ class DataFlowAnalyzerContext<FLOW : Flow>(
|
|||||||
val flowOnNodes: MutableMap<CFGNode<*>, FLOW>,
|
val flowOnNodes: MutableMap<CFGNode<*>, FLOW>,
|
||||||
val variablesForWhenConditions: MutableMap<WhenBranchConditionExitNode, DataFlowVariable>
|
val variablesForWhenConditions: MutableMap<WhenBranchConditionExitNode, DataFlowVariable>
|
||||||
) {
|
) {
|
||||||
|
fun reset() {
|
||||||
|
graphBuilder.reset()
|
||||||
|
variableStorage.reset()
|
||||||
|
flowOnNodes.clear()
|
||||||
|
variablesForWhenConditions.clear()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun <FLOW : Flow> empty(session: FirSession) =
|
fun <FLOW : Flow> empty(session: FirSession) =
|
||||||
DataFlowAnalyzerContext<FLOW>(
|
DataFlowAnalyzerContext<FLOW>(
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ abstract class Stack<T> {
|
|||||||
abstract fun top(): T
|
abstract fun top(): T
|
||||||
abstract fun pop(): T
|
abstract fun pop(): T
|
||||||
abstract fun push(value: T)
|
abstract fun push(value: T)
|
||||||
|
abstract fun reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> stackOf(vararg values: T): Stack<T> = StackImpl(*values)
|
fun <T> stackOf(vararg values: T): Stack<T> = StackImpl(*values)
|
||||||
@@ -33,6 +34,9 @@ private class StackImpl<T>(vararg values: T) : Stack<T>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override val size: Int get() = stack.size
|
override val size: Int get() = stack.size
|
||||||
|
override fun reset() {
|
||||||
|
stack.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NodeStorage<T : FirElement, N : CFGNode<T>> : Stack<N>(){
|
class NodeStorage<T : FirElement, N : CFGNode<T>> : Stack<N>(){
|
||||||
@@ -55,6 +59,11 @@ class NodeStorage<T : FirElement, N : CFGNode<T>> : Stack<N>(){
|
|||||||
operator fun get(key: T): N? {
|
operator fun get(key: T): N? {
|
||||||
return map[key]
|
return map[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
stack.reset()
|
||||||
|
map.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SymbolBasedNodeStorage<T, N : CFGNode<T>> : Stack<N>() where T : FirElement {
|
class SymbolBasedNodeStorage<T, N : CFGNode<T>> : Stack<N>() where T : FirElement {
|
||||||
@@ -77,4 +86,9 @@ class SymbolBasedNodeStorage<T, N : CFGNode<T>> : Stack<N>() where T : FirElemen
|
|||||||
operator fun get(key: FirBasedSymbol<*>): N? {
|
operator fun get(key: FirBasedSymbol<*>): N? {
|
||||||
return map[key]
|
return map[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun reset() {
|
||||||
|
stack.reset()
|
||||||
|
map.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+2
@@ -941,6 +941,8 @@ class ControlFlowGraphBuilder {
|
|||||||
fun reset() {
|
fun reset() {
|
||||||
exitsOfAnonymousFunctions.clear()
|
exitsOfAnonymousFunctions.clear()
|
||||||
exitsFromCompletedPostponedAnonymousFunctions.clear()
|
exitsFromCompletedPostponedAnonymousFunctions.clear()
|
||||||
|
lexicalScopes.reset()
|
||||||
|
lexicalScopes.push(stackOf())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dropSubgraphFromCall(call: FirFunctionCall) {
|
fun dropSubgraphFromCall(call: FirFunctionCall) {
|
||||||
|
|||||||
+4
@@ -229,6 +229,10 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
|
|||||||
towerDataContextForAnonymousFunctions.clear()
|
towerDataContextForAnonymousFunctions.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun cleanDataFlowContext() {
|
||||||
|
dataFlowAnalyzerContext.reset()
|
||||||
|
}
|
||||||
|
|
||||||
private inline fun updateLastScope(transform: FirLocalScope.() -> FirLocalScope) {
|
private inline fun updateLastScope(transform: FirLocalScope.() -> FirLocalScope) {
|
||||||
val lastScope = towerDataContext.localScopes.lastOrNull() ?: return
|
val lastScope = towerDataContext.localScopes.lastOrNull() ?: return
|
||||||
replaceTowerDataContext(towerDataContext.setLastLocalScope(lastScope.transform()))
|
replaceTowerDataContext(towerDataContext.setLastLocalScope(lastScope.transform()))
|
||||||
|
|||||||
+1
@@ -46,6 +46,7 @@ open class FirBodyResolveTransformer(
|
|||||||
override fun transformFile(file: FirFile, data: ResolutionMode): CompositeTransformResult<FirFile> {
|
override fun transformFile(file: FirFile, data: ResolutionMode): CompositeTransformResult<FirFile> {
|
||||||
checkSessionConsistency(file)
|
checkSessionConsistency(file)
|
||||||
context.cleanContextForAnonymousFunction()
|
context.cleanContextForAnonymousFunction()
|
||||||
|
context.cleanDataFlowContext()
|
||||||
@OptIn(PrivateForInline::class)
|
@OptIn(PrivateForInline::class)
|
||||||
context.file = file
|
context.file = file
|
||||||
packageFqName = file.packageFqName
|
packageFqName = file.packageFqName
|
||||||
|
|||||||
Reference in New Issue
Block a user