Commit Graph

186 Commits

Author SHA1 Message Date
Doug Gregor
3f1a6c84c2 Update tests for isolated conformances being enabled by default 2025-04-13 15:41:57 -07:00
Anthony Latsis
2d899d0e73 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsCommon.def 2025-04-05 12:31:20 +01:00
Doug Gregor
1b1f28decb Tighten up diagnostics wording a bit 2025-03-20 22:13:19 -07:00
Doug Gregor
9ea735b9ed Rework diagnostics for conformance isolation failures
A protocol conformance can be ill-formed due to isolation mismatches
between witnesses and requirements, or with associated conformances.
Previously, such failures would be emitted as a number of separate
errors (downgraded to warnings in Swift 5), one for each witness and
potentially an extra for associated conformances. The rest was a
potential flood of diagnostics that was hard to sort through.

Collect all of the isolation-related problems for a given conformance
together and produce a single error (downgraded to a warning when
appropriate) that describes the overall issue. That error will have up
to three notes suggesting specific courses of action:
* Isolating the conformance (when the experimental feature is enabled)
* Marking the witnesses as 'nonisolated' where needed
*

The diagnostic also has notes to point out the witnesses/associated
conformances that have isolation problems. There is a new educational
note that also describes these options.

We give the same treatment to missing 'distributed' on witnesses to a
distributed protocol.
2025-03-20 21:23:16 -07:00
Doug Gregor
cd99fb57fd [Diagnostics] Remove unhelpful notes from witness-isolation diagnostics
When diagnosing an isolation mismatch between a requirement and witness,
we would produce notes on the requirement itself suggesting the addition of
`async`. This is almost never what you want to do, and is often so far
away from the actual conforming type as to be useless. Remove this note,
and the non-function fallback that just points at the requirement, because
they are unhelpful.

This is staging for a rework of the way we deal with conformance-level
actor isolation problems.
2025-03-19 17:18:52 -07:00
Anthony Latsis
e626887dcc Sema: Improve requirement indicator note for actor_isolated_witness
`x declared here` is not helpful and clear enough, especially when there
are other notes attached. Swap it for a new note that says
`requirement x declared here`.
2025-01-14 14:52:41 +00:00
Anthony Latsis
f85eb97337 ConformanceChecker: Make actor_isolated_witness call out the protocol 2025-01-14 14:49:22 +00:00
Allan Shortlidge
cb578172ea Tests: Remove -disable-availability-checking in more tests that use concurrency.
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,
instead of disabling availability checking.
2024-10-19 12:35:20 -07:00
Slava Pestov
fefde3b4c4 Sema: Fix crash with property override and almost-valid superclass
It's possible that getSuperclassDecl() returns something but
getSuperclass() does not, for example if you reference a generic
superclass with missing or invalid generic arguments. We would
crash in that case when going down this particular code path.

However, the call to getSuperclass() and the entire function it
appeared in was actually unnecessary.

Fixes https://github.com/swiftlang/swift/issues/74651
Fixes rdar://problem/130394943
2024-08-02 11:41:59 -04:00
Hamish Knight
61156e1e6b [Sema] Avoid diagnosing overrides for invalid decls
Invalid decls won't match any overrides in the
base class, so avoid diagnosing that they don't
override anything.
2024-07-15 12:47:50 +01:00
Holly Borla
135e3f2ee9 Merge pull request #73889 from hborla/deprecate-anyactor
[Concurrency] Deprecate `AnyActor`.
2024-05-30 09:36:35 -07:00
Holly Borla
c20b0e0956 [Concurrency] Obsolete AnyActor in Swift 6 using a typealias. 2024-05-29 22:59:19 -07:00
Doug Gregor
5a0e70a2bc Update diagnostic text to address code review feedback 2024-05-20 22:06:40 -07:00
Doug Gregor
640042f396 Suggest @preconcurrency on conformances it could help
When diagnosing a case where an actor-isolated witness cannot satisfy
a non-isolated requirement, also suggest that the conformance could be
annotated with `@preconcurrency`.
2024-05-20 22:06:40 -07:00
Holly Borla
9ba481ad53 [Diagnostics] Clarify the wording of error_in_future_swift_version. 2024-03-01 12:05:51 -08:00
Holly Borla
eba4545536 [Concurrency] Warn if implied @unchecked Sendable conformances are not
re-stated.
2024-02-23 23:59:16 -08:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Holly Borla
ecd94e4908 [Concurrency] Diagnose @GlobalActor(unsafe) attributes with a fix-it to use
`@preconcurrency` instead.

