Commit Graph

180 Commits

Author SHA1 Message Date
Michael Gottesman
e92e9dff0c Make Feature a struct enum so we can put methods on it.
Just noticed this as I was looking at making other changes.

(cherry picked from commit 3ff9463957)
2025-05-14 16:07:04 -07:00
Meghana Gupta
cc72edb119 Introduce end_cow_mutation_addr instruction 2025-04-30 14:38:48 -07:00
nate-chandler
e539d0f996 Revert "[6.2] MoveOnlyChecker: Treat trivial stores as reinitializations rather than initializations." 2025-04-24 12:11:32 -07:00
Nate Chandler
875e67a2b9 [MoveOnly] Fix consumption of opened existentials.
Enable walking into `TypeOffsetSizePair`s from an existential into an
archetype.  And set the access kind on `open_existential_addr`
instructions which are the sources of rewritten `copy_addr`s to mutable.

rdar://141279635
2025-04-23 13:28:49 -07:00
Nate Chandler
f201ceebe1 [NFC] MoveOnly: Add parameter to function.
For now, it is unused.
2025-04-23 13:28:49 -07:00
Joe Groff
66764a3fc3 MoveOnlyChecker: Treat trivial stores as reinitializations rather than initializations.
A trivial store is allowed to occur on an existing live value, and should not
trigger an attempt to destroy the original value completely. Fixes rdar://147791932.
2025-04-16 07:44:53 -07:00
Joe Groff
b5d242ad2c MoveOnlyChecker: Don't follow trivial transitive uses of borrows.
Trivial values don't have ownership tracked, so their uses can't affect the
lifetime of the original borrow. Fixes rdar://148457155.
2025-04-02 13:25:46 -07:00
Andrew Trick
19c8bd625f Add FIXMEs for calls to liveness that fail to check pointer escapes. 2025-03-02 23:51:34 -08:00
Saleem Abdulrasool
4097255ea5 SILOptimizer: address C5030
i```
swift\lib\SILOptimizer\Mandatory\MoveOnlyAddressCheckerUtils.cpp(2981): warning C5030: attribute [[clang::fallthrough]] is not recognized
```

Replace the use of `clang::fallthrough` with `LLVM_FALLTHROUGH` which
properly uses the C++ standard spelling (`[[fallthrough]]`) depending on
the compiler version.
2025-02-07 15:04:38 -08:00
Andrew Trick
e705a6d7c3 Temporarily introduce AnyInteriorPointer operand ownership.
This is necessary to fix a recent OSSA bug that breaks common occurrences on
mark_dependence [nonescaping]. Rather than reverting that change above, we make
forward progress toward implicit borrows scopes, as was the original intention.

In the near future, all InteriorPointer instructions will create an implicit
borrow scope. This means we have the option of not emitting extraneous
begin/end_borrow instructions around intructions like ref_element_addr,
open_existential, and project_box. After that, we can also migrate
GuaranteedForwarding instructions like tuple_extract and struct_extract.
2025-02-05 16:23:02 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Gabor Horvath
1601564342 [cxx-interop] Import rvalue references as consuming parameters
Unfortunately, importing them as is results in ambiguous call sites.
E.g., std::vector::push_back has overloads for lvalue reference and
rvalue reference and we have no way to distinguish them at the call site
in Swift. To overcome this issue, functions with rvalue reference
parameters are imported with 'consuming:' argument labels.

Note that, in general, move only types and consuming is not properly
supported in Swift yet. We do not invoke the dtor for the moved-from
objects. This is a preexisting problem that can be observed with move
only types before this PR, so the fix will be done in a separate PR.
Fortunately, for most types, the moved-from objects do not require
additional cleanups.

rdar://125816354
2024-12-02 13:09:21 +00:00
Andrew Trick
4612728581 [NFC] Add BeginApplyInst::getEndApplyUses() API.
A begin_apply token may be used by operands that do not end the coroutine:
mark_dependence.

We need an API that gives us only the coroutine-ending uses. This blocks
~Escapable accessors.

end_borrow is considered coroutine-ending even though it does not actually
terminate the coroutine.

