Commit Graph

62 Commits

Author SHA1 Message Date
Michael Gottesman
b0a316796a [move-only] Restructure move only diagnostics so that we can properly emit diagnostics for ref_element_addr and global_addr. 2023-02-12 17:39:27 -08:00
Michael Gottesman
85ea8b5d5b [move-only] Rename CheckKind::NoImplicitCopy -> CheckKind::ConsumableAndAssignable
This fits the name of the check better. The reason I am doing this renaming is
b/c I am going to add a nonconsumable but assignable check for
global_addr/ref_element_addr/captures with var semantics.
2023-02-10 13:46:19 -08:00
Michael Gottesman
e70a7228cc [move-only] Integrate BorrowToDestructureTransform into the AddressChecker so we handle load [copy] switch_enum. 2023-02-08 13:22:59 -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
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
885eb21d37 [noimplicitcopy] Changes to borrow+gep -> destructure transform to support noimplicitcopy. 2023-01-25 14:55:52 -08:00
Michael Gottesman
6f940b4c4f [move-only] Implement the borrow-gep to destructure transform.
This enables us to emit the appropriate error for consuming uses of fields and
also causes us to eliminate copies exposed by using fields of a move only type
in a non-consuming way.

rdar://103271138
2023-01-24 16:56:11 -08:00
Michael Gottesman
1c459b6c5b [move-only-addr] Wire up the move only address checker to Field Sensitive Pruned Liveness Boundary.
This let me fix an issue around hoisting destroy_addr/store [assign] when
working in multi-block cfgs.

I also added some .sil tests.
2023-01-08 21:51:40 -08:00
Michael Gottesman
8e0aeffe62 [move-only-object] Make sure that we also convert copy_value -> explicit_copy_value for pure move only values along side no implicit copy values. 2023-01-08 14:03:52 -08:00
Michael Gottesman
4901529a72 [move-only-addr] Teach move only address checker that captured vars should be treated like inout arguments.
rdar://103313357
2022-12-15 09:59:36 -08:00
Michael Gottesman
c33b9ee8e3 [move-only] Refactor both implementations to use the same diagnostic infrastructure.
This let me clean up the parts of the address infrastructure that rely on the
object checker.
2022-12-15 09:59:35 -08:00