Commit Graph

128 Commits

Author SHA1 Message Date
Michael Gottesman
6718dbf17e [region-isolation] Change how we compute max in separateRegions as we loop rather than using a functional 2nd loop before the main loop. 2023-10-26 12:01:44 -07:00
Michael Gottesman
a46025d040 [region-isolation] Remove Partition::getRegion().
This was a piece of code that I added early while adding better unittesting for
Partition. Instead in that patch I added a forward declared class in Partition
called PartitionTester that could implement getRegion. I just forgot to remove
this.
2023-10-26 12:01:44 -07:00
Michael Gottesman
0bad8f9b67 [region-isolation] Rename SendNonSendable.cpp -> TransferNonSendable.cpp. 2023-10-26 12:01:44 -07:00
Michael Gottesman
4c7e13d3cb [region-isolation] Fix join to be a true union operation including the symmetric difference.
We were performing a union on the intersection of the lhs/rhs but were dropping
the parts of lhs/rhs that were in the symmetric difference of the two sets.

Without this, we would not diagnose cases like this where we had elements on the
lhs/rhs that were not in the intersection.

```
var closure: () -> () = {}

await transferToMain(closure)

if await booleanFlag {
   closure = {
     print(self.klass)
   }
} else {
   closure = {}
}
// At this point we would lose closure since they were different elements

await transferToMain(closure) // We wouldn't error on this!
```

rdar://117437059
2023-10-25 17:05:11 -07:00
Michael Gottesman
cfd00e842f [region-isolation] Fix header in PartitionUtils.h
NFC.
2023-10-25 13:17:20 -07:00
Michael Gottesman
c10c4fc10f Merge pull request #69387 from gottesmm/more-region-stuff
[region-isolation] Fix actor region propagation and some other smaller issues.
2023-10-25 11:46:19 -07:00
Michael Gottesman
30933db69f [region-isolation] When printing PartitionOps, print the instruction that they are derived from.
Otherwise, it is hard to tell what one is looking at when looking at the
pseudo-ir.
2023-10-24 16:36:02 -07:00
Michael Gottesman
9dfc9b6a2d [region-isolation] Track if a non-Sendable value was derived from an actor and treat its region as being within an actor's isolation domain.
Importantly, we determine at the error stage if a specific value that is
transferred is within the same region of a value that is Actor derived. This
means that we can in a flow insensitive manner determine the values that are
actor derived and then via propagating those values into various regions
determine the issue... using our region analysis to handle the flow sensitivity.

One important case to reason about here is that since we are relying on the
region propagation for flow sensitivity is that this solves the var case for
us. A var when declared is never marked as actor derived. Var uses only become
actor derived if the var was merged into a region that contain is actor
derived. That means that re-assigning to a non-actor derived value, eliminates
the actor derived bit.

As part of this, I also discovered I could just get rid of the captured uniquely
identified array in favor of just passing in an actor derived flag.

rdar://115656589
2023-10-24 16:35:00 -07:00
Michael Gottesman
d069169c0d Fix some typos. 2023-10-24 12:47:11 -07:00
Michael Gottesman
2c0efe6b8b [region-isolation] Go through the implementation again changing Consume -> Transfer.
I just missed these.
2023-10-23 13:52:14 -07:00
Michael Gottesman
578eafdb46 [region-isolation] Eliminate a temporary std::vector.
We can just pass in an ArrayRef here. I missed this inefficiency when I was
going through the pass earlier.
2023-10-23 12:24:17 -07:00
Michael Gottesman
fb7b4a3a32 [region-isolation] Add verbose logging to PartitionUtils behind a flag.
One needs to pass in the explicit flag to enable this as well as
-debug-flag=send-non-sendable. This makes it easier to debug the affect of
applying specific partition ops.
2023-10-23 12:24:17 -07:00
Michael Gottesman
8d46cc8c08 [isolation-regions] Rename Consume to Transfer.
Transfer is the terminology that we are using for something be transferred
across an isolation boundary, not consume. This also eliminates confusion with
consume which is a term being used around ownership.
2023-09-22 16:21:46 -05:00
Michael Gottesman
82fbde0e04 [send-non-sendable] Ensure that we properly warn if a field of a final actor is transferred.
Previously, we were not recognizing that a ref_element_addr from an actor object
is equivalent to the actor object and we shouldn't allow for it to be consumed.

rdar://115132118
2023-09-12 12:46:37 -05:00
Michael Gottesman
3a377a3e51 [send-non-sendable] When logging the pseudo-ir dump out the root representative value associated with pseudo-ir ids.
Really, we should just be using representative values here in general since it
serves the same purpose and makes it easier to trace back values. But this in
the short term makes the output easier to reason about.
2023-09-12 12:11:44 -05:00
Michael Gottesman
42df9c4c72 [send-non-sendable] Cleanup logging a little.
Specifically:

1. Converted llvm::errs() -> llvm::dbgs() when using LLVM_DEBUG.
2. Converted a dump method on errs to be a print method on dbgs that is called from dump with print(llvm::dbgs()).
2023-09-12 12:11:44 -05:00
Michael Gottesman
a1daf817f3 [send-non-sendable] Remove ASCII color from log output.
Not everyone uses color output and having to remove the ASCII color support is
annoying.
2023-09-11 09:07:29 -05:00
jturcotti
bb2f3c011e rename DeferredSendableChecking pass to SendNonSendable pass, handle more instructions such as try_apply and begin_apply, and fix bugs 2023-07-27 16:45:29 -07:00
jturcotti
853ef7cf3c fix bugs that present themselves when handling multiarg and varargs functions, including adding better debug dump methods 2023-07-20 14:01:08 -07:00
jturcotti
a83d7aa39c improve diagnostics about data races; highlight the individual expressions being sent and accessed as precisely as possible, and include information about specific non-sendable types and isolation crossings 2023-07-19 17:27:16 -07:00
jturcotti
55e8f9f2ed improve debug output, finalize explicit constructor refactor, and begin improving diagnostic messages 2023-07-18 15:58:56 -07:00
jturcotti
3868f1dc27 perform refactor to use named types as elements and regions in partitions, and ensure that all SILValues are converted once to TrackableSILValues in the SendNonSendable analysis pass 2023-07-18 13:32:43 -07:00
jturcotti
34113c4c0f implement searching for a ConsumeReason instead of just diagnosing accesses to consumed values 2023-07-14 16:12:52 -07:00
jturcotti
1d130390be add more comprehensive cases to tests, and fix many bugs, relying on much more potent resolution of addresses 2023-07-14 09:28:27 -07:00
jturcotti
1a716d82cf replace use of internal "projections" tracking map with usage of memutils' AccessStorage utilities 2023-07-14 09:28:26 -07:00
jturcotti
e7a1747af2 Tweak, improve, and debug the PartitionAnalysis engine until a fairly comprehensive suite of simple tests passes (region_based_sendability.swift) 2023-07-11 11:12:38 -07:00
jturcotti
29bd728f4c Begin to fill in the SendNonSendable SIL pass using a PartitionAnalysis engine, works for some simple examples but needs to address address values in SIL. 2023-07-10 15:20:14 -07:00
jturcotti
aae9f43bda Write PartitionUtils.h, implementing common utilities for manipulating a partition data structure that will be used for flow-sensitive, region-based Sendable checking. 2023-07-10 15:20:14 -07:00