Commit Graph

34 Commits

Author SHA1 Message Date
Michael Gottesman
85fafa5b1e [rbi] Begin tracking if a function argument is from a nonisolated(nonsending) parameter and adjust printing as appropriate.
Specifically in terms of printing, if NonisolatedNonsendingByDefault is enabled,
we print out things as nonisolated/task-isolated and @concurrent/@concurrent
task-isolated. If said feature is disabled, we print out things as
nonisolated(nonsending)/nonisolated(nonsending) task-isolated and
nonisolated/task-isolated. This ensures in the default case, diagnostics do not
change and we always print out things to match the expected meaning of
nonisolated depending on the mode.

I also updated the tests as appropriate/added some more tests/added to the
SendNonSendable education notes information about this.

(cherry picked from commit 14634b6847)
2025-07-09 12:25:03 -07:00
Michael Gottesman
065ffa3b72 [rbi] Convert all rbi tests to run also in NonisolatedNonsendingByDefault.
Going to update the tests in the next commit. This just makes it easier to
review.

(cherry picked from commit a6edf4fb90)
2025-07-09 12:24:17 -07:00
Michael Gottesman
0d519a1acb [sema] Change non-sendable -> non-Sendable in diagnostics.
This matches send non sendable but importantly also makes it clear that we are
talking about something that doesn't conform to the Sendable protocol which is
capitalized.

rdar://151802975
(cherry picked from commit 3ed4059a60)
2025-05-23 10:31:05 -07:00
Michael Gottesman
c48a9cc72f test updates 2024-12-02 16:54:12 -05:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Allan Shortlidge
c02fc4724d Tests: Remove -disable-availability-checking from many Concurrency tests.
Instead, use the `%target-swift-5.1-abi-triple` substitution to compile the tests
for deployment to the minimum OS versions required for use of _Concurrency APIs.
2024-10-18 16:21:51 -07:00
Holly Borla
bd1653e497 [Concurrency] Split up the non-Sendable result diagnostics and improve
wording.
2024-08-05 09:56:11 -07:00
Holly Borla
d40663dd66 [Concurrency] Flip the implicitly async select in a concurrency error.
This diagnostic was presenting "implicitly async" for explicitly async calls,
and vice versa, because the `select` was incorrect.
2024-07-31 06:46:07 -07:00
Michael Gottesman
ebedf63138 [region-isolation] Do not squelch use-after-transfer error even if the value is isolated to the same actor.
rdar://132074953
2024-07-19 02:25:53 -07:00
Michael Gottesman
03b26fd65b [region-isolation] Treat async let as a isolation inference boundary closure and fix diagnostics due to change.
Otherwise, we will assume that an async let autoclosure infers isolation from
its DeclContext... which we do not want. An async let autoclosure should always
be nonisolated + sending.

The diagnostic change that I mentioned in the header is that we were emitting
unfortunate "sending task or actor isolated could result in races" error. I
eliminated this by adding a new diagnostic for transfer non transferrable errors
happening in autoclosures. So now we emit this:

```swift
  func asyncLetInferAsNonIsolated<T : Actor>(
    isolation actor: isolated T
  ) async throws {
    async let subTask: Void = {
      await useValueAsyncNoReturnWithInstance(self, actor)
      // expected-warning @-1:47 {{sending 'self' risks causing data races}}
      // expected-note @-2 {{sending 'actor'-isolated 'self' into async let risks causing data races between nonisolated and 'actor'-isolated uses}}
    }()
    await subTask
```

I also noticed that we did not have enough test cases for autoclosures in
general so I also added a bunch of tests just so we can see what the current
behavior is. I think there are a few issues therein (I believe some may have
been reported due to '??').

rdar://130151318
2024-07-08 11:22:29 -07:00
Michael Gottesman
31df5f233f [region-isolation] Now that turning off region isolation has been removed cleanup transfernonsendable_asynclet.swift. NFC. 2024-07-01 13:12:36 -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
Holly Borla
1a07152ee0 [NFC][Concurrency] Remove -disable-region-based-isolation-with-strict-concurrency
from tests.
2024-06-19 20:48:59 -07:00
Michael Gottesman
bd472b12be [region-isolation] Make store_borrow a store operation that does not require.
TLDR:

The reason why I am doing this is it ensures that temporary store_borrow that we
create when materializing a value before were treated as uses. So we would error
on this:

```swift
@MainActor func transferToMain<T>(_ t: T) async {}

func test() async {
  let x = NonSendableKlass()
  await transferToMain(x)
  await transferToMain(x)
}
```

----

store_borrow is an instruction intended to be used to initialize temporary
alloc_stack with borrows. Since it is a temporary, we do not want to error on
the temporaries initialization... instead, we want to error on the use of the
temporary parameter.

This is achieved by making it so that store_borrow still performs an
assign/merge, but does not require that src/dest be alive. So the regions still
merge (yielding diagnostics for later uses).

It also required me to make it so that PartitionOp::{Assign,Merge} do not
require by default. Instead, we want the individual operations to always emit a
PartitionOp::Require explicitly (which they already did).

One thing to be aware of is that when it comes to diagnostics, we already know
how to find a temporaries original value and how to handle that. So this is the
last part of making store_borrow behave nicely.

rdar://129237675
2024-06-12 15:01:38 -07:00
Michael Gottesman
88729b9e34 [sending] Make {Transferring,Sending}ArgsAndResults a LANGUAGE_FEATURE instead of an UPCOMING_FEATURE.
TLDR: This makes it so that we always can parse sending/transferring but changes
the semantic language effects to be keyed on RegionBasedIsolation instead.

----

