Commit Graph

1032 Commits

Author SHA1 Message Date
Michael Gottesman
e3274b34ad [region-isolation] Move unhandled pack instructions away from the rest of unhandled instructions. 2024-02-02 14:50:10 -08:00
Guillaume Lessard
114f235d17 Merge pull request #71167 from vanvoorden/vanvoorden/inclusive-language
[Inclusive Language][Comments][Documentation] migrate "sanity" checks to "soundness" checks
2024-02-02 10:27:34 -08:00
Michael Gottesman
3acdc09895 [region-isolation] Add support for test_specification_inst. 2024-02-01 21:23:06 -08:00
Michael Gottesman
ce32a8dbe8 [region-isolation] Add support for store_unowned. 2024-02-01 21:22:25 -08:00
Michael Gottesman
531154c504 [region-isolation] Ignore deinit_existential_{addr,value}. They do not matter from a region perspective. 2024-02-01 21:21:51 -08:00
Michael Gottesman
4b4495bd71 [region-isolation] Mark dealloc_{ref,stack_ref,partial_ref} as ignored.
We do not care about them.
2024-02-01 21:21:18 -08:00
Michael Gottesman
0cd57e4431 [region-isolation] Add support for unconditional_checked_cast_addr. 2024-02-01 21:20:48 -08:00
Michael Gottesman
02ad3dedcb [region-isolation] Add support for unchecked_ref_cast_addr. 2024-02-01 21:20:20 -08:00
Michael Gottesman
b107a18f68 [region-isolation] Handle BeginCowMutation. 2024-02-01 21:19:52 -08:00
Michael Gottesman
3ffe5c5dff [region-isolation] Add increment_profiler_counter support. 2024-01-29 21:34:41 -08:00
Michael Gottesman
86ef55542c [region-isolation] Clean up the handling of ref_element_addr let for Sendable types.
Specifically, if we access a Sendable type from a ref_element_addr and the field
is mutable, we need to treat the use as a require since we could race on writing
to the field. If the field is a let though (and thus immutable), we can still
ignore it.

I also used this as an opportunity to add SIL tests for ref_element_addr.
2024-01-29 21:34:41 -08:00
Michael Gottesman
edf4543b0c [region-isolation] Add support for ref_tail_addr. 2024-01-29 21:34:41 -08:00
Doug Gregor
0cc529768a Merge pull request #70635 from DougGregor/async-sequence-typed-throws
Adopt typed throws in AsyncIteratorProtocol and AsyncSequence
2024-01-29 11:51:25 -08:00
Michael Gottesman
f077e4a9d7 [region-isolation] Fix the call site or self error for values used in the same region as a function argument.
This is just good to do and also makes it so that in my test case for
assumeIsolated, I get a better msg.
2024-01-25 20:40:56 -08:00
Michael Gottesman
7c79a24a1f [region-isolation] Values that are captured by an actor isolated closures are transferred to that closure.
This commit makes it so that we treat values captured by an actor isolated
closure as being transferred to that closure. I also introduced a new diagnostic
for these warnings that puts the main warning on the capture point of the value
so the user is able to see the actual capture that causes the transfer to occur:

```swift
  nonisolated func testLocal2() async {
    let l = NonSendableKlass()

    // This is not safe since we use l later.
    self.assumeIsolated { isolatedSelf in
      isolatedSelf.ns = l
    }

    useValue(l) // expected-note {{access here could race}}
  }
```

```
test.swift:74:14: warning: main actor-isolated closure captures value of non-Sendable type 'NonSendableKlass' from nonisolated context; later accesses to value could race
    useValue(x) // expected-warning {{main actor-isolated closure captures value of non-Sendable type 'NonSendableKlass' from nonisolated context; later accesses to value could race}}
             ^
test.swift:76:12: note: access here could race
  useValue(x) // expected-note {{access here could race}}
           ^
```

One thing to keep in mind is that if we have a function argument being captured
in this way, we still emit the "call site passes `self`" error. I am going to
begin cleaning that up in the next commit in this PR so that we emit a better
error here. But it makes sense to split these into two separate commits since
they are doing different things.

