Commit Graph

216 Commits

Author SHA1 Message Date
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
921e61b2fa Emit "in expansion of macro" notes for diagnostics within macro expansion buffers 2022-12-15 13:37:29 -08:00
Hamish Knight
9348688d72 [AST] Add descriptions for statement kinds
And plumb through the logic such that the
DiagnosticEngine can handle StmtKind. We could
introduce a separate DescriptiveStmtKind a la
DescriptiveDeclKind, but it would be a 1:1 map,
so I'm not convinced it's currently worth doing.
2022-12-02 13:23:11 +00:00
Artem Chikin
c51efbed9c Add option to suppress emission of remarks ('-suppress-remarks')
And enforce it especially in downstream contexts such as building interfaces of SDK dependencies, where the remarks are not actionable by the user.
2022-10-28 10:49:27 -07:00
Egor Zhdan
e9dedf3c27 [cxx-interop][SwiftCompilerSources] Use swift::DiagnosticEngine instead of BridgedDiagnosticEngine
This also removes `BridgedOptionalDiagnosticEngine`.

rdar://83361087
2022-07-14 11:06:31 +01:00
Hamish Knight
4f5bf99e07 [Parse] NFC: Allow sub-lexers to disable diagnostics
And `const` qualify a couple of params/methods.
2022-06-22 20:05:19 +01:00
Hamish Knight
07b3c765cd [DiagnosticEngine] Introduce DiagnosticQueue
This allows us to hold tentative diagnostics
independent of other diagnostic transactions.
2022-04-12 16:03:46 +01:00
Nuri Amari
130f2de7fd Improve ClangImporter failure diagnostics
This patch introduces new diagnostics to the ClangImporter to help
explain why certain C, Objective-C or C++ declarations fail to import
into Swift. This patch includes new diagnostics for the following entities:

- C functions
- C struct fields
- Macros
- Objective-C properties
- Objective-C methods

In particular, notes are attached to indicate when any of the above
entities fail to import as a result of refering an incomplete (only
forward declared) type.

The new diangostics are hidden behind two new flags, -enable-experimental-clang-importer-diagnostics
and -enable-experimental-eager-clang-module-diagnostics. The first flag emits diagnostics lazily,
while the second eagerly imports all declarations visible from loaded Clang modules. The first
flag is intended for day to day swiftc use, the second for module linting or debugging the importer.
2022-01-02 12:43:59 -05:00
John McCall
5eecc6ac07 Only warn about self capture in nested closures until Swift 6.
Swift has diagnosed implicit uses of class-reference `self` in
escaping closures for a long time as potentially leading to reference
cycles.  PR #35898 fixed a bug where we failed to diagnose this
condition in nested closures.  Unfortunately, treating this as an
error has proven problematic because there's a lot of code doing
it.  Requiring that code to be thoroughly stamped out before we
ship a compiler is just too much to ask.  Stage the fix in by
treating it as a warning in Swift versions prior to 6.

As with the non-nested case, this warning can be suppressed by
explicitly either capturing `self` or spelling out `self.` in the
access.

Fixes rdar://80847025.
2021-08-18 21:44:23 -04:00
Rintaro Ishizaki
ed1db1bed2 [CodeCompletion] Explain why results aren't recommended
* Implement 'getDiagnosticSeverity()' and 'getDiagnosticMessage()' on
  'CodeCompletionResult'
* Differentiate 'RedundantImportIndirect' from 'RedundantImport'
* Make non-Sendable check respects '-warn-concurrency'

rdar://76129658
2021-08-10 17:11:14 -07:00
Holly Borla
a06c4afcfa [Diagnostics] Add InFlightDiagnostic::warnUntilSwiftVersion to limit the
diagnostic behavior to a warning until the specified language version.

