Commit Graph

24 Commits

Author SHA1 Message Date
Andrew Trick
43debc529f [NFC] minor cleanup 2025-04-16 16:43:23 -07:00
Andrew Trick
0f728f0514 Fix BorrowingInstruction.visitEndBorrows to handle borrowed-from
For borrowed-from of a reborrow, the value is the block argument. So we need to
look through the borrowed-from user.
2025-02-26 01:40:42 -08:00
Andrew Trick
8decfa4910 Add BorrowingInstruction.innerValue 2025-02-26 00:37:20 -08:00
Andrew Trick
083ab98818 Simplify OwnershipLiveness.swift, remove reborrowingUse.
Remove complexity around reborrows. They no longer need special treatment.
2025-02-25 23:36:14 -08:00
Andrew Trick
907097421b Add BorrowingInstruction.dependentValue and .scopedValue
This consolidates the rules for borrow scopes so we can simplify interior liveness.
2025-02-25 23:08:55 -08:00
Andrew Trick
fda53929c2 Add support for borrowed-from to BorrowingInstruction.
All instructions with a "Borrow" operand ownership must be valid
BorrowingInstructions.
2025-02-25 23:08:54 -08:00
Andrew Trick
6c99017588 Minor comment cleanup and code formatting.
Extracted from the functional changes for clarity.
2025-02-25 23:08:53 -08:00
Erik Eckstein
c5b14c2b93 BorrowUtils: make unchecked_ownership_conversion to guaranteed ownership a BeginBorrowValue
BeginBorrowValue needs to handle all cases where a guaranteed value is produced.
Fixes a compiler crash.
2024-12-21 08:28:21 +01:00
Erik Eckstein
e934bb1321 BorrowUtils: support guaranteed forwarding phis without forwarding instructions when computing enclosing values
For example:

```
  %1 = begin_borrow %0
  %2 = br bb1(%1, %1)
bb1(%3 : @reborrow @guaranteed, %4: @guaranteed):
  // %4 is a guaranteed forwarding phi without any forwarding instructions between the begin_borrow and the incoming value.
```

Also improve the comments
2024-11-12 09:26:58 +01:00
Alexander Cyon
c18a24e499 [SwiftCompilerSources] Fix typos 2024-08-08 22:22:39 -07: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
f9015e0e11 SIL: fix BorrowedValue initializer for non-guaranteed function args 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
Andrew Trick
bdabc2145a Add computeKnownLiveness utility
To fix LifetimeDependenceScopeFixup in the presense of pointer escapes.
2024-03-18 17:38:12 -07:00
Andrew Trick
aa208bbf91 Add SILType::containsNoEscapeFunction()
Add PartialApplyInst.hasNoescapeCapture
Add PartialApplyInst.mayEscape

Refactor DiagnoseInvalidEscapingCaptures. This may change functionality because tuples containing a noescape closure are now correctly recognized. Although I'm not sure such tupes can ever be captured directly.
2024-03-18 17:38:12 -07:00
Andrew Trick
e84bcf520f Add computeBorrowLiveRange
Compute the live range for the borrow scopes of a guaranteed value. This returns a separate instruction range for
each of the value's borrow introducers. Unioning those ranges would be incorrect. We typically want their
intersection.
2024-03-05 17:08:13 -08:00
Andrew Trick
ef940c5297 Redesign gatherBorrowIntroducers to return BeginBorrowValues.
This avoids a lot of confusion because the callers expect this type. Fixing it just required some redundancy and
bridging in the EnclosigValues implementation.
2024-03-05 17:08:13 -08:00
Andrew Trick
15fef6868c BorrowUtils: add a comment 2024-02-12 09:57:14 -08:00
Andrew Trick
37171e698a Handle mark_dependence [nonescaping] like a borrowing instruction. 2024-01-22 23:57:03 -08:00
Andrew Trick
8341b73b8c Update OwnershipLiveness comments for code review. 2024-01-17 09:07:02 -08:00
Andrew Trick
196ae17405 Add a reborrow cache to EnclosingValues.
Along with motivating unit tests.
2024-01-17 08:37:14 -08:00
Andrew Trick
c10c545cbe OwnershipUtils review feedback: code formatting. 2024-01-17 08:37:14 -08:00
Andrew Trick
d445754e6f OwnershipUtils review feedback: Comments and examples. 2024-01-17 08:37:14 -08:00
Andrew Trick
1646a667c1 Add BorrowUtils: OSSA infrastructure for borrow scopes.
Key APIs necessary for using OSSA.

- BorrowingInstruction

- BeginBorrowValue

- scopeEndingOperands

- BorrowIntroducers

- EnclosingValues

- innerAdjacentPhis

These need to be complete to be correct.
2024-01-17 08:37:14 -08:00