From 9f17b5de973fa177d9171f926b4542295b288e4a Mon Sep 17 00:00:00 2001 From: pyos Date: Wed, 18 Jan 2023 12:02:00 +0100 Subject: [PATCH] FIR CFA: add edges according to constructor delegation --- .../testData/resolve/cfg/initBlock.dot | 78 ++++---- .../resolve/cfg/initBlockAndInPlaceLambda.dot | 74 +++---- .../cfg/postponedLambdaInConstructor.dot | 80 ++++---- .../resolve/cfg/propertiesAndInitBlocks.dot | 82 ++++---- .../problems/secondaryConstructorCfg.dot | 87 ++++---- .../boundSmartcasts/boundSmartcasts.dot | 12 +- .../boundSmartcastsInBranches.dot | 12 +- .../boundSmartcasts/functionCallBound.dot | 12 +- .../smartcasts/lambdas/lambdaInWhenBranch.dot | 12 +- .../resolve/smartcasts/nullability.dot | 24 +-- .../smartcasts/safeCalls/assignSafeCall.dot | 12 +- .../resolve/smartcasts/smartCastInInit.dot | 38 ++-- .../smartcasts/smartcastInByClause.dot | 70 +++---- .../resolve/smartcasts/smartcastToNothing.dot | 14 +- .../smartcasts/stability/overridenOpenVal.dot | 12 +- .../bad/callsInPlace/inAnonymousObject.dot | 42 ++-- .../bad/callsInPlace/inLocalClass.dot | 41 ++-- .../delegates/delegateWithAnonymousObject.dot | 156 +++++++-------- .../inference/plusAssignWithLambdaInRhs.dot | 12 +- .../dfa/cfg/ControlFlowGraphBuilder.kt | 99 ++++++---- .../codegen/box/smartCasts/kt44814.dot | 186 +++++++++--------- 21 files changed, 593 insertions(+), 562 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot index c019eaa3fe0..0ea42b2b419 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/initBlock.dot @@ -8,33 +8,33 @@ digraph initBlock_kt { 0 [label="Enter class Foo" style="filled" fillcolor=red]; subgraph cluster_1 { color=blue - 1 [label="Enter function " style="filled" fillcolor=red]; - 2 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 3 [label="Exit function " style="filled" fillcolor=red]; - } - subgraph cluster_2 { - color=blue - 4 [label="Enter init block" style="filled" fillcolor=red]; - subgraph cluster_3 { + 1 [label="Enter init block" style="filled" fillcolor=red]; + subgraph cluster_2 { color=blue - 5 [label="Enter block"]; - 6 [label="Const: Int(1)"]; - 7 [label="Variable declaration: lval x: R|kotlin/Int|"]; - 8 [label="Exit block"]; + 2 [label="Enter block"]; + 3 [label="Const: Int(1)"]; + 4 [label="Variable declaration: lval x: R|kotlin/Int|"]; + 5 [label="Exit block"]; } - 9 [label="Exit init block" style="filled" fillcolor=red]; + 6 [label="Exit init block" style="filled" fillcolor=red]; + } + subgraph cluster_3 { + color=blue + 7 [label="Enter function " style="filled" fillcolor=red]; + 8 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 9 [label="Exit function " style="filled" fillcolor=red]; } 10 [label="Exit class Foo" style="filled" fillcolor=red]; } 0 -> {1} [color=green]; 0 -> {10} [style=dotted]; - 0 -> {1 4} [style=dashed]; + 0 -> {1 7} [style=dashed]; 1 -> {2}; 2 -> {3}; - 3 -> {4} [color=green]; + 3 -> {4}; 4 -> {5}; 5 -> {6}; - 6 -> {7}; + 6 -> {7} [color=green]; 7 -> {8}; 8 -> {9}; 9 -> {10} [color=green]; @@ -44,40 +44,40 @@ digraph initBlock_kt { 11 [label="Enter class Bar" style="filled" fillcolor=red]; subgraph cluster_5 { color=blue - 12 [label="Enter function " style="filled" fillcolor=red]; - 13 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 14 [label="Exit function " style="filled" fillcolor=red]; - } - subgraph cluster_6 { - color=blue - 15 [label="Enter init block" style="filled" fillcolor=red]; - subgraph cluster_7 { + 12 [label="Enter init block" style="filled" fillcolor=red]; + subgraph cluster_6 { color=blue - 16 [label="Enter block"]; - 17 [label="Const: Int(1)"]; - 18 [label="Variable declaration: lval x: R|kotlin/Int|"]; - 19 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow]; - 20 [label="Throw: throw R|java/lang/Exception.Exception|()"]; - 21 [label="Stub" style="filled" fillcolor=gray]; - 22 [label="Const: Int(2)" style="filled" fillcolor=gray]; - 23 [label="Variable declaration: lval y: R|kotlin/Int|" style="filled" fillcolor=gray]; - 24 [label="Exit block" style="filled" fillcolor=gray]; + 13 [label="Enter block"]; + 14 [label="Const: Int(1)"]; + 15 [label="Variable declaration: lval x: R|kotlin/Int|"]; + 16 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow]; + 17 [label="Throw: throw R|java/lang/Exception.Exception|()"]; + 18 [label="Stub" style="filled" fillcolor=gray]; + 19 [label="Const: Int(2)" style="filled" fillcolor=gray]; + 20 [label="Variable declaration: lval y: R|kotlin/Int|" style="filled" fillcolor=gray]; + 21 [label="Exit block" style="filled" fillcolor=gray]; } - 25 [label="Exit init block" style="filled" fillcolor=gray]; + 22 [label="Exit init block" style="filled" fillcolor=gray]; + } + subgraph cluster_7 { + color=blue + 23 [label="Enter function " style="filled" fillcolor=gray]; + 24 [label="Delegated constructor call: super()" style="filled" fillcolor=gray]; + 25 [label="Exit function " style="filled" fillcolor=gray]; } 26 [label="Exit class Bar" style="filled" fillcolor=gray]; } 11 -> {12} [color=green]; 11 -> {26} [style=dotted]; - 11 -> {12 15} [style=dashed]; + 11 -> {12 23} [style=dashed]; 12 -> {13}; 13 -> {14}; - 14 -> {15} [color=green]; + 14 -> {15}; 15 -> {16}; 16 -> {17}; - 17 -> {18}; - 18 -> {19}; - 19 -> {20}; + 17 -> {18} [style=dotted]; + 18 -> {19} [style=dotted]; + 19 -> {20} [style=dotted]; 20 -> {21} [style=dotted]; 21 -> {22} [style=dotted]; 22 -> {23} [style=dotted]; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/initBlockAndInPlaceLambda.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/initBlockAndInPlaceLambda.dot index 38552389b7b..1af5c06bcdc 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/initBlockAndInPlaceLambda.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/initBlockAndInPlaceLambda.dot @@ -22,57 +22,57 @@ digraph initBlockAndInPlaceLambda_kt { 4 [label="Enter class C" style="filled" fillcolor=red]; subgraph cluster_3 { color=blue - 5 [label="Enter function " style="filled" fillcolor=red]; - 6 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 7 [label="Exit function " style="filled" fillcolor=red]; - } - subgraph cluster_4 { - color=blue - 8 [label="Enter init block" style="filled" fillcolor=red]; - subgraph cluster_5 { + 5 [label="Enter init block" style="filled" fillcolor=red]; + subgraph cluster_4 { color=blue - 9 [label="Enter block"]; - 10 [label="Access variable R|/a|"]; - 11 [label="Access variable R|/A.b|"]; - 12 [label="Enter safe call"]; - 13 [label="Postponed enter to lambda"]; - subgraph cluster_6 { + 6 [label="Enter block"]; + 7 [label="Access variable R|/a|"]; + 8 [label="Access variable R|/A.b|"]; + 9 [label="Enter safe call"]; + 10 [label="Postponed enter to lambda"]; + subgraph cluster_5 { color=blue - 14 [label="Enter function " style="filled" fillcolor=red]; - subgraph cluster_7 { + 11 [label="Enter function " style="filled" fillcolor=red]; + subgraph cluster_6 { color=blue - 15 [label="Enter block"]; - 16 [label="Access variable R|/a|"]; - 17 [label="Access variable R|/it|"]; - 18 [label="Function call: R|/C.C|(...)" style="filled" fillcolor=yellow]; - 19 [label="Exit block"]; + 12 [label="Enter block"]; + 13 [label="Access variable R|/a|"]; + 14 [label="Access variable R|/it|"]; + 15 [label="Function call: R|/C.C|(...)" style="filled" fillcolor=yellow]; + 16 [label="Exit block"]; } - 20 [label="Exit function " style="filled" fillcolor=red]; + 17 [label="Exit function " style="filled" fillcolor=red]; } - 21 [label="Postponed exit from lambda"]; - 22 [label="Function call: $subj$.R|kotlin/let|(...)" style="filled" fillcolor=yellow]; - 23 [label="Exit safe call"]; - 24 [label="Variable declaration: lval c: R|C?|"]; - 25 [label="Exit block"]; + 18 [label="Postponed exit from lambda"]; + 19 [label="Function call: $subj$.R|kotlin/let|(...)" style="filled" fillcolor=yellow]; + 20 [label="Exit safe call"]; + 21 [label="Variable declaration: lval c: R|C?|"]; + 22 [label="Exit block"]; } - 26 [label="Exit init block" style="filled" fillcolor=red]; + 23 [label="Exit init block" style="filled" fillcolor=red]; + } + subgraph cluster_7 { + color=blue + 24 [label="Enter function " style="filled" fillcolor=red]; + 25 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 26 [label="Exit function " style="filled" fillcolor=red]; } 27 [label="Exit class C" style="filled" fillcolor=red]; } 4 -> {5} [color=green]; 4 -> {27} [style=dotted]; - 4 -> {5 8} [style=dashed]; + 4 -> {5 24} [style=dashed]; 5 -> {6}; 6 -> {7}; - 7 -> {8} [color=green]; - 8 -> {9}; + 7 -> {8}; + 8 -> {9 20}; 9 -> {10}; - 10 -> {11}; - 11 -> {12 23}; + 10 -> {11 19}; + 10 -> {18} [style=dotted]; + 10 -> {11} [style=dashed]; + 11 -> {12}; 12 -> {13}; - 13 -> {14 22}; - 13 -> {21} [style=dotted]; - 13 -> {14} [style=dashed]; + 13 -> {14}; 14 -> {15}; 15 -> {16}; 16 -> {17}; @@ -82,7 +82,7 @@ digraph initBlockAndInPlaceLambda_kt { 20 -> {21}; 21 -> {22}; 22 -> {23}; - 23 -> {24}; + 23 -> {24} [color=green]; 24 -> {25}; 25 -> {26}; 26 -> {27} [color=green]; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/postponedLambdaInConstructor.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/postponedLambdaInConstructor.dot index 6b424324b82..c1b53221e3b 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/postponedLambdaInConstructor.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/postponedLambdaInConstructor.dot @@ -26,41 +26,41 @@ digraph postponedLambdaInConstructor_kt { 5 [label="Enter class B" style="filled" fillcolor=red]; subgraph cluster_3 { color=blue - 6 [label="Enter function " style="filled" fillcolor=red]; + 6 [label="Enter property" style="filled" fillcolor=red]; 7 [label="Access variable R|/s|"]; - 8 [label="Postponed enter to lambda"]; - subgraph cluster_4 { - color=blue - 9 [label="Enter function " style="filled" fillcolor=red]; - subgraph cluster_5 { - color=blue - 10 [label="Enter block"]; - 11 [label="Exit anonymous function expression"]; - subgraph cluster_6 { - color=blue - 12 [label="Enter function " style="filled" fillcolor=red]; - subgraph cluster_7 { - color=blue - 13 [label="Enter block"]; - 14 [label="Access variable R|/it|"]; - 15 [label="Exit block"]; - } - 16 [label="Exit function " style="filled" fillcolor=red]; - } - 17 [label="Exit block"]; - } - 18 [label="Exit function " style="filled" fillcolor=red]; - } - 19 [label="Postponed exit from lambda"]; - 20 [label="Function call: R|/s|.R|kotlin/let| kotlin/String|>(...)" style="filled" fillcolor=yellow]; - 21 [label="Delegated constructor call: super(...)" style="filled" fillcolor=yellow]; - 22 [label="Exit function " style="filled" fillcolor=red]; + 8 [label="Exit property" style="filled" fillcolor=red]; } - subgraph cluster_8 { + subgraph cluster_4 { color=blue - 23 [label="Enter property" style="filled" fillcolor=red]; - 24 [label="Access variable R|/s|"]; - 25 [label="Exit property" style="filled" fillcolor=red]; + 9 [label="Enter function " style="filled" fillcolor=red]; + 10 [label="Access variable R|/s|"]; + 11 [label="Postponed enter to lambda"]; + subgraph cluster_5 { + color=blue + 12 [label="Enter function " style="filled" fillcolor=red]; + subgraph cluster_6 { + color=blue + 13 [label="Enter block"]; + 14 [label="Exit anonymous function expression"]; + subgraph cluster_7 { + color=blue + 15 [label="Enter function " style="filled" fillcolor=red]; + subgraph cluster_8 { + color=blue + 16 [label="Enter block"]; + 17 [label="Access variable R|/it|"]; + 18 [label="Exit block"]; + } + 19 [label="Exit function " style="filled" fillcolor=red]; + } + 20 [label="Exit block"]; + } + 21 [label="Exit function " style="filled" fillcolor=red]; + } + 22 [label="Postponed exit from lambda"]; + 23 [label="Function call: R|/s|.R|kotlin/let| kotlin/String|>(...)" style="filled" fillcolor=yellow]; + 24 [label="Delegated constructor call: super(...)" style="filled" fillcolor=yellow]; + 25 [label="Exit function " style="filled" fillcolor=red]; } 26 [label="Exit class B" style="filled" fillcolor=red]; } @@ -77,27 +77,27 @@ digraph postponedLambdaInConstructor_kt { } 5 -> {6} [color=green]; 5 -> {26} [style=dotted]; - 5 -> {6 23} [style=dashed]; + 5 -> {6 9} [style=dashed]; 6 -> {7}; 7 -> {8}; - 8 -> {9 20}; - 8 -> {19} [style=dotted]; - 8 -> {9} [style=dashed]; + 8 -> {9} [color=green]; 9 -> {10}; 10 -> {11}; - 11 -> {12 17}; + 11 -> {12 23}; + 11 -> {22} [style=dotted]; 11 -> {12} [style=dashed]; 12 -> {13}; 13 -> {14}; - 14 -> {15}; + 14 -> {15 20}; + 14 -> {15} [style=dashed]; 15 -> {16}; + 16 -> {17}; 17 -> {18}; 18 -> {19}; - 19 -> {20} [color=green]; - 19 -> {21} [color=red]; 20 -> {21}; 21 -> {22}; 22 -> {23} [color=green]; + 22 -> {24} [color=red]; 23 -> {24}; 24 -> {25}; 25 -> {26} [color=green]; diff --git a/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot b/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot index 5483384ea24..06734c403af 100644 --- a/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot +++ b/compiler/fir/analysis-tests/testData/resolve/cfg/propertiesAndInitBlocks.dot @@ -92,22 +92,22 @@ digraph propertiesAndInitBlocks_kt { 29 [label="Enter class GetterLocalClass" style="filled" fillcolor=red]; subgraph cluster_11 { color=blue - 30 [label="Enter function " style="filled" fillcolor=red]; - 31 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 32 [label="Exit function " style="filled" fillcolor=red]; - } - subgraph cluster_12 { - color=blue - 33 [label="Enter init block" style="filled" fillcolor=red]; - subgraph cluster_13 { + 30 [label="Enter init block" style="filled" fillcolor=red]; + subgraph cluster_12 { color=blue - 34 [label="Enter block"]; - 35 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow]; - 36 [label="Throw: throw R|java/lang/Exception.Exception|()"]; - 37 [label="Stub" style="filled" fillcolor=gray]; - 38 [label="Exit block" style="filled" fillcolor=gray]; + 31 [label="Enter block"]; + 32 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow]; + 33 [label="Throw: throw R|java/lang/Exception.Exception|()"]; + 34 [label="Stub" style="filled" fillcolor=gray]; + 35 [label="Exit block" style="filled" fillcolor=gray]; } - 39 [label="Exit init block" style="filled" fillcolor=gray]; + 36 [label="Exit init block" style="filled" fillcolor=gray]; + } + subgraph cluster_13 { + color=blue + 37 [label="Enter function " style="filled" fillcolor=gray]; + 38 [label="Delegated constructor call: super()" style="filled" fillcolor=gray]; + 39 [label="Exit function " style="filled" fillcolor=gray]; } 40 [label="Exit class GetterLocalClass" style="filled" fillcolor=gray]; } @@ -117,15 +117,15 @@ digraph propertiesAndInitBlocks_kt { 26 -> {29} [style=dashed]; 27 -> {28}; 29 -> {30}; - 29 -> {33} [color=red]; + 29 -> {37} [color=red]; 29 -> {40} [style=dotted]; - 29 -> {30 33} [style=dashed]; + 29 -> {30 37} [style=dashed]; 30 -> {31}; 31 -> {32}; - 32 -> {33} [color=green]; - 33 -> {34}; - 34 -> {35}; - 35 -> {36}; + 32 -> {33}; + 33 -> {34} [style=dotted]; + 34 -> {35} [style=dotted]; + 35 -> {36} [style=dotted]; 36 -> {37} [style=dotted]; 37 -> {38} [style=dotted]; 38 -> {39} [style=dotted]; @@ -155,23 +155,23 @@ digraph propertiesAndInitBlocks_kt { 52 [label="Enter class InitializerLocalClass" style="filled" fillcolor=red]; subgraph cluster_18 { color=blue - 53 [label="Enter function " style="filled" fillcolor=red]; - 54 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 55 [label="Exit function " style="filled" fillcolor=red]; - } - subgraph cluster_19 { - color=blue - 56 [label="Enter init block" style="filled" fillcolor=red]; - subgraph cluster_20 { + 53 [label="Enter init block" style="filled" fillcolor=red]; + subgraph cluster_19 { color=blue - 57 [label="Enter block"]; - 58 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow]; - 59 [label="Throw: throw R|java/lang/Exception.Exception|()"]; - 60 [label="Stub" style="filled" fillcolor=gray]; - 61 [label="Const: Int(1)" style="filled" fillcolor=gray]; - 62 [label="Exit block" style="filled" fillcolor=gray]; + 54 [label="Enter block"]; + 55 [label="Function call: R|java/lang/Exception.Exception|()" style="filled" fillcolor=yellow]; + 56 [label="Throw: throw R|java/lang/Exception.Exception|()"]; + 57 [label="Stub" style="filled" fillcolor=gray]; + 58 [label="Const: Int(1)" style="filled" fillcolor=gray]; + 59 [label="Exit block" style="filled" fillcolor=gray]; } - 63 [label="Exit init block" style="filled" fillcolor=gray]; + 60 [label="Exit init block" style="filled" fillcolor=gray]; + } + subgraph cluster_20 { + color=blue + 61 [label="Enter function " style="filled" fillcolor=gray]; + 62 [label="Delegated constructor call: super()" style="filled" fillcolor=gray]; + 63 [label="Exit function " style="filled" fillcolor=gray]; } 64 [label="Exit class InitializerLocalClass" style="filled" fillcolor=gray]; } @@ -211,15 +211,15 @@ digraph propertiesAndInitBlocks_kt { 50 -> {51} [style=dotted]; 51 -> {76} [style=dotted]; 52 -> {53}; - 52 -> {56} [color=red]; + 52 -> {61} [color=red]; 52 -> {64} [style=dotted]; - 52 -> {53 56} [style=dashed]; + 52 -> {53 61} [style=dashed]; 53 -> {54}; 54 -> {55}; - 55 -> {56} [color=green]; - 56 -> {57}; - 57 -> {58}; - 58 -> {59}; + 55 -> {56}; + 56 -> {57} [style=dotted]; + 57 -> {58} [style=dotted]; + 58 -> {59} [style=dotted]; 59 -> {60} [style=dotted]; 60 -> {61} [style=dotted]; 61 -> {62} [style=dotted]; diff --git a/compiler/fir/analysis-tests/testData/resolve/problems/secondaryConstructorCfg.dot b/compiler/fir/analysis-tests/testData/resolve/problems/secondaryConstructorCfg.dot index 95fd637ffed..293e6e60040 100644 --- a/compiler/fir/analysis-tests/testData/resolve/problems/secondaryConstructorCfg.dot +++ b/compiler/fir/analysis-tests/testData/resolve/problems/secondaryConstructorCfg.dot @@ -8,84 +8,83 @@ digraph secondaryConstructorCfg_kt { 0 [label="Enter class B" style="filled" fillcolor=red]; subgraph cluster_1 { color=blue - 1 [label="Enter function " style="filled" fillcolor=red]; - 2 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 3 [label="Exit function " style="filled" fillcolor=red]; + 1 [label="Enter property" style="filled" fillcolor=red]; + 2 [label="Access variable R|/p0|"]; + 3 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_2 { color=blue 4 [label="Enter property" style="filled" fillcolor=red]; 5 [label="Access variable R|/p0|"]; - 6 [label="Exit property" style="filled" fillcolor=red]; + 6 [label="Access variable R|kotlin/String.length|"]; + 7 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_3 { color=blue - 7 [label="Enter property" style="filled" fillcolor=red]; - 8 [label="Access variable R|/p0|"]; - 9 [label="Access variable R|kotlin/String.length|"]; - 10 [label="Exit property" style="filled" fillcolor=red]; - } - subgraph cluster_4 { - color=blue - 11 [label="Enter init block" style="filled" fillcolor=red]; - subgraph cluster_5 { + 8 [label="Enter init block" style="filled" fillcolor=red]; + subgraph cluster_4 { color=blue - 12 [label="Enter block"]; - 13 [label="Access variable R|/p0|"]; - 14 [label="Access variable R|kotlin/String.length|"]; - 15 [label="Assignment: R|/B.p1|"]; - 16 [label="Const: String()"]; - 17 [label="Assignment: R|/B.p3|"]; - 18 [label="Exit block"]; + 9 [label="Enter block"]; + 10 [label="Access variable R|/p0|"]; + 11 [label="Access variable R|kotlin/String.length|"]; + 12 [label="Assignment: R|/B.p1|"]; + 13 [label="Const: String()"]; + 14 [label="Assignment: R|/B.p3|"]; + 15 [label="Exit block"]; } - 19 [label="Exit init block" style="filled" fillcolor=red]; + 16 [label="Exit init block" style="filled" fillcolor=red]; } - 20 [label="Exit class B" style="filled" fillcolor=red]; - } - subgraph cluster_6 { - color=blue - 21 [label="Enter function " style="filled" fillcolor=red]; - 22 [label="Access variable R|/p0|"]; - 23 [label="Delegated constructor call: this(...)" style="filled" fillcolor=yellow]; - subgraph cluster_7 { + subgraph cluster_5 { color=blue - 24 [label="Enter block"]; - 25 [label="Access variable R|/p1|"]; - 26 [label="Assignment: R|/B.p3|"]; - 27 [label="Exit block"]; + 17 [label="Enter function " style="filled" fillcolor=red]; + 18 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 19 [label="Exit function " style="filled" fillcolor=red]; } - 28 [label="Exit function " style="filled" fillcolor=red]; + subgraph cluster_6 { + color=blue + 20 [label="Enter function " style="filled" fillcolor=red]; + 21 [label="Access variable R|/p0|"]; + 22 [label="Delegated constructor call: this(...)" style="filled" fillcolor=yellow]; + subgraph cluster_7 { + color=blue + 23 [label="Enter block"]; + 24 [label="Access variable R|/p1|"]; + 25 [label="Assignment: R|/B.p3|"]; + 26 [label="Exit block"]; + } + 27 [label="Exit function " style="filled" fillcolor=red]; + } + 28 [label="Exit class B" style="filled" fillcolor=red]; } 0 -> {1} [color=green]; - 0 -> {20} [style=dotted]; - 0 -> {1 4 7 11} [style=dashed]; + 0 -> {28} [style=dotted]; + 0 -> {1 4 8 17 20} [style=dashed]; 1 -> {2}; 2 -> {3}; 3 -> {4} [color=green]; 4 -> {5}; 5 -> {6}; - 6 -> {7} [color=green]; - 7 -> {8}; + 6 -> {7}; + 7 -> {8} [color=green]; 8 -> {9}; 9 -> {10}; - 10 -> {11} [color=green]; + 10 -> {11}; 11 -> {12}; 12 -> {13}; 13 -> {14}; 14 -> {15}; 15 -> {16}; - 16 -> {17}; + 16 -> {17} [color=green]; 17 -> {18}; 18 -> {19}; - 19 -> {20} [color=green]; - 20 -> {21} [color=green]; - 20 -> {21} [style=dashed]; + 19 -> {20 28} [color=green]; + 20 -> {21}; 21 -> {22}; 22 -> {23}; 23 -> {24}; 24 -> {25}; 25 -> {26}; 26 -> {27}; - 27 -> {28}; + 27 -> {28} [color=green]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcasts.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcasts.dot index 8cd226ad234..344f489beb8 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcasts.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcasts.dot @@ -341,15 +341,15 @@ digraph boundSmartcasts_kt { 125 [label="Enter class D" style="filled" fillcolor=red]; subgraph cluster_28 { color=blue - 126 [label="Enter function " style="filled" fillcolor=red]; - 127 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 128 [label="Exit function " style="filled" fillcolor=red]; + 126 [label="Enter property" style="filled" fillcolor=red]; + 127 [label="Access variable R|/any|"]; + 128 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_29 { color=blue - 129 [label="Enter property" style="filled" fillcolor=red]; - 130 [label="Access variable R|/any|"]; - 131 [label="Exit property" style="filled" fillcolor=red]; + 129 [label="Enter function " style="filled" fillcolor=red]; + 130 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 131 [label="Exit function " style="filled" fillcolor=red]; } 132 [label="Exit class D" style="filled" fillcolor=red]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot index 9b8ff0dc393..1ab18f3380c 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/boundSmartcastsInBranches.dot @@ -8,15 +8,15 @@ digraph boundSmartcastsInBranches_kt { 0 [label="Enter class A" style="filled" fillcolor=red]; subgraph cluster_1 { color=blue - 1 [label="Enter function " style="filled" fillcolor=red]; - 2 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 3 [label="Exit function " style="filled" fillcolor=red]; + 1 [label="Enter property" style="filled" fillcolor=red]; + 2 [label="Const: String()"]; + 3 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_2 { color=blue - 4 [label="Enter property" style="filled" fillcolor=red]; - 5 [label="Const: String()"]; - 6 [label="Exit property" style="filled" fillcolor=red]; + 4 [label="Enter function " style="filled" fillcolor=red]; + 5 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 6 [label="Exit function " style="filled" fillcolor=red]; } 7 [label="Exit class A" style="filled" fillcolor=red]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.dot index 97a53d9673e..c62fe43dcac 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/boundSmartcasts/functionCallBound.dot @@ -26,15 +26,15 @@ digraph functionCallBound_kt { 5 [label="Enter class Sub" style="filled" fillcolor=red]; subgraph cluster_3 { color=blue - 6 [label="Enter function " style="filled" fillcolor=red]; - 7 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 8 [label="Exit function " style="filled" fillcolor=red]; + 6 [label="Enter property" style="filled" fillcolor=red]; + 7 [label="Access variable R|/data|"]; + 8 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_4 { color=blue - 9 [label="Enter property" style="filled" fillcolor=red]; - 10 [label="Access variable R|/data|"]; - 11 [label="Exit property" style="filled" fillcolor=red]; + 9 [label="Enter function " style="filled" fillcolor=red]; + 10 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 11 [label="Exit function " style="filled" fillcolor=red]; } 12 [label="Exit class Sub" style="filled" fillcolor=red]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/lambdas/lambdaInWhenBranch.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/lambdas/lambdaInWhenBranch.dot index 5ec9456316e..062d8c0fb19 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/lambdas/lambdaInWhenBranch.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/lambdas/lambdaInWhenBranch.dot @@ -26,15 +26,15 @@ digraph lambdaInWhenBranch_kt { 5 [label="Enter class SubClass1" style="filled" fillcolor=red]; subgraph cluster_3 { color=blue - 6 [label="Enter function " style="filled" fillcolor=red]; - 7 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 8 [label="Exit function " style="filled" fillcolor=red]; + 6 [label="Enter property" style="filled" fillcolor=red]; + 7 [label="Access variable R|/t|"]; + 8 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_4 { color=blue - 9 [label="Enter property" style="filled" fillcolor=red]; - 10 [label="Access variable R|/t|"]; - 11 [label="Exit property" style="filled" fillcolor=red]; + 9 [label="Enter function " style="filled" fillcolor=red]; + 10 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 11 [label="Exit function " style="filled" fillcolor=red]; } 12 [label="Exit class SubClass1" style="filled" fillcolor=red]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/nullability.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/nullability.dot index bade8c1ebfd..682568b73e0 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/nullability.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/nullability.dot @@ -59,15 +59,15 @@ digraph nullability_kt { 14 [label="Enter class QImpl" style="filled" fillcolor=red]; subgraph cluster_8 { color=blue - 15 [label="Enter function " style="filled" fillcolor=red]; - 16 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 17 [label="Exit function " style="filled" fillcolor=red]; + 15 [label="Enter property" style="filled" fillcolor=red]; + 16 [label="Access variable R|/data|"]; + 17 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_9 { color=blue - 18 [label="Enter property" style="filled" fillcolor=red]; - 19 [label="Access variable R|/data|"]; - 20 [label="Exit property" style="filled" fillcolor=red]; + 18 [label="Enter function " style="filled" fillcolor=red]; + 19 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 20 [label="Exit function " style="filled" fillcolor=red]; } 21 [label="Exit class QImpl" style="filled" fillcolor=red]; } @@ -108,15 +108,15 @@ digraph nullability_kt { 29 [label="Enter class QImplMutable" style="filled" fillcolor=red]; subgraph cluster_13 { color=blue - 30 [label="Enter function " style="filled" fillcolor=red]; - 31 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 32 [label="Exit function " style="filled" fillcolor=red]; + 30 [label="Enter property" style="filled" fillcolor=red]; + 31 [label="Access variable R|/data|"]; + 32 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_14 { color=blue - 33 [label="Enter property" style="filled" fillcolor=red]; - 34 [label="Access variable R|/data|"]; - 35 [label="Exit property" style="filled" fillcolor=red]; + 33 [label="Enter function " style="filled" fillcolor=red]; + 34 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 35 [label="Exit function " style="filled" fillcolor=red]; } 36 [label="Exit class QImplMutable" style="filled" fillcolor=red]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/assignSafeCall.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/assignSafeCall.dot index 9930c1e5068..24d43bd8a5c 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/assignSafeCall.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/safeCalls/assignSafeCall.dot @@ -8,15 +8,15 @@ digraph assignSafeCall_kt { 0 [label="Enter class A" style="filled" fillcolor=red]; subgraph cluster_1 { color=blue - 1 [label="Enter function " style="filled" fillcolor=red]; - 2 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 3 [label="Exit function " style="filled" fillcolor=red]; + 1 [label="Enter property" style="filled" fillcolor=red]; + 2 [label="Const: Int(1)"]; + 3 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_2 { color=blue - 4 [label="Enter property" style="filled" fillcolor=red]; - 5 [label="Const: Int(1)"]; - 6 [label="Exit property" style="filled" fillcolor=red]; + 4 [label="Enter function " style="filled" fillcolor=red]; + 5 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 6 [label="Exit function " style="filled" fillcolor=red]; } 7 [label="Exit class A" style="filled" fillcolor=red]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot index ecdddb4e329..09da23f6bec 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartCastInInit.dot @@ -52,39 +52,39 @@ digraph smartCastInInit_kt { 14 [label="Enter class Main" style="filled" fillcolor=red]; subgraph cluster_6 { color=blue - 15 [label="Enter function " style="filled" fillcolor=red]; - 16 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 17 [label="Exit function " style="filled" fillcolor=red]; - } - subgraph cluster_7 { - color=blue - 18 [label="Enter init block" style="filled" fillcolor=red]; - subgraph cluster_8 { + 15 [label="Enter init block" style="filled" fillcolor=red]; + subgraph cluster_7 { color=blue - 19 [label="Enter block"]; - 20 [label="Function call: R|/s|()" style="filled" fillcolor=yellow]; - 21 [label="Assignment: R|/Main.x|"]; - 22 [label="Access variable R|/Main.x|"]; - 23 [label="Smart cast: this@R|/Main|.R|/Main.x|"]; - 24 [label="Function call: this@R|/Main|.R|/Main.x|.R|/S.foo|()" style="filled" fillcolor=yellow]; - 25 [label="Exit block"]; + 16 [label="Enter block"]; + 17 [label="Function call: R|/s|()" style="filled" fillcolor=yellow]; + 18 [label="Assignment: R|/Main.x|"]; + 19 [label="Access variable R|/Main.x|"]; + 20 [label="Smart cast: this@R|/Main|.R|/Main.x|"]; + 21 [label="Function call: this@R|/Main|.R|/Main.x|.R|/S.foo|()" style="filled" fillcolor=yellow]; + 22 [label="Exit block"]; } - 26 [label="Exit init block" style="filled" fillcolor=red]; + 23 [label="Exit init block" style="filled" fillcolor=red]; + } + subgraph cluster_8 { + color=blue + 24 [label="Enter function " style="filled" fillcolor=red]; + 25 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 26 [label="Exit function " style="filled" fillcolor=red]; } 27 [label="Exit class Main" style="filled" fillcolor=red]; } 14 -> {15} [color=green]; 14 -> {27} [style=dotted]; - 14 -> {15 18} [style=dashed]; + 14 -> {15 24} [style=dashed]; 15 -> {16}; 16 -> {17}; - 17 -> {18} [color=green]; + 17 -> {18}; 18 -> {19}; 19 -> {20}; 20 -> {21}; 21 -> {22}; 22 -> {23}; - 23 -> {24}; + 23 -> {24} [color=green]; 24 -> {25}; 25 -> {26}; 26 -> {27} [color=green]; diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastInByClause.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastInByClause.dot index c4bfd55cb50..aac7dbd87f8 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastInByClause.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastInByClause.dot @@ -8,21 +8,21 @@ digraph smartcastInByClause_kt { 0 [label="Enter class A" style="filled" fillcolor=red]; subgraph cluster_1 { color=blue - 1 [label="Enter function " style="filled" fillcolor=red]; - 2 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 3 [label="Exit function " style="filled" fillcolor=red]; + 1 [label="Enter property" style="filled" fillcolor=red]; + 2 [label="Access variable R|/path|"]; + 3 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_2 { color=blue 4 [label="Enter property" style="filled" fillcolor=red]; - 5 [label="Access variable R|/path|"]; + 5 [label="Access variable R|/index|"]; 6 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_3 { color=blue - 7 [label="Enter property" style="filled" fillcolor=red]; - 8 [label="Access variable R|/index|"]; - 9 [label="Exit property" style="filled" fillcolor=red]; + 7 [label="Enter function " style="filled" fillcolor=red]; + 8 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 9 [label="Exit function " style="filled" fillcolor=red]; } 10 [label="Exit class A" style="filled" fillcolor=red]; } @@ -51,15 +51,15 @@ digraph smartcastInByClause_kt { 13 [label="Enter class Derived" style="filled" fillcolor=red]; subgraph cluster_6 { color=blue - 14 [label="Enter function " style="filled" fillcolor=red]; - 15 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 16 [label="Exit function " style="filled" fillcolor=red]; + 14 [label="Enter property" style="filled" fillcolor=red]; + 15 [label="Access variable R|/index|"]; + 16 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_7 { color=blue - 17 [label="Enter property" style="filled" fillcolor=red]; - 18 [label="Access variable R|/index|"]; - 19 [label="Exit property" style="filled" fillcolor=red]; + 17 [label="Enter function " style="filled" fillcolor=red]; + 18 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 19 [label="Exit function " style="filled" fillcolor=red]; } 20 [label="Exit class Derived" style="filled" fillcolor=red]; } @@ -101,26 +101,26 @@ digraph smartcastInByClause_kt { 40 [label="Enter class " style="filled" fillcolor=red]; subgraph cluster_11 { color=blue - 41 [label="Enter function " style="filled" fillcolor=red]; - 42 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 43 [label="Exit function " style="filled" fillcolor=red]; + 41 [label="Enter field" style="filled" fillcolor=red]; + 42 [label="Access variable R|/a|"]; + 43 [label="Smart cast: R|/a|"]; + 44 [label="Access variable R|/A.index|"]; + 45 [label="Function call: R|/Derived.Derived|(...)" style="filled" fillcolor=yellow]; + 46 [label="Exit field" style="filled" fillcolor=red]; } subgraph cluster_12 { color=blue - 44 [label="Enter field" style="filled" fillcolor=red]; - 45 [label="Access variable R|/a|"]; - 46 [label="Smart cast: R|/a|"]; - 47 [label="Access variable R|/A.index|"]; - 48 [label="Function call: R|/Derived.Derived|(...)" style="filled" fillcolor=yellow]; - 49 [label="Exit field" style="filled" fillcolor=red]; + 47 [label="Enter property" style="filled" fillcolor=red]; + 48 [label="Access variable R|/a|"]; + 49 [label="Smart cast: R|/a|"]; + 50 [label="Access variable R|/A.index|"]; + 51 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_13 { color=blue - 50 [label="Enter property" style="filled" fillcolor=red]; - 51 [label="Access variable R|/a|"]; - 52 [label="Smart cast: R|/a|"]; - 53 [label="Access variable R|/A.index|"]; - 54 [label="Exit property" style="filled" fillcolor=red]; + 52 [label="Enter function " style="filled" fillcolor=red]; + 53 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 54 [label="Exit function " style="filled" fillcolor=red]; } 55 [label="Exit class " style="filled" fillcolor=red]; } @@ -183,22 +183,22 @@ digraph smartcastInByClause_kt { 39 -> {56} [style=dotted]; 39 -> {40} [style=dashed]; 40 -> {41}; - 40 -> {44 50 61} [color=red]; + 40 -> {47 52 61} [color=red]; 40 -> {55} [style=dotted]; - 40 -> {41 44 50} [style=dashed]; + 40 -> {41 47 52} [style=dashed]; 41 -> {42}; 42 -> {43}; - 43 -> {44} [color=green]; - 43 -> {55} [color=red]; + 43 -> {44}; 44 -> {45}; 45 -> {46}; - 46 -> {47}; + 46 -> {47} [color=green]; + 46 -> {55} [color=red]; 47 -> {48}; 48 -> {49}; - 49 -> {50} [color=green]; - 49 -> {55} [color=red]; + 49 -> {50}; 50 -> {51}; - 51 -> {52}; + 51 -> {52} [color=green]; + 51 -> {55} [color=red]; 52 -> {53}; 53 -> {54}; 54 -> {55}; diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot index 9e85d778d42..9d3a58e73aa 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/smartcastToNothing.dot @@ -119,21 +119,21 @@ digraph smartcastToNothing_kt { 39 [label="Enter class A" style="filled" fillcolor=red]; subgraph cluster_11 { color=blue - 40 [label="Enter function " style="filled" fillcolor=red]; - 41 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 42 [label="Exit function " style="filled" fillcolor=red]; + 40 [label="Enter property" style="filled" fillcolor=red]; + 41 [label="Const: Int(1)"]; + 42 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_12 { color=blue 43 [label="Enter property" style="filled" fillcolor=red]; - 44 [label="Const: Int(1)"]; + 44 [label="Const: Boolean(true)"]; 45 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_13 { color=blue - 46 [label="Enter property" style="filled" fillcolor=red]; - 47 [label="Const: Boolean(true)"]; - 48 [label="Exit property" style="filled" fillcolor=red]; + 46 [label="Enter function " style="filled" fillcolor=red]; + 47 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 48 [label="Exit function " style="filled" fillcolor=red]; } 49 [label="Exit class A" style="filled" fillcolor=red]; } diff --git a/compiler/fir/analysis-tests/testData/resolve/smartcasts/stability/overridenOpenVal.dot b/compiler/fir/analysis-tests/testData/resolve/smartcasts/stability/overridenOpenVal.dot index 6707f8dd0f0..5635e018f98 100644 --- a/compiler/fir/analysis-tests/testData/resolve/smartcasts/stability/overridenOpenVal.dot +++ b/compiler/fir/analysis-tests/testData/resolve/smartcasts/stability/overridenOpenVal.dot @@ -8,15 +8,15 @@ digraph overridenOpenVal_kt { 0 [label="Enter class A" style="filled" fillcolor=red]; subgraph cluster_1 { color=blue - 1 [label="Enter function " style="filled" fillcolor=red]; - 2 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 3 [label="Exit function " style="filled" fillcolor=red]; + 1 [label="Enter property" style="filled" fillcolor=red]; + 2 [label="Access variable R|/x|"]; + 3 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_2 { color=blue - 4 [label="Enter property" style="filled" fillcolor=red]; - 5 [label="Access variable R|/x|"]; - 6 [label="Exit property" style="filled" fillcolor=red]; + 4 [label="Enter function " style="filled" fillcolor=red]; + 5 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 6 [label="Exit function " style="filled" fillcolor=red]; } 7 [label="Exit class A" style="filled" fillcolor=red]; } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.dot b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.dot index 63e41984fe4..4654e683c83 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.dot +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inAnonymousObject.dot @@ -20,27 +20,27 @@ digraph inAnonymousObject_kt { 5 [label="Enter class " style="filled" fillcolor=red]; subgraph cluster_4 { color=blue - 6 [label="Enter function " style="filled" fillcolor=red]; - 7 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 8 [label="Exit function " style="filled" fillcolor=red]; + 6 [label="Enter property" style="filled" fillcolor=red]; + 7 [label="Access variable R|/a|"]; + 8 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_5 { color=blue - 9 [label="Enter property" style="filled" fillcolor=red]; - 10 [label="Access variable R|/a|"]; - 11 [label="Exit property" style="filled" fillcolor=red]; - } - subgraph cluster_6 { - color=blue - 12 [label="Enter init block" style="filled" fillcolor=red]; - subgraph cluster_7 { + 9 [label="Enter init block" style="filled" fillcolor=red]; + subgraph cluster_6 { color=blue - 13 [label="Enter block"]; - 14 [label="Access variable R|/b|"]; - 15 [label="Assignment: R|/.leaked|"]; - 16 [label="Exit block"]; + 10 [label="Enter block"]; + 11 [label="Access variable R|/b|"]; + 12 [label="Assignment: R|/.leaked|"]; + 13 [label="Exit block"]; } - 17 [label="Exit init block" style="filled" fillcolor=red]; + 14 [label="Exit init block" style="filled" fillcolor=red]; + } + subgraph cluster_7 { + color=blue + 15 [label="Enter function " style="filled" fillcolor=red]; + 16 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 17 [label="Exit function " style="filled" fillcolor=red]; } 18 [label="Exit class " style="filled" fillcolor=red]; } @@ -72,20 +72,20 @@ digraph inAnonymousObject_kt { 4 -> {19} [style=dotted]; 4 -> {5} [style=dashed]; 5 -> {6}; - 5 -> {9 12 26} [color=red]; + 5 -> {9 15 26} [color=red]; 5 -> {18} [style=dotted]; - 5 -> {6 9 12} [style=dashed]; + 5 -> {6 9 15} [style=dashed]; 6 -> {7}; 7 -> {8}; 8 -> {9} [color=green]; 8 -> {18} [color=red]; 9 -> {10}; 10 -> {11}; - 11 -> {12} [color=green]; - 11 -> {18} [color=red]; + 11 -> {12}; 12 -> {13}; 13 -> {14}; - 14 -> {15}; + 14 -> {15} [color=green]; + 14 -> {18} [color=red]; 15 -> {16}; 16 -> {17}; 17 -> {18}; diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalClass.dot b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalClass.dot index a1614587594..9c79abe2db4 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalClass.dot +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/contracts/fromSource/bad/callsInPlace/inLocalClass.dot @@ -43,30 +43,30 @@ digraph inLocalClass_kt { } 19 [label="Exit init block" style="filled" fillcolor=red]; } - 20 [label="Exit class LocalClass" style="filled" fillcolor=red]; - } - subgraph cluster_7 { - color=blue - 21 [label="Enter function run" style="filled" fillcolor=red]; - subgraph cluster_8 { + subgraph cluster_7 { color=blue - 22 [label="Enter block"]; - 23 [label="Function call: R|/d|.R|SubstitutionOverride|()" style="filled" fillcolor=yellow]; - 24 [label="Exit block"]; + 20 [label="Enter function " style="filled" fillcolor=red]; + 21 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + subgraph cluster_8 { + color=blue + 22 [label="Enter block"]; + 23 [label="Function call: R|/b|.R|SubstitutionOverride|()" style="filled" fillcolor=yellow]; + 24 [label="Exit block"]; + } + 25 [label="Exit function " style="filled" fillcolor=red]; } - 25 [label="Exit function run" style="filled" fillcolor=red]; + 26 [label="Exit class LocalClass" style="filled" fillcolor=red]; } subgraph cluster_9 { color=blue - 26 [label="Enter function " style="filled" fillcolor=red]; - 27 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 27 [label="Enter function run" style="filled" fillcolor=red]; subgraph cluster_10 { color=blue 28 [label="Enter block"]; - 29 [label="Function call: R|/b|.R|SubstitutionOverride|()" style="filled" fillcolor=yellow]; + 29 [label="Function call: R|/d|.R|SubstitutionOverride|()" style="filled" fillcolor=yellow]; 30 [label="Exit block"]; } - 31 [label="Exit function " style="filled" fillcolor=red]; + 31 [label="Exit function run" style="filled" fillcolor=red]; } 0 -> {1}; 1 -> {2}; @@ -79,9 +79,9 @@ digraph inLocalClass_kt { 7 -> {8}; 8 -> {9}; 10 -> {11}; - 10 -> {14 21 26} [color=red]; - 10 -> {20} [style=dotted]; - 10 -> {11 14} [style=dashed]; + 10 -> {14 20 27} [color=red]; + 10 -> {26} [style=dotted]; + 10 -> {11 14 20} [style=dashed]; 11 -> {12}; 12 -> {13}; 13 -> {14} [color=green]; @@ -91,13 +91,14 @@ digraph inLocalClass_kt { 17 -> {18}; 18 -> {19}; 19 -> {20} [color=green]; - 20 -> {21 26} [color=green]; - 20 -> {21 26} [style=dashed]; + 20 -> {21}; 21 -> {22}; 22 -> {23}; 23 -> {24}; 24 -> {25}; - 26 -> {27}; + 25 -> {26} [color=green]; + 26 -> {27} [color=green]; + 26 -> {27} [style=dashed]; 27 -> {28}; 28 -> {29}; 29 -> {30}; diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot b/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot index fe0e7a91539..170cab7fa2e 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/delegates/delegateWithAnonymousObject.dot @@ -83,71 +83,71 @@ digraph delegateWithAnonymousObject_kt { 23 [label="Enter class IssuesListUserProfile" style="filled" fillcolor=red]; subgraph cluster_9 { color=blue - 24 [label="Enter function " style="filled" fillcolor=red]; - 25 [label="Delegated constructor call: super|>()" style="filled" fillcolor=yellow]; - 26 [label="Exit function " style="filled" fillcolor=red]; - } - subgraph cluster_10 { - color=blue - 27 [label="Enter property" style="filled" fillcolor=red]; - 28 [label="Postponed enter to lambda"]; - subgraph cluster_11 { + 24 [label="Enter property" style="filled" fillcolor=red]; + 25 [label="Postponed enter to lambda"]; + subgraph cluster_10 { color=blue - 29 [label="Enter function " style="filled" fillcolor=red]; - subgraph cluster_12 { + 26 [label="Enter function " style="filled" fillcolor=red]; + subgraph cluster_11 { color=blue - 30 [label="Enter block"]; - 31 [label="Enter anonymous object"]; - subgraph cluster_13 { + 27 [label="Enter block"]; + 28 [label="Enter anonymous object"]; + subgraph cluster_12 { color=blue - 32 [label="Enter class " style="filled" fillcolor=red]; - subgraph cluster_14 { + 29 [label="Enter class " style="filled" fillcolor=red]; + subgraph cluster_13 { color=blue - 33 [label="Enter function " style="filled" fillcolor=red]; - 34 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 35 [label="Exit function " style="filled" fillcolor=red]; + 30 [label="Enter function " style="filled" fillcolor=red]; + 31 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 32 [label="Exit function " style="filled" fillcolor=red]; } - 36 [label="Exit class " style="filled" fillcolor=red]; + 33 [label="Exit class " style="filled" fillcolor=red]; } - 37 [label="Exit anonymous object expression"]; - 38 [label="Exit block"]; + 34 [label="Exit anonymous object expression"]; + 35 [label="Exit block"]; } - 39 [label="Exit function " style="filled" fillcolor=red]; + 36 [label="Exit function " style="filled" fillcolor=red]; } - subgraph cluster_15 { + subgraph cluster_14 { color=blue - 40 [label="Enter function setValue" style="filled" fillcolor=red]; - subgraph cluster_16 { + 37 [label="Enter function setValue" style="filled" fillcolor=red]; + subgraph cluster_15 { color=blue - 41 [label="Enter block"]; - 42 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow]; - 43 [label="Access variable R|/value|"]; - 44 [label="Function call: R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(...)" style="filled" fillcolor=yellow]; - 45 [label="Jump: ^setValue R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(R|/value|)"]; - 46 [label="Stub" style="filled" fillcolor=gray]; - 47 [label="Exit block" style="filled" fillcolor=gray]; + 38 [label="Enter block"]; + 39 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow]; + 40 [label="Access variable R|/value|"]; + 41 [label="Function call: R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(...)" style="filled" fillcolor=yellow]; + 42 [label="Jump: ^setValue R|/IssueListView.IssueListView|().R|/IssueListView.updateFrom|(R|/value|)"]; + 43 [label="Stub" style="filled" fillcolor=gray]; + 44 [label="Exit block" style="filled" fillcolor=gray]; } - 48 [label="Exit function setValue" style="filled" fillcolor=red]; + 45 [label="Exit function setValue" style="filled" fillcolor=red]; } - subgraph cluster_17 { + subgraph cluster_16 { color=blue - 49 [label="Enter function getValue" style="filled" fillcolor=red]; - subgraph cluster_18 { + 46 [label="Enter function getValue" style="filled" fillcolor=red]; + subgraph cluster_17 { color=blue - 50 [label="Enter block"]; - 51 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow]; - 52 [label="Jump: ^getValue R|/IssueListView.IssueListView|()"]; - 53 [label="Stub" style="filled" fillcolor=gray]; - 54 [label="Exit block" style="filled" fillcolor=gray]; + 47 [label="Enter block"]; + 48 [label="Function call: R|/IssueListView.IssueListView|()" style="filled" fillcolor=yellow]; + 49 [label="Jump: ^getValue R|/IssueListView.IssueListView|()"]; + 50 [label="Stub" style="filled" fillcolor=gray]; + 51 [label="Exit block" style="filled" fillcolor=gray]; } - 55 [label="Exit function getValue" style="filled" fillcolor=red]; + 52 [label="Exit function getValue" style="filled" fillcolor=red]; } - 56 [label="Postponed exit from lambda"]; - 57 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|(...)" style="filled" fillcolor=yellow]; - 58 [label="Access variable this@R|/IssuesListUserProfile|"]; - 59 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|(...).#(...)" style="filled" fillcolor=yellow]; - 60 [label="Exit property delegate" style="filled" fillcolor=yellow]; - 61 [label="Exit property" style="filled" fillcolor=red]; + 53 [label="Postponed exit from lambda"]; + 54 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|(...)" style="filled" fillcolor=yellow]; + 55 [label="Access variable this@R|/IssuesListUserProfile|"]; + 56 [label="Function call: this@R|/IssuesListUserProfile|.R|/delegate|(...).#(...)" style="filled" fillcolor=yellow]; + 57 [label="Exit property delegate" style="filled" fillcolor=yellow]; + 58 [label="Exit property" style="filled" fillcolor=red]; + } + subgraph cluster_18 { + color=blue + 59 [label="Enter function " style="filled" fillcolor=red]; + 60 [label="Delegated constructor call: super|>()" style="filled" fillcolor=yellow]; + 61 [label="Exit function " style="filled" fillcolor=red]; } 62 [label="Exit class IssuesListUserProfile" style="filled" fillcolor=red]; } @@ -182,50 +182,50 @@ digraph delegateWithAnonymousObject_kt { } 23 -> {24} [color=green]; 23 -> {62} [style=dotted]; - 23 -> {24 27} [style=dashed]; + 23 -> {24 59} [style=dashed]; 24 -> {25}; - 25 -> {26}; - 26 -> {27} [color=green]; + 25 -> {26 53 54}; + 25 -> {26} [style=dashed]; + 26 -> {27}; 27 -> {28}; - 28 -> {29 56 57}; + 28 -> {29}; + 28 -> {34} [style=dotted]; 28 -> {29} [style=dashed]; 29 -> {30}; + 29 -> {37 46} [color=red]; + 29 -> {33} [style=dotted]; + 29 -> {30} [style=dashed]; 30 -> {31}; 31 -> {32}; - 31 -> {37} [style=dotted]; - 31 -> {32} [style=dashed]; 32 -> {33}; - 32 -> {40 49} [color=red]; - 32 -> {36} [style=dotted]; - 32 -> {33} [style=dashed]; 33 -> {34}; + 33 -> {37 46} [color=green]; + 33 -> {37 46} [style=dashed]; 34 -> {35}; 35 -> {36}; - 36 -> {37}; - 36 -> {40 49} [color=green]; - 36 -> {40 49} [style=dashed]; 37 -> {38}; 38 -> {39}; + 39 -> {40}; 40 -> {41}; 41 -> {42}; - 42 -> {43}; - 43 -> {44}; - 44 -> {45}; - 45 -> {48}; - 45 -> {46} [style=dotted]; - 46 -> {47} [style=dotted]; - 47 -> {48} [style=dotted]; - 49 -> {50}; - 50 -> {51}; - 51 -> {52}; - 52 -> {55}; - 52 -> {53} [style=dotted]; - 53 -> {54} [style=dotted]; - 54 -> {55} [style=dotted]; - 56 -> {57} [color=green]; - 56 -> {60} [color=red]; + 42 -> {45}; + 42 -> {43} [style=dotted]; + 43 -> {44} [style=dotted]; + 44 -> {45} [style=dotted]; + 46 -> {47}; + 47 -> {48}; + 48 -> {49}; + 49 -> {52}; + 49 -> {50} [style=dotted]; + 50 -> {51} [style=dotted]; + 51 -> {52} [style=dotted]; + 53 -> {54} [color=green]; + 53 -> {57} [color=red]; + 54 -> {55}; + 55 -> {56}; + 56 -> {57}; 57 -> {58}; - 58 -> {59}; + 58 -> {59} [color=green]; 59 -> {60}; 60 -> {61}; 61 -> {62} [color=green]; diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/plusAssignWithLambdaInRhs.dot b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/plusAssignWithLambdaInRhs.dot index 091f8aae708..7105ff9abaf 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/plusAssignWithLambdaInRhs.dot +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/plusAssignWithLambdaInRhs.dot @@ -54,15 +54,15 @@ digraph plusAssignWithLambdaInRhs_kt { 17 [label="Enter class A" style="filled" fillcolor=red]; subgraph cluster_5 { color=blue - 18 [label="Enter function " style="filled" fillcolor=red]; - 19 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; - 20 [label="Exit function " style="filled" fillcolor=red]; + 18 [label="Enter property" style="filled" fillcolor=red]; + 19 [label="Access variable R|/executor|"]; + 20 [label="Exit property" style="filled" fillcolor=red]; } subgraph cluster_6 { color=blue - 21 [label="Enter property" style="filled" fillcolor=red]; - 22 [label="Access variable R|/executor|"]; - 23 [label="Exit property" style="filled" fillcolor=red]; + 21 [label="Enter function " style="filled" fillcolor=red]; + 22 [label="Delegated constructor call: super()" style="filled" fillcolor=yellow]; + 23 [label="Exit function " style="filled" fillcolor=red]; } 24 [label="Exit class A" style="filled" fillcolor=red]; } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt index 6d0dc69d513..d3b12fd1189 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/cfg/ControlFlowGraphBuilder.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.declarations.utils.hasExplicitBackingField import org.jetbrains.kotlin.fir.declarations.utils.isLocal import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.expressions.builder.buildUnitExpression +import org.jetbrains.kotlin.fir.references.toResolvedConstructorSymbol import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.resolve.dfa.* import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType @@ -21,6 +22,7 @@ import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.util.ListMultimap import org.jetbrains.kotlin.fir.util.listMultimapOf import org.jetbrains.kotlin.utils.addToStdlib.runIf +import org.jetbrains.kotlin.utils.getOrPutNullable @OptIn(CfgInternals::class) class ControlFlowGraphBuilder { @@ -353,15 +355,17 @@ class ControlFlowGraphBuilder { else -> true } - private inline fun FirClass.forEachGraphOwner(block: (FirControlFlowGraphOwner, isInPlace: Boolean) -> Unit) { + private fun FirClass.firstInPlaceInitializedMember(): FirDeclaration? = + declarations.find { it is FirControlFlowGraphOwner && it !is FirFunction && it !is FirClass && it.memberShouldHaveGraph } + + private inline fun FirClass.forEachGraphOwner(block: (FirControlFlowGraphOwner) -> Unit) { for (member in declarations) { if (member is FirControlFlowGraphOwner && member.memberShouldHaveGraph) { - // TODO: class secondary constructors are called-in-place after everything else, and at most one is chosen. - block(member, (member is FirConstructor && member.isPrimary) || (member !is FirFunction && member !is FirClass)) + block(member) } if (member is FirProperty) { - member.getter?.let { block(it, false) } - member.setter?.let { block(it, false) } + member.getter?.let { block(it) } + member.setter?.let { block(it) } } } } @@ -401,18 +405,13 @@ class ControlFlowGraphBuilder { addEdgeIfLocalClassMember(enterNode) } - var foundInPlace = false if (enterNode.previousNodes.isNotEmpty()) { - klass.forEachGraphOwner { member, isInPlace -> - val kind = if (!isInPlace || foundInPlace) { - assert(member !is FirConstructor || !member.isPrimary) { - "primary constructor of $name not first called-in-place member, CFG will be wrong" - } - EdgeKind.DfgForward - } else { - EdgeKind.Forward.also { foundInPlace = true } - } - enterToLocalClassesMembers[(member as FirDeclaration).symbol] = enterNode to kind + val firstInPlace = klass.firstInPlaceInitializedMember() + klass.forEachGraphOwner { + val kind = if (firstInPlace == it || + (firstInPlace == null && it is FirConstructor && it.delegatedConstructor?.isThis != true) + ) EdgeKind.Forward else EdgeKind.DfgForward + enterToLocalClassesMembers[(it as FirDeclaration).symbol] = enterNode to kind } } return localClassEnterNode to enterNode @@ -440,32 +439,64 @@ class ControlFlowGraphBuilder { val calledInPlace = mutableListOf() val calledLater = mutableListOf() - klass.forEachGraphOwner { member, isInPlace -> - val graph = member.controlFlowGraphReference?.controlFlowGraph ?: return@forEachGraphOwner - if (isInPlace) calledInPlace.add(graph) else calledLater.add(graph) + val constructors = mutableMapOf() + klass.forEachGraphOwner { + val graph = it.controlFlowGraphReference?.controlFlowGraph ?: return@forEachGraphOwner + when (it) { + is FirConstructor -> constructors[it] = graph + is FirFunction, is FirClass -> calledLater.add(graph) + else -> calledInPlace.add(graph) + } } // Classes are not initialized in place so no point in merging data flow - it will not be used. val mergeDataFlow = klass is FirAnonymousObject && klass.classKind != ClassKind.ENUM_ENTRY val exitKind = if (mergeDataFlow) EdgeKind.Forward else EdgeKind.CfgForward - if (calledInPlace.isEmpty()) { - addEdge(enterNode, exitNode, preferredKind = exitKind) + + val lastInPlaceExit = calledInPlace.fold<_, CFGNode<*>>(enterNode) { lastNode, graph -> + // In local classes, we already have control flow (+ data flow) edge from `enterNode` + // to first in-place initializer. + if (lastNode !== enterNode || lastNode.previousNodes.isEmpty()) { + addEdgeToSubGraph(lastNode, graph.enterNode) + } + graph.exitNode + } + if (mergeDataFlow) { + // TODO: this is wrong. Not sure if it's possible to describe the correct data flow graph here. Things + // would be much easier if it was guaranteed that constructors are analyzed after all other members: + // they have no implicit return type anyway, and we could then pass correct data flow to them. + for (graph in calledInPlace) { + addEdge(graph.exitNode, exitNode, preferredKind = EdgeKind.DfgForward) + } + } + + val parentConstructors = mutableMapOf() + fun FirConstructor.parentConstructor(): FirConstructor? = parentConstructors.getOrPutNullable(this) { + // Break cycles in some way; there will be errors on delegated constructor calls in that case. + parentConstructors[this] = null + delegatedConstructor?.takeIf { it.isThis }?.calleeReference + ?.toResolvedConstructorSymbol(discardErrorReference = true)?.fir + ?.takeIf { parent -> this !in generateSequence(parent) { it.parentConstructor() } } + } + + for ((ctor, graph) in constructors) { + val delegatedConstructorExit = constructors[ctor.parentConstructor()]?.exitNode ?: lastInPlaceExit + // Similarly, if there are no in-place initializers, we already have control flow (+ data flow) edges + // from `enterNode` to all non-delegating constructors in local classes. + if (delegatedConstructorExit !== enterNode || delegatedConstructorExit.previousNodes.isEmpty()) { + addEdgeToSubGraph(delegatedConstructorExit, graph.enterNode) + } + addEdge(graph.exitNode, exitNode, preferredKind = exitKind) + } + + if (constructors.isEmpty()) { + // Interfaces have no constructors, add an edge from enter to exit so that methods aren't marked as dead. + addEdge(enterNode, exitNode, preferredKind = EdgeKind.CfgForward) } else { - if (enterNode.previousNodes.isEmpty()) { - // Control flow edge to first initializer was only added for local classes. - addEdge(enterNode, calledInPlace[0].enterNode, preferredKind = EdgeKind.CfgForward) - } - val lastInPlace = calledInPlace.reduce { a, b -> - if (mergeDataFlow) { - addEdge(a.exitNode, exitNode, preferredKind = EdgeKind.DfgForward) - } - addEdgeToSubGraph(a.exitNode, b.enterNode) - b - } - addEdge(lastInPlace.exitNode, exitNode, preferredKind = exitKind) // Fake edge to enforce ordering. addEdge(enterNode, exitNode, preferredKind = EdgeKind.DeadForward, propagateDeadness = false) } + // TODO: Here we're assuming that the methods are called after the object is constructed, which is really not true // (init blocks can call them). But FE1.0 did so too, hence the following code compiles and prints 0: // val x: Int @@ -478,7 +509,7 @@ class ControlFlowGraphBuilder { addEdgeToSubGraph(exitNode, graph.enterNode) } - enterNode.subGraphs = calledInPlace + enterNode.subGraphs = calledInPlace + constructors.values exitNode.subGraphs = calledLater return exitNode.takeIf { mergeDataFlow } to popGraph() } diff --git a/compiler/testData/codegen/box/smartCasts/kt44814.dot b/compiler/testData/codegen/box/smartCasts/kt44814.dot index 89ce3f42142..d6986ac859d 100644 --- a/compiler/testData/codegen/box/smartCasts/kt44814.dot +++ b/compiler/testData/codegen/box/smartCasts/kt44814.dot @@ -44,27 +44,27 @@ digraph kt44814_kt { 10 [label="Enter class FirPsiSourceElement [1]" style="filled" fillcolor=red]; subgraph cluster_5 { color=blue - 11 [label="Enter function [2]" style="filled" fillcolor=red]; - 12 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; - 13 [label="Exit function [2]" style="filled" fillcolor=red]; + 11 [label="Enter property [2]" style="filled" fillcolor=red]; + 12 [label="Access variable R|/psi| [2]"]; + 13 [label="Exit property [2]" style="filled" fillcolor=red]; } subgraph cluster_6 { color=blue 14 [label="Enter property [2]" style="filled" fillcolor=red]; - 15 [label="Access variable R|/psi| [2]"]; + 15 [label="Access variable R|/lighterASTNode| [2]"]; 16 [label="Exit property [2]" style="filled" fillcolor=red]; } subgraph cluster_7 { color=blue 17 [label="Enter property [2]" style="filled" fillcolor=red]; - 18 [label="Access variable R|/lighterASTNode| [2]"]; + 18 [label="Access variable R|/treeStructure| [2]"]; 19 [label="Exit property [2]" style="filled" fillcolor=red]; } subgraph cluster_8 { color=blue - 20 [label="Enter property [2]" style="filled" fillcolor=red]; - 21 [label="Access variable R|/treeStructure| [2]"]; - 22 [label="Exit property [2]" style="filled" fillcolor=red]; + 20 [label="Enter function [2]" style="filled" fillcolor=red]; + 21 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; + 22 [label="Exit function [2]" style="filled" fillcolor=red]; } 23 [label="Exit class FirPsiSourceElement [1]" style="filled" fillcolor=red]; } @@ -89,21 +89,21 @@ digraph kt44814_kt { 24 [label="Enter class FirLightSourceElement [1]" style="filled" fillcolor=red]; subgraph cluster_10 { color=blue - 25 [label="Enter function [2]" style="filled" fillcolor=red]; - 26 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; - 27 [label="Exit function [2]" style="filled" fillcolor=red]; + 25 [label="Enter property [2]" style="filled" fillcolor=red]; + 26 [label="Access variable R|/lighterASTNode| [2]"]; + 27 [label="Exit property [2]" style="filled" fillcolor=red]; } subgraph cluster_11 { color=blue 28 [label="Enter property [2]" style="filled" fillcolor=red]; - 29 [label="Access variable R|/lighterASTNode| [2]"]; + 29 [label="Access variable R|/treeStructure| [2]"]; 30 [label="Exit property [2]" style="filled" fillcolor=red]; } subgraph cluster_12 { color=blue - 31 [label="Enter property [2]" style="filled" fillcolor=red]; - 32 [label="Access variable R|/treeStructure| [2]"]; - 33 [label="Exit property [2]" style="filled" fillcolor=red]; + 31 [label="Enter function [2]" style="filled" fillcolor=red]; + 32 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; + 33 [label="Exit function [2]" style="filled" fillcolor=red]; } 34 [label="Exit class FirLightSourceElement [1]" style="filled" fillcolor=red]; } @@ -161,30 +161,30 @@ digraph kt44814_kt { 45 [label="Enter class LighterASTNode [1]" style="filled" fillcolor=red]; subgraph cluster_18 { color=blue - 46 [label="Enter function [2]" style="filled" fillcolor=red]; - 47 [label="Enter default value of _children [2]"]; - subgraph cluster_19 { - color=blue - 48 [label="Enter default value of _children [3]" style="filled" fillcolor=red]; - 49 [label="Function call: R|kotlin/collections/emptyList|() [3]" style="filled" fillcolor=yellow]; - 50 [label="Exit default value of _children [3]" style="filled" fillcolor=red]; - } - 51 [label="Exit default value of _children [2]"]; - 52 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; - 53 [label="Exit function [2]" style="filled" fillcolor=red]; + 46 [label="Enter property [2]" style="filled" fillcolor=red]; + 47 [label="Access variable R|/_children| [2]"]; + 48 [label="Exit property [2]" style="filled" fillcolor=red]; + } + subgraph cluster_19 { + color=blue + 49 [label="Enter property [2]" style="filled" fillcolor=red]; + 50 [label="Access qualifier /TokenType [2]"]; + 51 [label="Access variable R|/TokenType.Companion.MODIFIER_LIST| [2]"]; + 52 [label="Exit property [2]" style="filled" fillcolor=red]; } subgraph cluster_20 { color=blue - 54 [label="Enter property [2]" style="filled" fillcolor=red]; - 55 [label="Access variable R|/_children| [2]"]; - 56 [label="Exit property [2]" style="filled" fillcolor=red]; - } - subgraph cluster_21 { - color=blue - 57 [label="Enter property [2]" style="filled" fillcolor=red]; - 58 [label="Access qualifier /TokenType [2]"]; - 59 [label="Access variable R|/TokenType.Companion.MODIFIER_LIST| [2]"]; - 60 [label="Exit property [2]" style="filled" fillcolor=red]; + 53 [label="Enter function [2]" style="filled" fillcolor=red]; + 54 [label="Enter default value of _children [2]"]; + subgraph cluster_21 { + color=blue + 55 [label="Enter default value of _children [3]" style="filled" fillcolor=red]; + 56 [label="Function call: R|kotlin/collections/emptyList|() [3]" style="filled" fillcolor=yellow]; + 57 [label="Exit default value of _children [3]" style="filled" fillcolor=red]; + } + 58 [label="Exit default value of _children [2]"]; + 59 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; + 60 [label="Exit function [2]" style="filled" fillcolor=red]; } 61 [label="Exit class LighterASTNode [1]" style="filled" fillcolor=red]; } @@ -203,19 +203,19 @@ digraph kt44814_kt { } 45 -> {46} [color=green]; 45 -> {61} [style=dotted]; - 45 -> {46 54 57} [style=dashed]; + 45 -> {46 49 53} [style=dashed]; 46 -> {47}; - 47 -> {48 51}; - 47 -> {48} [style=dashed]; - 48 -> {49}; + 47 -> {48}; + 48 -> {49} [color=green]; 49 -> {50}; 50 -> {51}; 51 -> {52}; - 52 -> {53}; - 53 -> {54} [color=green]; - 54 -> {55}; + 52 -> {53} [color=green]; + 53 -> {54}; + 54 -> {55 58}; + 54 -> {55} [style=dashed]; 55 -> {56}; - 56 -> {57} [color=green]; + 56 -> {57}; 57 -> {58}; 58 -> {59}; 59 -> {60}; @@ -246,15 +246,15 @@ digraph kt44814_kt { 74 [label="Enter class Companion [2]" style="filled" fillcolor=red]; subgraph cluster_27 { color=blue - 75 [label="Enter function [3]" style="filled" fillcolor=red]; - 76 [label="Delegated constructor call: super() [3]" style="filled" fillcolor=yellow]; - 77 [label="Exit function [3]" style="filled" fillcolor=red]; + 75 [label="Enter property [3]" style="filled" fillcolor=red]; + 76 [label="Function call: R|/TokenType.TokenType|() [3]" style="filled" fillcolor=yellow]; + 77 [label="Exit property [3]" style="filled" fillcolor=red]; } subgraph cluster_28 { color=blue - 78 [label="Enter property [3]" style="filled" fillcolor=red]; - 79 [label="Function call: R|/TokenType.TokenType|() [3]" style="filled" fillcolor=yellow]; - 80 [label="Exit property [3]" style="filled" fillcolor=red]; + 78 [label="Enter function [3]" style="filled" fillcolor=red]; + 79 [label="Delegated constructor call: super() [3]" style="filled" fillcolor=yellow]; + 80 [label="Exit function [3]" style="filled" fillcolor=red]; } 81 [label="Exit class Companion [2]" style="filled" fillcolor=red]; } @@ -317,15 +317,15 @@ digraph kt44814_kt { 92 [label="Enter class KtModifierListOwner [1]" style="filled" fillcolor=red]; subgraph cluster_34 { color=blue - 93 [label="Enter function [2]" style="filled" fillcolor=red]; - 94 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; - 95 [label="Exit function [2]" style="filled" fillcolor=red]; + 93 [label="Enter property [2]" style="filled" fillcolor=red]; + 94 [label="Function call: R|/KtModifierList.KtModifierList|() [2]" style="filled" fillcolor=yellow]; + 95 [label="Exit property [2]" style="filled" fillcolor=red]; } subgraph cluster_35 { color=blue - 96 [label="Enter property [2]" style="filled" fillcolor=red]; - 97 [label="Function call: R|/KtModifierList.KtModifierList|() [2]" style="filled" fillcolor=yellow]; - 98 [label="Exit property [2]" style="filled" fillcolor=red]; + 96 [label="Enter function [2]" style="filled" fillcolor=red]; + 97 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; + 98 [label="Exit function [2]" style="filled" fillcolor=red]; } 99 [label="Exit class KtModifierListOwner [1]" style="filled" fillcolor=red]; } @@ -344,21 +344,21 @@ digraph kt44814_kt { 100 [label="Enter class FirModifier [1]" style="filled" fillcolor=red]; subgraph cluster_37 { color=blue - 101 [label="Enter function [2]" style="filled" fillcolor=red]; - 102 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; - 103 [label="Exit function [2]" style="filled" fillcolor=red]; + 101 [label="Enter property [2]" style="filled" fillcolor=red]; + 102 [label="Access variable R|/node| [2]"]; + 103 [label="Exit property [2]" style="filled" fillcolor=red]; } subgraph cluster_38 { color=blue 104 [label="Enter property [2]" style="filled" fillcolor=red]; - 105 [label="Access variable R|/node| [2]"]; + 105 [label="Access variable R|/token| [2]"]; 106 [label="Exit property [2]" style="filled" fillcolor=red]; } subgraph cluster_39 { color=blue - 107 [label="Enter property [2]" style="filled" fillcolor=red]; - 108 [label="Access variable R|/token| [2]"]; - 109 [label="Exit property [2]" style="filled" fillcolor=red]; + 107 [label="Enter function [2]" style="filled" fillcolor=red]; + 108 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; + 109 [label="Exit function [2]" style="filled" fillcolor=red]; } 110 [label="Exit class FirModifier [1]" style="filled" fillcolor=red]; } @@ -367,17 +367,17 @@ digraph kt44814_kt { 111 [label="Enter class FirLightModifier [2]" style="filled" fillcolor=red]; subgraph cluster_41 { color=blue - 112 [label="Enter function [3]" style="filled" fillcolor=red]; - 113 [label="Access variable R|/node| [3]"]; - 114 [label="Access variable R|/token| [3]"]; - 115 [label="Delegated constructor call: super|>(...) [3]" style="filled" fillcolor=yellow]; - 116 [label="Exit function [3]" style="filled" fillcolor=red]; + 112 [label="Enter property [3]" style="filled" fillcolor=red]; + 113 [label="Access variable R|/tree| [3]"]; + 114 [label="Exit property [3]" style="filled" fillcolor=red]; } subgraph cluster_42 { color=blue - 117 [label="Enter property [3]" style="filled" fillcolor=red]; - 118 [label="Access variable R|/tree| [3]"]; - 119 [label="Exit property [3]" style="filled" fillcolor=red]; + 115 [label="Enter function [3]" style="filled" fillcolor=red]; + 116 [label="Access variable R|/node| [3]"]; + 117 [label="Access variable R|/token| [3]"]; + 118 [label="Delegated constructor call: super|>(...) [3]" style="filled" fillcolor=yellow]; + 119 [label="Exit function [3]" style="filled" fillcolor=red]; } 120 [label="Exit class FirLightModifier [2]" style="filled" fillcolor=red]; } @@ -410,12 +410,12 @@ digraph kt44814_kt { 110 -> {111 121} [style=dashed]; 111 -> {112} [color=green]; 111 -> {120} [style=dotted]; - 111 -> {112 117} [style=dashed]; + 111 -> {112 115} [style=dashed]; 112 -> {113}; 113 -> {114}; - 114 -> {115}; + 114 -> {115} [color=green]; 115 -> {116}; - 116 -> {117} [color=green]; + 116 -> {117}; 117 -> {118}; 118 -> {119}; 119 -> {120} [color=green]; @@ -433,15 +433,15 @@ digraph kt44814_kt { 128 [label="Enter class FirModifierList [1]" style="filled" fillcolor=red]; subgraph cluster_46 { color=blue - 129 [label="Enter function [2]" style="filled" fillcolor=red]; - 130 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; - 131 [label="Exit function [2]" style="filled" fillcolor=red]; + 129 [label="Enter property [2]" style="filled" fillcolor=red]; + 130 [label="Function call: R|kotlin/collections/emptyList||>() [2]" style="filled" fillcolor=yellow]; + 131 [label="Exit property [2]" style="filled" fillcolor=red]; } subgraph cluster_47 { color=blue - 132 [label="Enter property [2]" style="filled" fillcolor=red]; - 133 [label="Function call: R|kotlin/collections/emptyList||>() [2]" style="filled" fillcolor=yellow]; - 134 [label="Exit property [2]" style="filled" fillcolor=red]; + 132 [label="Enter function [2]" style="filled" fillcolor=red]; + 133 [label="Delegated constructor call: super() [2]" style="filled" fillcolor=yellow]; + 134 [label="Exit function [2]" style="filled" fillcolor=red]; } 135 [label="Exit class FirModifierList [1]" style="filled" fillcolor=red]; } @@ -660,21 +660,21 @@ digraph kt44814_kt { 254 [label="Enter class FirLightModifierList [2]" style="filled" fillcolor=red]; subgraph cluster_71 { color=blue - 255 [label="Enter function [3]" style="filled" fillcolor=red]; - 256 [label="Delegated constructor call: super() [3]" style="filled" fillcolor=yellow]; - 257 [label="Exit function [3]" style="filled" fillcolor=red]; + 255 [label="Enter property [3]" style="filled" fillcolor=red]; + 256 [label="Access variable R|/modifierList| [3]"]; + 257 [label="Exit property [3]" style="filled" fillcolor=red]; } subgraph cluster_72 { color=blue 258 [label="Enter property [3]" style="filled" fillcolor=red]; - 259 [label="Access variable R|/modifierList| [3]"]; + 259 [label="Access variable R|/tree| [3]"]; 260 [label="Exit property [3]" style="filled" fillcolor=red]; } subgraph cluster_73 { color=blue - 261 [label="Enter property [3]" style="filled" fillcolor=red]; - 262 [label="Access variable R|/tree| [3]"]; - 263 [label="Exit property [3]" style="filled" fillcolor=red]; + 261 [label="Enter function [3]" style="filled" fillcolor=red]; + 262 [label="Delegated constructor call: super() [3]" style="filled" fillcolor=yellow]; + 263 [label="Exit function [3]" style="filled" fillcolor=red]; } 264 [label="Exit class FirLightModifierList [2]" style="filled" fillcolor=red]; } @@ -683,15 +683,15 @@ digraph kt44814_kt { 265 [label="Enter class FirPsiModifierList [2]" style="filled" fillcolor=red]; subgraph cluster_75 { color=blue - 266 [label="Enter function [3]" style="filled" fillcolor=red]; - 267 [label="Delegated constructor call: super() [3]" style="filled" fillcolor=yellow]; - 268 [label="Exit function [3]" style="filled" fillcolor=red]; + 266 [label="Enter property [3]" style="filled" fillcolor=red]; + 267 [label="Access variable R|/modifierList| [3]"]; + 268 [label="Exit property [3]" style="filled" fillcolor=red]; } subgraph cluster_76 { color=blue - 269 [label="Enter property [3]" style="filled" fillcolor=red]; - 270 [label="Access variable R|/modifierList| [3]"]; - 271 [label="Exit property [3]" style="filled" fillcolor=red]; + 269 [label="Enter function [3]" style="filled" fillcolor=red]; + 270 [label="Delegated constructor call: super() [3]" style="filled" fillcolor=yellow]; + 271 [label="Exit function [3]" style="filled" fillcolor=red]; } 272 [label="Exit class FirPsiModifierList [2]" style="filled" fillcolor=red]; }