This diagnosic is a warning until Swift 6, and it's ignored in swiftinterfaces.
2024-01-21 21:05:33 -08:00
Holly Borla
79593411d9 [Concurrency] Set preconcurrency for actor isolation created from unsafe global
actor attributes.
2024-01-19 09:29:13 -08:00
Doug Gregor
b7fd43949a Remove the TypedThrows experimental feature from the remaining tests 2024-01-03 22:08:56 -08:00
Doug Gregor
651d4f87b8 Merge pull request #70236 from DougGregor/required-inits-69965
Diagnose *all* cases where a subclass fails to override a required init
2023-12-05 11:59:14 -08:00
Doug Gregor
428d718635 Diagnose *all* cases where a subclass fails to override a required init
In cases where a subclass was unable to synthesize any initializers
(for example, because there were missing designated initializers in the
superclass), we were skipping checking of superclass required
initializers. This meant that we would silently accept subclasses that
cannot be initialized directly (that would produce an error), but
could at runtime be initialized via a required initializer... that
didn't account for the subclass.

Fixes the original problem from https://github.com/apple/swift/issues/69965,
but not the most minimal one.
2023-12-04 16:09:28 -08:00
Holly Borla
b5286580ee [Concurrency] Diagnose actor-isolated witnesses to nonisolated protocol
requirements for explicitly isolated types under minimal checking.
2023-12-01 18:23:37 -08:00
Doug Gregor
628f5cbc2c [Typed throws] Support overrides that are contravariant in the thrown error 2023-11-16 10:42:55 -08:00
Doug Gregor
3baf6ac31a Revert "[Typed throws] Support overrides that are contravariant in the thrown error" 2023-11-16 10:40:23 -08:00
Doug Gregor
33d694468c [Typed throws] Support overrides that are contravariant in the thrown error 2023-11-13 22:30:26 -08:00
Danilo Camarotto
78adeb6070 Incorrect location of 'async' for protocol in actor's fix suggestion (#69246)
* implementing changes and tests

* added unit test using throws

* adding test with distributed actor

* moved distributed-actor tests to another file

* revert import Distributed
2023-11-06 13:44:46 -03:00
Anthony Latsis
14b70f306b DiagnosticVerifier: Default expected fix-it start line to the diagnostic's 2023-03-08 12:10:27 +03:00
Kavon Farvardin
e288db42f0 prevent extensions from having designated inits for actors
When I began removing `convenience` from actor inits, I thought it would
be ok for an actor's extensions to be non-delegating. But that's wrong,
because the actor could be in a resilient module and still have its
properties change between stored and computed, meaning that there isn't
a practical way to allow this, unless if the extension and the actor
are in the same file.

For now, just re-ban this behavior before anybody notices :)
2022-06-30 15:52:15 -07:00
Konrad `ktoso` Malawski
60ef959fc0 adjust last tests 2022-06-22 09:43:45 +09:00
Slava Pestov
dac8d666ee Stop passing -requirement-machine-{abstract,inferred,protocol}-signatures flags in tests
These flags are now no-ops.
2022-05-10 12:56:17 -04:00
Doug Gregor
fdc6260bc1 Reimplement conformance isolation checking using the actor reference logic.
Reimplement the final client of ActorIsolationRestriction, conformance
isolation checking, to base it on the new "actor reference" logic.
Centralize the diagnostics emission so we have a single place where we
emit the primary diagnostic (which is heavily customized based on
actor isolation/distributed/etc.) and any relevant notes to make
adjustments to the witness and/or requirement, e.g., adding
'distributed', 'async', 'throws', etc. Improve the diagnostics
slightly by providing Fix-Its when suggesting that we add "async"
and/or "throws".