We cannot simply ask isLifetimeEnding, because end_apply and abort_apply do not
end any lifetime.
2024-11-18 01:37:00 -08:00
Andrew Trick
17a3b8a8a3 [MoveAddrChecker] load from borrowed value looks through mark_depend
Required to add dependencies to unsafe addressors.
2024-10-22 09:27:02 -07:00
Nate Chandler
9c887a1ab1 [MoveAddrChecker] Init'd looks thru mark_depend.
Extend the hack to determine whether an address begins initialized to
look through mark_dependence instructions.
2024-10-21 09:50:02 -07:00
Nate Chandler
0b47442068 [NFC] MoveAddrChecker: Extract reused expression.
To enable changing its definition.
2024-10-21 09:49:59 -07:00
Nate Chandler
062d063764 [NFC] MoveAddrChecker: Extracted function.
While the FIXME to derive whether an address begins initialized requires
auditing all sites where the instruction is emitted to begin with,
making this a predicate that depends only on the instruction can be done
now.
2024-10-21 09:49:38 -07:00
Joe Groff
de687db20f Disallow consuming self in a noncopyable deinit again.
The changes to allow for partial consumption unintentionally also allowed for
`self` to be consumed as a whole during `deinit`, which we don't yet want to
allow because it could lead to accidental "resurrection" and/or accidental
infinite recursion if the consuming method lets `deinit` be implicitly run
again. This makes it an error again. The experimental feature
`ConsumeSelfInDeinit` will allow it for test coverage or experimentation
purposes. rdar://132761460
2024-07-29 21:20:14 -07:00
Nate Chandler
042241af55 [NFC] MoveOnlyAddressChecker: Use isWithinBoundary
Switch back to the API meant for a single instruction now that it
properly handles dead-end regions.
2024-07-23 13:38:35 -07:00
Nate Chandler
4a397cc018 [NFC] OwnedLifetimeCan: Take DeadEndBlocksAnalysis
All clients of OwnedLifetimeCanonicalization pass an instance of the
analysis in.  For now, it's unused.
2024-07-22 21:51:28 -07:00
Nate Chandler
3eb288f92e [MoveOnlyAddressChecker] Exclusivity handles DEs.
Switch to the areUsesWithinBoundary API which takes dead-ends into
account.

rdar://131960619
2024-07-22 14:03:49 -07:00
Nate Chandler
dd730b849c [LifetimeCompletion] Flag instructions dead_end. 2024-07-03 16:44:35 -07:00
Nate Chandler
91fe12aab4 [NFC] SIL: Typed debug_value.poisonRefs. 2024-07-03 14:53:30 -07:00
Akira Hatanaka
42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.

@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.

rdar://122707697
2024-06-27 09:44:04 -07:00
Joe Groff
636a19d11b Merge pull request #74707 from jckarter/consume-during-borrow-checks
MoveOnlyAddressChecker: More robust checking for consume-during-borrow.
2024-06-26 08:22:04 -07:00
Joe Groff
27a8852290 MoveOnlyAddressChecker: More robust checking for consume-during-borrow.
- While an opaque borrow access occurs to part of a value, the entire scope of
  the access needs to be treated as a liveness range, so add the `EndAccess`es
  to the liveness range.
- The SIL verifier may crash the compiler on SILGen-generated code when the
  developer's source contains consume-during-borrow code patterns. Allow
  `load_borrow` instructions to be marked `[unchecked]`, which suppresses
  verifier checks until the move checker runs and gets a chance to properly
  diagnose these errors.

