Commit Graph

101 Commits

Author SHA1 Message Date
Michael Gottesman c36f842bed [diagnostic] Convert diagnostics-assert-on-{error,warning} and sil-region-isolation-assert-on-unknown-pattern from llvm::cl::opt globals to Swift frontend flags, and add -diagnostics-assert-on-group
llvm::cl::opt flags are compiled out in non-asserts builds, making these
debug flags unavailable in an important category of use cases — debugging
a release compiler in lldb. By promoting them to Swift frontend flags stored
in DiagnosticOptions/SILOptions, they are available in all build
configurations.

The three existing flags are migrated:
  -diagnostics-assert-on-error
  -diagnostics-assert-on-warning
  -sil-region-isolation-assert-on-unknown-pattern
    (backing field renamed to AbortOnUnknownRegionIsolationPatternError)

A new flag is added:
  -diagnostics-assert-on-group <group>
    Traps when any diagnostic belonging to the named group is emitted,
    allowing targeted breakpoints on a single diagnostic group rather than
    all errors or all warnings.

The assert-on-{error,warning,group} flags are intentionally kept separate
from the normal diagnostic suppression/escalation machinery so that they
remain useful while other diagnostics are also being emitted.

Tests are added for all four flags.
2026-05-14 17:36:08 -07:00
Allan Shortlidge 440120557e AST: Introduce the ModuleSelfImport diagnostic group. 2026-04-23 13:06:36 -07:00
Steven Wu 12f8d9c6c9 [TEST] Switch to use new swift-driver when running tests
Default to use new swift-driver to run lit tests as legacy swift driver
is deprecated for a long time. The lit tests for legacy drivers are also
disable when running new swift-driver.

Tests that relies on legacy swift driver (for example, tests merge
module) can be enabled on conditions `legacy_swift_driver`. Fix and
split up some existing tests that relies on legacy driver.
2026-03-23 09:48:45 -07:00
Artem Chikin 216a4f232e Add diagnostic warning group documentation for the 'ReturnTypeImplicitCopy' group 2026-03-20 09:23:07 +00:00
Artem Chikin e3f07a58f5 [Diagnostics] Display full diagnostic group parent chains
When a diagnostic belongs to a group that has a parent group (`GROUP_LINK` in `DiagnosticGroups.def`), display the full inheritance chain in the diagnostic output, including documentation hyperlinks and footnotes for each.

For example, a diagnostic in `ExistentialType` (child of `PerformanceHints`) now renders as:
```
warning: ... [#PerformanceHints::ExistentialType]
```
Groups without parents continue to display as before (`[#DeprecatedDeclaration]`).

Resolves rdar://170805800
2026-03-16 10:04:10 +00:00
Artem Chikin c0dee449c2 Merge pull request #87749 from artemcm/LocalDiagsForDiagGroup
[Diagnostics] Support diagnostic groups with toolchain-local-only documentation
2026-03-13 14:19:12 +00:00
Artem Chikin 2a6ab76bb3 Add option to have a diagnostic group have toolchain-local-only documentation 2026-03-10 15:11:33 +00:00
Evan Wilde 1f5d8f7451 Test: bad-generated-filenames.swift
Adding the 'ALLOW_RETRIES` to
`diagnostics/bad-generated-filenames.swift`

There is an occasional assertion failure in `c-index-test` that I
suspect is related to recent changes in the FileManager related to
filenames:

```
Assertion failed: (DirInfo &&
  "The directory of a virtual file should already be in the cache.")
```

This is happening in `getVirtualFileRef` in
`llvm-project/clang/lib/Basic/FileManager.cpp` on line 419.

https://github.com/swiftlang/llvm-project/blob/cb7976f735018074787ce9b86040c081bb568b93/clang/lib/Basic/FileManager.cpp#L418-L419
2026-02-25 08:15:48 -08:00
Evan Wilde 90048c3b3e FreeBSD: un-xfail bad-generated-filenames
Re-enabling the diagnostics/bad-generated-filenames.swift test.
I don't see what caused this test to be x-failed in the first place and
is causing CI failures due to unexpectedly passing. If it is crashing in
the future, I will need a core file or some way to reproduce it at
the bare minimum.
2026-02-23 21:29:35 -08:00
Pavel Yaskevich 2450e5a340 [Tests] NFC: XFAIL test/diagnostics/bad-generated-filenames.swift on FreeBSD
The issue is tracked by rdar://168250323
2026-02-20 09:55:45 -08:00
Jamie 94eab75e86 [Diagnostics]: restore unknown warning group behavior 2026-02-04 08:15:49 -06:00
Artem Chikin 9e35f82b2c [Diagnostics] Replace diagnostics' 'DefaultIgnore' option with a corresponding option on diagnostic groups
This brings this control in line with other diagnostic controls we have which operate on a per-group level.
'DefaultIgnoreWarnings' diagnostic group option applies to all warnings belonging to a certain diagnostic group.