With the last client of ActorIsolationRestriction gone, remove it
entirely.
2022-04-07 17:10:02 -07:00
Slava Pestov
4d15fa0087 RequirementMachine: Don't diagnose trivial circularity 'protocol P : P' as redundant
Every protocol gets an 'identity conformance' rule [P].[P] => [P].
A trivially-stated circularity is always redundant because of this
rule, and we diagnose circular inheritance elsewhere as a hard
error, so just add a special case to skip adding such a rule here
to avoid the useless warning on top of the existing error.
2022-04-05 21:12:51 -04:00
Slava Pestov
4068c9d707 Pass -requirement-machine-{protocol,inferred}-signatures=verify in remaining tests that fail due to diagnostics 2022-04-01 23:55:34 -04:00
Allan Shortlidge
093b8d32db [Sema] Emit an error for attempts to use @available on var declarations that have attached property wrappers. Availability is not supported on stored properties, and properties with property wrappers are stored properties with a layer of indirection. Also, add the same missing diagnostic for lazy vars.
Resolves rdar://82713248
2022-02-03 09:02:59 -08:00
Doug Gregor
104cd479fa Determine concurrency diagnostic behavior based on conformance context.
When determining whether to warn, error, or be silent about
concurrency-related issues detected between a protocol requirement and
its witness, decide based on the context of the conformance rather
than based on the context of the witness. Fixes rdar://88205585.
2022-01-28 15:13:23 -08:00
Doug Gregor
5a6f58e686 Teach witness matching to apply minimal/strict diagnostics rules.
This downgrades some errors to warnings in Swift 5 mode, and ensures that
we diagnose all conditions in Swift 6 mode.
2021-12-02 22:24:09 -08:00
Doug Gregor
7012a0580a Update a test 2021-11-18 22:12:58 -08:00
Kavon Farvardin
5e5af90a0a make synchronous inits have a nonisolated self 2021-11-04 19:04:13 -07:00
Slava Pestov
c8f3476f19 Don't use back-quotes in diagnostics 2021-09-15 18:38:34 -04:00
Doug Gregor
eeeea49764 Remove -enable-experimental-concurrency almost everywhere. 2021-07-26 21:24:43 -07:00
Doug Gregor
1e2012d816 Disable availability checking in tests that use concurrency 2021-07-20 12:46:26 -07:00
Doug Gregor
29f5d7a64a [SE-0302] Implement '@unchecked Sendable' syntax.
Parse and provide semantic checking for '@unchecked Sendable', for a
Sendable conformance that doesn't perform additional semantic checks
for correctness.

Part of rdar://78269000.
2021-07-11 12:29:53 -07:00
Doug Gregor
102c001137 [SE-0316] Ban "class subscript" in actors, too 2021-07-07 15:02:22 -07:00
Doug Gregor
2bb94f855b [SE-0306] Ban "class" methods and properties in actors.
Within actors, one should use "static", not "class".
Fixes rdar://80285441.
2021-07-07 14:44:02 -07:00
Doug Gregor
9ec20776c9 [SE-0306] Make actors semantically "final".
Treat actors as being semantically `final` throughout the type checker.
This allows, for example, a non-`required` initializer to satisfy a
protocol requirement.

We're leaving the ABI open for actor inheritance should we need it.

Addresses rdar://78269551.
2021-06-30 10:59:49 -07:00
Konrad `ktoso` Malawski
eada7df0e4 Ban classes from extending Actor and DistributedActor protocol explicitly (#38050)
* [Concurrency,Distributed] ban inheriting Actor and DistActor explicitly by class

* [Distributed] AnyActor can be a marker protocol
2021-06-25 06:06:35 +09:00
Doug Gregor
5004a5447b [Concurrency] Make "self" parameter of actor-isolated functions 'isolated'.
The notion of "actor-isolated" currently exists at the declaration level.
For functions, it is going to be captured in the function type itself,
where 'self' is declared to be 'isolated'. Model isolation both
ways: the 'self' of a method that is isolated to an actor instance
will be 'isolated' as well.

We are still using declaration-based checking of actor isolation.
However, by mirroring this information we can move more incrementally
over to doing checking based on 'isolated' parameters.
2021-06-07 23:59:38 -07:00
Doug Gregor
3fe712dfda [SE-0313] Enable nonisolated by default. 2021-05-21 15:17:43 -07:00
Pavel Yaskevich
aeddab4dd0 [Parse] Disallow use of actor as a declaration modifier
`actor` is a standalone contextual keyword now and should
be treated as such, `actor class` is no longer allowed
and results in a parse error.

Resolves: rdar://75753598
2021-05-19 16:18:32 -07:00