-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add groupings for the various diagnostics #82002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
# Swift Compiler Diagnostics | ||
# Swift compiler diagnostics | ||
|
||
@Metadata { | ||
@TechnologyRoot | ||
} | ||
|
||
Documentation on diagnostics emitted by the compiler. | ||
Documentation on diagnostics emitted by the compiler and settings that control them. | ||
|
||
|
||
## Topics | ||
|
||
- <doc:diagnostic-descriptions> | ||
- <doc:diagnostic-groups> | ||
- <doc:upcoming-language-features> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,47 @@ | ||
# `ExistentialAny` | ||
# Existential any (ExistentialAny) | ||
|
||
This diagnostic group includes errors and warnings pertaining to the `any` type | ||
syntax. | ||
`any` existential type syntax. | ||
|
||
This syntax was proposed in [SE-0335](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0335-existential-any.md). | ||
`any` syntax draws a line between constraint types and existential or boxed | ||
types. | ||
|
||
For example, `any Collection` is a boxed type abstracting over a value of a | ||
dynamic type that conforms to the protocol `Collection`, whereas the | ||
`Collection` part is the conformance constraint imposed on the type of the | ||
underlying value *as well as* a constraint type. | ||
The distinction between a conformance constraint and a constraint type can be | ||
clearly seen in classic generic syntax: `<T: Collection>`. | ||
|
||
Constraint types exist to express conformances and have no meaning in relation | ||
to values. | ||
## Overview | ||
|
||
`any` was introduced in Swift 5.6 to explicitly mark "existential types", i.e., abstract boxed types | ||
that conform to a set of constraints. For source compatibility, these are not diagnosed by default | ||
except for existential types constrained to protocols with `Self` or associated type requirements | ||
(as this was introduced in the same version): | ||
```swift | ||
func sillyFunction(collection: Collection) { // error | ||
// ... | ||
protocol Foo { | ||
associatedtype Bar | ||
|
||
func foo(_: Bar) | ||
} | ||
|
||
protocol Baz {} | ||
|
||
func pass(foo: Foo) {} // `any Foo` is required instead of `Foo` | ||
|
||
func pass(baz: Baz) {} // no warning or error by default for source compatibility | ||
``` | ||
|
||
When enabled via `-enable-upcoming-feature ExistentialAny`, the upcoming language feature | ||
`ExistentialAny` will diagnose *all* existential types without `any`: | ||
```swift | ||
func pass(baz: Baz) {} // `any Baz` required instead of `Baz` | ||
``` | ||
|
||
This will become the default in a future language mode. | ||
|
||
|
||
## Migration | ||
|
||
```sh | ||
-enable-upcoming-feature ExistentialAny:migrate | ||
``` | ||
|
||
Enabling migration for `ExistentialAny` adds fix-its that prepend all existential types with `any` | ||
as required. No attempt is made to convert to generic (`some`) types. | ||
|
||
|
||
## See Also | ||
|
||
- [SE-0335: Introduce existential `any`](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0335-existential-any.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,36 @@ | ||
# Member import visibility | ||
bnbarham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Member import visibility (MemberImportVisibility) | ||
|
||
Enables errors for uses of members that cannot be accessed because their defining module is not directly | ||
imported. | ||
|
||
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: | ||
|
||
``` | ||
## Overview | ||
|
||
Prior to enabling this feature, it was possible to use a member if it was declared in a module that | ||
was transitively imported. `MemberImportVisibility` unifies the visibility rules for members to | ||
match those of top-level, such that only members contained in a direct import are visible: | ||
|
||
```swift | ||
func getFileContents() throws -> String { | ||
// error: initializer 'init(contentsOfFile:)' is not available due to missing import of defining module 'Foundation' | ||
return try String(contentsOfFile: "example.txt") | ||
} | ||
``` | ||
|
||
To resolve the error, you must add an import of the module that defines the member. | ||
To resolve the error, add an import of the module that defines the member. | ||
|
||
|
||
## Migration | ||
|
||
```sh | ||
-enable-upcoming-feature MemberImportVisibility:migrate | ||
``` | ||
|
||
Enabling migration for `MemberImportVisibility` adds fix-its for the missing modules, i.e. those that | ||
declare members used in the file and are not directly imported. | ||
|
||
|
||
## See also | ||
|
||
- [SE-0444: Member import visibility](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md) | ||
|
||
These errors are only emitted when the `MemberImportVisibility` language mode is enabled. |
83 changes: 71 additions & 12 deletions
83
userdocs/diagnostics/nonisolated-nonsending-by-default.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,74 @@ | ||
# `NonisolatedNonsendingByDefault` | ||
# nonisolated(nonsending) by Default (NonisolatedNonsendingByDefault) | ||
|
||
This feature changes the behavior of nonisolated async | ||
functions to run on the actor to which the caller is isolated (if any) by | ||
default, and provides an explicit way to express the execution semantics for | ||
these functions. | ||
Runs nonisolated async functions on the caller's actor by default. | ||
|
||
This feature was proposed in [SE-0461](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0461-async-function-isolation.md) | ||
|
||
* The `@concurrent` attribute specifies that a function must always | ||
switch off of an actor to run. | ||
This is the default behavior without `NonisolatedNonsendingByDefault`. | ||
* The `nonisolated(nonsending)` modifier specifies that a function must always | ||
run on the caller's actor. | ||
This is the default behavior with `NonisolatedNonsendingByDefault`. | ||
## Overview | ||
|
||
Prior to this feature, nonisolated async functions *never* run on an actor's executor and instead | ||
switch to global generic executor. The motivation was to prevent unnecessary serialization and | ||
contention for the actor by switching off of the actor to run the nonisolated async function, but | ||
this does have a number of unfortunate consequences: | ||
1. `nonisolated` is difficult to understand | ||
2. Async functions that run on the caller's actor are difficult to express | ||
3. It's easy to write invalid async APIs | ||
4. It's difficult to write higher-order async APIs | ||
|
||
Introduced in Swift 6.2, `-enable-upcoming-feature NonisolatedNonsendingByDefault` changes the | ||
execution semantics of nonisolated async functions to always run on the caller's actor by default. A | ||
new `@concurrent` attribute can be added in order to specify that a function must *always* switch | ||
off of an actor to run. | ||
```swift | ||
struct S: Sendable { | ||
func performSync() {} | ||
|
||
// `nonisolated(nonsending)` is the default | ||
func performAsync() async {} | ||
|
||
@concurrent | ||
func alwaysSwitch() async {} | ||
} | ||
|
||
actor MyActor { | ||
let s: Sendable | ||
|
||
func call() async { | ||
s.performSync() // runs on actor's executor | ||
|
||
await s.performAsync() // runs on actor's executor | ||
|
||
s.alwaysSwitch() // switches to global generic executor | ||
} | ||
} | ||
``` | ||
|
||
A `nonisolated(nonsending)` modifier can also be used prior to enabling this upcoming feature in | ||
order to run on the caller's actor. To achieve the same semantics as above, `S` in this case would | ||
instead be: | ||
```swift | ||
struct S: Sendable { | ||
func performSync() {} | ||
|
||
nonisolated(nonsending) | ||
func performAsync() async {} | ||
|
||
// `@concurrent` is the default | ||
func alwaysSwitch() async {} | ||
} | ||
``` | ||
|
||
|
||
## Migration | ||
|
||
```sh | ||
-enable-upcoming-feature NonisolatedNonsendingByDefault:migrate | ||
``` | ||
|
||
Enabling migration for `NonisolatedNonsendingByDefault` adds fix-its that aim to keep the current | ||
async semantics by adding `@concurrent` to all existing nonisolated async functions and closures. | ||
|
||
|
||
## See Also | ||
|
||
- [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) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
# Extraneous @preconcurrency imports | ||
# Extraneous @preconcurrency imports (PreconcurrencyImport) | ||
|
||
|
||
This diagnostic group includes warnings that diagnose `@preconcurrency import` | ||
declarations that don't need `@preconcurrency`. It is an experimental warning | ||
that is currently disabled. | ||
Warnings that diagnose `@preconcurrency import` declarations that don't need `@preconcurrency`, | ||
experimental and disabled by default. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
# Strict language feature enablement | ||
|
||
By default, if an unrecognized feature name is specified with the | ||
`-enable-upcoming-feature` or `-enable-experimental-feature` flags, the compiler | ||
will ignore it without emitting a diagnostic since some projects must be | ||
simultaneously compatible with multiple versions of the language and toolchain. | ||
However, this warning group can be enabled to opt-in to detailed diagnostics | ||
about misspecified features. | ||
# Strict language feature enablement (StrictLanguageFeatures) | ||
|
||
Warnings for unrecognized feature names in `-enable-upcoming-feature` or | ||
`enable-experimental-feature`. | ||
|
||
|
||
## Overview | ||
|
||
By default, if an unrecognized feature name is specified with the `-enable-upcoming-feature` or | ||
`-enable-experimental-feature` flags, the compiler will ignore it without emitting a diagnostic | ||
since some projects must be simultaneously compatible with multiple versions of the language and | ||
toolchain. This can, however, lead to misspecified features. To diagnose these cases instead, enable | ||
`StrictLanguageFeatures`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would so much prefer the book to just call them existential. The "boxed" in "boxed protocol type" is overloaded and uncatchy, and the "protocol" is just not accurate.