Commit Graph

2864 Commits

Author SHA1 Message Date
Nate Chandler
91fe12aab4 [NFC] SIL: Typed debug_value.poisonRefs. 2024-07-03 14:53:30 -07:00
Michael Gottesman
8770e90e43 Fix a thinko.
I was working on c20abe570d and
03bfadea60 at the same time and I forgot to update
to use the new API in 03bfadea60 before I commited
c20abe570d. Sorry!
2024-07-02 21:00:59 -07:00
Michael Gottesman
c20abe570d Merge pull request #74919 from gottesmm/pr-d8b24a45ff257893c8172491f11a617fc00d5589
[region-isolation] Implement support for 'inout sending' diagnostics.
2024-07-02 20:16:25 -07:00
Meghana Gupta
c2fd130fa2 Merge pull request #74795 from meg-gupta/copyelimexpand
Enable ClosureLifetimeFixup's capture copy elimination for copyable types as well.
2024-07-02 20:06:08 -07:00
Meghana Gupta
a470b04bbf [NFC] clang-format some parts of ClousreLifetimeFixup 2024-07-02 16:26:51 -07:00
Meghana Gupta
c895a9ba10 Add a flag to disable copy elimination of captures in ClosureLifetimeFixup 2024-07-02 16:25:38 -07:00
Meghana Gupta
98074a86c4 Enable copy elimination of captures for all types in ClosureLifetimeFixup
rdar://130026658
2024-07-02 16:25:34 -07:00
Michael Gottesman
6fe749626f [region-isolation] Add 'inout sending' diagnostics.
Specifically:

1. We error now if one transfers an 'inout sending' parameter and does not
reinitialize it before the end of the function.

2. We error now if one merges an 'inout sending' parameter into an actor
isolated region and do not reinitialize it with a non-actor isolated value
before the end of the function.

rdar://126303739
2024-07-02 16:21:44 -07:00
Michael Gottesman
5d4b93fa5d [region-isolation] Add a wrapper ADT for RequireInst SILInstructions so we can attach a Kind and propagate it.
The reason why I am doing this is that I am adding support for failing to
reinitialize an inout sending parameter that was transferred. To make it really
easy to do I am just going to explicitly represent this on the RequireInst and
let the decision on what diagnostic to be done to be represented in the
pseudo-IR instead of trying to just infer it straight from the type of require
inst. This keeps all of the logic in the same place and attempts to keep the
diagnostic emitter not use logic and instead just emit.

This is NFC so I can make sure that things work before adding the additional code.
2024-07-02 16:21:44 -07:00
Michael Gottesman
e9e5c4eb4c [region-isolation] Ensure that some NDEBUG code is properly guarded. 2024-07-02 13:55:33 -07:00
Michael Gottesman
a13c1dc2dc Merge pull request #74869 from gottesmm/rdar130915737
[region-isolation] Improve async let errors to always use a new style error.
2024-07-01 16:24:32 -07:00
Michael Gottesman
02e003f0de [region-isolation] Change capturing a value into an async let that is not further sent into an actor isolated function to use a new style error.
Just going through and fixing sending errors.

rdar://130915737
2024-07-01 13:12:36 -07:00
Michael Gottesman
78d74cf716 [region-isolation] Make sil-region-isolation-assert-on-unknown-pattern also work with TransferNonSendable versions of the error.
This asserts only option is an option to make it quicker/easier to triage
unknown pattern match errors by aborting when we emit it (allowing one to
immediately drop into the debugger at that point).

Previously, it only happened for errors in RegionAnalysis not in
TransferNonSendable itself.
2024-07-01 13:12:36 -07:00
Meghana Gupta
d6729280f3 [NFC] clang-format parts of tryRewriteToPartialApplyStack 2024-07-01 09:53:14 -07:00
Meghana Gupta
56d59c9db3 [NFC] Rename OrigUnusedDuringClosureLifetimeWalker -> OrigUnmodifiedDuringClosureLifetimeWalker 2024-07-01 09:53:14 -07:00
Nate Chandler
451a814363 [MoveOnlyAddressChecker] Complete block args.
Now that the underlying issue (PrunedLiveness' merging of summaries for
branch instructions) has been fixed, reinstate lifetime completion and
add a test to verify that it behaves correctly.

