Commit Graph

94 Commits

Author SHA1 Message Date
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
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
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
Steven Wu
8ff3b05766 [NFC] Factor out DiagnosticBridge between swift-syntax
Refactor out the code that handles printing diagnostics from
swift-syntax.
2024-07-08 16:15:44 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ben Barham
69fc09f6bd [Frontend] Allow building without host Swift
There's no `swift_ASTGen_destroySourceFile` when we're not building
ASTGen.
2024-04-23 13:45:28 -07:00
Doug Gregor
8c0c666d94 [Diagnostics] Make sure we provide the proper file name 2024-02-14 13:27:42 -08:00
Doug Gregor
af5e0aaab4 Cache parsed source files in the PrintingDiagnosticConsumer
We were re-parsing each source file for each top-level diagnostic emitted,
which is... rather inefficient. Cache the parsed source files until
the PrintingDiagnosticConsumer goes away.
2024-02-14 08:29:34 -08:00
Hamish Knight
b61ee24d1b [Frontend] Support color output in DiagnosticVerifier
Move the color stream utilities into ColorUtils.h,
and use ColorStream to print diagnostic messages
if `-color-diagnostics` is passed.
2024-02-09 16:47:03 +00:00
Hamish Knight
5d99fe63e9 Rename get() -> unbridged() on bridging wrappers 2023-10-31 11:06:39 +00:00
Hamish Knight
6afde8a6d2 Remove CBasicBridging and CASTBridging
Merge with BasicBridging and ASTBridging
respectively. The changes here should be pretty
uncontroversial, I tried to keep it to just moving
code about.
2023-10-30 23:49:56 +00:00
Hamish Knight
356cf31d83 [ASTGen] Migrate onto some BasicBridging types
Migrate onto BridgedStringRef, and the
BasicBridging equivalents of BridgedSourceLoc
and BridgedArrayRef.
2023-10-30 23:49:53 +00:00
Rintaro Ishizaki
e01df929c2 [swift-parse-test] A parser performance check utility
```
% swift-parse-test -swift-parser -lib-parse -n 20 ../swift-syntax/Sources
files count: 228
total bytes: 5662399
total lines: 158428
iteration: 20
----
parser:  SwiftParser
wall clock time (ms): 3848
cpu time (ms): 3843
throughput (byte/sec): 355824
throughput (line/sec): 41225
----
parser:  libParse
wall clock time (ms): 296
cpu time (ms): 290
throughput (byte/sec): 4715281
throughput (line/sec): 546303
```
2023-10-28 20:23:26 -07:00
swift-ci
7bf0deea04 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-12 16:14:52 -07:00
Rintaro Ishizaki
f8c7bd94f3 [ASTGen] Cleanup string bridging
* BridgedString for ASTGen -> C++ string returnings
* Null terminated C-strings for C++ -> ASTGen string arguments
* UnsafeMutableRawPointer for C++ -> ASTGen diagnostic engine arguments
2023-10-12 12:57:28 -07:00
swift-ci
e767ad1bec Merge remote-tracking branch 'origin/main' into rebranch 2023-10-05 14:33:21 -07:00
Rintaro Ishizaki
7ac5d65479 [ASTGen] Use standard headers
For whatever reason, using standard headers in modules imported from
Swift code (i.e. depending on Darwin overlay) is no longer an issue.

