From a9397b7b23feec8295518d61c17bea85594912ac Mon Sep 17 00:00:00 2001 From: pyos Date: Sun, 11 Dec 2022 22:45:49 +0100 Subject: [PATCH] Test: FIR CFA: don't output two node fill colors --- .../resolve/cfg/flowFromInplaceLambda.dot | 2 +- .../testData/resolve/cfg/initBlock.dot | 6 +++--- .../inplaceLambdaInControlFlowExpressions.dot | 2 +- .../resolve/cfg/lambdaReturningObject.dot | 2 +- .../testData/resolve/cfg/lambdas.dot | 4 ++-- .../testData/resolve/cfg/loops.dot | 4 ++-- .../resolve/cfg/propertiesAndInitBlocks.dot | 16 ++++++++-------- .../resolve/cfg/returnValuesFromLambda.dot | 2 +- .../resolve/smartcasts/loops/endlessLoops.dot | 2 +- .../resolve/smartcasts/safeCalls/safeCalls.dot | 2 +- .../resolve/smartcasts/smartCastInInit.dot | 2 +- .../resolve/smartcasts/smartcastToNothing.dot | 4 ++-- .../delegates/delegateWithAnonymousObject.dot | 2 +- .../inference/plusAssignWithLambdaInRhs.dot | 6 +++--- .../dfa/cfg/ControlFlowGraphRenderer.kt | 18 +++++++----------- 15 files changed, 35 insertions(+), 39 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/flowFromInplaceLambda.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/flowFromInplaceLambda.dot index 1d356071a7e..c79da7b02cf 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/flowFromInplaceLambda.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/flowFromInplaceLambda.dot @@ -195,7 +195,7 @@ digraph flowFromInplaceLambda_kt { 97 [label="Stub" style="filled" fillcolor=gray]; 98 [label="Exit block" style="filled" fillcolor=gray]; } - 99 [label="Exit function materialize" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 99 [label="Exit function materialize" style="filled" fillcolor=gray]; } 91 -> {92}; 92 -> {93}; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot index bc0a1e6fa03..226d54ed336 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot @@ -61,13 +61,13 @@ digraph initBlock_kt { 23 [label="Variable declaration: lval y: R|kotlin/Int|" style="filled" fillcolor=gray]; 24 [label="Exit block" style="filled" fillcolor=gray]; } - 25 [label="Exit init block" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 25 [label="Exit init block" style="filled" fillcolor=gray]; } - 28 [label="Exit class Bar" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 28 [label="Exit class Bar" style="filled" fillcolor=gray]; } subgraph cluster_7 { color=blue - 12 [label="Enter function " style="filled" fillcolor=red style="filled" fillcolor=gray]; + 12 [label="Enter function " style="filled" fillcolor=gray]; 13 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; 14 [label="Exit function " style="filled" fillcolor=red]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/inplaceLambdaInControlFlowExpressions.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/inplaceLambdaInControlFlowExpressions.dot index ace5d8ff83c..bcc9b4919fd 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/inplaceLambdaInControlFlowExpressions.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/inplaceLambdaInControlFlowExpressions.dot @@ -16,7 +16,7 @@ digraph inplaceLambdaInControlFlowExpressions_kt { 6 [label="Stub" style="filled" fillcolor=gray]; 7 [label="Exit block" style="filled" fillcolor=gray]; } - 8 [label="Exit function materialize" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 8 [label="Exit function materialize" style="filled" fillcolor=gray]; } 0 -> {1}; 1 -> {2}; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/lambdaReturningObject.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/lambdaReturningObject.dot index 738aa3df170..d2e543e2471 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/lambdaReturningObject.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/lambdaReturningObject.dot @@ -60,7 +60,7 @@ digraph lambdaReturningObject_kt { 18 [label="Stub" style="filled" fillcolor=gray]; 19 [label="Exit block" style="filled" fillcolor=gray]; } - 20 [label="Exit function MyOut" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 20 [label="Exit function MyOut" style="filled" fillcolor=gray]; } 13 -> {14}; 14 -> {15}; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/lambdas.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/lambdas.dot index 91ba8998bed..80c00b77c7f 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/lambdas.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/lambdas.dot @@ -202,7 +202,7 @@ digraph lambdas_kt { 75 [label="Stub" style="filled" fillcolor=gray]; 76 [label="Exit block" style="filled" fillcolor=gray]; } - 77 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 77 [label="Exit function anonymousFunction" style="filled" fillcolor=gray]; } 65 [label="Postponed exit from lambda"]; 66 [label="Function call: R|/getInt|(...)" style="filled" fillcolor=yellow]; @@ -253,7 +253,7 @@ digraph lambdas_kt { 91 [label="Stub" style="filled" fillcolor=gray]; 92 [label="Exit block" style="filled" fillcolor=gray]; } - 93 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 93 [label="Exit function anonymousFunction" style="filled" fillcolor=gray]; } 81 [label="Postponed exit from lambda"]; 82 [label="Function call: R|/getInt|(...)" style="filled" fillcolor=yellow]; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/loops.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/loops.dot index d60e1cff6ad..85f8c3ce929 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/loops.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/loops.dot @@ -222,7 +222,7 @@ digraph loops_kt { 77 [label="Const: Int(1)" style="filled" fillcolor=gray]; 78 [label="Exit block" style="filled" fillcolor=gray]; } - 79 [label="Exit function testWhileTrue" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 79 [label="Exit function testWhileTrue" style="filled" fillcolor=gray]; } 65 -> {66}; 66 -> {67}; @@ -401,7 +401,7 @@ digraph loops_kt { 133 [label="Const: Int(1)" style="filled" fillcolor=gray]; 134 [label="Exit block" style="filled" fillcolor=gray]; } - 135 [label="Exit function testDoWhileTrue" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 135 [label="Exit function testDoWhileTrue" style="filled" fillcolor=gray]; } 121 -> {122}; 122 -> {123}; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot index cdb6309465d..31d5247bc5c 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot @@ -102,13 +102,13 @@ digraph propertiesAndInitBlocks_kt { 70 [label="Stub" style="filled" fillcolor=gray]; 71 [label="Exit block" style="filled" fillcolor=gray]; } - 72 [label="Exit init block" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 72 [label="Exit init block" style="filled" fillcolor=gray]; } - 65 [label="Exit class GetterLocalClass" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 65 [label="Exit class GetterLocalClass" style="filled" fillcolor=gray]; } subgraph cluster_13 { color=blue - 73 [label="Enter function " style="filled" fillcolor=red style="filled" fillcolor=gray]; + 73 [label="Enter function " style="filled" fillcolor=gray]; 74 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; 75 [label="Exit function " style="filled" fillcolor=red]; } @@ -151,7 +151,7 @@ digraph propertiesAndInitBlocks_kt { 30 [label="Stub" style="filled" fillcolor=gray]; 31 [label="Exit block" style="filled" fillcolor=gray]; } - 32 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 32 [label="Exit function anonymousFunction" style="filled" fillcolor=gray]; } subgraph cluster_17 { color=blue @@ -169,13 +169,13 @@ digraph propertiesAndInitBlocks_kt { 52 [label="Const: Int(1)" style="filled" fillcolor=gray]; 53 [label="Exit block" style="filled" fillcolor=gray]; } - 54 [label="Exit init block" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 54 [label="Exit init block" style="filled" fillcolor=gray]; } - 46 [label="Exit class InitializerLocalClass" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 46 [label="Exit class InitializerLocalClass" style="filled" fillcolor=gray]; } subgraph cluster_20 { color=blue - 55 [label="Enter function " style="filled" fillcolor=red style="filled" fillcolor=gray]; + 55 [label="Enter function " style="filled" fillcolor=gray]; 56 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; 57 [label="Exit function " style="filled" fillcolor=red]; } @@ -194,7 +194,7 @@ digraph propertiesAndInitBlocks_kt { 41 [label="Stub" style="filled" fillcolor=gray]; 42 [label="Exit block" style="filled" fillcolor=gray]; } - 43 [label="Exit function foo" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 43 [label="Exit function foo" style="filled" fillcolor=gray]; } 78 [label="Postponed exit from lambda"]; 79 [label="Function call: R|/run|(...)" style="filled" fillcolor=yellow]; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/returnValuesFromLambda.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/returnValuesFromLambda.dot index bc79cf35f8e..c99bb0908a8 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/returnValuesFromLambda.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/returnValuesFromLambda.dot @@ -182,7 +182,7 @@ digraph returnValuesFromLambda_kt { 65 [label="Stub" style="filled" fillcolor=gray]; 66 [label="Exit block" style="filled" fillcolor=gray]; } - 67 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 67 [label="Exit function anonymousFunction" style="filled" fillcolor=gray]; } 56 [label="Postponed exit from lambda" style="filled" fillcolor=gray]; 57 [label="Function call: R|kotlin/run|(...)" style="filled" fillcolor=gray]; diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/loops/endlessLoops.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/loops/endlessLoops.dot index 70c48836c2e..075229d84e2 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/loops/endlessLoops.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/loops/endlessLoops.dot @@ -623,7 +623,7 @@ digraph endlessLoops_kt { 212 [label="Function call: R|/x|.R|/A.foo|()" style="filled" fillcolor=gray]; 213 [label="Exit block" style="filled" fillcolor=gray]; } - 214 [label="Exit function test_7" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 214 [label="Exit function test_7" style="filled" fillcolor=gray]; } 197 -> {198}; 198 -> {199}; diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/safeCalls.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/safeCalls.dot index 4c85c464809..721f916848c 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/safeCalls.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/safeCalls.dot @@ -268,7 +268,7 @@ digraph safeCalls_kt { 115 [label="Stub" style="filled" fillcolor=gray]; 116 [label="Exit block" style="filled" fillcolor=gray]; } - 117 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 117 [label="Exit function anonymousFunction" style="filled" fillcolor=gray]; } 98 [label="Postponed exit from lambda" style="filled" fillcolor=gray]; 99 [label="Function call: $subj$.R|kotlin/let|(...)" style="filled" fillcolor=gray]; diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot index 75af9aed0aa..3dea80ee5f7 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot @@ -37,7 +37,7 @@ digraph smartCastInInit_kt { 11 [label="Stub" style="filled" fillcolor=gray]; 12 [label="Exit block" style="filled" fillcolor=gray]; } - 13 [label="Exit function s" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 13 [label="Exit function s" style="filled" fillcolor=gray]; } 6 -> {7}; 7 -> {8}; diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot index 183f0787bda..7cfb0baf60b 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot @@ -16,7 +16,7 @@ digraph smartcastToNothing_kt { 6 [label="Stub" style="filled" fillcolor=gray]; 7 [label="Exit block" style="filled" fillcolor=gray]; } - 8 [label="Exit function getNothing" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 8 [label="Exit function getNothing" style="filled" fillcolor=gray]; } 0 -> {1}; 1 -> {2}; @@ -103,7 +103,7 @@ digraph smartcastToNothing_kt { 36 [label="Stub" style="filled" fillcolor=gray]; 37 [label="Exit block" style="filled" fillcolor=gray]; } - 38 [label="Exit function myListOf" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 38 [label="Exit function myListOf" style="filled" fillcolor=gray]; } 30 -> {31}; 31 -> {32}; diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot b/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot index 6b4c9ee9127..609f0eae9c9 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot @@ -33,7 +33,7 @@ digraph delegateWithAnonymousObject_kt { 11 [label="Stub" style="filled" fillcolor=gray]; 12 [label="Exit block" style="filled" fillcolor=gray]; } - 13 [label="Exit function delegate" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 13 [label="Exit function delegate" style="filled" fillcolor=gray]; } 5 -> {6}; 6 -> {7}; diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/plusAssignWithLambdaInRhs.dot b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/plusAssignWithLambdaInRhs.dot index 8076ce117f4..df3ee2a98d1 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/plusAssignWithLambdaInRhs.dot +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/plusAssignWithLambdaInRhs.dot @@ -17,20 +17,20 @@ digraph plusAssignWithLambdaInRhs_kt { 7 [label="Postponed enter to lambda" style="filled" fillcolor=gray]; subgraph cluster_2 { color=blue - 12 [label="Enter function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 12 [label="Enter function anonymousFunction" style="filled" fillcolor=gray]; subgraph cluster_3 { color=blue 13 [label="Enter block" style="filled" fillcolor=gray]; 14 [label="Access variable R|/it|" style="filled" fillcolor=gray]; 15 [label="Exit block" style="filled" fillcolor=gray]; } - 16 [label="Exit function anonymousFunction" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 16 [label="Exit function anonymousFunction" style="filled" fillcolor=gray]; } 8 [label="Postponed exit from lambda" style="filled" fillcolor=gray]; 9 [label="Function call: R|/list|.R|kotlin/collections/plusAssign| kotlin/String|>(...)" style="filled" fillcolor=gray]; 10 [label="Exit block" style="filled" fillcolor=gray]; } - 11 [label="Exit function test" style="filled" fillcolor=red style="filled" fillcolor=gray]; + 11 [label="Exit function test" style="filled" fillcolor=gray]; } 0 -> {1}; 1 -> {2}; diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphRenderer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphRenderer.kt index 5be8abfb856..6a7ca508a69 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphRenderer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphRenderer.kt @@ -85,18 +85,14 @@ class FirControlFlowGraphRenderVisitor( } attributes += "label=\"$label\"" - fun fillColor(color: String) { + when { + node.isDead -> "gray" + node == node.owner.enterNode || node == node.owner.exitNode -> "red" + node is UnionNodeMarker -> "yellow" + else -> null + }?.let { attributes += "style=\"filled\"" - attributes += "fillcolor=$color" - } - - if (node == node.owner.enterNode || node == node.owner.exitNode) { - fillColor("red") - } - if (node.isDead) { - fillColor("gray") - } else if (node is UnionNodeMarker) { - fillColor("yellow") + attributes += "fillcolor=$it" } println(indices.getValue(node), attributes.joinToString(separator = " ", prefix = " [", postfix = "];")) if (node is ExitNodeMarker) {