Commit Graph

20 Commits

Author SHA1 Message Date
Andrew Trick
1b72c7bbf6 SILGenCleanup: extend to handle trivial local var scopes
Improves OSSALifetimeCompletion to handle trivial variables when running from
SILGenCleanup. This only affects lifetime dependence diagnostics.

For the purpose of lifetime diagnostics, trivial local variables are only valid
within their lexical scope. Sadly, SILGen only know how to insert cleanup code
on normal function exits. SILGenCleanup relies on lifetime completion to fix
lifetimes on dead end paths.

  %var = move_value [var_decl]
  try_apply %f() : $..., normal bb1, error error
error:
  extend_lifetime %var <=== insert this
  unreachable

This allows Span to depend on local unsafe pointers AND be used within
throwing closures:

    _ = a.withUnsafeBufferPointer {
      let buffer = $0
      let view = Span(_unsafeElements: buffer)
      return view.withUnsafeBufferPointer(\.count)
    }
2025-01-23 12:42:43 -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
be88e7c9d9 [NFC] OSSACompleteLifetime: Tweak control flow.
Use a switch rather than several ifs.
2024-12-06 16:22:24 -08:00
Nate Chandler
31675d6a1e [Gardening] Delete dead comment.
This comment referred to the now-deleted workaround
AvailabilityWithLeaks boundary kind.
2024-10-08 12:34:06 -07:00
Nate Chandler
dd730b849c [LifetimeCompletion] Flag instructions dead_end. 2024-07-03 16:44:35 -07:00
Nate Chandler
d641dc65bf [UnreachableLifetimeCompletion] Keep ctor arg.
Don't drop the argument, use it to initialize the member.
2024-07-03 15:27: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
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
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
2ee40246b8 [NFC] LifetimeCompletion: operator<<(boundary). 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
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
Meghana Gupta
3d75abc570 Add an option to force boundary completion of lexical values 2023-04-21 22:41:22 -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