Commit Graph

5 Commits

Author SHA1 Message Date
Brian Norman 75c6d06077 [FIR] Collect local properties for CFG analysis with a FIR visitor
When collecting local properties for property initialization analysis,
the nodes of the CFG were navigated. However, there are problems when
trying to determine what local properties are defined within do-while
loops. This is because the node order of a CFG does not always follow
the FIR structure order.

By converting the collector to a FIR visitor, we can maintain the
structural order needed for finding properties defined within do-while
loops. This does require some additional logic though to make sure we
do not navigate into elements which are not part of the original graph
navigation.

^KT-65911 Fixed
2024-03-01 07:12:56 +00:00
Brian Norman fced126c9f [FIR] Properties defined in a do-while may not always be initialized
Local properties defined within the body of a do-while loop can be used
in the condition of the loop. However, use of a `continue` may mean the
property isn't always initialized, even if it is initialized when it is
defined. So while a local property may be within scope and has an
initializer, this doesn't always mean that the property is initialized.

As such, properties that are defined within a do-while loop and also
used in the condition of the same do-while loop should be tracked. Then,
these properties should still be checked for proper initialization even
if they have an initializer.

^KT-64872 Fixed
2024-01-31 13:37:30 +00:00
Denis Zharkov a51078fda6 Turn off optimizations in case of do-while presence 2017-10-02 10:04:16 +03:00
Denis Zharkov 527daced46 Optimize CFG for cases of simple variables
Parameters/vals with an immediate initializer (which we assume is a
rather common situation) do not require any kind of complicated CFA

- Unused vals can be simply determined by linear traversal of
  the pseudocode
- Definite assignment is a bit more complicated: a read-instruction of val
  can be considered as a safe if it's located *after* the first write in
  the pseudocode. It works almost always beside the case with do/while
  (see the test changed). This case will be fixed in the further commits

The test for kt897.kt will also be fixed further, all other changes
might be considered as minor as they mostly change diagnostics for
already red code
2017-10-02 10:04:16 +03:00
Mikhail Glukhikh 436b0ec873 CFA merge for definition / initialization : more accurate handling of unknown variables #KT-13969 Fixed
(cherry picked from commit 4a96589)
2016-09-29 15:56:47 +03:00