115 Commits

Author SHA1 Message Date
Ben Barham
b29a0a9b3d Fix up the userdocs index
A few docs weren't added to the index, re-run the generation and fix the
test to actually run in order to catch future issues.
2025-12-06 10:18:19 +10:00
Pavel Yaskevich
22ec081377 [AST/Sema] Add a diagnostic group ExplicitSendable to replace -require-explicit-sendable
Always run explicit `Sendable` checks on public types and suppress
warning printing by default instead of using a special compiler argument.

Resolves: rdar://162394810
2025-11-04 17:53:20 -08:00
Kavon Farvardin
6b858b411c ManualOwnership: introduce 'DynamicExclusivity'
We can add warnings about dynamic exclusivity
checks that may happen on an access, with
explainers about why they happen for safety.
2025-10-24 16:59:44 -07:00
Kavon Farvardin
95a6719117 ManualOwnership: introduce 'SemanticCopies' diagnostic group
This includes documentation to explain how to understand
these diagnostics.
2025-10-24 16:59:41 -07:00
John Hui
781489f067 Merge pull request #85021 from j-hui/return-frt-diagnostics
[cxx-interop] Put RETURNS_RETAINED warnings in a diagnostic group

rdar://161932849
rdar://144976203
2025-10-24 12:05:48 -04:00
John Hui
1e5194c9a4 [cxx-interop] Re-word message and documentation for FRT diagnostics
Several changes:

- shorten the warning at the call-site of unannotated functions that
  return FRTS
- place the call to action ("annotate 'X' with 'Y'") at the diagnostic
  note attached to the unannotated callee, where the annotation should
  be made
- re-word the foreign-reference-type.md documentation to (1) reflect the
  diagnostic wording change, (2) give a little bit more background about
  why the annotations are needed, and (3) not be specific to C++ (since
  we can import FRTs from C as well)
2025-10-22 14:53:06 -07:00
Ben Barham
55f61a84ca Re-generate diagnostics index and cleanup old notes
This is mostly just cleanup:
1. Removes `diagnostic-descriptions.md` since it isn't used any more
2. Adds the group name to all the old notes files
3. Removes trailing whitespace
4. Adds "See Also" sections for notes that have links
2025-10-20 19:19:36 -07:00
John Hui
d47a2626e2 [cxx-interop] Clean up diagnostics for functions returning FRTs
- Delete baseline language feature WarnUnannotatedReturnOfCxxFrt,
  which won't really be useful to users
- Remove some references to "cxx", since FRTs are not exclusively
  imported from C++
- Clean up lit test RUN lines to use %{fs-sep}
2025-10-19 22:22:15 -07:00
Fahad Nayyar
facef0e034 [cxx-interop] Enabling WarnUnannotatedReturnOfCxxFrt on by default and add it to a diagnostic group
This change makes the warning for unannotated C++ functions returning foreign
reference types (FRT) enabled by default, improving memory safety for Swift/C++
interop users. Also added CxxForeignReferenceType diagnostic group for better control
2025-10-17 17:06:44 -07:00
Artem Chikin
7c74890bd8 [Performance Hints] Add simple check for returning of values of array and dictionary type
This check will run on each type-checked primary input of the current compilation and emit a warning diagnostic for all discovered occurences of this code pattern when the performance hint diagnostic is enabled
2025-10-02 10:31:13 -07:00
Doug Gregor
f1866d85d0 Fix indentation for the EmbeddedRestrictions diagnostic group 2025-09-23 13:16:17 -07:00
Allan Shortlidge
8a1338dfb2 AST/Sema: Diagnose references to permanently enabled availability domains
A "permanently enabled" availability domain is one that has been declared
always available and is also simultaneously has either an attribute that
makes it deprecated or universally unavailable.

Emit fix-its that remove (or update) `@available` attributes that restrict
availability in a permanently enabled domain. Also, emit warnings about
`if #available` queries that always return true because they check a
permanently enabled domain.

Resolves rdar://157601761.
2025-09-22 17:48:55 -07:00
Doug Gregor
11976c51c8 [Embedded] Document untyped throws restriction 2025-09-18 10:05:35 -07:00
Doug Gregor
a16c9f7ab4 [Embedded] Diagnose dynamic casts to existentials
Embedded Swift doesn't have protocol conformance metadata, so it cannot
handle dynamic casts to existentials (nor should it).

Another part of rdar://119383905.
2025-09-18 10:05:35 -07:00
Doug Gregor
ade6e55b0c [Embedded] Diagnose uses of generic methods on existential values
Generic methods declared in protocols (and extensions thereof) cannot
be used on existential values, because there is no way to specialize
them for all potential types. Diagnose such cases in Embedded Swift
mode and via `-Wwarning EmbeddedRestrictions`.