rdar://115438609
2023-10-04 15:12:17 -07:00
Allan Shortlidge
8ebe83f294 NFC: Fix unused function and variable warnings.
Fixes the following warnings:
```
../swift-project/swift/lib/Frontend/PrintingDiagnosticConsumer.cpp:374:33: warning: unused function 'getSourceBufferStack' [-Wunused-function]
static SmallVector<unsigned, 1> getSourceBufferStack(
                                ^
../swift-project/swift/lib/Sema/TypeCheckMacros.cpp:184:15: warning: unused variable 'ctx' [-Wunused-variable]
  ASTContext &ctx = macro->getASTContext();
              ^
../swift-project/swift/lib/Sema/TypeCheckMacros.cpp:191:8: warning: unused variable 'sourceFile' [-Wunused-variable]
  auto sourceFile = macro->getParentSourceFile();
       ^
../swift-project/swift/lib/Sema/TypeCheckMacros.cpp:999:13: warning: unused variable 'macroRole' [-Wunused-variable]
  MacroRole macroRole =
            ^
../swift-project/swift/lib/Sema/TypeCheckMacros.cpp:165:25: warning: unused function 'handleExternalMacroDefinition' [-Wunused-function]
static MacroDefinition  handleExternalMacroDefinition(
                        ^
../swift-project/swift/lib/Sema/TypeCheckMacros.cpp:940:16: warning: unused function 'getRawMacroRole' [-Wunused-function]
static uint8_t getRawMacroRole(MacroRole role) {
               ^
```
2023-09-29 11:04:14 -07:00
Ben Barham
119d08c6d1 Merge remote-tracking branch 'origin/main' into 20230929-merge-rebranch
Conflicts:
  - `CMakeLists.txt` caused by the extra `-D` added in rebranch to
    reduce the number of deprecation warnings.
  - `lib/Frontend/PrintingDiagnosticConsumer.cpp` caused by the removal
    of one of the `#if SWIFT_SWIFT_PARSER` on rebranch (probably should
    have been done on main).
2023-09-29 09:50:50 -07:00
Ben Barham
041691184c [CMake] Replace early swift-syntax with FetchContent
Use FetchContent to include swift-syntax directly in swift. This can be
thought of as an `add_subdirectory` for a directory outside the root.

