Commit Graph

4105 Commits

Author SHA1 Message Date
Doug Gregor
4f2476116d Suggest global actor isolation rather than 'isolated' for conformances
Update diagnostic and Fix-It to suggest global actor isolation on a
conformance (e.g, `@MainActor P`) rather than `isolated`.
2025-03-12 23:18:23 -07:00
Pavel Yaskevich
e9fd369824 [Sema] Allow use of @execution(...) attribute on closures 2025-03-12 17:29:40 -07:00
Tony Allevato
68876a6d4a Merge pull request #76636 from allevato/rich-identifiers
Support raw identifiers (backtick-delimited identifiers containing non-identifier characters).
2025-03-12 14:56:14 -04:00
Alexis Laferrière
c0a4056768 Merge pull request #79851 from xymus/deser-recover-conformance-xref
Serialization: Diagnose broken conformances from stale swiftmodule files
2025-03-11 15:07:38 -07:00
Tony Allevato
a68347f299 [Sema] Validate names of @objc declarations with raw identifiers.
If a decl is exported to Objective-C (explicitly or implicitly), it
must be given an explicit name that is a valid Objective-C identifier.
2025-03-11 17:18:44 -04:00
Michael Gottesman
04bb69f426 Merge pull request #79727 from gottesmm/pr-025c1133954b74e7b4eda77e1a6f3bcafd4eb6cf
[concurrency] Add initial support for SwiftSettings to control defaultIsolation at the file level.
2025-03-10 22:35:00 -07:00
Michael Gottesman
f64dd5a8d5 [concurrency] Add initial support for SwiftSettings to control defaultIsolation at the file level.
We introduce a new macro called #SwiftSettings that can be used in conjunction
with a new stdlib type called SwiftSetting to control the default isolation at
the file level. It overrides the current default isolation whether it is the
current nonisolated state or main actor (when -enable-experimental-feature
UnspecifiedMeansMainActorIsolated is set).
2025-03-10 17:33:45 -07:00
Alejandro Alonso
d0513a7aec Merge pull request #79665 from Azoy/value-generics-no-more-experiment
[AST] Make ValueGenerics feature always available
2025-03-10 15:14:34 -07:00
Rintaro Ishizaki
002d7d7cdf [Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning'
directives. Parser knows the diagnostics should be emitted or not.
2025-03-07 21:48:01 -08:00
Alexis Laferrière
fb3944f1b1 Serialization: Error on mismatch between requirements and confirmances
When deserialization a protocol conformance from a binary swiftmodule
file the compiler can encounter inconsistencies caused by stale module
files. Replace the hard crash with a proper error and print the list of
requirements and conformances being compared to stderr for manual
inspection. Recover silently when we can afford to, during indexing or
in LLDB.
2025-03-07 14:05:57 -08:00
Alexis Laferrière
ea5658eece Serialization: Protect readNormalProtocolConformanceXRef
Failures in `readNormalProtocolConformanceXRef` are usually caused by a
dependency change without the required rebuild of its dependents.
Display a proper error instead of crashing when encountering such an
issue during normal compilation. Recover silently when we can afford to,
during indexing or in LLDB.
2025-03-07 14:05:57 -08:00
Allan Shortlidge
6ab32cff94 Sema: Parameterize potential unavailability diagnostics to allow no version.
This allows `X is only available in` diagnostics to be emitted for potential
unavailability in domains that do not support versioning.
2025-03-06 13:04:18 -08:00
Allan Shortlidge
cad1ee75d5 AST: Optimize the layout of AvailabilityRange.
`AvailabilityRange` is now being used as a currency type in more of the
compiler, and some of those uses are in permanent `ASTContext` allocations. The
class wraps the `VersionRange` utility, which is itself a wrapper around
`llvm::VersionTuple` with some additional storage for representing sentinel
values. Even though the two sentinel values can be be represented with just a
single bit of additional storage on top of the 16 bytes required to represent
`VersionTuple`, because of alignment requirements the sentinel values end up
bloating the layout of `VersionRange` by many bytes.

To make `AvailabilityRange` and `VersionRange` more efficient to store, we can
instead reserve two unlikely `llvm::VersionTuple` bit patterns as the sentinel
values instead. The values chosen are the same ones LLVM uses to represent
version tuple tombstones and empty keys in a `DenseMap`.
2025-03-05 07:15:15 -08:00
Allan Shortlidge
fe0688c40e Sema: Update diagnostics to take AvailabilityRange instead of VersionTuple. 2025-03-04 19:41:04 -08:00
Pavel Yaskevich
157e71a791 Merge pull request #79478 from xedin/sendable-completion-handler-fixes
[TypeChecker/NameLookup] SE-0463: A few fixes for `SendableCompletionHandlers` feature
2025-03-04 09:34:10 -08:00
Pavel Yaskevich
eb7b76525c Merge pull request #79651 from xedin/sendability-checks-for-function-conversions
[Concurrency] Implement sendability checking for `@Sendable` function…
2025-03-04 09:33:59 -08:00
Doug Gregor
c169f8850b Merge pull request #79760 from DougGregor/isolated-conformances-checking
Ensure that isolated conformances originate in the same isolation domain
2025-03-04 07:49:53 -08:00
Holly Borla
8be41edf6f [Concurrency] Add a macro for wrapping a function body in a new task. 2025-03-03 20:51:14 -08:00
Doug Gregor
064e0c6264 Ensure that isolated conformances originate in the same isolation domain
This is the missing check for "rule #1" in the isolated conformances proposal,
which states that an isolated conformance can only be referenced within
the same isolation domain as the conformance. For example, a
main-actor-isolated conformance can only be used within main-actor code.
2025-03-03 17:47:50 -08:00
Doug Gregor
ee2450f212 Merge pull request #79724 from DougGregor/isolated-conformances-constraint-system
Prohibit isolated conformances with Sendable(Metatype) constraints
2025-03-01 13:16:32 -08:00
Doug Gregor
6a4d1a41c4 Prohibit isolated conformances with Sendable(Metatype) constraints
Within the constraint system, introduce a new kind of conformance constraint,
a "nonisolated conforms-to" constraint, which can only be satisfied by
nonisolated conformances. Introduce this constraint instead of the normal
conforms-to constraint whenever the subject type is a type parameter that
has either a `Sendable` or `SendableMetatype` constraint, i.e., when the type
or its values can escape the current isolation domain.
2025-03-01 08:19:42 -08:00
Allan Shortlidge
309db1c220 Sema: Update feature availability diagnostics to take AvailabilityDomain. 2025-02-28 14:46:34 -08:00
Allan Shortlidge
bc982097b9 AST/Sema: Adopt AvailabilityDomain arguments in even more diagnostics.
Update potential unavailability diagnostics to take `AvailabilityDomain`
instead of a platform string.
2025-02-28 14:13:24 -08:00
Allan Shortlidge
c89df2fc38 AST/Sema: Adopt AvailabilityDomain arguments in more diagnostics.
Update explicit unavailability and deprecation diagnostics to take
`AvailabiiltyDomain` instead of a platform string.
2025-02-28 13:57:00 -08:00
Doug Gregor
ffca6968ed [Isolated conformances] Diagnose conflict with isolated conformances and Sendable 2025-02-28 13:08:35 -08:00
Allan Shortlidge
272b2b43de AST: Accept AvailabilityDomains as diagnostic arguments.
This simplifies the code to emit availabilty diagnostics and ensures that they
display domain names consistently. While updating existing diagnostics, improve
consistency along other dimensions as well.
2025-02-28 09:18:38 -08:00
Allan Shortlidge
aaa0e0a7b3 AST/Parse: Parse custom availability domain specs in if #available(...).
Delay resolution of availability domain identifiers parsed in availability
specifications until type-checking. This allows custom domain specifications to
be written in `if #available` queries.
2025-02-27 23:07:55 -08:00
Doug Gregor
c7f9f2ee3a Rename "Unsafe" diagnostic group to "StrictMemorySafety"
This lines up with the feature name and is more consistent. Thank you,
Anthony, for the suggestion.
2025-02-27 16:21:11 -08:00
Alejandro Alonso
c1bb143648 Make ValueGenerics feature always available 2025-02-27 10:03:37 -08:00
Allan Shortlidge
e5cd36eeea Merge pull request #79656 from tshortli/defer-availability-domain-resolution
AST/Parse: Always delay AvailabilityDomain lookup to type-checking
2025-02-27 03:41:57 -08:00
Allan Shortlidge
b0afd07e14 AST/Parse: Always delay AvailabilityDomain lookup to type-checking.
This will unblock parsing and type-checking availability queries that specify
custom availability domains, e.g.:

```
if #available(CustomDomain) {
  // Use declarations protected by @available(CustomDomain)
}
```
2025-02-26 21:46:14 -08:00
Doug Gregor
db0d658351 Merge pull request #79645 from DougGregor/enable-se-0458-by-default
[SE-0458] Enable unsafe expressions / attributes / for..in effects by default
2025-02-26 18:51:58 -08:00
Pavel Yaskevich
45ca72ed73 [Concurrency] Implement sendability checking for @Sendable function type conversions
Function conversions that cross an isolation boundary require `Sendable`
argument and result types, and the destination function type must be `async`.
2025-02-26 16:11:16 -08:00
Doug Gregor
b7b5a2a19d [SE-0458] Enable unsafe expressions / attributes / for..in effects by default
With the acceptance of SE-0458, allow the use of unsafe expressions, the
@safe and @unsafe attributes, and the `unsafe` effect on the for..in loop
in all Swift code.

Introduce the `-strict-memory-safety` flag detailed in the proposal to
enable strict memory safety checking. This enables a new class of
feature, an optional feature (that is *not* upcoming or experimental),
and which can be detected via `hasFeature(StrictMemorySafety)`.
2025-02-26 12:30:07 -08:00
Doug Gregor
71e23ac757 Check consistency of isolation of conformances within other conformances
When a protocol conformance somehow depends on an isolated conformance, it
must itself be isolated to the same global actor as the conformance on
which it depends.
2025-02-25 23:03:50 -08:00
Allan Shortlidge
62c8e72f23 AST: Centralize AvailabilityDomain lookup.
Implement lookup of availability domains for identifiers on
`AvailabilityDomainOrIdentifier`. Add a bit to that type which represents
whether or not lookup has already been attempted. This allows both
`AvailableAttr` and `AvailabilitySpec` to share a common implementation of
domain lookup.
2025-02-25 22:00:31 -08:00
Doug Gregor
52c46f838a Parsing and type checking for the definition of isolated conformances
Allow a conformance to be "isolated", meaning that it stays in the same
isolation domain as the conforming type. Only allow this for
global-actor-isolated types.

When a conformance is isolated, a nonisolated requirement can be
witnessed by a declaration with the same global actor isolation as the
enclosing type.
2025-02-25 21:16:51 -08:00
Slava Pestov
7e58d8271f Merge pull request #79619 from slavapestov/cleanups-from-optimize-optional-conversion
Small cleanups from "optimize optional conversion"
2025-02-25 22:28:19 -05:00
Slava Pestov
d56d7045a2 Sema: Remove dead diagnostic 2025-02-25 17:22:41 -05:00
Doug Gregor
115abcb637 Merge pull request #79573 from DougGregor/unsafe-for-in-loop
[SE-0458] Implement "unsafe" effect for the for-in loop
2025-02-24 14:49:45 -08:00
Doug Gregor
50801f9c05 [SE-0458] Implement "unsafe" effect for the for-in loop
Memory unsafety in the iteration part of the for-in loop (i.e., the part
that works on the iterator) can be covered by the "unsafe" effect on
the for..in loop, before the pattern.
2025-02-23 22:50:39 -08:00
Allan Shortlidge
db29a1c6f4 Parse/Sema: Move #available query wildcard diagnostics to Sema.
In order to unblock resolution of availability domains during type-checking
instead of parsing, diagnostics about missing or superfluous wildcards in
availability specification lists need to move to Sema.
2025-02-23 22:09:33 -08:00
Pavel Yaskevich
d14635bec3 [TypeChecker] Allow @objc @implementation to mismatch on @Sendable in parameter positions
Just like for protocol matching, let's allow `@Sendable` mismatches
in parameter positions to make sure that it's possible for header
authors to add concurrency annotations without breaking clients.

This is especially important for `SendableCompletionHandlers` feature
that makes imported sync completion handler parameters `@Sendable`.
2025-02-21 14:19:21 -08:00
Pavel Yaskevich
18a9987e16 Merge pull request #79497 from xedin/execution-attr-diagnostics
[Sema] Either variant of `@execution` is incompatible with other isol…
2025-02-20 14:00:57 -08:00
Becca Royal-Gordon
369e6d3706 Merge pull request #79413 from beccadax/negative-the-predicates-had-no-effect
[PrintAsClang] Kill declaration sorting bugs super-dead
2025-02-19 21:20:56 -08:00
Pavel Yaskevich
613fbaf76e [Sema] Either variant of @execution is incompatible with other isolation
According to the proposal both variants cannot be used together
with other forms of isolation i.e. isolated parameters, global
actors, `@isolated(any)` attributes.
2025-02-19 20:06:15 -08:00
Allan Shortlidge
e90530990a Parse/Sema: Move some AvailabilitySpec diagnostics from Parse to Sema.
Eventually, querying the `AvailabilityDomain` associated with an
`AvailabilitySpec` will require invoking a request that takes a `DeclContext`.
This means that any diagnostics related to the domain identified by an
`AvailabilitySpec` need to be emitted during type-checking rather than parsing.
This change migrates several `AvailabilitySpec` diagnostics from Parse to Sema
to unblock further work.
2025-02-19 11:40:56 -08:00
Rintaro Ishizaki
b729746629 [AST] Make LifetimeDescriptor hold Identifier instead of StringRef
No reason to keep the name as a StringRef
2025-02-17 08:59:18 -08:00
Doug Gregor
4313f6790c [Strict memory safety] Diagnose unsafe types in the superclass of a class 2025-02-15 22:57:54 -08:00
Doug Gregor
c9cfed2007 [Strict safety] Diagnose types with unsafe storage
When a type definition involves unsafe types in its storage, require it
to be explicitly marked @unsafe or @safe.
2025-02-15 22:42:07 -08:00