This helper can be used to stage in fixes for stricter diagnostics
as warnings until the next major language version.
2021-07-07 16:52:37 -07:00
Becca Royal-Gordon
a414729918 “Wrap” invalid access note diagnostics
This shows up better in Xcode, which unfortunately doesn’t really display notes very clearly.
2021-05-21 16:10:12 -07:00
Ben Langmuir
006e78e672 Merge pull request #37320 from fwcd/sourcekit-diagnostic-ids
[SourceKit] Add id and category to diagnostics
2021-05-17 14:25:40 -07:00
Hassan
481b29b6ca [Localization] Delay loading localization
- Add `LocalizationProducerState` to manage the states of LocalizationProducers.
- Add `initializeImpl` and `initializeIfNeeded` to manage lazily initialization of `LocalizationProducer`s.
- Move constructing a localization producer from DiagEngine to `LocalizationProrducer` itself.
2021-05-14 01:28:55 +02:00
fwcd
9a86d2ecd2 Add diagnostic categories indicating deprecations and non-usage 2021-05-08 16:19:59 +02:00
fwcd
8c0e0e2ef7 Add DiagnosticEngine::diagnosticIDStringFor 2021-05-07 17:45:21 +02:00
Owen Voorhees
07fb294c8a [APIDigester] Provide a category when serializing diagnostics representing API or ABI breakage 2021-05-04 19:35:35 -07:00
Pavel Yaskevich
2eb57d231f Merge pull request #34319 from HassanElDesouky/localization-debug-diagnostics
[Diag] Print the diagnostic ID name from localization
2021-03-24 00:27:23 -07:00
Hassan
09b794d002 [Localization] Correct namings and improve comment 2021-03-23 22:39:35 +02:00
Hassan
8665e0cb55 [Localization] Move localization allocator from DiagEngine to the localization producer 2021-03-23 10:41:54 +02:00
Hassan
b34cf952e0 [DiagEngine] Make localizationSaver not optional and update comment 2021-03-21 20:04:49 +02:00
Hassan ElDesouky
f676066a43 Merge branch 'main' into localization-debug-diagnostics 2021-03-20 18:39:51 +02:00
Doug Gregor
e316a8ef90 [Importer] While pretty-printing decls for diagnostics, don't emit diagnostics.
The diagnostics system doesn't allow a diagnostic to be emitted while
another diagnostic is in flight. Doing so will cause an assertion in
the diagnostics machinery.

There's a longstanding cycle here when diagnostics emission
pretty-prints declarations that are imported from a Clang module, and
the Clang Importer emits a diagnostic. Squash this cycle forcefully,
dropping the diagnostic that the Clang importer would emit.
2021-03-19 09:33:55 -07:00
Becca Royal-Gordon
043434d338 [NFC] Add DiagnosticStateRAII
DiagnosticEngine tracks whether an error/warning was ignored so that it can also automatically ignore related notes. This can go rather poorly if you have logic between the warning/error and notes to determine which notes to emit, and this logic emits ignored diagnostics.

Add an RAII type to handle this situation and use it at all entry points into TypeCheckDeclObjC.cpp, since this code is about to start using ignored diagnostics pretty heavily.
2021-03-18 13:42:21 -07:00
Hassan
ef7551d4f5 [Localization] Add an allocator to to retain diagnostic strings 2021-03-17 10:23:02 +02:00
Hassan
1b0e8f9cec [Localization] Make localization producer handle printing diagnostics IDs 2021-03-14 17:38:34 +02:00
Becca Royal-Gordon
c58fe89841 [NFC] Add InFlightDiagnostic::limitBehavior()
This allows code to reduce the “severity” of a diagnostic at one particular emission site, so that (for instance) an error can be emitted as a warning in some situations. It also changes some code in TypeCheckConcurrency.cpp to use this new feature, allowing us to delete some redundant diagnostic definitions.
2021-03-03 15:32:52 -08:00
Becca Royal-Gordon
4a01b567e7 [NFC] Pass whole diagnostic into determineBehavior() 2021-03-03 14:11:13 -08:00
Becca Royal-Gordon
ed0f1f2f1b [NFC] Rework DiagnosticEngine::ignoreDiagnostic()
This feature was implemented with a per-diagnostic table of override DiagnosticBehaviors. That table was able to represent not only that a diagnostic should be ignored, but also many other states that were difficult to integrate with a feature I’m trying to introduce. Simplify the implementation so it can only represent ignoring a diagnostic, which has a much cleaner interaction with the new feature.
2021-03-03 14:11:13 -08:00
Becca Royal-Gordon
2052c26c14 [NFC] Un-nest DiagnosticState::Behavior 2021-03-03 14:11:13 -08:00
Robert Widmann
b3843afc3e Add an Abstraction For Full Qualification to DiagnosticEngine
Teach the diagnostic engine about a new wrapper type `FullyQualified<T>`. The intent is to clarify which parameters will be printed with additional qualification in diagnostic text. For now, this is only useful for types, so there's a bit of SFINAE guarding against misuse of the abstraction.

 rdar://63199963