Fixes rdar://124360175.
2024-06-25 14:10:02 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Akira Hatanaka
d92f181ace Create two versions (for caller and callee) of the functions that answer questions about parameter convention (#74124)
Create two versions of the following functions:

isConsumedParameter
isGuaranteedParameter
SILParameterInfo::isConsumed
SILParameterInfo::isGuaranteed
SILArgumentConvention::isOwnedConvention
SILArgumentConvention::isGuaranteedConvention

These changes will be needed when we add a new convention for
non-trivial C++ types as the functions will return different answers
depending on whether they are called for the caller or the callee. This
commit doesn't change any functionality.
2024-06-18 09:06:09 -07:00
Joe Groff
bb4c0d3d59 MoveOnlyAddressChecker: Turn assertion into early exit.
This condition can occur in practice if, while doing the walk back to find the liveness
reason for a consume-without-reinitialization of an `inout` binding through conditional
control flow, we visit a block that reinitializes the binding before any branch that
leaves the binding uninitialized. Fixes rdar://123604613.
2024-06-12 18:40:04 -07:00
nate-chandler
033fc2354f Merge pull request #74157 from nate-chandler/rdar128710064
[SILGen] Store_borrow into in_guaranteed.
2024-06-07 06:47:16 -07:00
Nate Chandler
000a33f04f [MoveOnlyAddressChecker] Don't destroy borrows.
If a marked location is used by `store_borrow`s, then all its users are
`store_borrow`s or `dealloc_stack`s, so there's nothing to destroy.
2024-06-06 11:20:16 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Joe Groff
291c60cd53 MoveOnlyAddressChecker: Ignore tsan markers.
Fixes https://github.com/apple/swift/issues/74042 .
2024-05-31 14:09:05 -07:00
nate-chandler
e74cfb02ae Merge pull request #73386 from nate-chandler/lifetime-completion/20240501/2
[LifetimeCompletion] Require boundary to be specified.
2024-05-10 07:18:22 -07:00
Joe Groff
2d61e3d26b Merge pull request #73531 from jckarter/forwarding-force-unwrap
SILGen: Treat Optional `x!` force unwrapping as a forwarding operation.
2024-05-09 08:35:29 -07:00
Nate Chandler
518de7c6b1 [LifetimeCompletion] Require boundary spec.
Don't default to one boundary or another based on whether the value
being completed is lexical.
2024-05-08 17:15:15 -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
Joe Groff
73ed03c827 Merge pull request #73380 from jckarter/mark-captured-no-implicit-copy-parameters
Consistently mark `borrowing` and `consuming` parameters for move-only checking when captured.
2024-05-02 08:56:10 -07:00
Joe Groff
90e1ecb864 Consistently mark borrowing and consuming parameters for move-only checking when captured.
When a `borrowing` or `consuming` parameter is captured by a closure,
we emit references to the binding within the closure as if it is non-implicitly
copyable, but we didn't mark the bindings inside the closure for move-only
checking to ensure the uses were correct, so improper consumes would go
undiagnosed and lead to assertion failures, compiler crashes, and/or
miscompiles. Fixes rdar://127382105
2024-05-01 13:41:28 -07:00
Nate Chandler
7009a18cc4 [MoveOnlyAddressChecker] Don't complete phis.
After 874971c40d, before running address
checking, all lifetimes in the function are completed.  That doesn't
quite work because lifetime completion expects not to encounter
reborrows or their adjacent phis.
2024-04-30 16:52:01 -07:00
Nate Chandler
5307ac666e [SIL] Permit end_borrow(begin_apply). 2024-04-25 17:03:41 -07:00
Nate Chandler
3e2d1d0e4c [MoveOnlyAddressChecker] Complete lifetimes first.
It relies on complete lifetimes for its analysis.  So if there are any
instructions to check, complete all lifetimes in the function first.
2024-04-19 14:47:35 -07:00
Nate Chandler
f174729a35 [MoveOnlyAddressChecker] OK destroy(pai[onstack])
A destroy_value of an on-stack partial apply isn't actually a consuming
use, so don't treat it as one.
2024-04-19 12:37:34 -07:00
Nate Chandler
23e7c36c5f [NoncopyablePartialConsumption] Ungate feature.
Remove all checks for the feature flag.  It's on all the time.
2024-04-19 12:37:34 -07:00
Augusto Noronha
ddeba619d8 Use dyn_cast_or_null when casting AccessPathWithBase's base
Even though AccessPathWithBase's SILValue base is not optional, casting
it will check the underlying ValueBase, which can be null.
2024-04-04 17:50:35 -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
Nate Chandler
53bffd2d41 [MoveOnlyAddressChecker] Handle takes of copyable.
Treat a take of a copyable value as a take.
2024-03-20 15:19:04 -07:00
Nate Chandler
4f6f8d9459 [NFC] MoveOnly: Map operand to list of ranges. 2024-03-20 12:52:57 -07:00
Nate Chandler
2ab2252233 [NFC] MoveOnly: Map inst to array of ranges. 2024-03-20 12:52:57 -07:00
Nate Chandler
ef6cde5474 [MoveOnlyPartialConsumption] Fix visibility check.
The implementation of isUsableFromInline asserts that the function not
be public, so check that it's not before calling it.
2024-03-20 12:52:57 -07:00