swift
[send-non-sendable] Treat final fields of actors and values returned from actor methods as non-transferrable
#68466
Merged

[send-non-sendable] Treat final fields of actors and values returned from actor methods as non-transferrable #68466

gottesmm
gottesmm1 year ago

This PR contains a bunch of small incremental changes. I am batching a little bit so that Slava can review them all together after their vacation.

Major Change:

  1. I changed how we handle final fields of actors so that we properly error upon them. This involved changing how we wire up values into the neverConsumedValue list. Before, we just inserted function arguments that were non-sendable into that list... of course since an actor is Sendable, the actor was never actually placed into the array. Instead what we do now is when we begin tracking a new value we see if we have a load [copy] or load_borrow. If we do, we look again for the AccessStorage root and if that is a ref_element_addr from an actor, we add the value to the never consumed value array.
  2. I changed how we handle methods and non-final fields (read: getters) of actors. Previously, we just would treat the non-sendable results of such methods as new values that could be transferred. This is incorrect since those values could contain values that are still referenced by the actor and transferred. Instead, with this PR, if we see that we are returning a method where self is an actor, we still mark the value as a new value, but we also mark it as not being able to be consumed. One interesting side-effect of this is that it means that if one passes a non-sendable argument to an actor method that returns a value, the argument in the caller becomes infected by the never consuming bit even if it is never used in the method. This actually matches what we already see when send non sendable is not enabled since a non-sendable value would not be allowed to be transferred anyways.

Small Changes:

  1. At the beginning I have a few cleanup commits around making the logging easier to understand and eliminating some unnecessary heap allocations.
  2. I converted the large is() code that is used for instruction translation to instead use a switch. In a subsequent commit I am going to make that switch exhaustive so we know we handle /all/ instructions.
  3. I discovered while doing this that one of the instructions that we didn't handle was project_box which as a result caused us to crash when handling certain closure capture situations.
  4. I modified the main test that I am going to start building up to emit diagnostics both with/without send non sendable.

rdar://115132118
rdar://115367810

gottesmm [send-non-sendable] Remove ASCII color from log output.
a1daf817
gottesmm [send-non-sendable] Convert SILInstruction translation to use an exha…
336ed714
gottesmm [send-non-sendable] Cleanup logging a little.
42df9c4c
gottesmm [send-non-sendable] Eliminate a bunch of temporary heap allocations c…
cd7213e3
gottesmm [send-non-sendable] Eliminate another pass by value of a std::vector.
969477ac
gottesmm [send-non-sendable] Convert some llvm::Optional -> std::optional.
acd1063c
gottesmm [send-non-sendable] When logging the pseudo-ir dump out the root repr…
3a377a3e
gottesmm [send-non-sendable] Make sure that we translate project_box into the …
3382352a
gottesmm [send-non-sendable] Ensure that we properly warn if a field of a fina…
82fbde0e
gottesmm [send-non-sendable] Add complete- warnings to sendnonsendable_basic.s…
0579b354
gottesmm [send-non-sendable] Warn if a non-final field of an actor is transfer…
4dcee718
gottesmm gottesmm requested a review from slavapestov slavapestov 1 year ago
gottesmm gottesmm requested a review from ktoso ktoso 1 year ago
gottesmm gottesmm requested a review from kavon kavon 1 year ago
gottesmm
gottesmm1 year ago
gottesmm gottesmm merged 163d5bce into main 1 year ago
gottesmm gottesmm deleted the actor-field-access-sns branch 1 year ago

Login to write a write a comment.

Login via GitHub

Reviewers
Assignees
No one assigned
Labels
Milestone