FIR CFG: join/unify data flow from postponed lambdas at each level

For example:

    foo(
        // `if` joins A & B
        if (condition)
            run { ... } // A
        else
            run { ... }, // B
        run { ... } // C
    ) // `foo` unifies `A & B` and `C`, so if it is not resolved itself,
      // further `if`s, `when`s, safe calls outside it, etc. continue
      // building the correct type predicate until the next completed
      // call.

^KT-44512 Fixed
This commit is contained in:
pyos
2022-06-13 14:17:34 +02:00
committed by teamcity
parent 755c54553a
commit 63b0708ed5
17 changed files with 720 additions and 623 deletions
File diff suppressed because it is too large Load Diff
@@ -28,7 +28,7 @@ FILE: flowFromInplaceLambda2.kt
^ R|/n|<R|kotlin/Nothing?|>()
}
)), R|/someCompletedCall|(Int(1)), R|kotlin/run|<R|kotlin/Int|>(<L> = run@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
R|<local>/x|.R|kotlin/String.length|
R|<local>/x|.<Inapplicable(UNSAFE_CALL): kotlin/String.length>#
^ Int(123)
}
))
@@ -52,7 +52,7 @@ FILE: flowFromInplaceLambda2.kt
^ Int(123)
}
))
R|<local>/x|.<Inapplicable(UNSAFE_CALL): kotlin/String.length>#
R|<local>/x|.R|kotlin/String.length|
}
public final fun test4(x: R|kotlin/String?|): R|kotlin/Unit| {
lvar p: R|kotlin/String?| = R|<local>/x|
@@ -74,11 +74,11 @@ FILE: flowFromInplaceLambda2.kt
}
}
), Int(1), R|kotlin/run|<R|kotlin/Int|>(<L> = run@fun <anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
R|<local>/p|.R|kotlin/String.length|
R|<local>/p|.<Inapplicable(UNSAFE_CALL): kotlin/String.length>#
^ Int(123)
}
))
R|<local>/p|.R|kotlin/String.length|
R|<local>/p|.<Inapplicable(UNSAFE_CALL): kotlin/String.length>#
}
}
@@ -92,7 +92,7 @@ FILE: flowFromInplaceLambda2.kt
^ String()
}
))
R|<local>/x|.R|kotlin/String.length|
R|<local>/x|.<Inapplicable(UNSAFE_CALL): kotlin/String.length>#
}
public final fun test6(x: R|kotlin/String?|): R|kotlin/Unit| {
R|/foo|<R|kotlin/Int|>(R|/id|<R|kotlin/Nothing?|>(when () {
@@ -21,7 +21,7 @@ fun test2(x: String?) {
foo(
id(run { x as String; n() }),
someCompletedCall(1),
run { x.length; 123 } // Bad (resolution order undefined)
run { x<!UNSAFE_CALL!>.<!>length; 123 } // Bad (resolution order undefined)
)
x.length // OK (x as String unconditional)
}
@@ -32,7 +32,7 @@ fun test3(x: String?) {
if (true) 1 else 2,
run { x<!UNSAFE_CALL!>.<!>length; 123 } // Bad (resolution order undefined)
)
x<!UNSAFE_CALL!>.<!>length // OK (x as String unconditional)
x.length // OK (x as String unconditional)
}
fun test4(x: String?) {
@@ -41,9 +41,9 @@ fun test4(x: String?) {
foo(
id(if (true) run { p = null; n() } else run { n() }),
1,
run { p.length; 123 } // Bad (p = null possible)
run { p<!UNSAFE_CALL!>.<!>length; 123 } // Bad (p = null possible)
)
p.length // Bad (p = null possible)
p<!UNSAFE_CALL!>.<!>length // Bad (p = null possible)
}
}
@@ -53,7 +53,7 @@ fun test5(x: String?, y: String?) {
1,
run { "" }
)
x.length // Bad (x as String conditional)
x<!UNSAFE_CALL!>.<!>length // Bad (x as String conditional)
}
fun test6(x: String?) {
@@ -63,14 +63,14 @@ digraph inplaceLambdaInControlFlowExpressions_kt {
24 [label="Postponed enter to lambda"];
subgraph cluster_9 {
color=blue
33 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
34 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_10 {
color=blue
34 [label="Enter block"];
35 [label="Function call: R|/materialize|<R|kotlin/String|>()"];
36 [label="Exit block"];
35 [label="Enter block"];
36 [label="Function call: R|/materialize|<R|kotlin/String|>()"];
37 [label="Exit block"];
}
37 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
38 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
25 [label="Postponed exit from lambda"];
26 [label="Function call: R|kotlin/run|<R|kotlin/String|>(...)"];
@@ -84,6 +84,7 @@ digraph inplaceLambdaInControlFlowExpressions_kt {
}
32 [label="Exit function test_1" style="filled" fillcolor=red];
}
33 [label="Merge postponed lambda exits"];
9 -> {10};
10 -> {11};
11 -> {12};
@@ -99,89 +100,89 @@ digraph inplaceLambdaInControlFlowExpressions_kt {
21 -> {29};
22 -> {23};
23 -> {24};
24 -> {33};
24 -> {34};
24 -> {25} [color=red];
24 -> {33} [style=dashed];
24 -> {34} [style=dashed];
25 -> {26};
26 -> {27};
27 -> {28};
28 -> {29};
29 -> {30};
29 -> {33 30};
30 -> {31};
31 -> {32};
33 -> {34};
34 -> {35};
35 -> {36};
36 -> {37};
37 -> {25} [color=green];
37 -> {38};
38 -> {33} [color=red];
38 -> {25} [color=green];
subgraph cluster_11 {
color=red
38 [label="Enter function test_2" style="filled" fillcolor=red];
39 [label="Enter function test_2" style="filled" fillcolor=red];
subgraph cluster_12 {
color=blue
39 [label="Enter block"];
40 [label="Enter block"];
subgraph cluster_13 {
color=blue
40 [label="Try expression enter"];
41 [label="Try expression enter"];
subgraph cluster_14 {
color=blue
41 [label="Try main block enter"];
42 [label="Try main block enter"];
subgraph cluster_15 {
color=blue
42 [label="Enter block"];
43 [label="Postponed enter to lambda"];
43 [label="Enter block"];
44 [label="Postponed enter to lambda"];
subgraph cluster_16 {
color=blue
58 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
59 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_17 {
color=blue
59 [label="Enter block"];
60 [label="Function call: R|/materialize|<R|kotlin/String|>()"];
61 [label="Exit block"];
60 [label="Enter block"];
61 [label="Function call: R|/materialize|<R|kotlin/String|>()"];
62 [label="Exit block"];
}
62 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
63 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
44 [label="Postponed exit from lambda"];
45 [label="Function call: R|kotlin/run|<R|kotlin/String|>(...)"];
46 [label="Exit block"];
45 [label="Postponed exit from lambda"];
46 [label="Function call: R|kotlin/run|<R|kotlin/String|>(...)"];
47 [label="Exit block"];
}
47 [label="Try main block exit"];
48 [label="Try main block exit"];
}
subgraph cluster_18 {
color=blue
48 [label="Catch enter"];
49 [label="Catch enter"];
subgraph cluster_19 {
color=blue
49 [label="Enter block"];
50 [label="Const: String()"];
51 [label="Exit block"];
50 [label="Enter block"];
51 [label="Const: String()"];
52 [label="Exit block"];
}
52 [label="Catch exit"];
53 [label="Catch exit"];
}
53 [label="Try expression exit"];
54 [label="Try expression exit"];
}
54 [label="Call arguments union" style="filled" fillcolor=yellow];
55 [label="Variable declaration: lval x: R|kotlin/String|"];
56 [label="Exit block"];
55 [label="Call arguments union" style="filled" fillcolor=yellow];
56 [label="Variable declaration: lval x: R|kotlin/String|"];
57 [label="Exit block"];
}
57 [label="Exit function test_2" style="filled" fillcolor=red];
58 [label="Exit function test_2" style="filled" fillcolor=red];
}
38 -> {39};
39 -> {40};
40 -> {41 48};
41 -> {42};
40 -> {41};
41 -> {42 49};
42 -> {43};
43 -> {58};
43 -> {44} [color=red];
43 -> {58} [style=dashed];
44 -> {45};
43 -> {44};
44 -> {59};
44 -> {45} [color=red];
44 -> {59} [style=dashed];
45 -> {46};
46 -> {47};
47 -> {53 48};
48 -> {49};
48 -> {57} [label=onUncaughtException];
47 -> {48};
48 -> {54 49};
49 -> {50};
49 -> {58} [label=onUncaughtException];
50 -> {51};
51 -> {52};
52 -> {53};
@@ -189,56 +190,57 @@ digraph inplaceLambdaInControlFlowExpressions_kt {
54 -> {55};
55 -> {56};
56 -> {57};
58 -> {59};
57 -> {58};
59 -> {60};
60 -> {61};
61 -> {62};
62 -> {54} [color=red];
62 -> {44} [color=green];
62 -> {63};
63 -> {55} [color=red];
63 -> {45} [color=green];
subgraph cluster_20 {
color=red
63 [label="Enter function test_3" style="filled" fillcolor=red];
64 [label="Enter function test_3" style="filled" fillcolor=red];
subgraph cluster_21 {
color=blue
64 [label="Enter block"];
65 [label="Postponed enter to lambda"];
65 [label="Enter block"];
66 [label="Postponed enter to lambda"];
subgraph cluster_22 {
color=blue
73 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
74 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_23 {
color=blue
74 [label="Enter block"];
75 [label="Function call: R|/materialize|<R|kotlin/String?|>()"];
76 [label="Exit block"];
75 [label="Enter block"];
76 [label="Function call: R|/materialize|<R|kotlin/String?|>()"];
77 [label="Exit block"];
}
77 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
78 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
66 [label="Postponed exit from lambda"];
67 [label="Function call: R|kotlin/run|<R|kotlin/String?|>(...)"];
68 [label="Check not null: R|kotlin/run|<R|kotlin/String?|>(...)!!"];
69 [label="Call arguments union" style="filled" fillcolor=yellow];
70 [label="Variable declaration: lval x: R|kotlin/String|"];
71 [label="Exit block"];
67 [label="Postponed exit from lambda"];
68 [label="Function call: R|kotlin/run|<R|kotlin/String?|>(...)"];
69 [label="Check not null: R|kotlin/run|<R|kotlin/String?|>(...)!!"];
70 [label="Call arguments union" style="filled" fillcolor=yellow];
71 [label="Variable declaration: lval x: R|kotlin/String|"];
72 [label="Exit block"];
}
72 [label="Exit function test_3" style="filled" fillcolor=red];
73 [label="Exit function test_3" style="filled" fillcolor=red];
}
63 -> {64};
64 -> {65};
65 -> {73};
65 -> {66} [color=red];
65 -> {73} [style=dashed];
66 -> {67};
65 -> {66};
66 -> {74};
66 -> {67} [color=red];
66 -> {74} [style=dashed];
67 -> {68};
68 -> {69};
69 -> {70};
70 -> {71};
71 -> {72};
73 -> {74};
72 -> {73};
74 -> {75};
75 -> {76};
76 -> {77};
77 -> {69} [color=red];
77 -> {66} [color=green];
77 -> {78};
78 -> {70} [color=red];
78 -> {67} [color=green];
}
@@ -69,16 +69,16 @@ digraph incorrectSmartcastToNothing_kt {
33 [label="Postponed enter to lambda"];
subgraph cluster_10 {
color=blue
43 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
45 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_11 {
color=blue
44 [label="Enter block"];
45 [label="Access variable R|<local>/it|"];
46 [label="Const: String(main.kts.compiled.cache)"];
47 [label="Function call: R|java/io/File.File|(...)"];
48 [label="Exit block"];
46 [label="Enter block"];
47 [label="Access variable R|<local>/it|"];
48 [label="Const: String(main.kts.compiled.cache)"];
49 [label="Function call: R|java/io/File.File|(...)"];
50 [label="Exit block"];
}
49 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
51 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
34 [label="Postponed exit from lambda"];
35 [label="Function call: $subj$.R|kotlin/let|<R|java/io/File|, R|java/io/File|>(...)"];
@@ -93,6 +93,8 @@ digraph incorrectSmartcastToNothing_kt {
}
42 [label="Exit function test" style="filled" fillcolor=red];
}
43 [label="Merge postponed lambda exits"];
44 [label="Merge postponed lambda exits"];
4 -> {5};
5 -> {6};
6 -> {7};
@@ -122,23 +124,25 @@ digraph incorrectSmartcastToNothing_kt {
30 -> {31};
31 -> {32 36};
32 -> {33};
33 -> {43};
33 -> {45};
33 -> {34} [color=red];
33 -> {43} [style=dashed];
33 -> {45} [style=dashed];
34 -> {35};
35 -> {36};
36 -> {37};
36 -> {43 37};
37 -> {38};
38 -> {39};
39 -> {40};
39 -> {44 40};
40 -> {41};
41 -> {42};
43 -> {44};
44 -> {45};
43 -> {44} [color=red];
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {49};
49 -> {34} [color=green];
49 -> {50};
50 -> {51};
51 -> {43} [color=red];
51 -> {34} [color=green];
}
@@ -135,14 +135,14 @@ digraph lambdaInWhenBranch_kt {
48 [label="Postponed enter to lambda"];
subgraph cluster_18 {
color=blue
81 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
82 [label="Enter function anonymousFunction" style="filled" fillcolor=red];
subgraph cluster_19 {
color=blue
82 [label="Enter block"];
83 [label="Access variable R|<local>/it|"];
84 [label="Exit block"];
83 [label="Enter block"];
84 [label="Access variable R|<local>/it|"];
85 [label="Exit block"];
}
85 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
86 [label="Exit function anonymousFunction" style="filled" fillcolor=red];
}
49 [label="Postponed exit from lambda"];
50 [label="Function call: String().R|kotlin/let|<R|kotlin/String|, R|kotlin/String|>(...)"];
@@ -195,6 +195,7 @@ digraph lambdaInWhenBranch_kt {
}
80 [label="Exit function foo" style="filled" fillcolor=red];
}
81 [label="Merge postponed lambda exits"];
28 -> {29};
29 -> {30};
30 -> {31};
@@ -215,14 +216,14 @@ digraph lambdaInWhenBranch_kt {
45 -> {46};
46 -> {47};
47 -> {48};
48 -> {81};
48 -> {82};
48 -> {49} [color=red];
48 -> {81} [style=dashed];
48 -> {82} [style=dashed];
49 -> {50};
50 -> {51};
51 -> {52};
52 -> {53};
53 -> {54};
53 -> {81 54};
54 -> {55};
55 -> {56};
56 -> {57};
@@ -249,10 +250,11 @@ digraph lambdaInWhenBranch_kt {
77 -> {78};
78 -> {79};
79 -> {80};
81 -> {82};
82 -> {83};
83 -> {84};
84 -> {85};
85 -> {49} [color=green];
85 -> {86};
86 -> {81} [color=red];
86 -> {49} [color=green];
}
@@ -826,7 +826,7 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
}
fun exitWhenExpression(whenExpression: FirWhenExpression) {
val (whenExitNode, syntheticElseNode) = graphBuilder.exitWhenExpression(whenExpression)
val (whenExitNode, syntheticElseNode, mergePostponedLambdaExitsNode) = graphBuilder.exitWhenExpression(whenExpression)
if (syntheticElseNode != null) {
val previousConditionExitNode = syntheticElseNode.firstPreviousNode as? WhenBranchConditionExitNode
// previous node for syntheticElseNode can be not WhenBranchConditionExitNode in case of `when` without any branches
@@ -844,6 +844,7 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
}
}
whenExitNode.mergeIncomingFlow()
mergePostponedLambdaExitsNode?.mergeIncomingFlow()
}
fun exitWhenSubjectExpression(expression: FirWhenSubjectExpression) {
@@ -1022,8 +1023,9 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
}
fun exitSafeCall(safeCall: FirSafeCallExpression) {
val node = graphBuilder.exitSafeCall().mergeIncomingFlow()
val flow = node.flow
val (node, mergePostponedLambdaExitsNode) = graphBuilder.exitSafeCall()
val flow = node.mergeIncomingFlow().flow
mergePostponedLambdaExitsNode?.mergeIncomingFlow()
val variable = variableStorage.getOrCreateVariable(flow, safeCall)
val receiverVariable = when (variable) {
@@ -1462,7 +1464,9 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
}
fun exitElvis(elvisExpression: FirElvisExpression, isLhsNotNull: Boolean) {
val node = graphBuilder.exitElvis().mergeIncomingFlow()
val (node, mergePostponedLambdaExitsNode) = graphBuilder.exitElvis()
node.mergeIncomingFlow()
mergePostponedLambdaExitsNode?.mergeIncomingFlow()
if (isLhsNotNull) {
elvisExpression.lhs.propagateNotNullInfo(node)
}
@@ -23,6 +23,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.fir.visitors.FirDefaultVisitor
import org.jetbrains.kotlin.utils.addToStdlib.popLast
import org.jetbrains.kotlin.utils.addToStdlib.runIf
import kotlin.random.Random
@@ -85,7 +86,7 @@ class ControlFlowGraphBuilder {
private val loopEnterNodes: NodeStorage<FirElement, CFGNode<FirElement>> = NodeStorage()
private val loopExitNodes: NodeStorage<FirLoop, LoopExitNode> = NodeStorage()
private val exitsFromCompletedPostponedAnonymousFunctions: MutableList<PostponedLambdaExitNode> = mutableListOf()
private val exitsFromCompletedPostponedAnonymousFunctions: MutableList<MutableList<CFGNode<*>>> = mutableListOf()
private val whenExitNodes: NodeStorage<FirWhenExpression, WhenExitNode> = NodeStorage()
private val whenBranchIndices: Stack<Map<FirWhenBranch, Int>> = stackOf()
@@ -341,7 +342,8 @@ class ControlFlowGraphBuilder {
val graph = popGraph().also { graph ->
assert(graph.declaration == anonymousFunction)
assert(graph.exitNode == exitNode)
exitsFromCompletedPostponedAnonymousFunctions.removeAll { it.owner == graph }
// TODO: disregarding the edges is probably not correct, though this should never find any nodes anyway
exitsFromCompletedPostponedAnonymousFunctions.lastOrNull()?.removeAll { it.owner == graph }
}
val postponedEnterNode = entersToPostponedAnonymousFunctions.remove(symbol)!!
@@ -361,7 +363,7 @@ class ControlFlowGraphBuilder {
}
if (invocationKind == EventOccurrencesRange.EXACTLY_ONCE && shouldPassFlowFromInplaceLambda.top()) {
exitsFromCompletedPostponedAnonymousFunctions += postponedExitNode
exitsFromCompletedPostponedAnonymousFunctions.lastOrNull()?.add(postponedExitNode)
}
val containingGraph = parentGraphForAnonymousFunctions.remove(symbol) ?: currentGraph
@@ -666,6 +668,7 @@ class ControlFlowGraphBuilder {
whenBranchIndices.push(whenExpression.branches.mapIndexed { index, branch -> branch to index }.toMap())
notCompletedFunctionCalls.push(mutableListOf())
levelCounter++
splitDataFlowForPostponedLambdas()
return node
}
@@ -696,7 +699,9 @@ class ControlFlowGraphBuilder {
return node
}
fun exitWhenExpression(whenExpression: FirWhenExpression): Pair<WhenExitNode, WhenSyntheticElseBranchNode?> {
fun exitWhenExpression(
whenExpression: FirWhenExpression
): Triple<WhenExitNode, WhenSyntheticElseBranchNode?, MergePostponedLambdaExitsNode?> {
val whenExitNode = whenExitNodes.pop()
// exit from last condition node still on stack
// we should remove it
@@ -710,10 +715,9 @@ class ControlFlowGraphBuilder {
} else null
whenExitNode.updateDeadStatus()
lastNodes.push(whenExitNode)
dropPostponedLambdasForNonDeterministicCalls()
levelCounter--
whenBranchIndices.pop()
return whenExitNode to syntheticElseBranchNode
return Triple(whenExitNode, syntheticElseBranchNode, joinDataFlowFromPostponedLambdasWith(whenExitNode))
}
// ----------------------------------- While Loop -----------------------------------
@@ -920,6 +924,7 @@ class ControlFlowGraphBuilder {
finallyExitNodes.push(createFinallyBlockExitNode(tryExpression))
}
notCompletedFunctionCalls.push(mutableListOf())
splitDataFlowForPostponedLambdas()
return enterTryExpressionNode to enterTryNodeBlock
}
@@ -1074,6 +1079,7 @@ class ControlFlowGraphBuilder {
fun enterCall() {
levelCounter++
splitDataFlowForPostponedLambdas()
}
fun exitIgnoredCall(functionCall: FirFunctionCall) {
@@ -1151,53 +1157,92 @@ class ControlFlowGraphBuilder {
return node to unionNode
}
/*
* This is needed for some control flow constructions which are resolved as calls (when and elvis)
* For usual call we have invariant that all arguments will be called before function call, but for
* when and elvis only one of arguments will be actually called, so it's illegal to pass data flow info
* from lambda in one of branches
*/
private fun dropPostponedLambdasForNonDeterministicCalls() {
exitsFromCompletedPostponedAnonymousFunctions.clear()
// Arguments are evaluated left to right, and this is how data flows.
// foo(run { x as String; 1 }, { /* x smartcasted to String */ x.length })
//
// However, as we need to fix type parameters before analyzing lambdas, this is not always the order of analysis;
// if that is possible, multiple lambdas should be considered to be concurrent.
//
// foo(run { x as String; genericFunction() }, run { /* x not smartcastable because this lambda may be resolved first */ 1 })
// /* x is smartcastable after the call */
//
// And if the lambda is conditional, then the data flow needs to be merged with other branches.
//
// foo(nullable?.let { x as String; genericFunction() }, run { 1 })
// /* x is not smartcastable */
//
// foo(nullable ?: run { x as String; genericFunction() }, run { 1 })
// /* x is not smartcastable */
//
// foo(if (condition) run { x as String; genericFunction() } else { genericFunction() }, run { 1 })
// /* x is not smartcastable */
//
// foo(if (condition) run { x as String; genericFunction() } else { x as String; genericFunction() }, run { 1 })
// /* x is smartcastable */
//
// `splitDataFlowForPostponedLambdas` in `enterX` should be matched with either `joinDataFlowFromPostponedLambdasWith`
// or `processUnionOfArguments` in `exitX`. The difference is that the latter creates an intersection of all the lambdas'
// type information (like after function calls - all casts from all lambdas are valid) while the former is a union
// (like after `if` - only the casts from one of the lambdas are valid, and we don't know which).
//
private fun splitDataFlowForPostponedLambdas() {
exitsFromCompletedPostponedAnonymousFunctions.add(mutableListOf())
}
private fun joinDataFlowFromPostponedLambdasWith(node: CFGNode<*>): MergePostponedLambdaExitsNode? {
val currentLevelExits = exitsFromCompletedPostponedAnonymousFunctions.popLast()
if (currentLevelExits.isEmpty()) {
return null
}
val joinNode = createMergePostponedLambdaExitsNode(node.fir)
addEdge(node, joinNode)
currentLevelExits.joinDataFlowFromPostponedLambdasTo(joinNode)
exitsFromCompletedPostponedAnonymousFunctions.lastOrNull()?.add(joinNode)
return joinNode
}
private fun MutableList<CFGNode<*>>.joinDataFlowFromPostponedLambdasTo(node: CFGNode<*>) {
for (exitNode in this) {
// To avoid storing nodes from subgraphs in the list, we have PostponedLambdaExitNode instead of the real
// exit node of the lambda subgraph. The latter is the previous node of the former. Everything else is
// already a join/union node in this graph.
val functionExitOrMerge = if (exitNode is PostponedLambdaExitNode) exitNode.lastPreviousNode else exitNode
addEdge(functionExitOrMerge, node, preferredKind = EdgeKind.DfgForward)
}
}
private fun processUnionOfArguments(
node: CFGNode<*>,
callCompleted: Boolean
): Pair<EdgeKind, UnionFunctionCallArgumentsNode?> {
if (!shouldPassFlowFromInplaceLambda.top()) return EdgeKind.Forward to null
var kind = EdgeKind.Forward
if (!callCompleted || exitsFromCompletedPostponedAnonymousFunctions.isEmpty()) {
val currentLevelExits = exitsFromCompletedPostponedAnonymousFunctions.popLast()
if (currentLevelExits.isEmpty()) {
return EdgeKind.Forward to null
}
val unionNode by lazy { createUnionFunctionCallArgumentsNode(node.fir) }
var hasDirectPreviousNode = false
var hasPostponedLambdas = false
val iterator = exitsFromCompletedPostponedAnonymousFunctions.iterator()
val lastPostponedLambdaExitNode = lastNode
while (iterator.hasNext()) {
val exitNode = iterator.next()
if (node.level >= exitNode.level) continue
hasPostponedLambdas = true
if (exitNode == lastPostponedLambdaExitNode) {
popAndAddEdge(node, preferredKind = EdgeKind.CfgForward)
kind = EdgeKind.DfgForward
hasDirectPreviousNode = true
if (!callCompleted || !shouldPassFlowFromInplaceLambda.top()) {
currentLevelExits.singleOrNull()?.let {
exitsFromCompletedPostponedAnonymousFunctions.lastOrNull()?.add(it)
return EdgeKind.Forward to null
}
addEdge(exitNode.lastPreviousNode, unionNode, preferredKind = EdgeKind.DfgForward)
iterator.remove()
val unionNode = createUnionFunctionCallArgumentsNode(node.fir)
currentLevelExits.joinDataFlowFromPostponedLambdasTo(unionNode)
exitsFromCompletedPostponedAnonymousFunctions.lastOrNull()?.addAll(currentLevelExits)
return EdgeKind.Forward to unionNode
}
if (hasPostponedLambdas) {
if (hasDirectPreviousNode) {
lastNodes.push(unionNode)
} else {
addNewSimpleNode(unionNode)
}
} else {
return EdgeKind.Forward to null
val unionNode = createUnionFunctionCallArgumentsNode(node.fir)
currentLevelExits.joinDataFlowFromPostponedLambdasTo(unionNode)
if (lastNode in currentLevelExits) {
popAndAddEdge(node, preferredKind = EdgeKind.CfgForward)
lastNodes.push(unionNode)
return EdgeKind.DfgForward to unionNode
}
return Pair(kind, unionNode)
addNewSimpleNode(unionNode)
return EdgeKind.Forward to unionNode
}
fun exitWhenSubjectExpression(expression: FirWhenSubjectExpression): WhenSubjectExpressionExitNode {
@@ -1290,19 +1335,21 @@ class ControlFlowGraphBuilder {
} else {
addEdge(lastNode, exitNode)
}
splitDataFlowForPostponedLambdas()
return enterNode
}
fun exitSafeCall(): ExitSafeCallNode {
fun exitSafeCall(): Pair<ExitSafeCallNode, MergePostponedLambdaExitsNode?> {
// There will be two paths towards this exit safe call node:
// one from the node prior to the enclosing safe call, and
// the other from the selector part in the enclosing safe call.
// Note that *neither* points to the safe call directly.
// So, when it comes to the real exit of the enclosing block/function,
// the safe call bound to this exit safe call node should be retrieved.
return exitSafeCallNodes.pop().also {
return exitSafeCallNodes.pop().let {
addNewSimpleNode(it)
it.updateDeadStatus()
it to joinDataFlowFromPostponedLambdasWith(it)
}
}
@@ -1310,6 +1357,7 @@ class ControlFlowGraphBuilder {
fun enterElvis(elvisExpression: FirElvisExpression) {
elvisRhsEnterNodes.push(createElvisRhsEnterNode(elvisExpression))
splitDataFlowForPostponedLambdas()
}
fun exitElvisLhs(elvisExpression: FirElvisExpression): Triple<ElvisLhsExitNode, ElvisLhsIsNotNullNode, ElvisRhsEnterNode> {
@@ -1342,12 +1390,11 @@ class ControlFlowGraphBuilder {
return Triple(lhsExitNode, lhsIsNotNullNode, rhsEnterNode)
}
fun exitElvis(): ElvisExitNode {
fun exitElvis(): Pair<ElvisExitNode, MergePostponedLambdaExitsNode?> {
val exitNode = exitElvisExpressionNodes.pop()
addNewSimpleNode(exitNode)
exitNode.updateDeadStatus()
dropPostponedLambdasForNonDeterministicCalls()
return exitNode
return exitNode to joinDataFlowFromPostponedLambdasWith(exitNode)
}
// ----------------------------------- Contract description -----------------------------------
@@ -244,6 +244,9 @@ fun ControlFlowGraphBuilder.createAnonymousObjectExpressionExitNode(fir: FirAnon
fun ControlFlowGraphBuilder.createUnionFunctionCallArgumentsNode(fir: FirElement): UnionFunctionCallArgumentsNode =
UnionFunctionCallArgumentsNode(currentGraph, fir, levelCounter, createId())
fun ControlFlowGraphBuilder.createMergePostponedLambdaExitsNode(fir: FirElement): MergePostponedLambdaExitsNode =
MergePostponedLambdaExitsNode(currentGraph, fir, levelCounter, createId())
fun ControlFlowGraphBuilder.createClassEnterNode(fir: FirClass): ClassEnterNode =
ClassEnterNode(currentGraph, fir, levelCounter, createId())
@@ -789,6 +789,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
return checkNotNullCall
}
dataFlowAnalyzer.enterCall()
checkNotNullCall.argumentList.transformArguments(transformer, ResolutionMode.ContextDependent)
checkNotNullCall.transformAnnotations(transformer, ResolutionMode.ContextIndependent)
@@ -228,17 +228,25 @@ class PostponedLambdaEnterNode(owner: ControlFlowGraph, override val fir: FirAno
return visitor.visitPostponedLambdaEnterNode(this, data)
}
}
class PostponedLambdaExitNode(owner: ControlFlowGraph, override val fir: FirAnonymousFunctionExpression, level: Int, id: Int) : CFGNode<FirAnonymousFunctionExpression>(owner, level, id) {
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
return visitor.visitPostponedLambdaExitNode(this, data)
}
}
class UnionFunctionCallArgumentsNode(owner: ControlFlowGraph, override val fir: FirElement, level: Int, id: Int) : CFGNode<FirElement>(owner, level, id) {
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
return visitor.visitUnionFunctionCallArgumentsNode(this, data)
}
}
class MergePostponedLambdaExitsNode(owner: ControlFlowGraph, override val fir: FirElement, level: Int, id: Int) : CFGNode<FirElement>(owner, level, id) {
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
return visitor.visitMergePostponedLambdaExitsNode(this, data)
}
}
class AnonymousFunctionExpressionExitNode(owner: ControlFlowGraph, override val fir: FirAnonymousFunctionExpression, level: Int, id: Int) : CFGNode<FirAnonymousFunctionExpression>(owner, level, id) {
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
return visitor.visitAnonymousFunctionExpressionExitNode(this, data)
@@ -107,6 +107,7 @@ fun CFGNode<*>.render(): String =
is AnonymousFunctionExpressionExitNode -> "Exit anonymous function expression"
is UnionFunctionCallArgumentsNode -> "Call arguments union"
is MergePostponedLambdaExitsNode -> "Merge postponed lambda exits"
is ClassEnterNode -> "Enter class ${owner.name}"
is ClassExitNode -> "Exit class ${owner.name}"
@@ -46,6 +46,10 @@ abstract class ControlFlowGraphVisitor<out R, in D> {
return visitNode(node, data)
}
open fun visitMergePostponedLambdaExitsNode(node: MergePostponedLambdaExitsNode, data: D): R {
return visitNode(node, data)
}
open fun visitAnonymousFunctionExpressionExitNode(node: AnonymousFunctionExpressionExitNode, data: D): R {
return visitNode(node, data)
}
@@ -32,6 +32,10 @@ abstract class ControlFlowGraphVisitorVoid : ControlFlowGraphVisitor<Unit, Nothi
visitNode(node)
}
open fun visitMergePostponedLambdaExitsNode(node: MergePostponedLambdaExitsNode) {
visitNode(node)
}
// ----------------------------------- Anonymous object -----------------------------------
open fun visitAnonymousObjectExitNode(node: AnonymousObjectExitNode) {
@@ -325,6 +329,10 @@ abstract class ControlFlowGraphVisitorVoid : ControlFlowGraphVisitor<Unit, Nothi
visitUnionFunctionCallArgumentsNode(node)
}
final override fun visitMergePostponedLambdaExitsNode(node: MergePostponedLambdaExitsNode, data: Nothing?) {
visitMergePostponedLambdaExitsNode(node)
}
// ----------------------------------- Anonymous object -----------------------------------
final override fun visitAnonymousObjectExitNode(node: AnonymousObjectExitNode, data: Nothing?) {
+118 -114
View File
@@ -468,7 +468,7 @@ digraph kt44814_kt {
}
141 -> {142};
142 -> {143};
143 -> {285} [color=green];
143 -> {287} [color=green];
subgraph cluster_47 {
color=red
@@ -595,20 +595,20 @@ digraph kt44814_kt {
191 [label="Postponed enter to lambda [8]"];
subgraph cluster_62 {
color=blue
237 [label="Enter function anonymousFunction [9]" style="filled" fillcolor=red];
239 [label="Enter function anonymousFunction [9]" style="filled" fillcolor=red];
subgraph cluster_63 {
color=blue
238 [label="Enter block [9]"];
239 [label="Access variable R|<local>/it| [9]"];
240 [label="Enter safe call [9]"];
241 [label="Access variable R|/LighterASTNode.tokenType| [9]"];
242 [label="Exit safe call [9]"];
243 [label="Access qualifier /TokenType [9]"];
244 [label="Access variable R|/TokenType.Companion.MODIFIER_LIST| [9]"];
245 [label="Equality operator == [9]"];
246 [label="Exit block [9]"];
240 [label="Enter block [9]"];
241 [label="Access variable R|<local>/it| [9]"];
242 [label="Enter safe call [9]"];
243 [label="Access variable R|/LighterASTNode.tokenType| [9]"];
244 [label="Exit safe call [9]"];
245 [label="Access qualifier /TokenType [9]"];
246 [label="Access variable R|/TokenType.Companion.MODIFIER_LIST| [9]"];
247 [label="Equality operator == [9]"];
248 [label="Exit block [9]"];
}
247 [label="Exit function anonymousFunction [9]" style="filled" fillcolor=red];
249 [label="Exit function anonymousFunction [9]" style="filled" fillcolor=red];
}
192 [label="Postponed exit from lambda [8]"];
193 [label="Function call: this@R|/FirModifierList.Companion.getModifierList|.R|/FirLightSourceElement.lighterASTNode|.R|/LighterASTNode.getChildren|(...).R|kotlin/collections/find|<R|LighterASTNode?|>(...) [7]"];
@@ -639,15 +639,15 @@ digraph kt44814_kt {
215 [label="Postponed enter to lambda [7]"];
subgraph cluster_65 {
color=blue
231 [label="Enter function anonymousFunction [8]" style="filled" fillcolor=red];
233 [label="Enter function anonymousFunction [8]" style="filled" fillcolor=red];
subgraph cluster_66 {
color=blue
232 [label="Enter block [8]"];
233 [label="Access variable R|<local>/it| [9]"];
234 [label="Function call: R|/FirModifierList.FirPsiModifierList.FirPsiModifierList|(...) [8]"];
235 [label="Exit block [8]"];
234 [label="Enter block [8]"];
235 [label="Access variable R|<local>/it| [9]"];
236 [label="Function call: R|/FirModifierList.FirPsiModifierList.FirPsiModifierList|(...) [8]"];
237 [label="Exit block [8]"];
}
236 [label="Exit function anonymousFunction [8]" style="filled" fillcolor=red];
238 [label="Exit function anonymousFunction [8]" style="filled" fillcolor=red];
}
216 [label="Postponed exit from lambda [7]"];
217 [label="Function call: $subj$.R|kotlin/let|<R|KtModifierList|, R|FirModifierList.FirPsiModifierList|>(...) [6]"];
@@ -655,17 +655,18 @@ digraph kt44814_kt {
219 [label="Exit block [6]"];
}
220 [label="Exit when branch result [5]"];
221 [label="Enter when branch result [5]"];
221 [label="Merge postponed lambda exits [6]"];
222 [label="Enter when branch result [5]"];
subgraph cluster_67 {
color=blue
222 [label="Enter block [5]"];
223 [label="Const: Null(null) [5]"];
224 [label="Exit block [5]"];
223 [label="Enter block [5]"];
224 [label="Const: Null(null) [5]"];
225 [label="Exit block [5]"];
}
225 [label="Exit when branch result [4]"];
226 [label="Exit when [3]"];
226 [label="Exit when branch result [4]"];
227 [label="Exit when [3]"];
}
227 [label="Jump: ^getModifierList when (this@R|/FirModifierList.Companion.getModifierList|) {
228 [label="Jump: ^getModifierList when (this@R|/FirModifierList.Companion.getModifierList|) {
==($subj$, Null(null)) -> {
Null(null)
}
@@ -684,11 +685,12 @@ digraph kt44814_kt {
}
}
[3]"];
228 [label="Stub [3]" style="filled" fillcolor=gray];
229 [label="Exit block [3]" style="filled" fillcolor=gray];
229 [label="Stub [3]" style="filled" fillcolor=gray];
230 [label="Exit block [3]" style="filled" fillcolor=gray];
}
230 [label="Exit function getModifierList [3]" style="filled" fillcolor=red];
231 [label="Exit function getModifierList [3]" style="filled" fillcolor=red];
}
232 [label="Merge postponed lambda exits [3]"];
169 -> {170};
170 -> {171};
171 -> {172};
@@ -697,7 +699,7 @@ digraph kt44814_kt {
174 -> {175};
175 -> {176};
176 -> {177};
177 -> {221 178};
177 -> {222 178};
178 -> {179};
179 -> {180};
180 -> {181};
@@ -711,15 +713,15 @@ digraph kt44814_kt {
188 -> {189};
189 -> {190};
190 -> {191};
191 -> {237};
191 -> {239};
191 -> {192} [color=red];
191 -> {237} [style=dashed];
191 -> {239} [style=dashed];
192 -> {193};
193 -> {194};
194 -> {199 195};
195 -> {196};
196 -> {197};
197 -> {230};
197 -> {231};
197 -> {198} [style=dotted];
198 -> {200} [style=dotted];
199 -> {200};
@@ -729,7 +731,7 @@ digraph kt44814_kt {
203 -> {204};
204 -> {205};
205 -> {206};
206 -> {226};
206 -> {227};
207 -> {208};
208 -> {209};
209 -> {210};
@@ -738,92 +740,94 @@ digraph kt44814_kt {
212 -> {213};
213 -> {214 218};
214 -> {215};
215 -> {231};
215 -> {233};
215 -> {216} [color=red];
215 -> {231} [style=dashed];
215 -> {233} [style=dashed];
216 -> {217};
217 -> {218};
218 -> {219};
218 -> {221 219};
219 -> {220};
220 -> {226};
221 -> {222};
220 -> {227};
221 -> {232} [color=red];
222 -> {223};
223 -> {224};
224 -> {225};
225 -> {226};
226 -> {227};
227 -> {230};
227 -> {228} [style=dotted];
227 -> {232 228};
228 -> {231};
228 -> {229} [style=dotted];
229 -> {230} [style=dotted];
231 -> {232};
232 -> {233};
230 -> {231} [style=dotted];
233 -> {234};
234 -> {235};
235 -> {236};
236 -> {216} [color=green];
237 -> {247 238};
238 -> {239};
239 -> {240 242};
236 -> {237};
237 -> {238};
238 -> {221} [color=red];
238 -> {216} [color=green];
239 -> {249 240};
240 -> {241};
241 -> {242};
241 -> {242 244};
242 -> {243};
243 -> {244};
244 -> {245};
245 -> {246};
246 -> {247};
247 -> {192} [color=green];
247 -> {237} [color=green style=dashed];
247 -> {248};
248 -> {249};
249 -> {192} [color=green];
249 -> {239} [color=green style=dashed];
subgraph cluster_68 {
color=red
248 [label="Enter function boxImpl [3]" style="filled" fillcolor=red];
250 [label="Enter function boxImpl [3]" style="filled" fillcolor=red];
subgraph cluster_69 {
color=blue
249 [label="Enter block [3]"];
250 [label="Function call: R|/LighterASTNode.LighterASTNode|() [6]"];
251 [label="Function call: R|kotlin/collections/listOf|<R|LighterASTNode|>(...) [5]"];
252 [label="Function call: R|/LighterASTNode.LighterASTNode|(...) [4]"];
253 [label="Function call: R|/FlyweightCapableTreeStructure.FlyweightCapableTreeStructure|() [4]"];
254 [label="Function call: R|/FirLightSourceElement.FirLightSourceElement|(...) [3]"];
255 [label="Variable declaration: lval sourceElement: R|FirSourceElement?| [3]"];
256 [label="Access variable R|<local>/sourceElement| [4]"];
257 [label="Function call: (this@R|/FirModifierList.Companion|, R|<local>/sourceElement|).R|/FirModifierList.Companion.getModifierList|() [3]"];
258 [label="Variable declaration: lval result: R|FirModifierList?| [3]"];
251 [label="Enter block [3]"];
252 [label="Function call: R|/LighterASTNode.LighterASTNode|() [6]"];
253 [label="Function call: R|kotlin/collections/listOf|<R|LighterASTNode|>(...) [5]"];
254 [label="Function call: R|/LighterASTNode.LighterASTNode|(...) [4]"];
255 [label="Function call: R|/FlyweightCapableTreeStructure.FlyweightCapableTreeStructure|() [4]"];
256 [label="Function call: R|/FirLightSourceElement.FirLightSourceElement|(...) [3]"];
257 [label="Variable declaration: lval sourceElement: R|FirSourceElement?| [3]"];
258 [label="Access variable R|<local>/sourceElement| [4]"];
259 [label="Function call: (this@R|/FirModifierList.Companion|, R|<local>/sourceElement|).R|/FirModifierList.Companion.getModifierList|() [3]"];
260 [label="Variable declaration: lval result: R|FirModifierList?| [3]"];
subgraph cluster_70 {
color=blue
259 [label="Enter when [3]"];
261 [label="Enter when [3]"];
subgraph cluster_71 {
color=blue
260 [label="Enter when branch condition [4]"];
261 [label="Access variable R|<local>/result| [5]"];
262 [label="Type operator: (R|<local>/result| is R|FirModifierList.FirLightModifierList|) [5]"];
263 [label="Exit when branch condition [4]"];
262 [label="Enter when branch condition [4]"];
263 [label="Access variable R|<local>/result| [5]"];
264 [label="Type operator: (R|<local>/result| is R|FirModifierList.FirLightModifierList|) [5]"];
265 [label="Exit when branch condition [4]"];
}
subgraph cluster_72 {
color=blue
264 [label="Enter when branch condition else [5]"];
265 [label="Exit when branch condition [5]"];
266 [label="Enter when branch condition else [5]"];
267 [label="Exit when branch condition [5]"];
}
266 [label="Enter when branch result [6]"];
268 [label="Enter when branch result [6]"];
subgraph cluster_73 {
color=blue
267 [label="Enter block [6]"];
268 [label="Const: String(Fail) [6]"];
269 [label="Exit block [6]"];
269 [label="Enter block [6]"];
270 [label="Const: String(Fail) [6]"];
271 [label="Exit block [6]"];
}
270 [label="Exit when branch result [5]"];
271 [label="Enter when branch result [5]"];
272 [label="Exit when branch result [5]"];
273 [label="Enter when branch result [5]"];
subgraph cluster_74 {
color=blue
272 [label="Enter block [5]"];
273 [label="Const: String(OK) [5]"];
274 [label="Exit block [5]"];
274 [label="Enter block [5]"];
275 [label="Const: String(OK) [5]"];
276 [label="Exit block [5]"];
}
275 [label="Exit when branch result [4]"];
276 [label="Exit when [3]"];
277 [label="Exit when branch result [4]"];
278 [label="Exit when [3]"];
}
277 [label="Jump: ^boxImpl when () {
279 [label="Jump: ^boxImpl when () {
(R|<local>/result| is R|FirModifierList.FirLightModifierList|) -> {
String(OK)
}
@@ -832,13 +836,11 @@ digraph kt44814_kt {
}
}
[3]"];
278 [label="Stub [3]" style="filled" fillcolor=gray];
279 [label="Exit block [3]" style="filled" fillcolor=gray];
280 [label="Stub [3]" style="filled" fillcolor=gray];
281 [label="Exit block [3]" style="filled" fillcolor=gray];
}
280 [label="Exit function boxImpl [3]" style="filled" fillcolor=red];
282 [label="Exit function boxImpl [3]" style="filled" fillcolor=red];
}
248 -> {249};
249 -> {250};
250 -> {251};
251 -> {252};
252 -> {253};
@@ -852,64 +854,66 @@ digraph kt44814_kt {
260 -> {261};
261 -> {262};
262 -> {263};
263 -> {271 264};
263 -> {264};
264 -> {265};
265 -> {266};
265 -> {273 266};
266 -> {267};
267 -> {268};
268 -> {269};
269 -> {270};
270 -> {276};
270 -> {271};
271 -> {272};
272 -> {273};
272 -> {278};
273 -> {274};
274 -> {275};
275 -> {276};
276 -> {277};
277 -> {280};
277 -> {278} [style=dotted];
278 -> {279} [style=dotted];
277 -> {278};
278 -> {279};
279 -> {282};
279 -> {280} [style=dotted];
280 -> {281} [style=dotted];
281 -> {282} [style=dotted];
subgraph cluster_75 {
color=red
281 [label="Enter class Companion [2]" style="filled" fillcolor=red];
282 [label="Exit class Companion [2]" style="filled" fillcolor=red];
283 [label="Enter class Companion [2]" style="filled" fillcolor=red];
284 [label="Exit class Companion [2]" style="filled" fillcolor=red];
}
281 -> {282} [color=green];
283 -> {284} [color=green];
subgraph cluster_76 {
color=red
283 [label="Enter class FirModifierList [1]" style="filled" fillcolor=red];
284 [label="Part of class initialization [1]"];
285 [label="Exit class FirModifierList [1]" style="filled" fillcolor=red];
285 [label="Enter class FirModifierList [1]" style="filled" fillcolor=red];
286 [label="Part of class initialization [1]"];
287 [label="Exit class FirModifierList [1]" style="filled" fillcolor=red];
}
283 -> {284} [color=green];
284 -> {285} [style=dotted];
284 -> {141} [color=green];
284 -> {141} [style=dashed];
285 -> {286} [color=green];
286 -> {287} [style=dotted];
286 -> {141} [color=green];
286 -> {141} [style=dashed];
subgraph cluster_77 {
color=red
286 [label="Enter function box [1]" style="filled" fillcolor=red];
288 [label="Enter function box [1]" style="filled" fillcolor=red];
subgraph cluster_78 {
color=blue
287 [label="Enter block [1]"];
288 [label="Access qualifier /FirModifierList [2]"];
289 [label="Function call: Q|FirModifierList|.R|/FirModifierList.Companion.boxImpl|() [1]"];
290 [label="Jump: ^box Q|FirModifierList|.R|/FirModifierList.Companion.boxImpl|() [1]"];
291 [label="Stub [1]" style="filled" fillcolor=gray];
292 [label="Exit block [1]" style="filled" fillcolor=gray];
289 [label="Enter block [1]"];
290 [label="Access qualifier /FirModifierList [2]"];
291 [label="Function call: Q|FirModifierList|.R|/FirModifierList.Companion.boxImpl|() [1]"];
292 [label="Jump: ^box Q|FirModifierList|.R|/FirModifierList.Companion.boxImpl|() [1]"];
293 [label="Stub [1]" style="filled" fillcolor=gray];
294 [label="Exit block [1]" style="filled" fillcolor=gray];
}
293 [label="Exit function box [1]" style="filled" fillcolor=red];
295 [label="Exit function box [1]" style="filled" fillcolor=red];
}
286 -> {287};
287 -> {288};
288 -> {289};
289 -> {290};
290 -> {293};
290 -> {291} [style=dotted];
291 -> {292} [style=dotted];
290 -> {291};
291 -> {292};
292 -> {295};
292 -> {293} [style=dotted];
293 -> {294} [style=dotted];
294 -> {295} [style=dotted];
}
@@ -6,6 +6,6 @@ fun foo(y: String?) {
var x: String? = ""
if (x != null) {
bar(y?.let { x = null; it })<!UNSAFE_CALL!>.<!>length
x.length // Smart cast is not possible
x<!UNSAFE_CALL!>.<!>length // Smart cast is not possible
}
}
@@ -3,8 +3,8 @@ fun foo(y: String?) {
if (x != null) {
with(y?.let { x = null; it }) {
this<!UNSAFE_CALL!>.<!>length
x.length
x<!UNSAFE_CALL!>.<!>length
}
x.length
x<!UNSAFE_CALL!>.<!>length
}
}