This adds a bunch more warnings to the standard library that we'll
need to clean up, probably by `#if`'ing more code out.

Part of rdar://119383905.
2025-09-18 10:05:35 -07:00
Doug Gregor
844ba5f4f8 [Embedded] Diagnose non-final generic methods in class in the type checker
Move the diagnostic about non-final generic methods in classes up to
the type checker, so that it is available to `-Wwarning
EmbeddedRestrictions` and earlier in the pipeline. The SIL version of
this is still available as a backstop.

Yet another part of rdar://133874555.
2025-09-18 10:05:33 -07:00
Doug Gregor
7d21bc332a [Embedded] Diagnose untyped throws as an Embedded Swift restriction
Untyped throws depends on existentials (`any Error`), and is therefore
not available in Embedded Swift. Introduce a diagnostic that diagnoses
any use of untyped throws, suggesting that one use typed throws
instead.

Make this an opt-in diagnostic enabled with `-Wwarning
EmbeddedRestrictions`, whether in Embedded Swift or not, using the
"default ignore" flag on these new warnings. Document this new
diagnostic group, and put the existing Embedded Swift error about
weak/unowned references in it as well.

Part of the general push to have the type checker identify code that
will not compile as Embedded Swift earlier, rdar://133874555.
2025-09-14 21:48:50 -07:00
Owen Voorhees
6bcaa0aaf1 Add documentation to static exclusivity diagnostics
Based on https://www.swift.org/blog/swift-5-exclusivity/

Co-Authored-By: Andrew Trick <atrick@apple.com>
2025-08-27 18:02:14 -07:00
Owen Voorhees
b7a910e50a Document the 'module not testable' diagnostic 2025-08-22 08:46:48 -07:00
Allan Shortlidge
dacd986f1b AST: Introduce a warning group for a versioned #if canImport diagnostic.
This allows developers to control whether these diagnostics are considered
errors when `-warnings-as-errors` is specified.

