Commit Graph

191 Commits

Author SHA1 Message Date
Michael Gottesman
feec25cb05 [region-isolation] Mark get_async_continuation{,addr} and extract_executor as AssertingIfNonSendable. 2024-02-02 14:50:10 -08:00
Michael Gottesman
4414636f5f [region-isolation] Add support for bind_memory and rebind_memory. 2024-02-02 14:50:10 -08:00
Michael Gottesman
62a64d3b37 [region-isolation] Update for throw_addr.' 2024-02-02 14:50:10 -08:00
Michael Gottesman
45bb16764e [region-isolation] Add support for await_async_continuation. 2024-02-02 14:50:10 -08:00
Michael Gottesman
4218f5b79d [region-isolation] Teach the checker about unmanaged {retain, release, autorelease}. 2024-02-02 14:50:10 -08:00
Michael Gottesman
0cfe58cca1 [region-isolation] Mark all assign_* variants as asserting since they should be eliminated by DI before we run. 2024-02-02 14:50:10 -08:00
Michael Gottesman
3cacb1f86d [region-isolation] Add support for mark_function_escape. 2024-02-02 14:50:10 -08:00
Michael Gottesman
e3274b34ad [region-isolation] Move unhandled pack instructions away from the rest of unhandled instructions. 2024-02-02 14:50:10 -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
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