rdar://121345525
2024-01-25 20:40:56 -08:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Doug Gregor
e96dcac7b4 Make sure we always have a SILFunction for region-based isolation checking
Some values (such as `undef`) might not be associated with a function.
2024-01-25 16:04:48 -08:00
Michael Gottesman
00f1e1ec33 [region-isolation] Make it so that we only propagate actor self if the callee takes self as isolated.
rdar://121387872
2024-01-23 15:20:23 -08:00
Michael Gottesman
fd14a97033 [region-isolation] Ensure that global actor guarded globals are treated as being actor specific state.
So for instance, one cannot transfer them, just like actor state.
2024-01-19 15:38:41 -08:00
Michael Gottesman
50aaad376b Merge pull request #70836 from gottesmm/transferring-parameter
[region-isolation] Add support for transferring parameters.
2024-01-19 11:10:58 -08:00
Michael Gottesman
23adcbadb9 [region-isolation] Eliminate some UB caused by dereferencing unchecked optionals.
llvm::Optional<T> used to make it so that in asserts builds if one dereferenced the optional and nothing was there, one would get an assert. std::optional<T> does not have that property.
2024-01-18 13:20:28 -08:00
Michael Gottesman
9303c40162 [region-isolation] Teach region isolation that assigning into a transferring parameter is a transfer of the value.
The specific semantics is if we assign into a transferring parameter's field,
then we "merge" src's value into the transferring parameter, so we
conservatively leave the region of the transferring parameter alone. If we
assign over the entire transferring parameter, we perform an assign fresh since
any value that used to be in the transferring parameter cannot reference
anything in its new value since they are all gone.
2024-01-18 13:20:28 -08:00
Michael Gottesman
26a75fe5e6 [region-isolation] Implement checking for transferring parameters.
NOTE: This does not handle yet assignment into transferring parameters. In the
next commit, I am going to teach the checker that assigning into such a
parameter is a transfer.
2024-01-18 13:20:28 -08:00
Michael Gottesman
861d9678ed [region-isolation] Add support for value_to_bridge_object. 2024-01-17 16:39:35 -08:00
Michael Gottesman
9b9102bef2 [region-isolation] Add support for autorelease_value. 2024-01-17 15:18:53 -08:00
Michael Gottesman
d514c6eb7d [region-isolation] Make it harder for instruction classification and looking for base values through LookThrough insts to get out of sync.
To ensure that we preserve the correct behavior here, I added classification
helper functions that classify if an instruction can be look through. I used
this to drive the find base value code and added in asserts in the instruction
classifier to ensure that if an instruction is ever classified as LookThrough,
one of the helper routines handles it.
2024-01-17 14:50:52 -08:00
Michael Gottesman
5aec06fb75 [region-isolation] Add support for is_unique. 2024-01-17 14:19:59 -08:00
Michael Gottesman
855b9ff376 [region-isolation] Add support for drop_deinit. 2024-01-17 14:14:47 -08:00
Michael Gottesman
38dd567e6d [region-isolation] Add support for bridge_object_to_word. 2024-01-17 14:09:47 -08:00
Michael Gottesman
d10346bd98 [region-isolation] Add support for unowned_copy_value. 2024-01-17 14:08:37 -08:00
Michael Gottesman
dadc16bf94 [region-isolation] Add support for classify_bridge_object. 2024-01-17 14:07:48 -08:00
Michael Gottesman
872edea4a0 [region-isolation] Add support for debug_step. 2024-01-17 14:07:32 -08:00
Michael Gottesman
f6d7983632 [region-isolation] Add support for ref_to_unowned and unowned_to_ref. 2024-01-17 14:05:55 -08:00
Michael Gottesman
c49fb33d29 [region-isolation] Change look through check to use a switch instead of an isa list.
I am doing this because I discovered that mark_dependence was being
misclassified as assigned even though we wanted to treat it as being look
through in its first operand and since I kept on hitting merge conflicts with
the isa list option.

With this commit:

1. I am converting it to a switch in a utility function. That should prevent the
merge conflicts.

2. I also fixed mark_dependence's semantics.

3. I added an assert into CONSTANT_TRANSLATION(..., LookThrough) to make sure
that the switch and the CONSTANT_TRANSLATION code stays in sync.
2024-01-17 14:03:11 -08:00
Michael Gottesman
053e30d46d [region-isolation] Make sure not to run RegionAnalysis on functions that we do not support.
Before this commit, this was done at the beginning of TransferNonSendable. I
thought that those checks would be sufficient to ensure that
RegionAnalysisFunctionInfo was not created for functions that we do not
support. Turns out when we perform certain forms of verification, we force all
function analyses to be created for all functions meaning that we would create a
RegionAnalysisFunctionInfo for such an unsupported function causing us to hit
asserts.