This reverts commit c552b90b61
("Temporarily turn off completing lifetimes of block arguments").

rdar://130427564
2024-06-28 15:07:31 -07:00
Meghana Gupta
e4566c84b0 Merge pull request #74768 from meg-gupta/clffix
Fixes to ClosureLifetimeFixup's copy elimination for noncopyable values
2024-06-27 18:52:08 -07:00
Meghana Gupta
e71cd4b005 Improve copy elimination of noncopyable captures in ClosureLifetimeFixup
For a mark_dependence user of the stack, look through the mark_dependence chain
to match the partial_apply.

Since this is a superset of the `markDepChain` logic, remove that.
So that we don't have 2 ways to check for the same.
2024-06-27 10:34:29 -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
Meghana Gupta
960619b0a0 Fix ClosureLifetimeFixup's copy elimination for noncopyable values
On finding unrecognized user, reset `initialization` of the stack so that we
don't inadvertently eliminate copy
2024-06-27 02:55:29 -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
Alejandro Alonso
cb2a766470 Handle existential_metatype in moveonlytype eliminator 2024-06-25 14:16:53 -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
Meghana Gupta
c552b90b61 Temporarily turn off completing lifetimes of block arguments 2024-06-24 08:14:18 -07:00
Mishal Shah
790d4da2e4 Merge pull request #74593 from Azoy/why-are-we-copying
[SILOptimizer] Handle the mark_dependence chain when eliminating copies in ClosureLifetimeFixup
2024-06-21 15:44:57 -07:00
Alejandro Alonso
8ed84e8aed Handle the mark_dependence chain when eliminating copies in ClosureLifetimeFixup 2024-06-20 14:44:11 -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
Andrew Trick
2f747ad607 Fix MoveOnlyWrappedTypeEliminator; handle dealloc_box
Speculatively fixes
rdar://129185450: Unhandled SIL Instruction: dealloc_box %3
2024-06-17 07:20:01 -07:00
Anton Korobeynikov
0f4dacd47b [AutoDiff] Fix custom derivative thunk for Optional (#74378)
Enable the nil coalescing operator (aka `??`) for Optional type.

Fixes #55882

Co-authored-by: Andrew Savonichev <andrew.savonichev@gmail.com>
2024-06-13 10:53:18 -07:00
Joe Groff
f564732804 Merge pull request #74374 from jckarter/dead-before-live-def-block-assertion-failure
MoveOnlyAddressChecker: Turn assertion into early exit.
2024-06-13 09:34:41 -07:00
nate-chandler
6694bbab90 Merge pull request #74360 from nate-chandler/rdar127518559
[ConsumeAddrChecker] Diagnose consumes of borrows.
2024-06-12 20:33:07 -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
cc40e29f2c [ConsumeAddrChecker] Diagnose consumes of borrows.
When checking a `mark_unresolved_move_addr` instruction, first check
whether it is legal to consume the source.

rdar://127518559&125817827
2024-06-12 13:13:45 -07:00
Slava Pestov
c270597fd0 SIL: Fix false positive in FlowIsolation with DynamicSelfType usage
If an instruction references the DynamicSelfType by calling a
static member with `Self.foo()`, we consider this a type-dependent
use of `self`. This means that at runtime we may need to load the
isa pointer, but we don't need to touch any other protected state
from the instance.

Therefore, we can skip type-dependent uses in the analysis to
avoid false positives in this case.

An existing test case already exercised the overly-conservative
behavior, so I just updated it to not expect an error.

Fixes rdar://129676769.
2024-06-12 12:01:18 -04:00
nate-chandler
3aca85bfb3 Merge pull request #74298 from nate-chandler/rdar129593468
[NoncopyableWrapperElim] Process undef values.
2024-06-12 06:55:48 -07:00
Nate Chandler
5d63fcfef6 [MOWTE] Visit undef values.
Such values' types may also also be move-only wrapped.
2024-06-11 17:02:36 -07:00
Nate Chandler
69fa1ae2d2 [MOWTE] Start madeChange at false. 2024-06-11 17:02:24 -07:00
Nate Chandler
d0341ddc7d [NFC] MOWTE: Deleted dead array.
The modified arguments were recorded but never used.
2024-06-11 17:02:20 -07:00
Nate Chandler
8883e88f54 [NFC] MOWTE: Deduplicated code.
Replaced copy-pasted code with a twice-invoked closure.  In preparation
to add a third invocation.
2024-06-11 17:02:19 -07:00
Nate Chandler
78c18374c3 [NFC] SIL: Extracted has "any" move-only wrapping.
This predicate is used in several places.
2024-06-11 16:25:14 -07:00
Max Desiatov
12f402f715 Revert "[AutoDiff] Fix custom derivative thunk for Optional (#71721)" (#74268)
This reverts commit aa5dddb952.

Fixes `preset=buildbot,tools=RA,stdlib=DA` CI job, which without this revert fails on `AutoDiff/SILGen/nil_coalescing.swift` test.
2024-06-11 09:24:19 +01:00
nate-chandler
0351ecd6fb Merge pull request #74196 from nate-chandler/lifetime-completion/20240606/1
[LifetimeCompletion] Removed "with leaks" mode.
2024-06-10 11:32:44 -07:00
Doug Gregor
25830d6bc3 Merge pull request #74225 from DougGregor/flow-sensitive-actor-init-isolation
Teach `#isolation` to respect the flow-sensitive nature of actor initializers
2024-06-10 01:52:38 -07:00
Doug Gregor
d1ae73f436 Handle flow-sensitive #isolation in distributed actor initializers.
Distributed actors can be treated as actors by accessing the `asLocalActor`
property. When lowering `#isolation` in a distributed actor initializer,
use a separate builtin `flowSensitiveDistributedSelfIsolation` to
capture the conformance to `DistributedActor`, and have Definite
Initialization introduce the call to the `asLocalActor` getter when
needed.
2024-06-09 22:48:43 -07:00
Doug Gregor
956243cd7e Teach #isolation to respect the flow-sensitive nature of actor initializers
Actor initializers have a flow-sensitive property where they are isolated
to the actor being initialized only after the actor instance itself is
fully-initialized. However, this behavior was not being reflected in
the expansion of `#isolation`, which was always expanding to `self`,
even before `self` is fully formed.

This led to a source compatibility issue with code that used the async
for..in loop within an actor initializer *prior* to the point where the
actor was fully initialized, because the type checker is introducing
the `#isolation` (SE-0421) but Definite Initialization properly rejects
the use of `self` before it is initialized.

Address this issue by delaying the expansion of `#isolation` until
after the actor is fully initialized. In SILGen, we introduce a new
builtin for this case (and *just* this case) called
`flowSensitiveSelfIsolation`, which takes in `self` as its argument
and produces an `(any Actor)?`. Definite initialization does not treat
this as a use of `self`. Rather, it tracks these builtins and
replaces them either with `self` (if it is fully-initialized at this
point) or `nil` (if it is not fully-initialized at this point),
mirroring the flow-sensitive isolation semantics described in SE-0327.

Fixes rdar://127080037.
2024-06-07 14:54:20 -07:00
Joe Groff
6210c2e9d2 Merge pull request #74187 from jckarter/moveonly-wrapped-type-eliminator-missing-case
Add missing OpenExistentialAddr no-changes-needed case to MoveOnlyWrappedTypeEliminator.
2024-06-07 07:57:09 -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
5dc3cf1296 [LifetimeCompletion] Removed "with leaks" mode.
Now that the two known issues which resulted in invalid SIL being
provided to lifetime completion have been addressed, tighten up the
completion done on the availability boundary not to allow leaks.
2024-06-06 16:48:46 -07:00
Joe Groff
49aac80da8 Add missing OpenExistentialAddr no-changes-needed case to MoveOnlyWrappedTypeEliminator.
Fixes rdar://126875325.
2024-06-06 13:06:24 -07:00