2020-11-09 15:04:31 -08:00
Doug Gregor
2f7ff6aa39 [Concurrency] Allow ActorIsolation in diagnostic messages.
ActorIsolation is rendered as a descriptive phrase before an entity,
e.g, "actor-independent" or "global actor 'UIActor'-isolated" when
used in diagnostics.
2020-10-13 21:41:03 -07:00
Pavel Yaskevich
c17bdaf715 [AST] Adjust Diagnostic transaction to only track pending errors 2020-09-01 13:57:03 -07:00
Saleem Abdulrasool
fe0a945898 AST: split out diagnostics serialization
Create a new diagnostics serialization library, splitting out of
swiftAST to reduce the overheads for building the tooling for
cross-compiling the toolchain.  This should reduce the build time for
swift-serialize-diagnostics to enable cross-compilation.
2020-08-24 09:21:55 -07:00
Pavel Yaskevich
a12ac414a1 Merge pull request #33509 from xedin/rdar-65320500
[FunctionBuilders] Implement graceful handling of pre-check failures
2020-08-18 00:58:15 -07:00
Pavel Yaskevich
fddfd6d782 [BuilderTransform] Suppress diagnostics produced by preCheckExpression 2020-08-17 12:37:17 -07:00
HassanElDesouky
4a429d0ac7 [Diag] Refactor diagnosticStringFor to return StringRef
Signed-off-by: HassanElDesouky <hassaneldesouky@icloud.com>
2020-08-17 12:00:06 +02:00
Nathan Hawes
3aa4f74981 Add missing include to fix build issues on master-next and master-rebranch 2020-08-06 11:30:23 -07:00
HassanElDesouky
a84cf7f9e8 [Locale] Serialize YAML to an OnDiskHashTable format and create a tool for serialization 2020-08-05 15:52:46 -07:00
HassanElDesouky
063e92aa53 Create frontend flags for localization 2020-06-30 23:12:40 +02:00
Hassan ElDesouky
6a444433ec [Diag] Refactor DiagnosticEngine to use YAML files - Reopen (#32483)
Introduce localization support for diagnostics via file-per-language store in `YAML` format.
Add `LocalizationFormat` interface and its implementation `YAMLLocalizationProducer`.
Augment `DiagnosticEngine` to support localization when applicable.
2020-06-24 23:09:12 -07:00
Pavel Yaskevich
acd73a30a3 Revert "[GSoC] Refactor DiagnosticEngine to use YAML files" (#32460) 2020-06-18 22:08:22 -04:00
HassanElDesouky
dede714a8f Change diagnostics from using DiagNodes to strings 2020-06-17 21:38:04 +02:00
HassanElDesouky
8d79027a62 Use clang-format 2020-06-17 20:45:11 +02:00
HassanElDesouky
f3a9708071 Use clang-format 2020-06-17 20:34:14 +02:00
HassanElDesouky
4e29883d24 Refactor DiagnosticEngine to use YAML files 2020-06-17 20:25:46 +02:00
Owen Voorhees
791312fb74 Turn Educational Notes On-By-Default (#30583)
* [Diagnostics] Turn educational notes on-by-default

* [Diagnostics] Only include educational notes in printed output if -print-educational-notes is passed

* Make -print-educational-notes a driver option

* [Diagnostics] Issue a printed remark if educational notes are available, but disabled

* [docs] Update educational notes documentation and add a contributing guide

* [Diagnostics] Cleanup PrintingDiagnosticConsumer handling of edu notes

* Revert "[Diagnostics] Issue a printed remark if educational notes are available, but disabled"
For now, don't notify users if edu notes are available but disabled. This decision can be reevaluated later.
2020-03-27 15:29:48 -07:00
Owen Voorhees
69b513afaf [Diagnostics] Updated (experimental) diagnostic printing style (#30027)
* [Diagnostics] Experimental diagnostic printing updates

This new style directly annotates small snippets of code with
error messages, highlights and fix-its. It also uses color more
effectively to highlight important segments.

* [Diagnostics] Stage educational notes and experimental formatting behind separate frontend flags

educational notes -> -enable-educational-notes
formatting -> -enable-experimental-diagnostic-formatting

* [Diagnostics] Refactor expensive line lookups in diag formatting

* [Diagnostics] Refactor some PrintingDiagnosticConsumer code into a flush method

* [Diag-Experimental-Formatting] Custom formatting for Xcode editor placeholders

* [Diag-Experimental-Formatting] Better and more consistent textual description of fix its

* [Diags-Experimental-Formatting] Handle lines with tab characters correctly when rendering highlights and messages

Tabs are converted to 2 spaces for display purposes.

* [Diag-Experimental-Formatting] Refactor byte-to-column mapping for efficiency

* [Diag-Experimental-Formatting] Fix line number indent calculation

* [Diag-Experimental-Formatting] Include indicators of insertions and deletions in the highlight line

Inserts are underlined by green '+' chars, deletions by red '-' chars.

* [Diag-Experimental-Formatting] Change color of indicator arrow for non-ASCII anchored messages
* [Diag-experimental-formatting] Make tests less sensitive to line numbering

* [Diag-Experimental-Formatting] Update tests to allow windows path separators

* [Diag-Experimental-Formatting] Bug fixes for the integrated REPL
2020-03-03 08:48:32 -08:00
Saleem Abdulrasool
7d8aac60ca disambiguate some type shadowing (NFCI)
Adjust the type shadowing identified by GCC 7.  The declaration shadows
a type which changes the meaning of the identifier subsequently.
2019-12-23 15:34:55 -08:00
Brent Royal-Gordon
6a8598a99c [NFC] Remove DeclNameRef staging calls 2019-12-11 00:55:18 -08:00