From 7dd91df10b23e2cc431507982a066c1c1eb3d4a3 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Thu, 2 Apr 2020 12:25:53 +0300 Subject: [PATCH] [FIR] Don't analyze with DFA already analyzed classes --- .../resolve/cfg/localClassesWithImplicit.dot | 80 +++++++++---------- .../FirDeclarationsResolveTransformer.kt | 18 +++-- 2 files changed, 51 insertions(+), 47 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/localClassesWithImplicit.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/localClassesWithImplicit.dot index ee0191b018f..cc8386fe616 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/localClassesWithImplicit.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/localClassesWithImplicit.dot @@ -80,29 +80,62 @@ digraph localClassesWithImplicit_kt { subgraph cluster_6 { color=red 26 [label="Enter function foo" style="filled" fillcolor=red]; - 28 [label="Postponed enter to lambda"]; subgraph cluster_7 { + color=blue + 71 [label="Enter function baz" style="filled" fillcolor=red]; + 73 [label="Const: Int(1)"]; + 74 [label="Jump: ^baz Int(1)"]; + 75 [label="Stub" style="filled" fillcolor=gray]; + 72 [label="Exit function baz" style="filled" fillcolor=red]; + } + subgraph cluster_8 { + color=blue + 57 [label="Enter function bar" style="filled" fillcolor=red]; + 59 [label="Postponed enter to lambda"]; + subgraph cluster_9 { + color=blue + 64 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; + 66 [label="Access variable R|/b|"]; + 67 [label="Access variable #"]; + 68 [label="Access variable R|/a|"]; + 69 [label="Access variable R|kotlin/String.length|"]; + 70 [label="Function call: this@R|/A|.R|/A.baz|()"]; + 65 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; + } + 60 [label="Postponed exit from lambda"]; + 61 [label="Function call: R|/myRun|(...)"]; + 62 [label="Jump: ^bar R|/myRun|( = myRun@fun (): R|kotlin/Int| { + R|/b|.# + R|/a|.R|kotlin/String.length| + ^ this@R|/A|.R|/A.baz|() +} +)"]; + 63 [label="Stub" style="filled" fillcolor=gray]; + 58 [label="Exit function bar" style="filled" fillcolor=red]; + } + 28 [label="Postponed enter to lambda"]; + subgraph cluster_10 { color=blue 33 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; 35 [label="Access variable R|/a|"]; 36 [label="Access variable R|kotlin/String.length|"]; - subgraph cluster_8 { + subgraph cluster_11 { color=blue 37 [label="Enter when"]; - subgraph cluster_9 { + subgraph cluster_12 { color=blue 39 [label="Enter when branch condition "]; 40 [label="Access variable R|/b|"]; 41 [label="Type operator: (R|/b| is R|kotlin/String|)"]; 42 [label="Exit when branch condition"]; } - subgraph cluster_10 { + subgraph cluster_13 { color=blue 50 [label="Enter when branch condition else"]; 51 [label="Exit when branch condition"]; } 52 [label="Enter when branch result"]; - subgraph cluster_11 { + subgraph cluster_14 { color=blue 53 [label="Enter block"]; 54 [label="Const: Int(1)"]; @@ -110,7 +143,7 @@ digraph localClassesWithImplicit_kt { } 56 [label="Exit when branch result"]; 43 [label="Enter when branch result"]; - subgraph cluster_12 { + subgraph cluster_15 { color=blue 44 [label="Enter block"]; 45 [label="Access variable R|/b|"]; @@ -175,32 +208,6 @@ digraph localClassesWithImplicit_kt { 54 -> {55}; 55 -> {56}; 56 -> {38}; - - subgraph cluster_13 { - color=red - 57 [label="Enter function bar" style="filled" fillcolor=red]; - 59 [label="Postponed enter to lambda"]; - subgraph cluster_14 { - color=blue - 64 [label="Enter function anonymousFunction" style="filled" fillcolor=red]; - 66 [label="Access variable R|/b|"]; - 67 [label="Access variable #"]; - 68 [label="Access variable R|/a|"]; - 69 [label="Access variable R|kotlin/String.length|"]; - 70 [label="Function call: this@R|/A|.R|/A.baz|()"]; - 65 [label="Exit function anonymousFunction" style="filled" fillcolor=red]; - } - 60 [label="Postponed exit from lambda"]; - 61 [label="Function call: R|/myRun|(...)"]; - 62 [label="Jump: ^bar R|/myRun|( = myRun@fun (): R|kotlin/Int| { - R|/b|.# - R|/a|.R|kotlin/String.length| - ^ this@R|/A|.R|/A.baz|() -} -)"]; - 63 [label="Stub" style="filled" fillcolor=gray]; - 58 [label="Exit function bar" style="filled" fillcolor=red]; - } 57 -> {59}; 59 -> {64}; 59 -> {60} [color=red]; @@ -217,15 +224,6 @@ digraph localClassesWithImplicit_kt { 68 -> {69}; 69 -> {70}; 70 -> {65}; - - subgraph cluster_15 { - color=red - 71 [label="Enter function baz" style="filled" fillcolor=red]; - 73 [label="Const: Int(1)"]; - 74 [label="Jump: ^baz Int(1)"]; - 75 [label="Stub" style="filled" fillcolor=gray]; - 72 [label="Exit function baz" style="filled" fillcolor=red]; - } 71 -> {73}; 73 -> {74}; 74 -> {72}; diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index 4a073b6d12c..0ce26da5f5e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -281,8 +281,12 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer) return regularClass.runAllPhasesForLocalClass(transformer, components, data).compose() } + val notAnalyzed = regularClass.resolvePhase < transformerPhase + return withTypeParametersOf(regularClass) { - dataFlowAnalyzer.enterClass() + if (notAnalyzed) { + dataFlowAnalyzer.enterClass() + } val oldConstructorScope = primaryConstructorParametersScope val oldContainingClass = containingClass primaryConstructorParametersScope = null @@ -299,11 +303,13 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer) } transformDeclarationContent(regularClass, data).single as FirRegularClass } - if (!implicitTypeOnly) { - val controlFlowGraph = dataFlowAnalyzer.exitRegularClass(result) - result.transformControlFlowGraphReference(ControlFlowGraphReferenceTransformer, controlFlowGraph) - } else { - dataFlowAnalyzer.exitClass() + if (notAnalyzed) { + if (!implicitTypeOnly) { + val controlFlowGraph = dataFlowAnalyzer.exitRegularClass(result) + result.transformControlFlowGraphReference(ControlFlowGraphReferenceTransformer, controlFlowGraph) + } else { + dataFlowAnalyzer.exitClass() + } } containingClass = oldContainingClass primaryConstructorParametersScope = oldConstructorScope