Commit Graph

185 Commits

Author SHA1 Message Date
Meghana Gupta
6f375aa6b6 Look through forwarding instructions while querying ownership root
Fixes rdar://142507746
2025-01-10 11:52:06 -08:00
Meghana Gupta
4cab04e190 Fix reborrow verifier to look through borrowed from 2024-12-16 10:23:18 -08:00
Andrew Trick
4612728581 [NFC] Add BeginApplyInst::getEndApplyUses() API.
A begin_apply token may be used by operands that do not end the coroutine:
mark_dependence.

We need an API that gives us only the coroutine-ending uses. This blocks
~Escapable accessors.

end_borrow is considered coroutine-ending even though it does not actually
terminate the coroutine.

We cannot simply ask isLifetimeEnding, because end_apply and abort_apply do not
end any lifetime.
2024-11-18 01:37:00 -08:00
Erik Eckstein
7bf0010c92 SIL: remove computeIsReborrow
This API computes the re-borrow flags for guaranteed phis based on the presence of forwarding instructions in the incoming values.
This is not correct in all cases, because optimizations can optimize away forwarding instructions.

Fixes a verifier crash: rdar://139280579
2024-11-12 09:26:59 +01:00
Erik Eckstein
83224b255e SIL: automatically set the reborrow flags for phi-arguments when creating an end_borrow or setting the operand of an end_borrow
This is done for all transitively incoming phi-arguments of an end_borrow operand.
2024-11-12 09:26:58 +01:00
Nate Chandler
5a93b7d7d5 [Test] Underscored visit_inner_adjacent_phis.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:18 -07:00
Nate Chandler
1fbc526bc8 [Test] Underscored find_borrow_introducers.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:18 -07:00
Nate Chandler
a3922144f6 [Test] Underscored find_enclosing_defs.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:18 -07:00
Nate Chandler
7119b9e713 [Test] Underscored has_pointer_escape.
Use underscores rather than hyphens so that text editors understand the
name as a single word.
2024-07-25 13:50:18 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -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
81fa65772f [OwnershipLiveness] End at extend_lifetime.
When visiting consumes, also visit `extend_lifetime` instructions.
These instructions are not lifetime ending, but together with the
consumes, they enclose the users of a value.

