Commit Graph

6 Commits

Author SHA1 Message Date
Alexander Cyon
c18a24e499 [SwiftCompilerSources] Fix typos 2024-08-08 22:22:39 -07:00
Erik Eckstein
16697882e8 SimplifyBeginBorrow: fix isDestroyed(after:)
The previous implementation just checked that a value's only uses besides the begin_borrow were destroys. That's insufficient to say the value is destroyed after the borrow (i.e. that all its destroys are dominated by the borrow). Add the relevant dominance check.

Fixes a compiler crash

rdar://119873930
2023-12-20 11:41:40 +01:00
Andrew Trick
b637f06acd [SIL] Bridge findPointerEscape() and fix OnoneSimplifyable
Do not bridge the hasPointerEscape flag until it is implemented.
2023-12-18 09:16:55 -08:00
Erik Eckstein
fc534e1c28 SwiftCompilerSources: better APIs for handling resilient nominal types
* add `NominalTypeDecl.isResilient`

* make the return type of `Type.getNominalFields` optional and return nil in case the nominal type is resilient.
This forces users of this API to think about what to do in case the nominal type is resilient.
2023-11-27 09:21:33 +01:00
Erik Eckstein
3bfabf6e8a SimplifyBeginBorrow: don't remove begin_borrow instructions which have the [point_escape] flag set. 2023-11-14 12:26:23 +01:00
Erik Eckstein
4f09d29afd Optimizer: add simplification for begin_borrow
Try to replace a begin_borrow with its owned operand.

This is either possible if the borrowed value (or a forwarded value if it) is copied:

```
  %1 = begin_borrow %0
  %2 = struct_extract %1     // a chain of forwarding instructions
  %3 = copy_value %1
  // ... uses of %3
  end_borrow %1
```
->
```
  %1 = copy_value %0
  %3 = destructure_struct %0 // owned version of the forwarding instructions
  // ... uses of %3
```

Or if the borrowed value is destroyed immediately after the borrow scope:

```
  %1 = begin_borrow %0
  %2 = struct_extract %1     // a chain of forwarding instructions
  // ... uses of %2
  end_borrow %1
  destroy_value %1           // the only other use of %0 beside begin_borrow
```
->
```
  %2 = destructure_struct %0 // owned version of the forwarding instructions
  // ... uses of %2
  destroy_value %2
```
2023-11-13 20:18:07 +01:00