Commit Graph

96 Commits

Author SHA1 Message Date
Dmitriy Novozhilov fc57f48c8f [FIR] Union CFG edges from postponed lambdas only if outer call was analyzed independently
Before this change nodes unification was called if outer call was
  completed in the FULL mode, but it may happen even if this call is
  actually a part of some other outer call
2023-07-07 06:45:20 +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
Svyatoslav Kuzmich a3e2d2804c [Wasm] Update testData after adding K2 and new test infra support.
- Actualize muted K2 tests
- Actualize muted K1 tests with module systems because legacy Wasm test
  infra had no respect for "// MODULE: ..." test directives
2023-06-25 10:20:40 +02:00
Dmitriy Novozhilov 6409bf2fe8 [FIR] Store expressions of receivers inside candidates instead of ReceiverValue
This is needed because of mutable nature of receiver values: implicit
  receiver values can be modified because of smartcasts, but in candidate
  we need to store snapshot of receiver in the form it was at the beginning
  of the resolution

^KT-58823 Fixed
2023-06-09 22:51:31 +00:00
Dmitriy Novozhilov c55ddab1bf [Test] Reproduce KT-58823 2023-06-09 22:51:31 +00:00
Sergej Jaskiewicz f2031ae642 [IR] Don't print multifile/synthetic facade class names in irText tests
This only applies to JVM and fq-names in declaration references
in IR dumps.

This enables us to run more irText tests on platforms other than JVM
(see KT-58605).
2023-06-05 10:40:17 +00:00
Sergej Jaskiewicz fd76a34277 [IR] Don't print flags in declaration references in irText tests
This doesn't reduce the quality of tests, because the flags are still
printed for declarations themselves. We only omit them in references.

However, this makes the tests more compatible with non-JVM backends
(see KT-58605), because flags of referenced stdlib declarations may
differ among target platforms.
2023-05-30 17:26:30 +00:00
Dmitriy Novozhilov d7d7620db2 [FIR2IR] Correctly calculate signature for non-dynamic calls on dynamic receiver
If dispatch receiver is dynamic and call on it is not dynamic that means
  that this call was resolved to some specific declaration because of
  smartcast. So we should use original type of this declaration as
  dispatch receiver during calculation of IdSignature instead of Any
  (which came from dynamic type). Otherwise we will have two different
  signatures for the same member declaration

^KT-57682 Fixed
2023-04-03 12:20:01 +00:00
Kirill Rakhman 7a6a3a0b1d [FIR2IR] Fix generation of val initialization after smart-cast, again
#KT-57284
2023-03-17 13:29:48 +00:00
Kirill Rakhman 0e721c8fc2 [FIR2IR] Fix generation of val initialization after smart-cast
If neither setter nor backing field were found for an assignment call,
search overridden properties for backing fields.

^KT-57105 Fixed
2023-03-10 09:30:51 +00:00
pyos 9f17b5de97 FIR CFA: add edges according to constructor delegation 2023-01-26 13:12:11 +00:00
Artem Kobzar 71486a321c [K/JS] Add support of compilation with ES-classes 2023-01-17 18:14:17 +00:00
pyos e86b87fe0b Test: FIR CFA: fix the names of some nodes 2023-01-10 15:40:52 +02:00
pyos b548473544 FIR CFA: automatically compute node levels 2023-01-10 15:40:50 +02:00
pyos 17ee8f3a7b FIR CFA: put primary constructor before other class members 2023-01-10 15:40:50 +02:00
pyos c6e9afb788 FIR CFA: remove class initializer part nodes
Instead, attach subgraphs directly to the class enter node.
2023-01-10 15:40:50 +02:00
pyos 54f32a6fba Test: FIR CFA: index nodes in rendering order 2023-01-10 15:40:49 +02:00
pyos 4c6eff9174 FIR CFA: compute subgraph relationships automatically
No more `addSubGraph`. Also no more `owner` in graphs.

^KT-40526 Obsolete
^KT-40582 Obsolete
2023-01-10 15:40:48 +02:00
pyos cb8cb1f610 FIR CFA: attach accessors and nested classes as class subgraphs 2023-01-10 15:40:48 +02:00
pyos 5d4fb3ead8 FIR CFA: add control flow between default parameter values
function enter -> default 1 -> default 2 -> rest of function
                   \----------^ \----------^

This probably has no effect (in non-stupid code, at least), but it makes
graph construction more architecturally correct (now value parameters'
subgraphs get attached to a node).
2023-01-10 15:40:48 +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 aadea0e26f FIR CFA: properly visit subgraphs in checkers
Interpretation: a graph A is a subgraph of B if information available at
nodes of A depends on the paths taken in B. For example, local classes
are subgraphs of a graph in which they are declared, and members of
those classes are subgraphs of the local class itself - because these
members can reference captured values.

Consequences:

 * if graph G is a subgraph of node N, then G is a subgraph of N's
   owner;
 * `ControlFlowAnalysisDiagnosticComponent` will only visit root graphs;
 * `graph.traverse` will ignore subgraph boundaries, as if all subgraphs
   are inlined into one huge root graph;
 * if a control flow checker needs information from a declaration to
   which a graph is attached, it must look at subgraphs explicitly.

