Commit Graph

60 Commits

Author SHA1 Message Date
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Kavon Farvardin
5230b19ef6 Test: replace '@_moveOnly' with '~Copyable' 2024-07-23 11:05:33 -07:00
Joe Groff
10f9289ef8 Enable 'BorrowingSwitch' feature. 2024-05-14 07:31:59 -07:00
Nate Chandler
de8f1c0b69 [NoncopyablePartialConsumption] Promote to feature 2024-04-19 12:37:34 -07:00
Nate Chandler
943cc3cc7c [NoncopyablePartialConsumption] Enable.
SE-429 was accepted.

rdar://126275392
2024-04-11 08:19:29 -07:00
Joe Groff
ec1023466f Optimizer/OptUtils: Don't trivially remove dead-looking unchecked_enum_data.
Under OSSA, the instruction may still be structurally responsible for consuming
its operand even if the result is dead, so we can't remove it without breaking
invariants.

More generally, this should probably apply to any instruction which consumes
one or more of its operands, has no side effects, and doesn't produce any
nontrivial results that require further consumption to keep the value alive.
I went with this targeted fix, since it addresses a problem that shows up
in practice (rdar://125381446) and the more general change appears to
disturb the optimizer pipeline while building the standard library.
2024-04-09 14:52:03 -07:00
Nate Chandler
9861422eeb [SIL] Key consume checking off var_decl attr.
Previously, the lexical attribute on begin_borrow instructions was used.
This doesn't work for values without lexical lifetimes which are
consumed, e.g. stdlib CoW types.  Here, the new var_decl attribute on
begin_borrow is keyed off of instead.  This flag encodes exactly that a
value corresponds to a source-level VarDecl, which is the condition
under which checking needs to run.

rdar://118059326
2023-11-28 07:26:09 -08:00
Kavon Farvardin
a9194a5063 [nfc] replace some uses of @_moveOnly 2023-10-28 23:57:09 -07:00
Michael Gottesman
3dde9df468 [move-only] Emit an error if we /ever/ partially consume a noncopyable type.
The reason why I am doing this is that this was not part of the original
evolution proposal (it was called an extension) and after some discussion it was
realized that partial consumption would benefit from discussion on the forums.

rdar://111353459
2023-06-27 13:52:49 -07:00
Kavon Farvardin
219f94fd1a tailor reinit-after-consume message for closure captures
rdar://109908383
2023-06-12 21:04:25 -07:00
Kavon Farvardin
e71594725a be specific that only escaping closures prevent consumption
rdar://109908383
2023-06-12 17:15:46 -07:00
Michael Gottesman
07677c252b Revert "add and update tests for Copyable types not having ownership modifiers"
This reverts commit 87f190be20.
2023-06-06 12:37:49 -04:00
Joe Groff
359e045192 Require switch on a noncopyable-type binding to be explicitly consume-d.
Pattern matching as currently implemented is consuming, but that's not
necessarily what we want to be the default behavior when borrowing pattern
matching is implemented. When a binding of noncopyable type is pattern-matched,
require it to be annotated with the `consume` operator explicitly. That way,
when we introduce borrowing pattern matching later, we have the option to make
`switch x` do the right thing without subtly changing the behavior of existing
code. rdar://110073984
2023-06-02 18:14:37 -07:00
Michael Gottesman
577e76b0f6 [move-only] Change closure capture diagnostic for let patterns to say that it cannot be captured by an escaping closure.
rdar://109742587
2023-05-28 13:58:59 -07:00
Kavon Farvardin
03d2017a84 reword 'other consume here' to 'consumed again here'
this also fixes a bug where sometimes we simply emit
'consumed here' twice and other times we'd said 'other
consume here' for the same "consumed more than once"
message. so I went through and changed all of the 2nd
consumes into "consumed again".

rdar://109281444
2023-05-24 20:56:39 -07:00
Kavon Farvardin
667459ee75 tighten up consistency in terminology
- refer to a "consuming use" as simply a "consume", to reserve "use" for non-consuming uses.
- refer to "non-consuming uses" as just a "use".
- don't call it a "user defined deinit" and instead a "deinitializer" to match Sema
- be specific about what binding a closure is capturing that is preventing consumption.

rdar://109281444
2023-05-24 20:56:38 -07:00
Kavon Farvardin
e9e6cdaf2e remove "within a closure" since you can't consume any captured noncopyable binding
rdar://109281444
2023-05-24 20:56:38 -07:00
Kavon Farvardin
616395c6ed specify "inout" for missing reinit error
rdar://109281444
2023-05-24 20:56:37 -07:00
Kavon Farvardin
3149102fea reword "boundary use" to just "non-consuming"
rdar://109281444
2023-05-24 20:56:37 -07:00
Kavon Farvardin
31aa2f77e3 polish noncopyable types diagnostic wordings
- replaces "move-only" terminology with "noncopyable"
- replaces compiler jargon like "guaranteed parameters"
  and "lvalue" with corresponding language-level notions
- simplifies diagnostics about closures.

and probably more.

rdar://109281444
2023-05-24 20:56:36 -07:00
Michael Gottesman
07979f0f80 [move-only] Do not attempt to process mark_must_check if we detect they have a partial_apply that was identified by an earlier diagnostic as escaping.
Previously, we would emit a "compiler doesn't understand error" since we would
detect the escape and fail. That is the correct behavior here if the
partial_apply is not already identified as escaping by an earlier pass. But in
the case where we see that the partial_apply's callee was marked with
semantics::NO_MOVEONLY_DIAGNOSTICS, then we:

1. Suppress the "compiler doesn't understand error" for this specific
   mark_must_check.

2. Suppress function wide the "copy of noncopyable type" error. Since we stopped
   processing the mark_must_check that was passed to the partial_apply, we may
   have left copies of noncopyable types on that mark_must_check value. This is
   ok since the user will get the error, will recompile, and if any further show
   up after they fix the inout escaping issue, they will be emitted
   appropriately.
2023-05-14 14:57:56 -07:00
Michael Gottesman
9ff33c50df Update tests for allocbox to stack error change.
I also extended the tests to handle more interesting cases.

NOTE: There are a few cases where we introduced some new do not understand
errors. I am going to fix that in the next commit. I just wanted to completely
update the tests for the manner in which the allocbox to stack change affects
them.
2023-05-14 14:57:56 -07:00
Michael Gottesman
a4fcdd893e [move-only] Fix a thinko where we are treating inout convention as a consuming use instead of liveness use.
rdar://109217216
2023-05-11 10:56:42 -07:00
Michael Gottesman
7f0ef3daf7 [move-only] When assigning a var that escapes into a closure into another local, emit the correct error message.
With some of the changes that I have made, we began to emit a mark_must_check
[no_copy] on a copy_addr here. This change teaches the move address checker how
to recognize that in this case if we have a project_box it is actually b/c we
have something captured by an escaping closure.
2023-05-04 13:07:17 -07:00
Michael Gottesman
224674cad1 [move-only] Ensure that we treat captured escaping closure arguments as such even if the closure doesn't actually escape
Specifically, we already have the appropriate semantics for arguments captured
by escaping closures but in certain cases allocbox to stack is able to prove
that the closure doesn’t actually escape. This results in the capture being
converted into a non-escaping SIL form. This then causes the move checker to
emit the wrong kind of error.

The solution is to create an early allocbox to stack that doesn’t promote move
only types in boxes from heap -> stack if it is captured by an escaping closure
but does everything else normally. Then once the move checking is completed, we
run alloc box to stack an additional time to ensure that we keep the guarantee
that heap -> stack is performed in those cases.

rdar://108905586
2023-05-04 12:25:19 -07:00
Kavon Farvardin
87f190be20 add and update tests for Copyable types not having ownership modifiers
part of resolving rdar://108538971
2023-05-03 13:47:06 -07:00
Michael Gottesman
739417ff09 [move-only] Convert __shared to borrowing in move only tests.
These are the same semantically, just the mangling is slightly different. The
benefit of doing this is that we are actually testing what we expect our users
to do.

rdar://108511703
2023-04-25 10:51:04 -07:00
Michael Gottesman
e3054a003c [move-only] Clone all __owned tests into consuming tests.
I left in the __owned tests of course.

rdar://108511703
2023-04-25 10:51:04 -07:00
Michael Gottesman
b585a1870f [move-only] If we diagnose an invalid escaping capture, turn off noncopyable checking in the closure.
The reason why I am doing this is that currently SILGen knows when emitting said
closure that we are going to emit an error (that it does not have enough
information to emit itself since it doesn't know the caller), so doesn't emit
move checking markers. The result is that the move checker will not eliminate
any copies in the closure and thus will emit a "copy of noncopyable type found"
error and tell the user to file a bug. This just suppresses that.

rdar://108511866
2023-04-25 10:51:03 -07:00
Michael Gottesman
438974a2b9 [move-only] When emitting borrows for move only types, use a load [copy] instead of a load_borrow.
The reason why I am doing this is that otherwise if one has a function that
takes both a guaranteed and an owned parameter, we will break OSSA invariants
since the load [take] will invalidate the load_borrow. So instead, we put in a
load_borrow knowing that the move checker will convert it to a load_borrow
assuming that the two pass exclusivity checking.

NOTE: Because of some missing functionality in subsequent tests, I had to
disable one test (moveonly_escaping_definite_initialization.swift) and also add
some checks for copy of noncopyable object errors. They will go away in the next
2 commits.

rdar://108510987
2023-04-25 10:51:03 -07:00
Michael Gottesman
94fb5ce2f9 [move-only] Treat empty structs as if they have a single element.
rdar://104395115
2023-04-12 20:56:31 -07:00
Kavon Farvardin
2c7d9a5047 update tests given move-only types are enabled
the main things still left behind the experimental flag(s) are
- move-only classes (guarded by MoveOnlyClasses feature)
- noimplicitcopy
- the _borrow operator
2023-03-14 18:35:13 -07:00
Joe Groff
ecceb02e2a Implement consume x operator with the accepted SE-0366 syntax.
Implement it as a contextual operator that only parses as an operator when
followed by an identifier.
2023-03-01 17:37:54 -08:00
Michael Gottesman
799dba1184 [move-only] Suppress moveonly errors when an inout is captured by an escaping closure since we will already emit a more specific capture error. 2023-02-20 13:54:23 -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
Kavon Farvardin
c948f3c04f add ownership to tests using noncopyable parameters 2023-02-16 22:08:13 -08:00
Michael Gottesman
9e8de2ebf9 [move-only] Add sil-verify-all to all tests. 2023-02-13 01:21:18 -08:00
Michael Gottesman
e58c45fa1e [move-only] Add support for ref_element_addr with AssignableButNotConsumable semantics.
rdar://104874497
2023-02-12 17:39:27 -08:00
Michael Gottesman
61b63839b2 [move-only] Now that borrow to destructure transform knows how to handle switch_enum, emit move only enum switches at +0. 2023-02-08 13:59:14 -08:00
Michael Gottesman
ef5903f14e Merge pull request #63443 from gottesmm/pr-1c9625a7ee5b17755b835a7ff4aa7d4d7f6a04d6
[move-only] For now ban non-final classes from containing move only stored fields.
2023-02-06 15:01:00 -08:00
Michael Gottesman
3c976e9d79 [move-only] For now ban non-final classes from containing move only stored fields.
Just closing this hole for now until we have enough time to implement this the
correct way.
2023-02-05 13:08:44 -08:00
Michael Gottesman
9ae7ff30dd [move-only] Wire up emission of the location for non-consuming uses for objects and emit more precise errors for consuming use errors.
Specifically, previously if we emitted an error we just dumped all of the
consuming uses. Now instead for each consuming use that needs a copy, we perform
a search for a specific boundary use (consuming or non-consuming) that is
reachable from the former and emit a specialized error for it. Thus we emit for
the two consuming case the normal consumed twice error, and now for
non-consuming errors we emit the "use after consume" error.
2023-02-04 10:43:13 -08:00
Michael Gottesman
20479c96fb [move-only] Refactor CanonicalizeOSSALifetime::canonicalizeValueLifetime into an API that computes liveness and a second API that rewrites copies/destroys and fix up MoveOnly checkers to use it.
For those who are unaware, CanonicalizeOSSALifetime::canonicalizeValueLifetime()
is really a high level driver routine for the functionality of
CanonicalizeOSSALifetime that computes liveness and then rewrites copies using
boundary information. This change introduces splits the implementation of
canonicalizeValueLifetime into two parts: a first part called computeLiveness
and a second part called rewriteLifetimes. Internally canonicalizeValueLifetime
still just calls these two methods.

The reason why I am doing this is that it lets the move only object checker use
the raw liveness information computed before the rewriting mucks with the
analysis information. This information is used by the checker to compute the raw
liveness boundary of a value and use that information to determine the list of
consuming uses not on the boundary, consuming uses on the boundary, and
non-consuming uses on the boundary. This is then used by later parts of the
checker to emit our errors.

Some additional benefits of doing this are:

1. I was able to eliminate callbacks in the rewriting stage of
CanonicalOSSALifetimes which previously gave the checker this information.

2. Previously the move checker did not have access to the non-consuming boundary
uses causing us to always fail appropriately, but sadly not emit a note showing
the non-consuming use. I am going to wire this up in a subsequent commit.

The other change to the implementation of the move checker that this caused is
that I needed to add an extra diagnostic check for instructions that consume the
value twice or consume the value and use the value. The reason why this must be
done is that liveness does not distinguish in between different operands on the
same instruction meaning such an error would be lost.
2023-02-04 10:43:13 -08:00
Kavon Farvardin
d2da71a58c update existing tests after banning move-only types in generics
A number of our existing tests put move-only types in optionals and
used them as arguments to generic type parameters. It turns out that
many of these appearances in the tests were not crucial for the test's
functionality itself.

The little coverage for force-unwrapping an Optional<moveOnly>
that was lost will be regained once we make these types sound.

I also tried to tidy up some of the tests with consistent naming for
operations on values, i.e., `consumeVal` and `borrowVal` functions.
2023-02-01 23:38:28 -08:00
Michael Gottesman
e6ac700d75 [move-only] QoI: Fix up error notes from "{non,}consuming use" -> "{non,}consuming use here".
rdar://104926091
2023-02-01 12:05:02 -08:00
Michael Gottesman
4e86268243 [move-only] Teach the borrow to destructure transform how to handle consuming/non-consuming uses on the same instruction.
NOTE: The additional errors that are occuring in the move only object checker is
b/c I tweaked checkDestructureUsesOnBoundary so that when it detects an error it
continues instead of returns. This ensures that we get more that we emit errors
for multiple violations instead of just the first one.

rdar://104900171
2023-02-01 12:04:41 -08:00
Michael Gottesman
89176928ee Merge pull request #63213 from gottesmm/rdar103271138
[move-only] Implement borrow+struct_extract to restructure transform
2023-01-26 07:19:10 -08:00
Michael Gottesman
27ecd84cd0 Add some more tests 2023-01-26 01:05:27 -08:00