Commit Graph

2864 Commits

Author SHA1 Message Date
Andrew Trick
ae64ff5cb0 Rename PrunedLiveness.clear() to invalidate()
Because SILBitfield cannot be cleared.
2023-03-22 01:36:48 -07:00
Andrew Trick
15796e3ff9 PrunedLiveness: add a SILFunction argument
So that liveness can migrate to using a SILBitfield.
2023-03-22 01:36:48 -07:00
Konrad `ktoso` Malawski
345c221f56 [Concurrency] Distributed actor's unownedExecutor should be optional (#64499) 2023-03-22 08:40:41 +09:00
Michael Gottesman
bbd2ad4de9 [move-only] Wire up proper debug info for addresses.
I included here SIL tests and in a separate PR against lldb included lldb tests
that validate as we step that the values are validated/invalidated as
appropriate.

rdar://106767457
2023-03-19 16:37:08 -07:00
Michael Gottesman
3de646e7c4 [move-only] Change global_addr assignable_but_not_consumable accesses such that they are initialized at end of lifetime.
I also added an interpreter test that validates that ref_element_addr works as
expected (I fixed that in an earlier commit, but did not add an interpreter
test).

rdar://106724277
2023-03-16 12:28:59 -07:00
eeckstein
58e42b3d87 Merge pull request #64385 from eeckstein/fix-predictablememopt
PredictableMemOpt: fix a wrong debug info location type
2023-03-15 19:44:47 +01:00
Kavon Farvardin
a8a44ebb17 Merge pull request #64106 from kavon/enable-moveonly-by-default
Enable moveonly / noncopyable types by default
2023-03-15 09:59:29 -07:00
Erik Eckstein
4ea9d0454d PredictableMemOpt: fix a wrong debug info location type
Fixes a crash in the debug info verification

