Commit Graph

88 Commits

Author SHA1 Message Date
Pavel Yaskevich
9e562881fe [TypeChecker] Improve diagnostics for access to actor-isolated values outside of the actor
Replaces generic `expression is 'async' but is not marked with 'await`
diagnostic with a tailed one for cases where there is an access to an
actor-isolated value outside of its actor without `await` keyword.

This makes the diagnostics for async and sync contexts consistent
and actually identifies a problem instead of simply pointing out
the solution.

Resolves: rdar://151720646
2025-05-23 00:20:18 -07:00
Michael Gottesman
3ed4059a60 [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
2025-05-22 11:37:58 -07:00
Anthony Latsis
925b72eaec Merge pull request #76337 from DePasqualeOrg/grammar-compound-modifiers
Grammatical corrections for compound modifiers
2025-04-25 13:50:52 +01:00
Anthony
c9b17383c8 Grammatical corrections for compound modifiers 2025-04-24 09:21:32 +02:00
Anthony Latsis
2cd90bdd69 AST: Quote attributes more consistently in DiagnosticsSema.def 2025-04-22 18:23:36 +01:00
Holly Borla
6ca27d3f84 [Concurrency] Allow capturing pack expansions in @Sendable closures
if the pattern type conforms to `Sendable`.
2025-03-24 08:50:01 -07:00
Slava Pestov
e37a2d065d Sema: Fix Sendable generic parameter fixit
Fixes rdar://problem/144644342.
2025-02-27 13:15:13 -05:00
Anthony Latsis
eeb991122a [NFC] Switch from backticks to quotes in several diagnostics 2025-01-29 07:49:27 +00:00
Michael Gottesman
c48a9cc72f test updates 2024-12-02 16:54:12 -05:00
Allan Shortlidge
082f0ac4b5 Tests: Use a more natural spelling for ABI triple lit substitutions.
`%target-swift-5.8-abi-triple` instead of `%target-swift-abi-5.8-triple`, for
example.
2024-10-18 10:11:36 -07:00
Ben Langmuir
7d11d43d6d [test] Add explicit targets to tests depending on the default
Add specific deployment target versions to some tests that need to test
10.x-specific behaviours and are currently depending on the default
deployment target.

Certain tests were only checking either the stable or unstable ABI
depending on the platform the test was running. In those cases I doubled
up the checks so that we would test both cases on platforms that
supported it. This might use a bit of extra time on targets that only
support the stable ABI, but it seemed worth it for the additional
coverage in CI.
2024-08-29 07:55:14 -07:00
Guillaume Lessard
79bf5d51ca Merge pull request #75782 from glessard/rdar133343460-incorrectly-sendable
[stdlib] fix sendability of ManagedBufferPointer
2024-08-08 16:28:19 -07:00
Guillaume Lessard
a9a7c8aa88 [test] check non-sendability of ManagedBuffer[Pointer] 2024-08-08 11:31:16 -07:00
Holly Borla
976d92143c [Concurrency] Split up the non-Sendable property diagnostics and improve
wording.
2024-08-05 14:56:45 -07:00
Holly Borla
9f0b2ec746 [Concurrency] Minor wording change to witness and override Sendable diagnostics. 2024-08-05 10:05:08 -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
933f8eb8a0 [Concurrency] Split up the non-Sendable argument diagnostics and improve
wording.

Splitting up the diagnostic into separate diagnostics based on the reference
kind is easier for me to read. The wording of the error message now puts
the problem -- crossing an isolation boundary -- at the center of the message,
and attempts to clarify how the value crosses an isolation boundary. E.g. for
the witness diagnostics, the value crosses an isolation boundary when calling
the witness through the protocol requirement in generic code.

This change does not add any additional information to the diagnostics, but it'd
be valuable to show both the source and destination isolation.
2024-08-05 08:23:30 -07:00
Holly Borla
9c941920fa Merge pull request #75578 from hborla/correct-implicit-async-diagnostic
[Concurrency] Flip the implicitly async `select` in a concurrency error.
2024-07-31 14:33:50 -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
Holly Borla
dfea802e51 [Concurrency] Delete sendable checking subsumed by region isolation.
Sema's sendable checking is subsumed by the region isolation SIL pass. Now
that region isolation is always enabled under complete concurrency checking,
the code can be deleted from the actor isolation checker. Note that this
removes these diagnostics from targeted concurrency checking. I think it's
better to remove these diagnostics from targeted checking because in many
cases, they're false positive data-race reports that the programmer ultimately
won't have to address. If we want these diagnostics in targeted checking, we
should do it via region isolation.
2024-07-30 22:11:49 -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
Holly Borla
85b66d1dc2 [ConformanceLookup] Always prefer unavailable Sendable conformances from the
defining module, and diagnose redundant Sendable conformances.

We still allow re-stating inherited unchecked Sendable conformances in
subclasses because inherited Sendable conformances are surprising when
they opt out of static checking. Otherwise, warning on redundant Sendable
conformances nudges programmers toward cleaning up unnecessary retroactive
Sendable conformances over time as libraries incrementally add the
conformances directly.
2024-07-11 20:33:24 -07:00
Holly Borla
7356fe8c8a [ConformanceLookup] Don't allow skipping inherited unavailable conformances
in favor of explicit available ones.

The type checker does not support the notion of multiple protocol
conformances; there can only be one conformance, and if that conformance
is unavailable, you cannot specify your own available conformance. This
is important for Sendable checking; if a framework specifies that a type
is explicitly not Sendable with an unavailable Sendable conformance,
clients cannot ignore Sendable violations involving that type. If a
superclass wants to allow subclasses to add a Sendable conformance, it
should not declare an unavailable Sendable conformance.
2024-07-10 11:58:17 -07:00
Michael Gottesman
474aa47732 [concurrency] Standardize sending of non-isolated -> nonisolated to match the keyword 'nonisolated'.
rdar://130827967
2024-06-29 18:09:38 -07:00
Michael Gottesman
4697546e09 [sending] Mark Task.init,detached, and friends as sending methods instead of __owned @Sendable so we can capture non-isolated values. 2024-06-21 02:24:03 -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
Slava Pestov
3196164341 Sema: Fix request cycle with isolation inference
Fixes rdar://129024926.
2024-06-03 13:41:42 -04:00
Michael Gottesman
06c32d74ff [region-isolation] Teach SIL isolation inference how to infer applies isolation from their callee's isolation.
This fixes a few issues I missed in the past bit of commits.

I need to fix one issue around async let, but I am going to fix it when I do a
sweep across async let.
2024-05-28 17:31:09 -07:00
Holly Borla
1ec5808119 [Availability] Diagnose unavailable conformances in UnderlyingToOpaqueExpr.
Change the availability checker to check substitution maps of underlying
values for opaque result types to diagnose unavailable conformances. This
change also makes sure `Sendable` availability diagnostics are errors in
Swift 6 mode.
2024-05-16 21:14:06 -07:00
Holly Borla
e044e3d390 [Concurrency] Implicit global actor attributes imply Sendable.
Sendable derivation was only checking for explicit global actor
attributes. It should also account for inferred global actor
attributes, e.g. from protocol conformances.
2024-05-15 22:28:47 -07:00
Holly Borla
29b8e6e6b0 [Concurrency] Un-gate implicit nonisolated access to struct vars and isolated
subclassing.

These features are additive, and they don't need to be gated behind the
`GlobalActorIsolatedTypesUsability` upcoming feature. The other inference
changes, including `@Sendable` inference for global-actor-isolated function
types, and global-actor inference on protocol refinements, remain gated
behind the upcoming flag.
2024-05-14 11:43:25 -07:00
Michael Gottesman
50c2d678f2 [region-isolation] When inferring isolation for an argument, handle non-self isolated parameters as well as self parameters that are actor isolated.
As part of this I went through how we handled inference and rather than using a
grab-bag getActorIsolation that was confusing to use, I created split APIs for
specific use cases (actor instance, global actor, just an apply expr crossing)
that makes it clearer inside the SILIsolationInfo::get* APIs what we are
actually trying to model. I found a few issues as a result and fixed most of
them if they were small. I also fixed one bigger one around computed property
initializers in the next commit. There is a larger change I didn't fix around allowing function
ref/partial_apply with isolated self parameters have a delayed flow sensitive
actor isolation... this will be fixed in a subsequent commit.

This also fixes a bunch of cases where we were printing actor-isolated instead
of 'self' isolated.

rdar://127295657
2024-05-10 15:33:44 -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
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
Holly Borla
38cc9511ee [Concurrency] Stage in new Async{Throwing}Stream.init(unfolding:) errors
as warnings.

Marking the closure parameter to these inits as `@Sendable` changed the
inferred isolation of closure arguments in actor-isolated contexts, which
caused new effects checker errors when accessing isolated properties and
methods without `await`. Mark these `init`s as `@preconcurrency`, and fix
the effects checker to downgrade those errors to warnings when the context
of the call is `@preconcurrency`.
2024-04-26 18:09:37 -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
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
7368de2a20 [region-isolation] Remove variable_defined_here from named use after transfer error.
This is just a pseudo-why are these two things part of the same region error. I
am going to remove this for now and the proper form of this diagnostic will come
back when I land the region history functionality.
2024-03-19 13:19:08 -07:00
Michael Gottesman
afbcf85727 [region-isolation] Change named transfer non transferable error to use the dynamic merged IsolationRegionInfo found during dataflow.
I also eliminated the very basic "why is this task isolated" part of the warning
in favor of the larger, better, region history impl that I am going to land
soon. The diagnostic wasn't that good in the first place and also was fiddly. So
I removed it for now.

rdar://124960994
2024-03-18 12:13:36 -07:00
Michael Gottesman
8f149b4d0e [Concurrency] Change TypeBase::isSendable() to return false for unavailable conformances.
rdar://122174496
2024-03-11 11:29:52 -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
Holly Borla
75858cd211 [Concurrency] Allow capturing nonisolated(unsafe) local variables in
`@Sendable` closures.
2024-03-04 15:04:46 -08:00
Holly Borla
7cc2afd0d4 [Concurrency] Fix an issue where nonisolated(unsafe) did not suppress
`Sendable` warnings on stored properties of `Sendable` types.
2024-03-04 14:46:24 -08:00
Michael Gottesman
f296529ee0 [region-isolation] Change the main race error to be "transferring {could,may} cause a race"
As I was updating tests in the previous commit, I noticed that this would read better to me.
2024-02-22 13:50:06 -08:00