Resolves rdar://157694667.
2025-08-11 16:06:06 -07:00
Ben Barham
5ee91339c3 [userdocs] Automatically generate doc indices
Add a tool for automatically generating the doc indices for notes,
groups, and features.
2025-07-07 13:59:09 -07:00
Ben Barham
b7aa160630 Clean up some newly added userdocs 2025-07-02 22:44:31 -07:00
Steven Wu
a298c7532e [Caching] Put caching diagnostics into its own DiagnosticGroups (#82507)
Add explanation and documentation for swift caching diagnostics.

rdar://154335823

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->

---------

Co-authored-by: Allan Shortlidge <tshortli@gmail.com>
2025-06-27 15:15:12 -07:00
Artem Chikin
a35c112a70 Merge pull request #81919 from artemcm/DiagnoseMissingModulesSeenInSerializedSearchPaths
[Dependency Scanning] On failure to locate a module, attempt to diagnose if binary dependencies contain search paths with this module.
2025-06-11 18:00:01 -07:00
Allan Shortlidge
26d589e099 Merge pull request #82075 from tshortli/diagnose-unrecognized-availability-domains-as-errors
AST: Diagnose unrecognized platforms as errors with `CustomAvailability` enabled
2025-06-09 18:22:30 -07:00
Allan Shortlidge
c0589753d4 Merge pull request #82079 from tshortli/implementation-only-deprecation-diagnostic-group
AST: Add a warning group for `@_implementationOnly` deprecation diagnostics
2025-06-09 17:43:30 -07:00
Ben Barham
b3dd0ac2fa [Doc] Add missing diagnostic groups
These were meant to be part of #82002, but forgot to add them.
2025-06-07 11:13:16 -07:00
Allan Shortlidge
8ceba34f62 AST: Add a warning group for @_implementationOnly deprecation diagnostics.
This allows developers to control the level of these diagnostics.

Resolves rdar://152735425.
2025-06-06 19:12:32 -07:00
Allan Shortlidge
85444fd1e5 AST: Diagnose unrecognized platforms as errors with CustomAvailability enabled.
When the CustomAvailability experimental feature is enabled, make it an error
to specify an unrecognized availability domain name. Also, add these
diagnostics to a diagnostic group so that developers can control their behavior
when they are warnings.

Resolves rdar://152741624.
2025-06-06 17:30:01 -07:00
Ben Barham
5dadb5dfd9 Merge pull request #82002 from bnbarham/update-feature-docs
Add groupings for the various diagnostics
2025-06-06 10:23:14 -07:00
Ben Barham
32ec5a61b7 Add groupings for the various diagnostics
Also make the titles and one line summaries a little more consistent (at
least for diagnsotic groups and upcoming language features, haven't gone
through the educational notes).
2025-06-05 15:49:46 -07:00
Artem Chikin
d4abba10a5 Add a new diagnostic group and documentation for the module-not-found failure which specifies that a missing module dependency can be found on a search path serialized in another Swift binary module dependency. 2025-06-04 16:57:01 -07:00
Doug Gregor
9f0dda5417 Add a diagnostic group for the diagnostic about non-Sendable metatypes.
This is a new restriction that folks are sure to run into, so provide
it with some actionable documentation. Fixes rdar://152450956.
2025-06-03 16:45:28 -07:00
Allan Shortlidge
aca604660f AST/Sema: Make MemberImportVisibility a migratable feature.
The migration to `MemberImportVisibility` can be performed mechanically by
adding missing import declarations, so offer automatic migration for the
feature.

Resolves rdar://151931597.
2025-05-30 15:34:08 -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
Mishal Shah
0d0ba1d0ff Merge pull request #81652 from hborla/concurrency-error-summary
[Diagnostics] Add a brief summary to the documentation for several concurrency errors.
2025-05-21 08:35:49 -07:00
Holly Borla
5fe71f1880 [Diagnostics] Add a brief summary to the documentation for several
concurrency errors.
2025-05-20 15:22:50 -07:00
Pavel Yaskevich
0bcbde4940 [Diagnostics] Replace last references to AsyncCallerExecution with NonisolatedNonsendingByDefault 2025-05-09 13:03:01 -07:00
Pavel Yaskevich
fbaf7ce017 [Diagnostics] Rename the note file to match the NonisolatedNonsendingByDefault feature group declaration 2025-05-09 11:52:29 -07:00
Allan Shortlidge
24fa9c8703 ClangImporter: Introduce the #ClangDeclarationImport diagnostic group.
The warnings that ClangImporter emits about issues it encounters while
importing declarations from Clang modules should all belong to a diagnostic
group so that users of `-warnings-as-errors` can control their behavior using
the compiler flags introduce with SE-0443. It's especially important that these
diagnostics be controllable since they are often caused by external
dependencies and therefore the developer may not have any control over whether
they are emitted.

The `#ClangDeclarationImport` diagnostic group is intentionally broad so that
developers have a way to control all of these diagnostics with a single
`-Wwarning` flag. I fully expect that we'll introduce finer-grained diagnostic
groups for some of these diagnostics in the future, but those groups should be
hierarchically nested under `#ClangDeclarationImport`, which is supported by
SE-0443.

Resolves rdar://150524204.
2025-05-05 14:16:53 -07:00
Pavel Yaskevich
4b1695b999 [Docs] NFC: Remove last remaining references to @execution attribute 2025-04-15 00:08:17 -07:00
Pavel Yaskevich
2b4ba84e64 [Diagnostics] Update educational note for AsyncCallerExecution feature to match @execution attribute split 2025-04-11 15:59:25 -07:00
David Cummings
cd53f9634a Prepare diagnostics docs for docc generation
Update the diagostic docs so that they can be built with docc:
    * Add technologyroot (diagnostics.md) to aggregate all markdown files
    * Fixed warnings in a few diagnostics docs

This allows the creation of docc documentation with a single
invocation of docc. It will generate the landing page from
diagnostics.md and include all of the diagnostics as subarticles.

The subarticles are accessible via the name of the markdown file,
which is being used as the ID for these diagnostics.
E.g. existential-any.

The docc docs for these documents can be generated locally with the
following command:
>docc preview --allow-arbitrary-catalog-directories userdocs/diagnostics
2025-04-03 14:58:37 -04:00
Doug Gregor
1c5372858b [SE-0470] Ensure that one cannot form an isolated conformance when Self: Sendable
While here, fix some issues around implied isolated conformances (we
could get into an inconsistent state). Also provide an educational
note discussing isolated conformances and the kinds of errors one can
see when they are used from outside of their isolation domain.
2025-04-02 18:19:09 -07:00
Doug Gregor
da34300a44 Improve diagnostic group documentation for strict memory safety
This both had the wrong file name (so it couldn't be found), and was a
bit out-of-date. Update it.
2025-03-28 15:05:18 -07:00
Doug Gregor
8fd02d7ccd Merge pull request #80190 from DougGregor/conformance-isolation-diagnostics
Rework diagnostics for conformance isolation failures
2025-03-21 02:54:53 -07: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
Anthony Latsis
c49947579a Sema: Implement adoption mode for AsyncCallerExecution 2025-03-18 01:58:31 +00:00
Holly Borla
3a744d2116 Merge pull request #79509 from hborla/educational-notes
[Educational Notes] Start adding educational notes for data-race safety.
2025-03-04 11:22:11 -08:00