Skip to content

Commit 5dadb5d

Browse files
authored
Merge pull request #82002 from bnbarham/update-feature-docs
Add groupings for the various diagnostics
2 parents 9597735 + 32ec5a6 commit 5dadb5d

10 files changed

+183
-65
lines changed

userdocs/diagnostics/clang-declaration-import.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# Imported Clang Declaration Warnings (`ClangDeclarationImport`)
1+
# Imported Clang declaration warnings (ClangDeclarationImport)
22

3+
Covers all warnings related to malformed APIs that are imported into Swift from C, C++, and Obj-C headers.
34

4-
This diagnostic group covers all warnings related to malformed APIs that are imported into Swift from C, C++, and Obj-C headers.
5+
6+
## Overview
57

68
As one example of a potential malformed API diagnostic, suppose a Clang module dependency contained the following declaration:
79

userdocs/diagnostics/deprecated-declaration.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# Deprecated Declaration Warnings (`DeprecatedDeclaration`)
1+
# Deprecated declaration warnings (DeprecatedDeclaration)
22

3+
Warnings related to deprecated APIs that may be removed in future versions and should be replaced with more current alternatives.
34

4-
This diagnostic group includes warnings related to deprecated APIs that may be removed in future versions and should be replaced with more current alternatives.
5+
## Overview
56