Add a flag to LinearLiveness to control whether these instructions are
added so that the verifier can use verify that all such instructions
appear outside the linear lifetime boundary (not including them).
2024-06-05 16:28:28 -07:00
Nate Chandler
29d046fa42 [SIL] Add BorrowedValueKind::BeginApplyToken.
The token is a guaranteed value introduced by the begin_apply and
consumed by its end_apply, abort_apply, and end_borrow users.
2024-04-25 17:03:43 -07:00
Erik Eckstein
96cf03fe95 OwnershipUtils: fix a warning
Removed a left over from the work on the borrowed-from instruction
2024-04-15 12:18:05 +02:00
Erik Eckstein
e14c1d1f62 SIL, Optimizer: update and handle borrowed-from instructions
Compute, update and handle borrowed-from instruction in various utilities and passes.
Also, used borrowed-from to simplify `gatherBorrowIntroducers` and `gatherEnclosingValues`.
Replace those utilities by `Value.getBorrowIntroducers` and `Value.getEnclosingValues`, which return a lazily computed Sequence of borrowed/enclosing values.
2024-04-10 13:38:10 +02:00
Erik Eckstein
ac4bc89c9a SIL: add the borrowed-from instruction.
It declares from which enclosing values a guaranteed phi argument is borrowed from.
2024-04-10 13:38:10 +02:00
Andrew Trick
d7b9149ee5 Fix visitNonEscapingLifetimeEnds to handle mark_dependence uses
Now it visits unknown uses separately rather than asserting.
2024-03-22 14:29:57 -07:00
Meghana Gupta
3ebef80261 Fix utilities that may see phis of mark_dependence [nonescaping] 2024-03-20 15:44:11 -07:00
Nate Chandler
9f6c30919b [NFC] SIL: Typed begin_borrow's isLexical. 2024-03-08 22:27:50 -08:00
Andrew Trick
37171e698a Handle mark_dependence [nonescaping] like a borrowing instruction. 2024-01-22 23:57:03 -08:00
Evan Wilde
312bd47f4c Merge remote-tracking branch 'main' into 'rebranch' 2023-10-16 23:00:12 -07:00
Joe Groff
25061fb281 Merge pull request #69169 from jckarter/store-borrow-lifetime-nesting
SIL: Treat store_borrow as borrowing its source, and have the move-only checker account for borrow scopes.
2023-10-16 13:51:40 -07:00
Joe Groff
1dcf271fe0 SIL: Treat store_borrow as borrowing its source, and have the move-only checker account for borrow scopes.
When rewriting uses of a noncopyable value, the move-only checker failed to take into account
the scope of borrowing uses when establishing the final lifetimes of values. One way this
manifested was when borrowed values get reabstracted from value to in-memory representations,
using a store_borrow instruction, the lifetime of the original borrow would be ended immediately
after the store_borrow begins rather than after the matching end_borrow. Fix this by, first,
changing `store_borrow` to be treated as a borrowing use of its source rather than an
interior-pointer use; this should be more accurate overall since `store_borrow` borrows the
entire source value for a well-scoped duration balanced by `end_borrow` instructions. That done,
change MoveOnlyBorrowToDestructureUtils so that when it sees a borrow use, it ends the borrow
at the end(s) of the use's borrow scope, instead of immediately after the beginning of the use.
2023-10-16 09:12:25 -07:00
swift-ci
56f70e947a Merge remote-tracking branch 'origin/main' into rebranch 2023-10-10 11:53:54 -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
Evan Wilde
309aed4925 Add SmallSetVector replacement
llvm::SmallSetVector changed semantics
(https://reviews.llvm.org/D152497) resulting in build failures in Swift.
The old semantics allowed usage of types that did not have an
`operator==` because `SmallDenseSet` uses `DenseSetInfo<T>::isEqual` to
determine equality. The new implementation switched to using
`std::find`, which internally uses `operator==`. This type is used
pretty frequently with `swift::Type`, which intentionally deletes
`operator==` as it is not the canonical type and therefore cannot be
compared in normal circumstances.

This patch adds a new type-alias to the Swift namespace that provides
the old semantic behavior for `SmallSetVector`. I've also gone through
and replaced usages of `llvm::SmallSetVector` with the
`Swift::SmallSetVector` in places where we're storing a type that
doesn't implement or explicitly deletes `operator==`. The changes to
`llvm::SmallSetVector` should improve compile-time performance, so I
left the `llvm::SmallSetVector` where possible.
2023-07-25 12:28:27 -07:00
Nate Chandler
194904f854 [OwnershipUtils] NFC: Deduplicated implementation.
The only difference between visitLocalScopeEndingUses and
getLocalScopeEndingInstructions is that the former evaluates a lambda
with each `Operand *` and the latter adds `->getUser()` to a
SmallVectorImpl for each.  So factor the latter through the former and
add the users to the SmallVectorImpl in the lambda.
2023-07-11 08:22:59 -07:00
Nate Chandler
9417651d00 [Test] Ensourced find-borrow-introducers.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
8f0378c3bc [Test] Ensourced find-enclosing-defs.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
a3db694af2 [Test] Ensourced visit-inner-adjacent-phis.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Nate Chandler
2e317907fd [Test] Ensourced has-pointer-escape.
Moved the test next to the code it calls.
2023-07-04 11:52:13 -07:00
Meghana Gupta
07863444d2 Introduce ForwardingOperation wrapper type
APIs on ForwardingInstruction should be written as static taking in
a SILInstruction as a parameter making it awkward.

Introduce a ForwardingOperation wrapper type and move the apis from the
old "mixin" class to the wrapper type.

Add new api getForwardedOperands()
2023-07-01 10:42:38 -07:00
Meghana Gupta
df1c3b7ac1 Simplify select_enum forwarding instruction
Remove OwnershipForwardingSelectEnumInstBase, inherit SelectEnumInst from
OwnershipForwardingSingleValueInstruction instead.
2023-06-28 14:39:21 -07:00
Meghana Gupta
28df449d38 Merge pull request #66723 from meg-gupta/improvefindpointerescape
Refactor swift::findPointerEscape and handle additional cases
2023-06-21 21:04:21 -07:00
Meghana Gupta
6d3b4e0520 Handle borrow uses and interior pointer uses in swift::findPointerEscape 2023-06-21 00:35:42 -07:00
Meghana Gupta
4862eccd8d Consolidate swift::findPointerEscape(SILValue) and swift::findPointerEscape(BorrowedValue) 2023-06-20 21:13:55 -07:00
Meghana Gupta
031255c2d8 Rename hasPointerEscape -> findPointerEscape 2023-06-20 21:13:55 -07:00
Meghana Gupta
16c300c2af Remove OwnershipForwardingConversionInst, ConversionInst.
Add new ConversionOperation abstraction, use this in place of ConversionInst
2023-06-15 10:53:28 -07:00
Meghana Gupta
6df7ebbb4e Update and add new apis on ForwardingInstruction 2023-06-15 10:53:06 -07:00
Meghana Gupta
43b20ca3d8 Remove special case for MoveOnlyWrapperToCopyableValueInst and MoveOnlyWrapperToCopyableBoxInst 2023-06-14 12:10:21 -07:00
Meghana Gupta
0e27cd18d7 Remove FirstArgOwnershipForwardingSingleValueInst, GuaranteedFirstArgForwardingSingleValueInst, OwnedFirstArgForwardingSingleValueInst, AllArgForwardingSingleValueInst
Replace their uses with OwnershipForwardingSingleValueInstruction.
2023-06-14 12:04:58 -07:00
Meghana Gupta
7cb3733e29 Rename OwnershipForwardingMixin -> ForwardingInstruction 2023-06-14 10:40:32 -07:00
Michael Gottesman
70ab38d9da [move-only] Add a new instruction: moveonlywrapper_to_copyable_box.
I am going to use this to unwrap ${ @moveOnly T } so that I can pass it to
partial_apply that expect a ${ T }
2023-06-06 14:26:22 -04:00
Meghana Gupta
1dc713e2f7 Add new flags "reborrow" and "escaping" to SILArgument.
"reborrow" flag on the SILArgument avoids transitive walk over the phi operandsi
to determine if it is a reborrow in multiple utilities.
SIL transforms must keep the flag up-to-date by calling SILArgument::setReborrow.
SILVerifier checks to ensure the flag is not invalidated.

Currently "escaping" is not used anywhere.
2023-05-11 12:31:37 -07:00
nate-chandler
2984f0a236 Merge pull request #65417 from nate-chandler/rdar108514447
[SemanticARCOpts] Promote moved load [copy]s to load_borrows.
2023-04-27 06:59:02 -07:00
Nate Chandler
b686e81085 [OwnershipUtils] Add move as OwnedValueIntroducer. 2023-04-25 11:37:30 -07:00
Michael Gottesman
c577055100 [move-only] Instead of using AccessUseVisitor to visit addresses use TransitiveAddressVisitor.
This makes it so that the move address checker is not dependent on starting the
traversal at a base object. I also included verifier checks that the API can
visit all address uses for:

1. project_box.
2. alloc_stack.
3. ref_element_addr.
4. ref_tail_addr.
5. global_addr_inst.

this is because this visitor is now apart of the SIL API definition as being
able to enumerate /all/ addresses derived from a specific chosen address value.

This is a refactoring NFCI change.

rdar://108510644
2023-04-25 10:51:03 -07:00
nate-chandler
28bbbd5614 Merge pull request #65114 from nate-chandler/nfc/20230412/2/delete-duplicate-api
[SIL] NFC: Removed visitBorrowIntroducingUserResults.
2023-04-24 15:20:16 -07:00
Nate Chandler
c40f7c3d0a [OwnershipUtils] Undef isn't introduced/enclosed.
Previously, calling `visitEnclosingDefs` or `visitBorrowIntroducers`
would crash if the `SILValue` argument were an instance of `SILUndef`
because both instantiate a `::FindEnclosingDefs` with the the result of
of calling `getFunction()` on that argument and `::FindEnclosingDefs` in
turn uses that result to create a `ValueSet`; but
`SILUndef::getFunction` returns `nullptr`, which is illegal to use as
the function for a `ValueSet`(or any other data structure relying on
`NodeBits`).

If the function specified as a separate argument, no values would be
visited and `true` would be returned.  Instead of burdening the API with
a separate argument, check for `SILUndef` up front and return `true`.
2023-04-19 13:57:59 -07:00
Meghana Gupta
264d86d26c Implement InteriorLivenessVisitor::handleInnerBorrow for all BorrowingOperand kinds
Not all BorrowingOperand introduce a BorrowedValue. Add a new api to get the defining value
for use in InteriorLivenessVisitor::handleInnerBorrow.
2023-04-12 14:42:23 -07:00