Commit Graph

20 Commits

Author SHA1 Message Date
Brian Norman 0881910a1b [FIR] Rewind DFA after call arguments for correct receiver smartcasting
^KT-63709 Fixed
2023-12-08 14:32:22 +00:00
Brian Norman b55fda0c55 [FIR] Create CFG for files to track top-level property initialization
In order to properly analyze top-level property initialization, a
control-flow graph must be created for FirFiles. This change adds the
foundation for the file CFG and updates body resolve to create the CFG.
Checking the CFG for proper initialization is separated into a following
change to ease code review.

KT-56683
2023-08-31 12:50:52 +00:00
Dmitrii Gridin 09ca335b7e [FIR] CFG: drop redundant edges
Edges from class to its functions and nested classes are redundant
and lead to extra resolution work in lazy resolve mode

^KT-59600 Fixed
2023-07-04 12:07:04 +00:00
pyos 54f32a6fba Test: FIR CFA: index nodes in rendering order 2023-01-10 15:40:49 +02:00
pyos 74758278d7 FIR CFA: attach method graphs to class exit node
Even for non-local classes. This ensures that the CFG edges in this case
will only go to a subgraph, not to an unrelated graph.
2023-01-10 15:40:48 +02:00
pyos faf0129a5d Test: FIR CFA: sort edges by style & target node id 2023-01-10 15:40:46 +02:00
pyos a9be27e330 FIR CFG: add union nodes
Quick quiz:

 Q: In a CFG, what does `a -> b -> c -> d` mean?
 A: `a`, then `b`, then `c`, then `d`.

 Q: In a CFG, what does `a -> b -> d; a -> c -> d` mean?
 A: `a`, then `b` or `c`, then `d`.

 Q: So how do you encode "a, then (b, then c) or (c, then b), then d`?
 A: You can't.

Problem is, you need to, because that's what `a; run2({ b }, { c }); d`
does when `run2` has a contract that it calls both its lambda arguments
in-place: `shuffle(listOf(block1, block2)).forEach { it() }` is a
perfectly valid implementation for it, as little sense as that makes.

So that's what union nodes solve. When a node implements
`UnionNodeMarker`, its inputs are interpreted as "all visited in some
order" instead of the normal "one of the inputs is visited".

Currently this is used for data flow. It *should* also be used for
control flow, but it isn't. But it should be. But that's not so easy.

BTW, `try` exit is NOT a union node; although lambdas in one branch can
be completed according to types' of lambdas in another, data does not
flow between the branches anyway (since we don't know how much of the
`try` executed before jumping into `catch`, and `catch`es are mutually
exclusive) so a `try` expression is more like `when` than a function
call with called-in-place-exactly-once arguments. The fact that
`exitTryExpression` used `processUnionOfArguments` in a weird way
should've hinted at that, but now we know for certain.
2022-12-08 10:19:29 +00:00
pyos 16b8811697 FIR DFA: take all statements from ?. if result is non-null.
I.e. a?.f(b as T) != null => b is T.

This also allows to remove the copyAllInformationFrom hack by moving the
edge directly in the control flow graph.
2022-12-08 10:19:28 +00:00
Simon Ogorodnik 513af2dfbc FIR. Refactor smart-cast representation in FIR tree
Make smart-casts non-transparent expression without delegation
to underlying FirQualifiedAccessExpression, as children delegation in
fir tree has unclear semantics
Remove two different kinds of tree nodes for smart-casts
2022-08-15 21:46:11 +00:00
Andrey Zinovyev 7e9f27436a [FIR] Fix cfg for safe call inside elvis 2021-07-19 13:40:31 +03:00
Dmitriy Novozhilov 4225813d79 [FIR] Update CFG dumps according to changed order of visiting class children 2021-06-29 21:03:29 +03:00
Ilya Kirillov 0cf00d0f72 FIR: fix FirDefaultPropertyAccessor phase to BODY_RESOLVE 2021-04-15 15:23:56 +03:00
Dmitriy Novozhilov 102c9c08d0 [FIR] Resolve elvis call as special synthetic call
Before that commit we desugared `a ?: b` as

when (val elvis = a) {
    null -> b
    else -> elvis
}

It was incorrect, because `a` should be resolved in dependent mode,
  but when it was `elvis` initializer it was resolved in independent
  mode, so we can't infer type for `a` in some complex cases
2020-07-02 15:10:51 +03:00
Dmitriy Novozhilov 26458875d5 [FIR] Add checker for uninitialized properties 2020-06-19 15:53:09 +03:00
Dmitriy Novozhilov 12ed8c3bb4 [FIR-TEST] Update CFG dumps according to new nodes order 2020-06-19 15:53:04 +03:00
Dmitriy Novozhilov 87859b0faa [FIR] Introduce new algorithm for building CFG for declarations 2020-06-19 15:53:00 +03:00
Dmitriy Novozhilov 1d39270b3e [FIR] Don't pass data flow to property accessors of non local classes 2020-04-03 10:08:24 +03:00
Dmitriy Novozhilov 1d1b8d3290 [FIR-TEST] Update cfg dumps according to previous commits 2020-04-03 10:08:23 +03:00
Dmitriy Novozhilov 8cb6e8f8af [FIR] Add control flow graph for class initialization 2020-04-03 10:08:17 +03:00
Dmitriy Novozhilov cc07ae96b3 [FIR-TEST] Move analysis tests to separate module 2020-03-19 09:51:01 +03:00