Commit Graph

10 Commits

Author SHA1 Message Date
Hamish Knight
c3b055a9a8 [Profiler] Improve if statement coverage
Fix counters for regions following `else if`s, fix
the counters for `else if` conditions, and fix
handling of `break` statements. Also while here,
clean up the handling of branch exit regions such
that we don't generate multiple overlapping
regions for each branch, but a single region at
the end of the entire `if` statement that accounts
for all exiting control flow.

rdar://104078910
rdar://104079242
2023-12-04 11:09:01 +00:00
Hamish Knight
322ce4e3f4 [Profiler] Fix handling of property wrapper backing inits
Previously we were walking into the
PropertyWrapperValuePlaceholderExpr when generating
coverage for a property wrapper backing initializer.
This meant that we were duplicating the coverage of
the initializer expression, and it could cause
crashes if a refined counter was introduced within
the top-most expression region, such as with a
throwing expression in a `try!`.

rdar://118939162
2023-11-29 22:58:29 +00:00
Hamish Knight
b430a025ea Merge pull request #69986 from hamishknight/try-try-again 2023-11-27 20:18:53 +00:00
Hamish Knight
ff1c42aabd [Profiler] Fix throwing expressions in if conditions
Previously we would ignore the effect that an if
statement or ternary's condition exit counter might
have on its branches, as we assumed a condition
can't do any control flow. However, in the case
where the condition throws an error, we need to
account for the error branch.
2023-11-21 15:02:56 +00:00
Hamish Knight
59275b20b1 [Profiler] Correctly handle try? expressions
Ensure that `try?` expressions appropriately
scope the regions generated by child
error-throwing expressions, such that the
non-error branch does not extend beyond the region
of the `try?`.
2023-11-21 15:02:56 +00:00
Hamish Knight
e8d3d1aef3 [Profiler] Fix ternary error handling coverage
Previously the branches of a ternary would cut off
the coverage after a throwing expression, since
they have their own region, and we pop child
regions when leaving. Update the logic to use the
existing counter adjustment logic when we leave
the scope, ensuring that we push a new counter to
reflect the exit count of the scope.
2023-11-21 15:02:56 +00:00
Hamish Knight
ff145a261b [test] Couple of coverage test tweaks 2023-11-17 01:16:20 +00:00
Hamish Knight
d9f3047871 [Profiler] Fix DoCatchStmt coverage handling
The logic here previously worked by computing the
exit count by taking the parent count and
subtracting any control flow that jumped out of the
clauses. With `try` handling fixed, this no longer
works correctly, since a `try` shouldn't be
subtracted if the error is caught be one of the
catches, as that's not actually leaving the
statement. We could write the logic to determine
where a `try` is jumping to, but the logic here is
already pretty brittle, relying on being sprinkled
in various different places.

For now, let's take the more straightforward
approach and handle do-catches the same way we
handle switches, we initialize the exit counter to
0, and add on each exit count of each branch. This
lets us re-use the existing CaseStmt handling
logic. This doesn't necessarily produce the most
optimal counter expressions, but I want to replace
this all with a SILOptimizer pass anyway, which
will be able to much more easily compute optimal
counter expressions.

rdar://100470244
2023-11-16 17:28:57 +00:00
Hamish Knight
49ad980b86 [Profiler] Map regions for error-throwing AST nodes
Map a counter for the error branch of a given
potentially-throwing expression, and subtract it
from the following region count.

rdar://34244637
2023-11-16 17:28:57 +00:00
Hamish Knight
509a78102b [test] Rename a test file
And rename the functions in it
2023-11-16 17:28:57 +00:00