The inheritance rules are:
- Marking a diagnostic group as 'DefaultIgnoreWarnings' means warnings belonging to this group will not be emitted by-default
  - Warnings belonging to sub-groups of this group will also not be emitted by-default
- Enabling a 'DefaultIgnoreWarnings' group (with '-Werror','-Wwarning', etc.) means warnings belonging to this group will be emitted.
  - Warnings belonging to sub-groups of this group will also be emitted.
  - Warnings belonging to super-groups of this group will not be affected.
2025-10-29 09:42:03 -07:00
Hamish Knight 13023de4c4 [Evaluator] Avoid emitting duplicate "through reference here" notes
Filter out any duplicate notes to help cut down on the noise for
request cycle diagnostics. Some of the note locations here still aren't
great, but this at least stops us from repeating them for each
intermediate request.
2025-10-05 20:48:08 +01:00
Anthony Latsis b0b0cff317 [NFC][test] Move scattered DiagnosticVerifier tests into subdirectory 2025-05-07 02:34:46 +01:00
Anthony Latsis 4f4141fea8 Frontend: Obsolete -fixit-all and -emit-fixits-path
With `ARCMigrate` and `arcmt-test` removed from clang in
https://github.com/llvm/llvm-project/pull/119269 and the new code
migration experience under way (see
https://github.com/swiftlang/swift-evolution/pull/2673), these options
are no longer relevant nor known to be in use. They were introduced
long ago to support fix-it application in Xcode.

For now, turn them into a no-op and emit a obsoletion warning.
2025-05-07 02:30:30 +01:00
Doug Gregor 5b5a3e3d07 Point at diagnostic group documentation on docs.swift.org 2025-04-14 20:08:24 -07:00
Doug Gregor b182c96bd7 Print diagnostic group names by default
Print diagnostic groups as part of the LLVM printer in the same manner as the
Swift one does, always. Make `-print-diagnostic-groups` an inert option, since we
always print diagnostic group names with the `[#GroupName]` syntax.

As part of this, we no longer render the diagnostic group name as part
of the diagnostic *text*, instead leaving it up to the diagnostic
renderer to handle the category appropriately. Update all of the tests
that were depending on `-print-diagnostic-groups` putting it into the
text to instead use the `{{documentation-file=<file name>}}`
diagnostic verification syntax.
2025-03-29 15:40:56 -07:00
Doug Gregor e88f8995e1 [Diagnostics] Eliminate educational notes in favor of diagnostic groups
We've been converging the implementations of educational notes and
diagnostic groups, where both provide category information in
diagnostics (e.g., `[#StrictMemorySafety]`) and corresponding
short-form documentation files. The diagnostic group model is more
useful in a few ways:

* It provides warnings-as-errors control for warnings in the group
* It is easier to associate a diagnostic with a group with
GROUPED_ERROR/GROUPED_WARNING than it is to have a separate diagnostic
ID -> mapping.
* It is easier to see our progress on diagnostic-group coverage
* It provides an easy name to use for diagnostic purposes.

Collapse the educational-notes infrastructure into diagnostic groups,
migrating all of the existing educational notes into new groups.
Simplify the code paths that dealt with multiple educational notes to
have a single, possibly-missing "category documentation URL", which is
how we're treating this.
2025-03-29 15:40:35 -07:00
Doug Gregor 7d569b989d [Diagnostics] Remove rendering of educational notes to the terminal
We're moving over to a model where we provide direct links to educational notes /
diagnostic group notes whenever relevant. Rendering the Markdown from these
files to the terminal is less relevant with this approach, so remove it from the
compiler.
2025-03-28 14:12:27 -07:00
Doug Gregor 708300966d [Diagnostics] Fix recognition of URLs in category file/URL 2025-03-24 10:14:25 -07:00
Doug Gregor fc508daaf7 [Serialized diagnostics] Emit category documentation URL
Emit the category documentation URL into serialized diagnostics as part of
the existing RECORD_CATEGORY, using the form

  <category name>@<category URL>

and keeping the existing "category name length" field referring to the
length of the category name itself (up to the @). There is a corresponding
update to libclang to process such category names correctly and add
API, but it isn't strictly necessary: readers that use the category
name length field correctly will see no behavior change, whereas
readers that ignore it will merely see the extra `@<category URL>`.

This is a step toward staging out our (mis)use of the "flags" field as
the place to stash educational note and diagnostic group documentation
URLs.
2025-03-22 14:27:29 -07:00
Doug Gregor 29b4f3ddbd [Diagnostics] Print category footnotes at the end of translation
When printing diagnostics, category names are printed as [#<category-name>]
at the end of a diagnostic. For all of the category names that are mentioned
in this manner, print "footnotes" at the end of compilation providing
documentation references to each category, e.g.,

    [#deprecated]: <http://example.com/deprecated>
    [#StrictMemorySafety]: <http://example.com/memory-safety>

Right now, these point into the markdown files in the installed toolchain,
same as the URLs behind references. That is subject to change in the future.
2025-03-09 14:36:51 -07:00
Pavel Yaskevich b26c8aa930 [Tests] NFC: Add a test-case for printing child notes associated with errors/warnings 2025-03-06 18:34:57 -08:00
Doug Gregor db2fa7bcda [Diagnostics] Use the educational note name for the category name 2025-03-04 09:14:48 -08:00
Doug Gregor aafd24bfed Prefer diagnostic group names for diagnostic categories over the ad hoc ones 2025-02-27 19:40:23 -08:00
Doug Gregor 779acb3d15 [Diagnostics] Record diagnostic groups in serialized diagnostics
The serialized diagnostic format has some extra fields that we can
adopt for diagnostic groups. Specifically:
* Category: store the diagnostic group name here
* Flags: extend the hack used by educational notes of placing Markdown file paths here
2025-02-27 17:26:48 -08:00
Doug Gregor 528d642fc5 Make the Fix-It JSON writer produce proper JSON
While here, also sort and deduplicate output entries, and stop having
the Python script try to

The Python script is still messing up the files in some cases, but
I haven't tracked it down. Instead, I have a small Swift program
that does the same thing more easily.
2024-12-14 21:49:57 -08:00
Rintaro Ishizaki 40c8d817fb [Diagnostics] Support "swift" style diagnostics at EOF
Adjust the valid position checking and special handle EOF position.
If the requested location is at EOF, use the last token, but still
emit the diagnostics at the specificied location.

rdar://138426038
2024-11-21 06:27:37 -08:00
Doug Gregor 90e2b60413 Merge pull request #76813 from DougGregor/pretty-print-decl-request
Turn pretty-printing of a declaration into a request
2024-10-01 19:44:05 -07:00
Doug Gregor 5df96a7a6e Turn pretty-printing of a declaration into a request
The diagnostics engine has some code to pretty-print a declaration when
there is no source location for that declaration. The declaration is
pretty-printed into a source buffer, and a source location into that
buffer is synthesizes. This applies to synthesized declarations as well
as those imported from Swift modules (without source code) or from Clang.

Reimplement this pretty-printing for declarations as a request. In
doing so, change the manner in which we do the printing: the
diagnostics engine printed the entire enclosing type into a buffer
whose name was the module + that type. This meant that the buffer was
shared by every member of that type, but also meant that we would end
up deserializing a lot of declarations just for printing and
potentially doing a lot more work for these diagnostics.
2024-10-01 15:49:15 -07:00
Dmitrii Galimzianov aa5e10f8d2 [Diagnostics] DeprecatedDeclaration group 2024-09-25 23:18:25 +02:00
Dmitrii Galimzianov a8b71ea97f Add -print-diagnostic-groups flag
This change adds the `-print-diagnostic-groups` flag as described by SE-0443.
2024-09-11 13:34:42 +02:00
Dmitrii Galimzianov 070c77ebcf fixup! [Diagnostics] Add -[no-]warning-as-error flags for precise control over warning behavior 2024-09-07 07:55:27 +02:00
Dmitrii Galimzianov 28883b6654 [Diagnostics] Add -[no-]warning-as-error flags for precise control over warning behavior
This commit adds new compiler options -no-warning-as-error/-warning-as-error which allows users to specify behavior for exact warnings and warning groups.
2024-09-07 01:14:43 +02:00
Rintaro Ishizaki 8a8c96bd66 [Tests] Update for "swift" diagnostic style change
SwiftDiagnostics now emits ASCII characters instead of Unicode line
characters.
2024-04-01 17:09:23 -07:00
Doug Gregor 8cd2f34654 Generalize tests for both diagnostic styles, or force the LLVM style
These tests are using FileCheck to check the result of diagnostic
formatting in ways that don't match the new formatter. Force the old
formatter or, where possible, generalize so that they match both
formatters.
2024-02-19 02:48:37 -10:00
Doug Gregor a51a172035 Make a few tests independent of the default diagnostic style 2024-02-19 02:48:36 -10:00
Pavel Yaskevich 5763f9f632 Merge pull request #70391 from xedin/rdar-118993780
[Diagnostics] Add educational notes into serialized diagnostics
2023-12-13 16:14:03 -08:00
Alexis Laferrière dda7e96503 Merge pull request #70424 from xymus/ambiguity
AST: Specify the module name in errors on ambiguities across modules
2023-12-13 16:07:41 -08:00
Alexis Laferrière 72083bf7e3 Diagnostics: Specify the module name on ambiguities across modules
When a file defining an API is included in two modules, clients calling
that API may get an error about the ambiguity on the duplicated API.
That error is not very helpful when it takes into account the
swiftsourceinfo data and points to the source file instead of the
module. In such a case the notes point twice to the same file and line
of code.

Improve this diagnostic by appending the module name to the notes when a
candidate is found outside of the module.

rdar://116255141
2023-12-13 11:12:39 -08:00
Pavel Yaskevich a549048c90 [Diagnostics] Add educational notes into serialized diagnostics
Use flag record (currently unused) to emit semi-colon separated
list of paths to educational notes associated with a diagnostic.

Resolves: rdar://118993780
2023-12-12 12:59:48 -08:00
Doug Gregor 288ae78693 [Serialized diagnostics] Avoid generating filenames that break the reader
The serialized diagnostics reader has one very specific limitation it
places on filenames: they must not end in `/`, because that makes them
look like a directory. This is not documented, and the diagnostics
reader will unceremoniously crash when trying to read such a file.

While the reader should be fixed to at least fail gracefully in such
cases, Swift also shouldn't generate such filenames. Right now, they
can be generated when referencing an entity named `/` that is
synthesized or comes from a module. When we encounter such file names,
append `_operator` to avoid the problem.

Fixes rdar://118217560.
2023-11-30 14:54:02 -08:00
Alexis Laferrière 4cd10483f4 [Sema] Name the decl in the error on package level without a package 2023-09-19 17:13:19 -07:00
Alexis Laferrière 1a4a47fee3 [Sema] Merge diagnostics about package modifier outside of a package
Show the same error for both decls and imports when using the package
access level and no package name is set. Also brings up this check to
run once on decls and avoid repeated diagnostics.
2023-09-19 15:01:16 -07:00
Slava Pestov fd06bd87aa AST: Allow the extended type of an extension to refer to be a tuple type
Either directly, or via a type alias.
2023-09-05 23:21:26 -04:00
Doug Gregor 9bf512adf0 [Diagnostics] Remove the C++ formatter for the "Swift" diagnostic style
We'll be using the new swift-syntax diagnostic formatter in the near
future, as it is nearly available on all host platforms. So, remove
the C++ formatter that did source-line annotation, falling back to the
"LLVM" style when swift-syntax is not compiled in.
2023-09-04 22:22:17 -07:00
Michael Spencer b2640e15e4 [test] Rename all module.map files to module.modulemap
`module.map` as a module map name has been discouraged since 2014, and
Clang will soon warn on its usage. This patch renames all instances of
`module.map` in the Swift tests to `module.modulemap` in preparation
for this change to Clang.

rdar://106123303
2023-08-21 15:58:59 -07:00
Ellie Shin 79a2ff5efd Merge pull request #66189 from apple/es-diag
Improve diagnostics when package acl is used but no package-name is passed
2023-05-27 12:23:10 -07:00
Ellie Shin 854e7dca46 s/passed/specified 2023-05-26 17:10:32 -07:00
Ellie Shin 61dd3008f8 Improve diagnostics when package acl is used but no package-name is passed 2023-05-26 15:59:51 -07:00