67
The `DeprecatedDeclaration` group covers the following warnings:
78
- Use of a function annotated with `@available(<platform>, deprecated: <version>)`
@@ -65,10 +66,3 @@ The `DeprecatedDeclaration` group covers the following warnings:
6566
func enqueue(_ job: __owned Job) {} // 'Executor.enqueue(Job)' is deprecated as a protocol requirement; conform type 'C' to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead
6667
}
6768
```
68-
69-
## Usage Example
70-
71-
```sh
72-
swiftc -Werror DeprecatedDeclaration file.swift
73-
swiftc -warnings-as-errors -Wwarning DeprecatedDeclaration file.swift
74-
```

userdocs/diagnostics/diagnostics.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
# Swift Compiler Diagnostics
1+
# Swift compiler diagnostics
22

33
@Metadata {
44
@TechnologyRoot
55
}
66

7-
Documentation on diagnostics emitted by the compiler.
7+
Documentation on diagnostics emitted by the compiler and settings that control them.
8+
9+
10+
## Topics
11+
12+
- <doc:diagnostic-descriptions>
13+
- <doc:diagnostic-groups>
14+
- <doc:upcoming-language-features>
Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
1-
# `ExistentialAny`
1+
# Existential any (ExistentialAny)
22

3-
This diagnostic group includes errors and warnings pertaining to the `any` type
4-
syntax.
3+
`any` existential type syntax.
54

6-
This syntax was proposed in [SE-0335](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0335-existential-any.md).
7-
`any` syntax draws a line between constraint types and existential or boxed
8-
types.
95

10-
For example, `any Collection` is a boxed type abstracting over a value of a
11-
dynamic type that conforms to the protocol `Collection`, whereas the
12-
`Collection` part is the conformance constraint imposed on the type of the
13-
underlying value *as well as* a constraint type.
14-
The distinction between a conformance constraint and a constraint type can be
15-
clearly seen in classic generic syntax: `<T: Collection>`.
16-
17-
Constraint types exist to express conformances and have no meaning in relation
18-
to values.
6+
## Overview
197

8+
`any` was introduced in Swift 5.6 to explicitly mark "existential types", i.e., abstract boxed types
9+
that conform to a set of constraints. For source compatibility, these are not diagnosed by default
10+
except for existential types constrained to protocols with `Self` or associated type requirements
11+
(as this was introduced in the same version):
2012
```swift
21-
func sillyFunction(collection: Collection) { // error
22-
// ...
13+
protocol Foo {
14+
associatedtype Bar
15+
16+
func foo(_: Bar)
2317
}
18+
19+
protocol Baz {}
20+
21+
func pass(foo: Foo) {} // `any Foo` is required instead of `Foo`
22+
23+
func pass(baz: Baz) {} // no warning or error by default for source compatibility
2424
```
25+
26+
When enabled via `-enable-upcoming-feature ExistentialAny`, the upcoming language feature
27+
`ExistentialAny` will diagnose *all* existential types without `any`:
28+
```swift
29+
func pass(baz: Baz) {} // `any Baz` required instead of `Baz`
30+
```
31+
32+
This will become the default in a future language mode.
33+
34+
35+
## Migration
36+
37+
```sh
38+
-enable-upcoming-feature ExistentialAny:migrate
39+
```
40+
41+
Enabling migration for `ExistentialAny` adds fix-its that prepend all existential types with `any`
42+
as required. No attempt is made to convert to generic (`some`) types.
43+
44+
45+
## See Also
46+
47+
- [SE-0335: Introduce existential `any`](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0335-existential-any.md)

userdocs/diagnostics/member-import-visibility.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
1-
# Member import visibility
1+
# Member import visibility (MemberImportVisibility)
22

3+
Enables errors for uses of members that cannot be accessed because their defining module is not directly
4+
imported.
35

4-
This diagnostic group includes the errors that are emitted when a member declaration cannot be accessed because the module defining that member has not been directly imported by the file containing the reference:
56

6-
```
7+
## Overview
8+
9+
Prior to enabling this feature, it was possible to use a member if it was declared in a module that
10+
was transitively imported. `MemberImportVisibility` unifies the visibility rules for members to
11+
match those of top-level, such that only members contained in a direct import are visible:
12+
13+
```swift
714
func getFileContents() throws -> String {
815
// error: initializer 'init(contentsOfFile:)' is not available due to missing import of defining module 'Foundation'
916
return try String(contentsOfFile: "example.txt")
1017
}
1118
```
1219

13-
To resolve the error, you must add an import of the module that defines the member.
20+
To resolve the error, add an import of the module that defines the member.
21+
22+
23+
## Migration
24+
25+
```sh
26+
-enable-upcoming-feature MemberImportVisibility:migrate
27+
```
28+
29+
Enabling migration for `MemberImportVisibility` adds fix-its for the missing modules, i.e. those that
30+
declare members used in the file and are not directly imported.
31+
32+
33+
## See also
34+
35+
- [SE-0444: Member import visibility](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md)
1436

15-
These errors are only emitted when the `MemberImportVisibility` language mode is enabled.
Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,74 @@
1-
# `NonisolatedNonsendingByDefault`
1+
# nonisolated(nonsending) by Default (NonisolatedNonsendingByDefault)
22

3-
This feature changes the behavior of nonisolated async
4-
functions to run on the actor to which the caller is isolated (if any) by
5-
default, and provides an explicit way to express the execution semantics for
6-
these functions.
3+
Runs nonisolated async functions on the caller's actor by default.
74

8-
This feature was proposed in [SE-0461](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0461-async-function-isolation.md)
95

10-
* The `@concurrent` attribute specifies that a function must always
11-
switch off of an actor to run.
12-
This is the default behavior without `NonisolatedNonsendingByDefault`.
13-
* The `nonisolated(nonsending)` modifier specifies that a function must always
14-
run on the caller's actor.
15-
This is the default behavior with `NonisolatedNonsendingByDefault`.
6+
## Overview
7+
8+
Prior to this feature, nonisolated async functions *never* run on an actor's executor and instead
9+
switch to global generic executor. The motivation was to prevent unnecessary serialization and
10+
contention for the actor by switching off of the actor to run the nonisolated async function, but
11+
this does have a number of unfortunate consequences:
12+
1. `nonisolated` is difficult to understand
13+
2. Async functions that run on the caller's actor are difficult to express
14+
3. It's easy to write invalid async APIs
15+
4. It's difficult to write higher-order async APIs
16+
17+
Introduced in Swift 6.2, `-enable-upcoming-feature NonisolatedNonsendingByDefault` changes the
18+
execution semantics of nonisolated async functions to always run on the caller's actor by default. A
19+
new `@concurrent` attribute can be added in order to specify that a function must *always* switch
20+
off of an actor to run.
21+
```swift
22+
struct S: Sendable {
23+
func performSync() {}
24+
25+
// `nonisolated(nonsending)` is the default
26+
func performAsync() async {}
27+
28+
@concurrent
29+
func alwaysSwitch() async {}
30+
}
31+
32+
actor MyActor {
33+
let s: Sendable
34+
35+
func call() async {
36+
s.performSync() // runs on actor's executor
37+
38+
await s.performAsync() // runs on actor's executor
39+
40+
s.alwaysSwitch() // switches to global generic executor
41+
}
42+
}
43+
```
44+
45+
A `nonisolated(nonsending)` modifier can also be used prior to enabling this upcoming feature in
46+
order to run on the caller's actor. To achieve the same semantics as above, `S` in this case would
47+
instead be:
48+
```swift
49+
struct S: Sendable {
50+
func performSync() {}
51+
52+
nonisolated(nonsending)
53+
func performAsync() async {}
54+
55+
// `@concurrent` is the default
56+
func alwaysSwitch() async {}
57+
}
58+
```
59+
60+
61+
## Migration
62+
63+
```sh
64+
-enable-upcoming-feature NonisolatedNonsendingByDefault:migrate
65+
```
66+
67+
Enabling migration for `NonisolatedNonsendingByDefault` adds fix-its that aim to keep the current
68+
async semantics by adding `@concurrent` to all existing nonisolated async functions and closures.
69+
70+
71+
## See Also
72+
73+
- [SE-0461: Run nonisolated async functions on the caller's actor by default](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0461-async-function-isolation.md)
74+
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# Extraneous @preconcurrency imports
1+
# Extraneous @preconcurrency imports (PreconcurrencyImport)
22

3-
4-
This diagnostic group includes warnings that diagnose `@preconcurrency import`
5-
declarations that don't need `@preconcurrency`. It is an experimental warning
6-
that is currently disabled.
3+
Warnings that diagnose `@preconcurrency import` declarations that don't need `@preconcurrency`,
4+
experimental and disabled by default.
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
# Strict language feature enablement
2-
3-
By default, if an unrecognized feature name is specified with the
4-
`-enable-upcoming-feature` or `-enable-experimental-feature` flags, the compiler
5-
will ignore it without emitting a diagnostic since some projects must be
6-
simultaneously compatible with multiple versions of the language and toolchain.
7-
However, this warning group can be enabled to opt-in to detailed diagnostics
8-
about misspecified features.
1+
# Strict language feature enablement (StrictLanguageFeatures)
2+
3+
Warnings for unrecognized feature names in `-enable-upcoming-feature` or
4+
`enable-experimental-feature`.
5+
6+
7+
## Overview
8+
9+
By default, if an unrecognized feature name is specified with the `-enable-upcoming-feature` or
10+
`-enable-experimental-feature` flags, the compiler will ignore it without emitting a diagnostic
11+
since some projects must be simultaneously compatible with multiple versions of the language and
12+
toolchain. This can, however, lead to misspecified features. To diagnose these cases instead, enable
13+
`StrictLanguageFeatures`.

userdocs/diagnostics/strict-memory-safety.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
# Strict Memory Safety Warnings (`StrictMemorySafety`)
1+
# Strict memory safety (StrictMemorySafety)
22

3+
Warnings that identify the use of language constructs and library APIs that can undermine memory
4+
safety, disabled by default.
35

4-
This diagnostic group includes warnings that identify the use of language constructs and library APIs that can undermine memory safety. They are enabled by the `-strict-memory-safety` compiler flag. Examples of memory-unsafe code in Swift include:
6+
7+
## Overview
8+
9+
Strict memory safety can be enabled with the `-strict-memory-safety` compiler flag. Examples of
10+
memory-unsafe code in Swift include:
511

612
- Use of a function or type annotated with `@unsafe`:
713
```swift
@@ -69,4 +75,4 @@ The warnings produced by strict memory safety can be suppressed by acknowledging
6975
@safe struct MyTemporaryBuffer<T> {
7076
private var storage: UnsafeBufferPointer<T>
7177
}
72-
```
78+
```

userdocs/diagnostics/unknown-warning-group.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
# Unknown "Warning Group" Warnings (`UnknownWarningGroup`)
1+
# Unknown warning group (UnknownWarningGroup)
22

3-
The `UnknownWarningGroup` diagnostic group addresses warnings related to the specification of unrecognized warning groups in compilation flags.
3+
Warnings for unrecognized warning groups specified in `-Wwarning` or `-Werror`.
4+
5+
6+
## Overview
47

58
```sh
69
swiftc -Werror non_existing_group file.swift

0 commit comments

Comments
 (0)