Commit Graph

1057 Commits

Author SHA1 Message Date
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
Joe Groff
82e566a23a SILGen: Treat Optional x! force unwrapping as a forwarding operation.
Like `?` or property access, `x!` can be borrowing, consuming, or mutated
through depending on the use site and the ownership of the base value.
Alter SILGen to emit `x!` as a borrowing operation when the result is only
used as a borrow. Fix the move-only checker not to treat the unreachable
branch as a dead path for values and try to destroy the value unnecessarily
and possibly out-of-order with cleanups on the value. Fixes rdar://127459955.
2024-05-08 15:35:07 -07:00
Nate Chandler
c84e196b16 [Test] Reenable SIL unit tests on windows.
Use `fflush(stdout)` from C++.

Issue 73252.
2024-05-06 12:20:16 -07:00
Nate Chandler
06921cfe84 [SIL] Hollow out Builtin.copy, deprecate _copy.
The copy operator has been implemented and doesn't use it.  Remove
`Builtin.copy` and `_copy` as much as currently possible.

Source compatibility requires that `_copy` remain in the stdlib.  It is
deprecated here and just uses the copy operator.

Handling old swiftinterfaces requires that `Builtin.copy` be defined.
Redefine it here as a passthrough--SILGen machinery will produce the
necessary copy_addr.

rdar://127502242
2024-05-03 15:56:25 -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
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
nate-chandler
1a0a44c9a0 Merge pull request #73174 from nate-chandler/rdar126863003
[MoveOnlyAddressChecker] Fix empty deiniting struct representation.
2024-04-22 15:38:28 -07:00
nate-chandler
a354528321 Merge pull request #73155 from nate-chandler/lifetime-completion/20240419/1
[LifetimeCompletion] Don't destroy alloc_boxes.
2024-04-22 11:33:36 -07:00
Nate Chandler
5325a4d5f8 [MoveOnlyAddressChecker] Fix empty struct repr.
An empty struct without a deinit gets a single bit which is used to
track the struct's liveness.  Previously, an empty struct with a deinit
also only got a single bit.  Consequently, when discarding the struct
(i.e. dropping the deinit), there was no bit left to represent the
struct.  This resulted in a failure to track liveness for the value.

rdar://126863003
2024-04-22 08:42:14 -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
d11d97d210 [FSPL] Use autogen'd loc. 2024-04-19 12:38:11 -07:00
Nate Chandler
d28a12d356 [MoveOnlyAddressChecker] Handle enum deinits.
Previously, the enum representation was fixed to represent the different
cases payloads separately with the unchecked_take_enum_data_addr
instruction consuming all fields but that whose address is obtained.
In a few places, handling for enum deinits was left undone with an
assertion that the enum not have one.

Here, the deinit bit of the enum is shifted to the end.  And the
assertions are replaced with handling.  Finally, the logic for inserting
destroys after switch_enum_addr instructions is fixed.
2024-04-19 12:37:34 -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
Alejandro Alonso
f5e10e2c0b Get rid of sil instruction and use a builtin for addressOfRawLayout 2024-03-27 11:36:29 -07: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
50b358c64f Merge pull request #72359 from meg-gupta/skiphismdi
Fix utilities that may see phis of mark_dependence [nonescaping]
2024-03-21 18:28:08 -07:00
Nate Chandler
a0a1ff2a04 [MoveOnlyAddressChecker] Fix enum repr.
Change FieldSensitive's enum representation to allow distinguishing
among the elements with associated value.  Consider
`unchecked_take_enum_data_addr` to consume all other fields than that
taken.

rdar://125113258
2024-03-21 10:48:32 -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
4f6f8d9459 [NFC] MoveOnly: Map operand to list of ranges. 2024-03-20 12:52:57 -07:00
Nate Chandler
76348df0cf [MoveOnlyAddressChecker] Fix repr for consumes.
An instruction can consume multiple (discontiguous) fields.  Use a
SmallBitVector to track the fields consumed by an instruction rather
than a TypeTreeLeafRange.

rdar://125103951
2024-03-20 12:08:48 -07:00
Nate Chandler
7feb7e2675 [NFC] FSPrunedLiveness: Move impl to cpp file.
The function is long and will get longer.
2024-03-20 08:20:16 -07:00
Joe Groff
dc4c874c49 Merge pull request #72452 from jckarter/pruned-liveness-try-apply-conditional-def
FieldSensitivePrunedLiveness: Handle conditionality of `try_apply` defs.
2024-03-20 07:43:42 -07:00
Joe Groff
1166f2e0d8 FieldSensitivePrunedLiveness: Handle conditionality of try_apply defs.
A `try_apply` with indirect out arguments is only a def for those arguments on
the success path. Model this by sinking the def-ness of the instruction into the
success branch of the try_apply, and introducing a new `DeadToLiveEdge` mode for
block liveness which stops propagation of use-before-def conditions into the
block that introduced the def. Fixes rdar://118567869.
2024-03-19 22:46:26 -07:00
Erik Eckstein
20ca456601 SIL: fix runtime effect of copy_addr of trivial types
Fixes a false performance error
Reported in https://forums.swift.org/t/generic-type-nolocks-trouble/70667
2024-03-18 13:18:12 +01:00
Meghana Gupta
237b70c7d4 Merge pull request #72314 from meg-gupta/fixnonestructonly
Fix ownership of move-only structs in SIL
2024-03-15 01:28:12 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Meghana Gupta
a15d5fea09 Fix ownership of move-only structs in SIL
Not doing this for enums yet because it is tripping the ownership verifier

