Commit Graph

39 Commits

Author SHA1 Message Date
Nate Chandler
bf80307c03 [OSSACompleteLifetime] Recurse into scoped addrs.
Previously, when determining and completing lifetimes of scoped
addresses, `computeTransitiveLiveness` was used to determine the
liveness used for completing the lifetime.

That approach had two problems:
(1) The function does not find scope-ending uses of `load_borrow`s.
    The result was determining that the lifetime of the enclosing
    `store_borrow` ended before that of the `load_borrow`.
(2) The function did not complete lifetimes of values defined within the
    scoped address whose lifetimes the scoped address had to contain.
    This was an inconsistency between the handling of scoped addresses
    and that of values.

Here, both are addressed by implementing a `TransitiveAddressWalker` (as
`computeTransitiveLiveness`'s callee does) which not only visits
existing `end_borrow`s of `load_borrows` but completes them (and other
inner guaranteed values or scoped addresses).

rdar://141246601
2024-12-13 15:04:29 -08:00
Nate Chandler
618b99c3e9 [NFC] OSSACompleteLifetime: Extracted method.
In preparation to expand it.
2024-12-13 12:22:31 -08:00
Nate Chandler
be7518b389 [OSSACompleteLifetime] Handle scoped addresses.
Complete scopes of scoped addresses (introduced by `store_borrow` and
`begin_access`) in dead end blocks via
`ScopedAddressValue::computeTransitiveLiveness`.

rdar://141037060
2024-12-06 16:22:24 -08:00
Nate Chandler
7fb5d31261 [NFC] OSSACompleteLifetime: Move function up.
Avoid a separate declaration.
2024-12-06 16:22:24 -08:00
Nate Chandler
36203de6d4 [NFC] OSSACompleteLifetime: Extracted function.
In preparation for adding a second caller.
2024-12-06 16:22:24 -08:00
Nate Chandler
7012edc06f [Gardening] Test: Updated comment. 2024-12-05 07:31:19 -08:00
Erik Eckstein
abbd9d3fd6 OSSALifetimeCompletion: need to look through borrowed-from when creating an end_borrow
Fixes a verifier crash

rdar://134728428
2024-09-03 14:46:13 +02:00
Nate Chandler
d669c1d220 [LifetimeCompletion] Avoid instruction list walk.
When computing the available region, a forward walk is done from the
non-lifetime-ending boundary of the live region.  That boundary consists
of (1) the target blocks of boundary edges, (2) dead defs, and (3) last
users which are non-consuming.  This forward walk is done at the block
level, so neither the specific dead def (for (2)) nor specific last
non-consuming user (for (3)) is required to perform the walk; indeed
currently these are computed and then immediately used only to obtain
the blocks in which they appear and then discarded.  Avoid computing the
specific dead defs and specific last non-consuming users by switching to
a lower-fidelity liveness boundary computation via
`PrunedLivenessBlockBoundary`.
2024-08-26 16:24:51 -07:00
Nate Chandler
812891cf81 [NFC] PrunedLiveness: Clarified boundary API.
When checking whether an instruction is contained in a liveness
boundary, a pointer to a DeadEndBlocks instance must always be passed.
When the pointer is null, it is only checked that the instruction occurs
within the direct live region.  When the pointer is non-null, it is
checked whether the instruction occurs within the region obtained by
extending the live region up to the availability boundary within
dead-end regions that are adjacent to the non-lifetime-ending portion of
the liveness boundary.
2024-07-23 13:38:35 -07:00
Nate Chandler
1d47d3ca0d [OME] Erase dead_end lifetime ends.
Such instructions are inserted to ensure complete OSSA lifetimes and
should be removed when lowering out of OSSA.
2024-07-03 16:44:35 -07:00
Nate Chandler
dd730b849c [LifetimeCompletion] Flag instructions dead_end. 2024-07-03 16:44:35 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Nate Chandler
5dc3cf1296 [LifetimeCompletion] Removed "with leaks" mode.
Now that the two known issues which resulted in invalid SIL being
provided to lifetime completion have been addressed, tighten up the
completion done on the availability boundary not to allow leaks.
2024-06-06 16:48:46 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Nate Chandler
84da0ed4c5 [LifetimeCompletion] Add extend_lifetimes.
The new instructions are inserted after every "user" (according to
InteriorLiveness' SSAPrunedLiveness instance) outside the linear
liveness boundary.
2024-06-05 16:28:28 -07:00
Nate Chandler
087bf6a75b [LifetimeCompletion] NFC: Add helper.
It visits users discovered by an SSAPrunedLiveness instance (such as
that used by InteriorLiveness) which are outside the LinearLifetime
boundary.
2024-06-05 16:28:28 -07:00
Nate Chandler
65397fafb3 [NFC] LifetimeCompletion: Tweaked helper class.
VisitAvailabilityBoundary now has a single public method.
2024-06-05 16:28:28 -07:00
Nate Chandler
a52cc7ae19 [NFC] LifetimeCompletion: Note boundary kind.
When visiting an availability boundary, note what kind of end is
involved.  For now, there's only one.
2024-06-05 16:28:28 -07:00
Nate Chandler
77d26e1eff [NFC] LifetimeCompletion: Rename helper fn.
It visits the availability boundary, so call it
`visitAvailabilityBoundary`.  It's not clear what "unreachable lifetime
ends" are.
2024-06-05 16:27:45 -07:00
Nate Chandler
632406762c [LifetimeCompletion] Add availability_with_leaks.
The new boundary allows for invalid OSSA where values are not consumed
on paths leading to blocks that exit the function normally.  In such
cases, the value is allowed to continue leaking as before.
2024-05-08 17:15:15 -07:00
Nate Chandler
518de7c6b1 [LifetimeCompletion] Require boundary spec.
Don't default to one boundary or another based on whether the value
being completed is lexical.
2024-05-08 17:15:15 -07:00
Nate Chandler
c11a2cef91 [NFC] LifetimeCompletion: Fix switch order.
Match the declaration order.
2024-05-08 17:15:14 -07:00
Nate Chandler
de5d2ece86 [NFC] LifetimeCompletion: Improve lambda name.
This lambda has to do with availability or the lack thereof but
unreachable instructions are of interest in this context so using the
wrong name confuses things unnecessarily.
2024-05-08 17:15:14 -07:00
Nate Chandler
a0b8324eb3 [Test] Used underscores in test name.
Makes it easier to search for since editors will see it as a single
name.
2024-05-08 17:15:14 -07:00
Nate Chandler
2ca995177c [NFC] LifetimeCompletion: Lift default a level. 2024-05-01 08:57:01 -07:00
Nate Chandler
5383df755a [NFC] LifetimeCompletion: Clarify modes.
Completion is done along a boundary, either the availability or the
liveness boundary.  Represent which with a type.  Update docs and names.
2024-05-01 08:57:01 -07:00
Nate Chandler
fcd25ead54 [NFC] LifetimeCompletion: Clarify doc and code. 2024-05-01 08:57:00 -07:00
Nate Chandler
9c16318ad9 [NFC] LifetimeCompletion: Simplified enum wrapper. 2024-05-01 08:57:00 -07:00
Nate Chandler
6a01bf4d70 [LifetimeCompletion] Don't destroy alloc_boxes.
A destroy_value of an alloc_box unconditionally destroys the value
within the box.  On unreachable paths, such memory may not be
initialized, so it cannot be destroyed unconditionally.  Moreover,
destroying values stored in memory is outside the purview of OSSA
lifetime completion.
2024-04-21 20:56:39 -07:00
Nate Chandler
9ca6b9ac1f [Test] Print to stdout.
In the C++ sources it is slightly more convenient to dump to stderr than
to print to stdout, but it is rather more unsightly to print to stderr
from the Swift sources.  Switch to stdout.  Also allows the dump
functions to be marked debug only.
2023-10-10 08:19:44 -07:00
Nate Chandler
ad33b5de34 [OSSALifetimeCompletion] Handle available boundary
Not every block in a region which begins with the non-lifetime-ending
boundary of a value and ending with unreachable-terminated blocks has
the value available.  If the unreachable-terminated blocks in this
boundary are not available, it is incorrect to insert destroys of the
value in them: it is an overconsume on some paths.  Previously,
however, destroys were simply being inserted at the unreachable.

Here, this is fixed by finding the boundary of availability within that
region and inserting destroys before the terminators of the blocks on
that boundary.

rdar://116255254
2023-10-05 09:15:58 -07:00
Nate Chandler
43d5743875 [OSSALifeComp] NFC: Extracted visit unreachable.
Extracted the new visitUnreachableLifetimeEnds static member of
OSSALifetimeCompletion from the preexisting
endLifetimeAtUnreachableBlocks which now calls through the former.
2023-09-20 13:40:08 -07:00
Nate Chandler
50f2a0250f [Test] Ensourced ossa-lifetime-completion.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Meghana Gupta
3d75abc570 Add an option to force boundary completion of lexical values 2023-04-21 22:41:22 -07:00
Meghana Gupta
8346eb3199 Fix dead end block collection while completing lexical lifetimes
A dead end block can be visited multiple times on each of its
predecessors path. Use BasicBlockWorklist::pushIfNotVisited api for insertion.
2023-04-06 15:47:32 -07:00
Andrew Trick
54d40822f8 Fix a comment typo 2023-04-04 10:22:32 -07:00
Andrew Trick
0c8ecb54bf Revert "MultiDefPrunedLiveness: add support for arbitrary uses/defs." 2023-03-28 17:43:42 -07:00
Andrew Trick
8a0d5ff5fd Fix a comment typo 2023-03-23 18:59:32 -07:00
Andrew Trick
ccd08ca4b4 Add a completeOSSALifetime utility
Add local lifetime-ending operations to any owned or borrowed value.

This puts a single value into valid OSSA form so that linear lifetime
checking will pass.

Also adds UnreachableLifetimeCompletion which fixes OSSA after
converting a code path to unreachable (e.g. DiagnoseUnreachable and MandatoryInlining).
2023-03-01 21:04:09 -08:00