In this commit, I move the check to whether or not we support a function into
RegionAnalysisFunctionInfo itself and use that to determine if we should run
TransferNonSendable. This additionally allows me to change
RegionAnalysisFunctionInfo so that one can construct one for an unsupported
function... as long as one doesn't actually touch any of its methods. If one
does, I put in an assert so we will know that operator error has occured.
2024-01-10 13:41:12 -08:00
Michael Gottesman
a9dc4ed6cc [region-isolation] Refactor out the Region analysis from TransferNonSendable.
NFCI. This is just a pure refactor of the analysis part of TransferNonSendable
into a separate SIL level analysis so it can be reused by other passes.

The reason that I am committing this earlier is that I am working concurrently
on other patches that change TransferNonSendable itself and I want to avoid
issues when rebasing those patches. Getting this patch into tree earlier avoids
that.

This is in preparation for adding a new flow sensitive initialization pass that
combines region based analysis with the current flow sensitive isolation's
diagnostic emitter. The idea is that we want to preserve the diagnostics from
that pass rather than try to make our own as an initial step.
2024-01-10 13:41:12 -08:00
Erik Eckstein
cc83a7d414 add the "array.copy_into_vector" array-semantic 2023-12-09 18:49:57 +01:00
Meghana Gupta
86b651330b Revert "Merge pull request #69807 from apple/revert-69450-uninarrayfix"
This reverts commit cabb5e109f, reversing
changes made to 09688abb02.
2023-12-06 08:29:50 -08:00
Erik Eckstein
e80fedc52a move CalleeCache from SILOptimizer to SIL
Extract the CalleeCache from BasicCalleeAnalysis so that it can be used in SIL without BasicCalleeAnalysis
2023-12-01 19:20:18 +01:00
Mishal Shah
e8de333daf Revert "Add a mark_dependence while emitting SIL for uninitialized array allocation " 2023-11-12 09:43:13 -08:00
Meghana Gupta
baebc7d00b Handle mark_dependence in Differentiation 2023-10-31 11:07:36 -07:00
Meghana Gupta
473905b6b2 Handle mark_dependence in ArrayElementPropagation 2023-10-27 14:19:21 -07:00
swift-ci
56f70e947a Merge remote-tracking branch 'origin/main' into rebranch 2023-10-10 11:53:54 -07:00
Nate Chandler
9ca6b9ac1f [Test] Print to stdout.
In the C++ sources it is slightly more convenient to dump to stderr than
to print to stdout, but it is rather more unsightly to print to stderr
from the Swift sources.  Switch to stdout.  Also allows the dump
functions to be marked debug only.
2023-10-10 08:19:44 -07:00
swift-ci
6cf1f90e79 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-04 04:35:13 -07:00
Tony Allevato
5f5b24f96e [C++20] Make operator{==,!=}s const.
In C++20, the compiler will synthesize a version of the operator
with its arguments reversed to ease commutativity. This reversed
version is ambiguous with the hand-written operator when the
argument is const but `this` isn't.
2023-10-03 17:10:57 -04:00
swift-ci
8b0b25f404 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-02 13:33:12 -07:00
Kuba Mracek
28a3d583c8 [embedded] Re-enable ReleaseDevirtualizer and teach it to look for specialized destructors 2023-09-29 16:28:59 -07:00
swift-ci
a41a67e7cb Merge remote-tracking branch 'origin/main' into rebranch 2023-09-22 01:43:50 -07:00
Andrew Savonichev
2f7b42ceaf [AutoDiff] Handle init_enum_data_addr and inject_enum_addr for Optional (#68300)
Optional's `init_enum_data_addr` and `inject_enum_addr` instructions are generated in presence of non-loadable Optional values. The compiler used to treat these instructions as inactive, and this resulted in silent run-time
issues described in #64223.

The patch marks `init_enum_data_addr` as "active" if its Optional operand is also active, and in PullbackCloner we differentiate through it and the related `inject_enum_addr`.

However, we only determine this relation in simple cases when both instructions are in the same block. There is no def-use relation between them (both take the same Optional operand), so if there is more than one set of instructions
operating on the same Optional, or there is some control flow, we currently bail out.

In PullbackCloner, we walk over instructions in reverse order and start from `inject_enum_addr` and its `Optional<Wrapped>.TangentVector` operand. Assuming that is is already initialized, we emit an `unchecked_take_enum_data_addr` and set it as the adjoint buffer of `init_enum_data_addr`. The Optional value is
invalidated, and we have to destroy the enum data address later when we reach `init_enum_data_addr`.
2023-09-22 01:07:16 -07:00