We dont have move-only tuples yet.
2024-03-13 16:24:57 -07:00
Nate Chandler
9f6c30919b [NFC] SIL: Typed begin_borrow's isLexical. 2024-03-08 22:27:50 -08:00
John McCall
0a282c044f Unify all of the task-creation builtins coming out of SILGen.
We've been building up this exponential explosion of task-creation
builtins because it's not currently possible to overload builtins.
As long as all of the operands are scalar, though, it's pretty easy
to peephole optional injections in IRGen, which means we can at
least just use a single builtin in SIL and then break it apart in
IRGen to decide which options to set.

I also eliminated the metadata argument, which can easily be recreated
from the substitutions.  I also added proper verification for the builtin,
which required (1) getting `@Sendable` right more consistently and (2)
updating a bunch of tests checking for things that are not actually
valid, like passing a function that returns an Int directly.
2024-03-06 22:21:12 -05:00
cui fliter
127077b3aa chore: fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 17:23:22 +08:00
Slava Pestov
f6ec97db80 SIL: Fix isPotentiallyAnyObject(), and move from AST to SIL 2024-02-29 18:13:28 -05:00
Nate Chandler
6100a1b495 Allow partial consumption of self in deinit.
Basic support for partial consumption in deinit without full support for
all future uses of drop_deinit.
2024-02-28 15:57:09 -08:00
Michael Gottesman
11f0ff6e32 [sil] Ensure that all SILValues have a parent function by making it so that SILUndef is uniqued at the function instead of module level.
For years, optimizer engineers have been hitting a common bug caused by passes
assuming all SILValues have a parent function only to be surprised by SILUndef.
Generally we see SILUndef not that often so we see this come up later in
testing. This patch eliminates that problem by making SILUndef uniqued at the
function level instead of the module level. This ensures that it makes sense for
SILUndef to have a parent function, eliminating this possibility since we can
define an API to get its parent function.

rdar://123484595
2024-02-27 13:14:47 -08:00
Andrew Trick
a048455ad4 Fix MarkUnresolvedReferenceBindingInst handling
It should be treated as a marker instruction. This looks like a mistake.
2024-02-26 00:12:07 -08:00
Andrew Trick
a3cbc28078 SwiftCompilerSources: Add enum BeginAccess.AccessKind
So we can switch over it.
2024-02-25 10:22:06 -08:00
Erik Eckstein
68cc6c8780 SwiftCompilerSources: add all missing instruction classes
And require that all new instructions must be added and registered in SwiftCompilerSources as well.
2024-02-22 07:12:10 +01:00
Ben Barham
5637284e48 Merge pull request #71368 from bnbarham/std-optional-all-the-things
Migrate llvm::Optional to std::optional
2024-02-21 16:54:00 -08:00
nate-chandler
b719a6aac1 Merge pull request #71783 from nate-chandler/nfc/20240221/1
[NFC] Removed non-verifier uses of MemoryLocations.
2024-02-21 12:44:10 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Joe Groff
01405ba2e8 Fixes for compound payloads in borrowing switches.
Fill in a missing path for destructuring loadable elements from
address-only tuples in a borrowing context. Enclose projections in their
own separate accesses so that they are analyzed independently by the
move checker.
2024-02-19 17:37:34 -08:00
Nate Chandler
600164257a [NFC] Moved SmallBitVector dumping to Basic.
Moved out of MemoryLocations.h and merged the implementations of <<,
keeping the version from MemoryLocations with its brackets and commas
available via a flag but defaulting the implementation previously in the
header.
2024-02-19 11:41:38 -08:00
Erik Eckstein
171cca4ec7 PerformanceDiagnostics: print an error in embedded swift if a value type deinit cannot be devirtualized
Not de-virtualized value type deinits can require metatype in case the deinit needs to be called via the value witness table.
Usually this does not happen because deinits are mandatory de-virtualized. But it can show up if e.g. wrong build options are used.

rdar://122651706
2024-02-15 14:01:45 +01:00
John McCall
b23bc82cdb Merge pull request #71574 from rjmccall/isolation-any-sil-irgen
SIL and IRGen support for `@isolated(any)` function types
2024-02-13 11:57:16 -05:00
Joe Groff
2170b4e725 Merge pull request #71489 from jckarter/borrowing-switch-8
MoveOnlyAddressUtils: Fixes for borrowing switch over address-only types.
2024-02-13 07:51:40 -08:00