Commit Graph

180 Commits

Author SHA1 Message Date
Nate Chandler
a955a01cab [Gardening] MoveOnly: Replaced dyn_cast with isa. 2024-03-20 12:35:14 -07:00
Nate Chandler
1d3925afcc [Gardening] MoveOnly: Renamed variable. 2024-03-20 12:35:14 -07:00
Nate Chandler
8624f1342e [Gardening] MoveOnly: Annotated auto pointers. 2024-03-20 12:35:14 -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
b6f0b358ba [MoveOnly] Track inst-consumed bits in same SBV.
Previously, whenever an instruction was recorded as a final consume, a
new entry was added to finalBlockConsumes.  Here, this is changed to add
the new bits being consumed by the instruction to the preexisting
SmallBitVector, if there is one.
2024-03-20 11:58:25 -07:00
Nate Chandler
2b363c5bc3 [NFC] MoveOnly: Renamed nonconsumingUses.
The name `livenessUses` doesn't readily communicate the fact that those
uses are all non-consuming.
2024-03-20 11:51:30 -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
Nate Chandler
11dd0e4aa6 [NFC] SIL: Typed debug_value's wasMoved.
Help avoid errors with boolean flags by using the new
UsesMoveableValueDebugInfo_t.
2024-03-08 21:24:39 -08:00
Nate Chandler
e40581a61b [MoveChecker] Visit and delete markers in PO.
Visit in post-order in order to resolve markers from the inside out,
required for per-field consume.
2024-03-06 20:54:17 -08:00
cui fliter
127077b3aa chore: fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-03-05 17:23:22 +08: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
Joe Groff
a82f8a9f1f Merge pull request #71942 from jckarter/reenable-borrow-to-destructure-transform
Reenable BorrowToDestructureTransform during the MoveOnlyAddressChecker.
2024-02-28 07:31:15 -08:00
Joe Groff
62b05c8e42 Reenable BorrowToDestructureTransform during the MoveOnlyAddressChecker.
The comment stated that this was used to turn switches into consumes (which
is no longer relevant), but it looks like it is also necessary for the
move-only address checker to be able to properly understand partial consumes
of fields in some code patterns. Now that we surround borrowing switches
in plenty of opaque accesses to protect them from being pried apart by the
move checker, it should be safe to reenable this.
2024-02-27 20:11:58 -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
Joe Groff
d671f2a6c0 MoveOnlyAddressChecker: Treat opaque accesses consistently in CopiedLoadBorrowEliminationVisitor.
Don't prepare loads from inside an opaque access that the checker isn't going to visit.
Fixes rdar://123601728.
2024-02-26 15:50:03 -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
0491755de9 Consume switch subjects under an opaque sub-access.
This prevents the move-only checker from trying to analyze the bindings
as partial consumptions, which ought to be unnecessary since SILGen
will always fully consume the subject as part of forming the bindings.
2024-02-20 16:35:39 -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
Joe Groff
810880c7fa MoveOnlyAddressChecker: Relax more checks to accommodate borrowing switch codegen.
`unchecked_take_enum_data_addr` should not be considered a write when it's non-
destructive; this should eventually be an inherent property of the instruction,
but there are other passes which miscompile currently if we change that now.
Meanwhile, wrapping a copyable value should always be considered an initialization
too.
2024-02-19 09:26:43 -08:00
Nate Chandler
da968dbd58 [MoveChecker] Ban exported partial consumption.
To avoid dialecticization based on compilation mode, ban for
non-resilient modules partial consumption of aggregates which would be
illegal were those modules instead resilient.
2024-02-15 16:25:53 -08:00
Joe Groff
0365c6abba MoveOnlyAddressUtils: Fixes for borrowing switch over address-only types.
Relax some existing pattern matches and add some unhandled instructions to the
walkers so that borrowing switches over address-only enums are properly analyzed
for incorrect consumption. Add a `[strict]` flag to `mark_unresolved_move_only_value`
to indicate a borrow access that should remain a borrow access even if the subject
is later stack-promoted from a box.
2024-02-12 20:20:50 -08:00
Joe Groff
2f519f42c6 SILGen: Emit borrowing switch subjects under a formal access.
Ensure that dependent accesses are properly nested when a subject isn't directly
a borrowed parameter binding.
2024-02-05 19:39:10 -08:00
Nate Chandler
03f904af0c [MoveChecker] Separate partial reinit from consume 2024-01-29 18:29:40 -08:00
Nate Chandler
bff7618353 [MoveChecker] Don't add defs to liveness.
When extending liveness, the instructions prior to a preexisting destroy
are added to liveness.  If that prior instruction is the def, adding it
to liveness results in multi-def liveness understanding that there is a
prior def.

Fixes a bug exposed by adding coroutine ends to liveness rather than
function ends.
2024-01-29 12:31:25 -08:00
Nate Chandler
c06d5dbb0b [MoveChecker] All assigns add the same scope ends.
Use the same code path to add users at which an address must have been
reinitialized for both kinds of mark_unresolved_non_copyable_value which
permit assignment.
2024-01-29 11:49:30 -08:00
Nate Chandler
5441ff1d97 [MoveChecker] Distinguished scope end diagnostics.
There are several kinds of scopes at which it is required that an
address be initialized:
(1) the whole function -- for inout argument to the function
(2) the region a coroutine is active -- for an inout yielded by a
    coroutine into the function
(3) the region of a memory access -- for a `begin_access [modify]`.

The move checker enforces that they are initialized at that point by
adding instructions at which the field must be live to liveness.

Previously, all such scopes used the end of the function as the point at
which the memory had to have been reinitialized.  Here, the relevant end
of scope markers are used instead.