rdar://106594725
2023-03-15 16:54:57 +01:00
Konrad `ktoso` Malawski
41f99fc2ae [Executors][Distributed] custom executors for distributed actor (#64237)
* [Executors][Distributed] custom executors for distributed actor

* harden ordering guarantees of synthesised fields

* the issue was that a non-default actor must implement the is remote check differently

* NonDefaultDistributedActor to complete support and remote flag handling

* invoke nonDefaultDistributedActorInitialize when necessary in SILGen

* refactor inline assertion into method

* cleanup

* [Executors][Distributed] Update module version for NonDefaultDistributedActor

* Minor docs cleanup

* we solved those fixme's

* add mangling test for non-def-dist-actor
2023-03-15 23:42:55 +09:00
Michael Gottesman
b3bbaec709 Merge pull request #64366 from gottesmm/pr-63fcd3307c126048533239ab77552bb5acdc728c
[move-only] Treat mark_must_check assignable_but_not_consumable as ending initialized
2023-03-14 17:12:11 -07:00
Michael Gottesman
02a12d4142 [move-only] Make sure to treat ref_element_addr mutable address accesses similar to inout.
I also slightly changed the codegen around where we insert the mark_must_check.
Specifically, before we would emit the mark_must_check directly on the
ref_element_addr and then insert the access. This had the unfortunate effect
that we would hoist any destroy_addr that were actually needed out of the access
scope. Rather than do that, I now insert the mark_must_check on the access
itself. This results in the destroy_addr being within the scope (like the
mark_must_check itself).

rdar://105910066
2023-03-14 14:03:20 -07:00
Michael Gottesman
8f9772dcf1 [move-only] Make sure to treat (mark_must_check (begin_access (project_box (@capture box arg)))) like an inout term user requiring situation.
We already did this for the situation without the begin_access. In truth, using
the terminator is a bit too wide, but it works for these sorts of arguments that
use assignable_but_not_consumable so for expediency (and since we are just
walking blocks), I just decided to do something quick.

rdar://106208343
2023-03-14 14:03:20 -07:00
Kavon Farvardin
d4992be0d3 [bug fix] avoid generating explicit_copy_* for copyable types
The move checker was converting some kinds of copies
into their `explicit_copy_*` versions, despite the
type of the copy being a copyable type. This was
causing random crashes in some narrow circumstances.

resolves rdar://106669967
2023-03-13 22:39:31 -07:00
Kavon Farvardin
12d33b2b84 run the move-checker if lexical borrow scopes are enabled
this pulls just the move checking passes out from
behind the experimental flag.
2023-03-13 22:39:31 -07:00
Michael Gottesman
156523e598 [move-only] Update the address checker description comment given changes to the algorithm. 2023-03-12 14:55:19 -07:00
Holly Borla
dce70f373f [SILGen] Emit MaterializePackExprs.
The subexpression of a MaterializePackExpr (which is always a tuple value
currently) is emitted while preparing to emit a pack expansion expr, and its
elements are projected from within the dynamic pack loop. This means that a
materialized pack is only evaluated once, rather than being evaluated on
every iteration over the pack elements.
2023-03-09 21:44:03 -08:00
Michael Gottesman
c3787df2a9 [move-only] Remove misguided handling of inout.
I think this was just an incorrect fix. The actual issue is that the memory
lifetime verifier views debug_value as requiring a live address... but at the
same time, we do not want to emit diagnostics for a debug_value... we want to do
it for other things. So my solution is to add debug_value to the final liveness
computation, but not use it earlier when we use said liveness to compute
diagnostics.

rdar://106442224
2023-03-08 12:18:10 -08:00
Michael Gottesman
f5acc07bbc [move-only] Fix crash due to an earlier change I made to move end_borrow out of addressUseChecker and into the liveness checker.
This just makes sure that we won't crash on it and emit a proper message. I
think we should improve the message, but this at least gives a proper error.

rdar://106340382
2023-03-06 18:13:00 -08:00
Michael Gottesman
f055bdc3aa [reference-bindings] Add initial prototype of the reference binding transform pass. 2023-03-03 17:14:41 -08:00
Mishal Shah
aced44a84b Merge pull request #63187 from apple/rebranch
Merge `rebranch` into `main` to support `stable/20221013` llvm-project branch
2023-03-03 11:01:34 -08:00
swift-ci
d0f88433da Merge pull request #63822 from kavon/resilient-noncopyable
Support resilient properties of move-only type
2023-03-03 01:24:37 -08:00
Mishal Shah
e256b56545 Merge branch 'main' into rebranch 2023-03-02 18:25:09 -08:00
Kavon Farvardin
6e5b49a410 no_consume_or_assign ref_element_addr should not have any destroys
This fixes an issue when doing move-checking on a read accessor,
where the field is only borrowed. After the MoveOnlyAddressChecker
ran on it, it'd inject a destroy that didn't get "claimed":

```
  %2 = ref_element_addr %0 : $ListOfFiles, #ListOfFiles.file
  %3 = mark_must_check [no_consume_or_assign] %2 : $*File
  %4 = begin_access [read] [dynamic] %3 : $*File
  %5 = load_borrow %4 : $*File
  yield %5 : $File, resume bb1, unwind bb2

bb1:
  end_borrow %5 : $File
  end_access %4 : $*File
  destroy_addr %2 : $*File // BAD
  %9 = tuple ()
  return %9 : $()
```

The approach of this fix is to recognize that at the point we're
injecting destroys, we would have emitted diagnostics and stopped
already if there were any consuming uses that we need to clean-up
after, since we're in `no_consume_or_assign` checking mode here
when just reading the field.
2023-03-02 15:14:24 -08:00
Andrew Trick
bffe0e7736 Merge pull request #64022 from atrick/ossa-complete-util
[NFC] Add SILGenCleanup::completeOSSLifetimes
2023-03-02 08:53:44 -08:00
Andrew Trick
32baaf7876 Add SILGenCleanup::completeOSSLifetimes
Presently under -enable-ossa-complete-lifetimes.

This allows SILGen to skip OSSA cleanups, for example at dead-end
blocks.

Long term, we may remove OSSA cleanups from SILGen entirely (except
for lexical borrow scopes). This changes lets us experiment with that
option.
2023-03-01 21:41:46 -08:00
Andrew Trick
103a6fefb8 LinearLifetimeChecker - make DeadEndBlocks optional 2023-03-01 21:41:46 -08:00
Nate Chandler
49f1debebe [MandatoryInliner] Stack nest at OSSA lowering.
Now that in OSSA `partial_apply [on_stack]`s are represented as owned
values rather than stack locations, it is possible for their destroys to
violate stack discipline.  A direct lowering of the instructions to
non-OSSA would violate stack nesting.

Previously, when inlining, it was assumed that non-coroutine callees
maintained stack discipline.  And, when inlining an OSSA function into a
non-OSSA function, OSSA instructions were lowered directly.  The result
was that stack discipline could be violated.

Here, when inlining a function in OSSA form into a function lowered out
of OSSA form, stack nesting is fixed up.
2023-02-28 15:40:46 -08:00
Nate Chandler
32685ce68e [Inliner] Add per-inlining verification.
Previously, there was an -Xllvm option to verify after all inlining to a
particlar caller.  That makes it a chore to track down which apply's
inlining resulted in invalid code.  Here, a new option is added that
verifies after each run of the inliner.
2023-02-28 15:40:46 -08:00
swift-ci
71dffd81fc Merge remote-tracking branch 'origin/main' into rebranch 2023-02-22 12:53:43 -08:00
nate-chandler
77feef5125 Merge pull request #63766 from nate-chandler/lexical_lifetimes/per-function
Add attr to enable lexical lifetime per function.
2023-02-22 12:33:45 -08:00
swift-ci
e73ce4fd57 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-22 07:53:41 -08:00
Joe Groff
6fd7762cdd Merge pull request #63798 from jckarter/owned-nonescaping-closure-asserts
[SIL] Add assertions to check assumptions about owned noescape closures.
2023-02-22 07:51:12 -08:00
swift-ci
770a8900b4 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-20 18:53:55 -08:00
Joe Groff
cf81c2015a Factor out helper to find the original PartialApplyInst deallocated by a DestroyValueInst in OSSA, if any 2023-02-20 18:23:20 -08:00
Michael Gottesman
7d5476d3e6 Remove some optnone that snuck in. 2023-02-20 14:35:18 -08:00
Michael Gottesman
1dd896ded9 [move-only] Implement escaping closure semantics.
NOTE: A few of the test patterns need to be made better, but this patch series
is large enough, I want to get it into tree and iterate.
2023-02-20 11:04:21 -08:00
Michael Gottesman
50af8fd493 [move-only] Box owned arguments like let parameters. 2023-02-20 11:04:21 -08:00
Michael Gottesman
a571357cce [move-only] Change noncopyable lets to be emitted as boxes like vars.
Some notes:

1. This ensures that if we capture them, we just capture the box by reference.

2. We are still using the old incorrect semantics for captures. I am doing this
   so I can bring this up in separate easy to understand patches all of which
   pass all of the moveonly tests.

3. Most of the test edits are due to small differences in error messages in
   between the object and address checker.

4. I had to add a little support to the move only address checker for a small
   pattern that doesn't occur with vars but do es occur for lets when we codegen
   like this, specifically around enums. The pattern is we perform a load_borrow
   and then copy_value and then use the result of the copy_value. Rather than fight
   SILGen pattern I introduced a small canonicalization into the address checker which
   transforms that pattern into a load [copy] + begin_borrow to restore the codegen
   to a pattern the checker expects.

5. I left noimplicitcopy alone for now. But we should come back around and fix
   it in a similar way. I just did not have time to do so.
2023-02-20 11:04:21 -08:00
Michael Gottesman
f4e1b2a8f2 [move-only] Update SILGen/MoveCheckers so that vars are emitted in eagerly projected box form.
This is the first slice of bringing up escaping closure support. The support is
based around introducing a new type of SILGen VarLoc: a VarLoc with a box and
without a value. Because the VarLoc only has a box, we have to in SILGen always
eagerly reproject out the address from the box. The reason why I am doing this
is that it makes it easy for the move checker to distinguish in between
different accesses to the box that we want to check separately. As such every
time that we open the box, we insert a mark_must_check
[assignable_but_not_consumable] on that project. If allocbox_to_stack manages to
determine that the box can be stack allocated, we eliminate all of the
mark_must_check and place a new mark_must_check [consumable_and_assignable] on
the alloc_stack.  The end result is that we get the old model that we had before
and also can support escaping closures.
2023-02-20 11:04:21 -08:00
Michael Gottesman
5f7b0d0d0e [gardening] Delete an empty header that snuck in. 2023-02-20 11:04:07 -08:00
swift-ci
07e68ff91a Merge remote-tracking branch 'origin/main' into rebranch 2023-02-19 20:53:22 -08:00
Michael Gottesman
79f65047d4 Teach the ownership model eliminator how to lower explicit-copy-addr.
Later parts of the pipeline do not know about the instruction, so we need to
lower it there. This is additionally safe since we will not be performing move
only checking later in the pipeline.
2023-02-19 15:05:58 -08:00
Michael Gottesman
6c922af8aa [move-only] Combine the address/object checker in the same pass so that we only run cleanups once.
Otherwise, sometimes when the object checker emits a diagnostic and cleans up
the IR, some of the cleaned up copies are copies that should have been handled
by the address checker. The end result is that the address checker does not emit
diagnostics for that IR. I found this problem was exascerbated when writing code
for escaping closures.

This commit also cleans up the passes in preparation for at a future time moving
some of the transformations into the utils folder.
2023-02-19 13:55:22 -08:00
swift-ci
d20d6a9d45 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-18 17:14:50 -08:00
Nate Chandler
ec1a5e0911 Add attr to enable lexical lifetime per function.
Enables modules to migrate to the new lifetime rules incrementally.
2023-02-18 11:59:54 -08:00
Michael Gottesman
9597195401 [move-only] Fix a small thinko in the MoveOnlyBorrowToDestructureTransform.
Specifically, our operand /could/ be a SILArgument. In that case, oldInst in all
of these cases will be a nullptr. So make sure to only delete them if we
actually found a defining instruction.
2023-02-17 16:04:47 -08:00
Michael Gottesman
2c137512b0 [move-only] Add an error that is emitted if the move checker misses a copy and asks to file a bug. 2023-02-17 16:04:46 -08:00
swift-ci
c81c374491 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-17 15:34:22 -08:00
Michael Gottesman
bfd140f988 Merge pull request #62937 from jckarter/nonescaping-closure-move-only
[WIP] Treat nonescaping closure types as owned types in SIL; use borrowing to model capture lifetimes
2023-02-17 15:30:31 -08:00
swift-ci
08bc6ec292 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-17 12:35:58 -08:00