The default build directory will be `_deps/swiftsyntax-subbuild/`, though
the modules and shared libraries will be built in `lib/swift/host` by
passing down `SWIFT_HOST_LIBRARIES_DEST_DIR` to avoid copying them as we
were doing previously.
2023-09-18 14:44:10 -07:00
swift-ci
6dcf2a4872 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-07 16:36:57 -07:00
Doug Gregor
7287ad00b7 [Diagnostics] Let the swift-syntax formatter handle multiple files itself 2023-09-05 17:57:43 -07:00
swift-ci
3b8132730e Merge remote-tracking branch 'origin/main' into rebranch 2023-09-05 06:54:06 -07:00
Doug Gregor
eb9b736e29 Use SwiftInt consistently 2023-09-04 22:36:16 -07: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
Doug Gregor
c7881fbae2 Fix int/SwiftInt confusion in diagnostic printing code 2023-09-01 23:31:25 -07:00
Doug Gregor
448402c608 [Diagnostics] Free memory associated with printed string 2023-09-01 22:03:09 -07:00
Doug Gregor
8efe6a6b0c [New diagnostics] Don't aggregate across warnings/errors.
The "grouped diagnostics" feature can handle multiple
warnings/errors/remarks in a single grouping, but doing so isn't very
ergonomic for users because the primary warning/error/remark can be
buried in the source file. As a first step toward improving this
situation, always break up groups at a new warning/error/remark.
2023-09-01 16:28:25 -07:00
swift-ci
5dc6d1bb72 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-10 02:55:46 -07:00
Hamish Knight
35a98f3828 [ASTGen] Allow querying of enabled features
For now this is using C interop, we ought to be
using C++ interop, but that's a much bigger
change.
2023-08-09 19:35:50 +01:00
Evan Wilde
4f27bb28ba Add missing headers
Found a few more missing headers. Adding them in now.
2023-08-03 10:06:44 -07:00
Evan Wilde
88cad7a6a3 [NFC] resolve unused function warning
getSourceBufferStack is only used when SWIFT_SWIFT_PARSER is enabled. I
had it turned off, so I was getting 'unused function' warnings.
2023-07-17 10:55:57 -07: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
Doug Gregor
0d6de9e4a1 [Diagnostics] Switch swift-syntax diagnostic style to grouped diagnostics
Use the new "grouped diagnostics" feature of the swift-syntax
diagnostic rendering to emit printed diagnostics under the
swift-syntax diagnostic style. This emits macro expansion buffers as
text to the terminal, inset in a box where the macro was expanded, so
that there is more context for understanding how the macro was
expanded and what went wrong inside it.
2023-02-27 08:56:21 -08:00
Doug Gregor
8871129896 [Macros] Add frontend flag to dump macro expansions for diagnostics.
Add frontend flag `-emit-macro-expansion-files diagnostics` to emit any
macro expansion buffers referenced by diagnostics into files in a
temporary directory. This makes debugging type-checking failures in
macro expansions far easier, because you can see them after the
compiler process has exited.
2023-01-30 18:05:53 -08:00
Doug Gregor
c7b7c4a8d4 Colorize swift-syntax diagnnostics when requested 2023-01-25 21:29:23 -08:00
Doug Gregor
39c622ff84 [Diagnostics] Make sure the code builds without the new Swift parser 2023-01-22 09:41:15 -08:00
Doug Gregor
bdf1183757 [Diagnostics] Add a swift-syntax diagnostic style
The SwiftDiagnostics module within swift-syntax has a diagnostic
pretty-printer that does a nice rendering of the source code with
diagnostics placed inside gaps between the code lines.
Introduce another `-diagnostic-style` argument, `swift-syntax`,
to bridge from the pretty-printed C++ diagnostics over to the
swift-syntax diagnostics engine.
2023-01-21 23:09:56 -08:00
Doug Gregor
3e8f0b2bd6 [Diagnostics] Fix a crash in the "swift" diagnostic printing style.
When there are no excerpts, we should assume indentation of zero.
2023-01-20 21:35:29 -08:00
Victoria Mitchell
0639a9e2fb review: rename Attribute to InlineAttributes 2022-07-21 17:22:41 -06:00
Victoria Mitchell
76fe621c1f markup: add support for swift-cmark inline attributes
rdar://96830173
2022-07-21 08:13:07 -06:00
Josh Soref
38c0de0598 Spelling frontend (#42465)
* spelling: calculated

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: compilations

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: containing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dependency

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: dependent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: diagnose

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: explicit

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: explicitly

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: feature

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: fulfill

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: fulfillment

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: invoke

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: module

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: multiple

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: nonexistent

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: omitted

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: optimization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: performing

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: primaries

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: propagate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: sacrifices

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: scanned

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: substitution

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: successful

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: typecheck

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: unobtrusive

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: utilities

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-20 15:18:37 -07:00
Minhyuk Kim
e924cf6104 Replace usages of StringRef.find(Key) != StringRef::npos to StringRef.contains(Key) 2021-02-04 00:42:04 +09:00
Owen Voorhees
e40e86fc94 Merge pull request #32017 from owenv/diag-style-opt
[Diagnostics] Add -diagnostic-style=(llvm|swift) to control printed output
2020-05-27 20:22:23 -07:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Owen Voorhees
c4e67e29ed [Diagnostics] Add -diagnostic-style=(llvm|swift) to control printed output
This default formatting style remains the same "LLVM style". "Swift style"
is what was previously enabled via -enable-experimental-diagnostic-formatting
2020-05-20 19:34:15 -05:00
Owen Voorhees
96696c8823 [Diag-Experimental-Formatting] Add a formatting test for Swift diags emitted in clang virtual files 2020-05-12 18:40:20 -07:00
Owen Voorhees
f00953c62d [Diags-Experimental-Formatting] Fixes for printing diagnostics when #sourceLocation is used
- Always use the line number in the actual source file when extracting excerpts and adding highlights/fix-its
- Always use the display name when printing excerpt titles
- Don't print surrounding lines when an annotated line is in a virtual file

This reverts commit f919e047834eddf8863723b9db1fcb8d344d2006.
2020-05-12 18:40:20 -07:00
Owen Voorhees
780174d3ed [Diags-Experimental-Formatting] Design updates
- Bold diagnostic message text
- Change line numbers and file header to unbolded cyan color to emphazize code snippets/message text
- More compact printing of a single message with unknown location
- If a diagnostic includes excerpts from multiple files, horizontally align the line numbers
- Indent filenames with '=' so they appear to the right of line numbers
2020-04-22 13:38:42 -07:00
Robert Widmann
58e63f7185 Merge pull request #28313 from owenv/verifier-consumer
[DiagnosticVerifier] Make DiagnosticVerifier a DiagnosticConsumer
2020-03-30 17:46:30 -07:00