More importantly, here the diagnostic is made to vary--the diagnostic,
that is, that is issued in the face an address not being initialized at
the end of these different kind of scopes.
2024-01-29 11:49:30 -08:00
Nate Chandler
4ea2440bfe [NFC] MoveChecker: Merged partial mutation checks.
Simplified diagnostic emission to use a single code path.
2024-01-29 11:49:30 -08:00
Nate Chandler
5f3d2938d7 [NFC] MoveChecker: Inverted control flow.
Exited early.
2024-01-29 11:49:30 -08:00
Nate Chandler
b757b2e99d [FSPrunedLiveness] Return bitfield from isDefBlock 2024-01-29 11:49:30 -08:00
Nate Chandler
330f300c4b [NFC] FSPrunedLiveness: Deduplicated initDef impls
Add a new SILNode taking overload and change the SILInstruction and
SILValue taking overloads to call it.
2024-01-29 11:49:29 -08:00
Nate Chandler
e8364d632c [Gardening] MoveChecker: Tweaked comment. 2024-01-25 11:01:14 -08:00
Joe Groff
1b9a0712bf Move-only check the value projected from addressors.
Mark the result of a move-only addressor as unresolved. The pointed-at value
cannot be consumed so ensure that only [read] or [modify] accesses are
performed. Update the move-only checker to recognize code patterns
from addressors.
2023-12-15 10:10:44 -08:00
Joe Groff
18e31157fd Move-only-check the result of modify coroutines.
Following https://github.com/apple/swift/pull/70333, do the same thing for
modify coroutines, marking the result so that we check uses of the result to
ensure it isn't consumed (without being reinitialized).
2023-12-12 09:02:24 -08:00
Joe Groff
96c87dbf81 Move-only-check the yielded result from read coroutines when they're noncopyable.
Mark the result of starting a read coroutine to be checked by the move-only checker, and then
update the pattern matching in the move checker itself so that it recognizes code patterns
involving yielding from and receiving yields from read coroutines. Teach move only diagnostics
to get the property name for an access through a read coroutine from the referenced declaration.
2023-12-11 10:54:52 -08:00
Joe Groff
f126b714bf MoveOnlyChecker: Properly insert cleanup for dead try_apply def.
When a address-only noncopyable value is dead-def'ed by an indirect return from a `try_apply`,
the cleanup should be inserted on the normal return successor block. Fixes rdar://118255228.
2023-11-15 08:42:07 -08:00
Andrew Trick
43e88fd0f1 Fix MoveOnlyTypeChecker to handle address taking instructions
address_to_pointer and fix_lifetime
2023-10-30 12:22:26 -07:00
swift-ci
7fc36edb98 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-27 09:34:12 -07:00
Nate Chandler
05bec97203 [FSPrunedLiveness] Add extendToNonUse.
And use it in lifetime maximization.

The preexisting member function updateForUse has been updated to match
PrunedLiveness and gravitate towards lifetimeEnding=false.

For a fixed instruction and bit, if called with lifetimeEnding=true and
then lifetimeEnding=false, the lifetime-ending-ness of the instruction
at the bit will be false; and if it is again called with
lifetimeEnding=true, the lifetime-ending-ness of the instruction at the
bit will remain false.

In contrast the new member function extendToUse does not alter the
lifetime-ending-ness if it is already set.  If it is unset, the function
sets the bit to lifetimeEnding=false.
2023-09-26 11:45:23 -07:00
Sophia Poirier
86d368f364 Merge remote-tracking branch 'upstream/main' into fix-rebranch-automerger 2023-08-31 14:10:52 -07:00
Michael Gottesman
37d60a08bb [move-only] Rename mark_must_check -> mark_unresolved_non_copyable_value.
I was originally hoping to reuse mark_must_check for multiple types of checkers.
In practice, this is not what happened... so giving it a name specifically to do
with non copyable types makes more sense and makes the code clearer.

Just a pure rename.
2023-08-30 22:29:30 -07:00
swift-ci
d35a7743ef Merge remote-tracking branch 'origin/main' into rebranch 2023-08-29 00:15:35 -07:00
Michael Gottesman
18ac69d8d7 Remove a clang optimize off that snuck into tree. 2023-08-28 18:40:30 -07:00
swift-ci
4fe55c5732 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-11 00:35:20 -07:00
swift-ci
2667df0799 Merge pull request #67760 from atrick/fix-closure-moveonly-arg
Fix compiler crashes with consuming and borrowing keywords.
2023-08-11 00:32:41 -07:00
swift-ci
525350af1b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-10 22:14:25 -07:00
Michael Gottesman
29350907fc Convert TransitiveAddressWalker to use CRTP instead of virtual functions. 2023-08-10 12:58:50 -07:00
Andrew Trick
83ce3a1777 Rename getArgumentOperandConvention to getCaptureConvention
The name was misleading and problematic. There is already a
getArgumentConvention which is completely different.
2023-08-10 11:17:53 -07:00
Becca Royal-Gordon
3eebc6dddb Merge branch 'main' into rebranch
# Conflicts:
#	lib/SILOptimizer/Differentiation/Common.cpp
2023-08-04 15:09:50 -07:00
Michael Gottesman
c9be4bda49 Merge pull request #67677 from gottesmm/borrowed-base-silgenlvalue
[move-only] Ensure that we properly nest accesses to base values if the base is noncopyable or the accessor result is noncopyable.
2023-08-04 12:26:19 -07:00
Michael Gottesman
c3d2276241 [silgen] Eliminate two more cases around subscripts where we were not borrowing.
Also, the store_borrow work in the previous patch caused some additional issues
to crop up. I fixed them in this PR and added some tests in the process.
2023-08-02 11:09:31 -07:00