For example, consider the `callsInPlace` checker. When a function
has a `callsInPlace` contract and a local declaration, the checker must
visit that local declaration to ensure it does not capture the allegedly
called-in-place argument - hence `graph.traverse` will look at the
nodes. However, the local declaration can also be a function with its
own `callsInPlace` contracts, so the checker should also run for it in
isolation. If that sounds quadratic, that's because unfortunately it is.
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
Steven Schäfer 6af616d3c3 FIR: make declarations marked with 'override' implicitly open
#KT-52236 Fixed
2022-12-14 21:46:41 +00:00
pyos c4c05f5248 FIR CFG: remove ordering from control flow through in-place lambdas
Old graph:

  arg -> lambda enter -> ... -> lambda exit -> lambda enter -> ... ->
   -> lambda exit -> call

New graph:

  arg -+-> lambda enter -> ... -> lambda exit -+-> call
       \-> lambda enter -> ... -> lambda exit -/
2022-12-08 10:19:31 +00: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
Ilya Chernikov 78ca733c38 FIR JS: add K2 variants of all other JS tests
except tests that are not possible to add without some modifications in
the test infra. See todos on the commented-out test declarations
2022-11-12 16:28:24 +01:00
Ilya Chernikov 5b3816cce5 Test infra: refactor IGNORE_BACKEND directive
treat it as a general one, introduce *_K1 and *_K2 variants for
more specific ignoring
2022-11-12 16:28:23 +01:00
pyos 5a2ec4a0d5 FIR CFG: merge data flow if called-in-place lambda may not be called 2022-07-11 18:11:30 +03:00
pyos 63b0708ed5 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
2022-06-15 20:05:49 +00:00
Denis.Zharkov c1904004c4 FIR: Fix case when smartcast receiver is used for call to private method
^KT-54432 Fixed
2022-06-01 16:02:30 +00:00
Dmitriy Novozhilov 6e2402620f [FIR] Fix collecting member candidates on receiver with smartcast
^KT-51460 Fixed
^KT-51827
2022-04-07 12:18:48 +00:00
Ilya Chernikov 5d6e2b57a7 Sort sealed class inheritors to ensure reproducible builds with IC
without this sorting the inheritors field in the metadata may depend on
whether some inheritors are compiled in the IC round or not.
2022-03-30 08:35:30 +00:00
Alexander Korepanov 69295f2cf0 [JS IR] IC invalidation refactoring
- Huge refactoring for IC
  - Update hash combination logic
  - Introduce value class for IC hashes
  - Calc md5 directly by function IR
  - Split IC logic by classes
  - Move JsIrLinkerLoader into separate file
  - CacheUpdateStatus is a sealed class
  - Render TYPE_PARAMETER reified flag

^KT-51081 Fixed
^KT-51084 Fixed
2022-03-15 05:34:19 +00:00
Dmitriy Novozhilov 330574cab6 [FIR] Properly support smartcasts on stable when subjects in when conditions
^KT-49860 Fixed
2021-11-26 11:26:21 +03:00
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00
Dmitriy Novozhilov b454fcc1e0 [FIR] Save IR dumps to .ir.txt files instead of .txt in tests
This is needed to avoid clashes between different dumps from different
  handlers
2021-10-12 17:26:36 +03:00
Dmitry Petrov 31d7d341d4 JVM_IR KT-41214 minor: update testData 2021-10-09 17:07:37 +03:00
Dmitriy Novozhilov 63d841247c [FIR2IR] Properly setup IrClass.sealedSubclasses 2021-10-09 17:07:36 +03:00
Svyatoslav Kuzmich 6eb81517a0 [Wasm] Unmute passed Wasm tests 2021-10-02 06:14:35 +00:00
Svyatoslav Kuzmich c88cde2f8b [Wasm] DONT_TARGET_WASM_BACKEND => IGNORE_BACKEND in testdata 2021-10-02 06:14:35 +00:00
Alexander Udalov afacff326d JVM IR: fix smart cast on argument of 'throw'
#KT-48163 Fixed
2021-08-09 22:34:44 +02:00
Dmitriy Novozhilov 1d491fdce6 [FIR] Don't create union call node for lambda from one when branch and call from condition of another 2021-08-06 22:57:18 +03:00
Tianyu Geng 4726dcce40 FIR DFA: smartcast variable to Nothing? on null assignment
In order to make resolution still work for members not available from
`Nothing`, we track the type without `Nothing?` and use that for
resolution instead.
2021-08-06 22:57:15 +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
Andrey Zinovyev d360932ebc [FIR] Fill overriddenSymbols for fake overridden IrProperty 2021-06-17 13:24:12 +03:00
Mikhail Glukhikh a255f44d6e FIR2IR KT-46578 add overridden properties generation 2021-05-14 16:20:20 +03:00
Dmitry Petrov 53c1de172f IR KT-46578 add IrProperty#overriddenSymbols 2021-05-14 16:20:18 +03:00
Ilya Kirillov 0cf00d0f72 FIR: fix FirDefaultPropertyAccessor phase to BODY_RESOLVE 2021-04-15 15:23:56 +03:00