Commit Graph

88 Commits

Author SHA1 Message Date
Anthony Latsis
fb5d1f0538 [6.2] Cherry-pick "[NFC][test] Move scattered DiagnosticVerifier tests into subdirectory"
(cherry picked from commit b0b0cff317)
2025-05-07 15:28:37 +01:00
Anthony Latsis
8a14528728 [6.2] Cherry-pick "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.

(cherry picked from commit 46c394788a84d5932289c71274dd32ea2d61d9dc)
2025-05-07 15:28:17 +01:00
Doug Gregor
4c99a0eccd Point at diagnostic group documentation on docs.swift.org 2025-04-15 07:03:25 -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
Hiroshi Yamauchi
b419f68045 Fix the new diagnostic formatter adding extra whitespace on Windows
The swift driver emits extra newlines because it applies the LF ->
CRLF conversions again on the outpt from the child processes. Fix it
by using the binary mode when outputting the output from the child
processes.

Fixes: #64413
2023-05-23 15:33:10 -07:00
Ellie Shin
3a4cd362ac Allow all unicode characters in package-name input
Error if the input is empty
Resolves rdar://104617274
2023-04-20 11:16:30 -07:00
Ellie Shin
60b264be58 Handle null package context more gracefully
Resolves rdar://106819422
2023-03-28 19:10:32 -07:00
Ellie Shin
be56f4dd4a Add REQUIRES to package-name-diagnostics test 2023-03-16 11:53:21 -07:00
Ellie Shin
0fe0d6d221 Allow Swift as a package name
Update AccessScope::isChildOf
Add more tests for package access level
Resolves rdar://106728606
2023-03-14 17:17:14 -07:00
Doug Gregor
5c31b31d24 Disable tests that aren't expected to work now 2023-03-03 12:07:33 -08:00
Doug Gregor
53989ad72c [Diagnostics] Use the new swift-syntax formatter for -diagnostic-style swift.
We're going to move toward the new swift-syntax formatter. Use it for
the "swift" diagnostic style instead of the experimental formatter
written in C++.

There are some tests for the experimental formatter in C++ that test
precise formatting of diagnostics. I've disabled them in the same
places where the new swift-syntax formatter is enabled, for now. We
may choose to remove them entirely, because swift-syntax itself is
where the specific format is defined, and has those same kinds of
tests already.
2023-03-02 21:58:27 -08:00
Ellie Shin
ecc2042b3f Add error checks for input package name
Resolves rdar://103531208
2022-12-21 18:25:02 -08:00
Pavel Yaskevich
5a164c5f8a [Frontend] Switch from YAML to .strings based localization 2022-08-22 10:23:06 -07:00
Josh Soref
76ffd608f6 spelling: nonexistent
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-05-01 04:00:16 -04:00
Pavel Yaskevich
966f58f044 [Tests] NFC: Adjust all the test-cases improved by multi-statement inference 2022-03-08 01:13:44 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Pavel Yaskevich
67d87e104f [Tests] NFC: Adjust all the test-cases improved by multi-statement inference 2021-11-15 16:42:06 -08:00