The key thing that makes this all work is that I changed all of the "special"
semantic changes originally triggered on *ArgsAndResults to now be triggered
based on RegionBasedIsolation being enabled. This makes a lot of sense since we
want these semantic changes specifically to be combined with the checkers that
RegionBasedIsolation turns on. As a result, even though this causes these two
features to always be enabled, we just parse it but we do not use it for
anything semantically.

rdar://128961672
2024-06-01 23:25:16 -07:00
Michael Gottesman
de85b79423 [concurrency] Make GlobalActorIsolatedTypesUsability an upcoming swift 6 feature.
rdar://118244451
2024-05-13 18:40:58 -07:00
Michael Gottesman
f64f2529fb [region-isolation] Some more diagnostic wordsmithing.
rdar://127580781
2024-05-06 19:20:07 -07:00
Michael Gottesman
e4db879112 [region-isolation] Some more diagnostic wordsmithing.
rdar://127580781
2024-05-06 12:09:10 -07:00
Michael Gottesman
787bb7d249 [region-isolation] Create a non-"callee" kind of error for async let.
I am doing this separately from the previous fix for just normal region
isolation since without transferring args and results enabled, we do not hit
this code path. But since I am here, I want to fix it at the same time.

rdar://127588005
2024-05-05 22:39:59 -07:00
Michael Gottesman
f02172a323 [region-isolation] Change terminology to use the term 'risk' instead of could. 2024-05-05 18:01:05 -07:00
Michael Gottesman
a933c14b77 [region-isolation] Only print the type of region that a value is in if it is not disconnected.
Just another diagnostic tweak.
2024-05-05 18:01:05 -07:00
Michael Gottesman
0b761109e2 [region-isolation] If we can infer the callee's name, use that instead of just saying 'callee'.
I also wordsmithed the error message to use the term 'risk' instead of less
negative terms.
2024-05-05 18:01:05 -07:00
Michael Gottesman
699692bd39 [region-isolation] Change diagnostics from using the term transferring -> sending.
rdar://127580781
2024-05-05 18:00:54 -07:00
Michael Gottesman
a56d0f5ded [region-isolation] Tweak the main transferring diagnostic.
Specifically, I am transforming it from "may cause a race" -> "may cause a data
race". Adding data is a small thing, but it adds a bunch of nice clarity.
2024-04-06 22:50:26 -07:00
Michael Gottesman
b3e837c16c [region-isolation] Enable region isolation by default with strict-concurrency.
I added a disable flag -disable-region-based-isolation-with-strict-concurrency
so that we do not need to update the current tests. It is only available when
asserts are enabled to ensure users cannot use it.

rdar://125918028
2024-04-04 13:07:32 -07:00
Michael Gottesman
7cda418d45 [region-isolation] Convert the isolation having autoclosure expr error to use a named variant.
It was pretty easy to do since I already have the name from the AST.
2024-03-23 21:17:41 -07:00
Michael Gottesman
2f9b519758 [region-isolation] Wordsmith "{access,use} here could race".
I am doing this since it isn't always going to be an access. We may not have
memory. We are talking about uses here!

I was able to just use sed so it was an easy fix.
2024-03-23 17:19:09 -07:00
Michael Gottesman
357a53ab48 [region-isolation] Clean up use after transfer error to use the dynamic isolation information of the transfered operand value in its diagnostic message.
As an example of the change:

-  // expected-note @-1 {{'x' is transferred from nonisolated caller to main actor-isolated callee. Later uses in caller could race with potential uses in callee}}
+  // expected-note @-1 {{transferring disconnected 'x' to main actor-isolated callee could cause races in between callee main actor-isolated and local nonisolated uses}}

Part of the reason I am doing this is that I am going to be ensuring that we
handle a bunch more cases and I wanted to fix this diagnostic before I added
more incaranations of it to the tests.
2024-03-22 13:12:51 -07:00
Michael Gottesman
8b899b8f71 [region-isolation] Teach variable_name_inference how to infer through store_borrow initialized variables.
This eliminates a bunch of cases where we couldn't infer the name of a variable
and used the type based diagnostic.

It also eliminates an 'unknown' case for move checking.
2024-03-19 13:19:09 -07:00
Michael Gottesman
acca7353db [transferring] Make async let take a transferring result if its result is non-Sendable.
Some notes:

1. If the result is non-Sendable and we didn't infer something that is
transferring, we still emit the current sema error that says that one cannot
assign a non-Sendable value to an async let.

2. When region isolation is enabled, but transferring args and results are
disabled, we leave the async let semantics alone. This means that the async let
closure is still @Sendable and one cannot pass in non-Sendable values to it.
2024-03-13 15:30:54 -07:00
Michael Gottesman
99e3f7fb13 [region-isolation] Make RegionBasedIsolation an upcoming feature for swift 6.
To make the tests pass, I had to teach sil-opt how to setup upcoming features
since it did not know how to parse them.

rdar://124100266
2024-03-05 15:15:14 -08:00
Michael Gottesman
1776ce4820 [region-isolation] Make sure that we can handle an async let without any captures correctly.
Previously, we assumed we would always have a partial_apply. In the case where
we do not capture any values this is not true since we instead have a
thin_to_thick_function.
2024-02-27 14:10:15 -08:00
Michael Gottesman
3641050675 [region-isolation] Wordsmith some diagnostics.
I tried to make them shorter and standardized on "; later accesses could race"
as the mark on a diagnostic that the problem was that a race was occuring
(before we had several small different variations).
2024-01-19 15:38:41 -08:00
Michael Gottesman
c0b9f4008e [transfer-nonsendable] Rename tests from sendnonsendable_* -> transfernonsendable_*
I also renamed sendnonsendable_basic.sil ->
transfernonsendable_instruction_matching.sil since that is what the test is
intended to be used for... mechanical instruction level modeling tests rather
than more complex crashers.
2023-12-15 11:21:31 -08:00