Commit Graph

341 Commits

Author SHA1 Message Date
Luciano Almeida
8a711644d6 [Diagnostics] Do not use canonical type for aka diagnostics instead visiting the type recursivelly desugaring 2021-01-14 01:02:35 -03: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
Saidhon Orifov
2855ef3f94 Revert change for storedDiagnosticInfos 2020-10-30 18:56:59 -04:00
Saidhon Orifov
ed768ce464 Change macro to DIAG in storedDiagnosticInfos array 2020-10-29 18:25:46 -04:00
Saidhon Orifov
7db8b0f537 [DiagnosticsQol] Modify diagnostic macro into single DIAG 2020-10-28 21:33:12 -04:00
Kavon Farvardin
34d22105b8 implemented parsing and typechecking for @actorIndependent(unsafe)
[broken] first impl of @actorIndependent in the type checker.

[broken] fixed mistake in my parsing code wrt invalid source range

[broken] found another spot where ActorIndependent needs custom handling

[broken] incomplete set of @actorIndependent(unsafe) tests

updates to ActorIndependentUnsafe

[fixed] add FIXME plus simple handling of IndependentUnsafe context

finished @actorIndependent(unsafe) regression tests

added wip serialization / deserialization test

focus test to just one actor class

round-trip serialize/deserialize test for @actorIndependent

serialize -> deserialize -> serialize -> compare to original

most of doug's comments

addressed robert's comments

fix printing bug; add module printing to regression test

[nfc] update comment for ActorIsolation::IndependentUnsafe
2020-10-19 15:20:24 -07: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
Brent Royal-Gordon
9dcec05309 Fix non-public imported declaration diagnostic bug
When DiagnosticEngine needs to diagnose something about an imported declaration, it uses ASTPrinter to print the declaration’s interface into a source buffer and then diagnoses it there. However, this code only printed public declarations, so it failed to account for features like `@testable import` which allow less-than-public declarations to be imported. Errors involving these declarations would therefore be diagnosed at <unknown>:0.

This commit changes DiagnosticEngine to determine the access level of the declaration it needs to print and, if it is below `Public`, instead prints a separate interface whose minimum access level is low enough to include the desired declaration.
2020-09-23 14:04:17 -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
HassanElDesouky
4a429d0ac7 [Diag] Refactor diagnosticStringFor to return StringRef
Signed-off-by: HassanElDesouky <hassaneldesouky@icloud.com>
2020-08-17 12:00:06 +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
Pavel Yaskevich
123af8137d Update lib/AST/DiagnosticEngine.cpp
Co-authored-by: Suyash Srijan <suyashsrijan@outlook.com>
2020-06-17 13:13:59 -07:00
Pavel Yaskevich
14363ff58e Update lib/AST/DiagnosticEngine.cpp
Co-authored-by: Suyash Srijan <suyashsrijan@outlook.com>
2020-06-17 13:13:47 -07:00
HassanElDesouky
dede714a8f Change diagnostics from using DiagNodes to strings 2020-06-17 21:38:04 +02:00
HassanElDesouky
d6f706cddc Remove repeated headers 2020-06-17 20:49:33 +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
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Anthony Latsis
74252028ca AST: Rename getFullName -> getName on ValueDecl & MissingMemberDecl 2020-04-23 05:16:55 +03:00
Eric York
8a1a194f36 [SR-12460] Don't crash when missing a type in a Diagnostic message. (#30979)
* Don't crash when missing a type in a Diagnostic message.
Print an empty string for the missing type.

Resolves SR-12460

* Added new diagnostic message, eg. "operator '==' declared in extension must be 'static'"
2020-04-14 16:13:06 -07: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
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01: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
Daniel Rodríguez Troitiño
6792e0bcfd Merge pull request #28170 from drodriguez/msc-alternative-to-array-designators
[Visual C++] Provide alternative to array designators.
2019-11-09 12:17:24 -08:00
Daniel Rodríguez Troitiño
eb7a26db09 [Visual C++] Provide alternative to array designators.
Even if they are supported in GCC and Clang, C99 array designators are
not part of the current C++ standard (they will be in C++20), so they
are not supported in Visual C++.

This commit provides an alternative for Visual C++ (which should work in
other compilers) which doesn't use array designators.

I think Clang 10 will start printing a warning about this incorrect
usage.
2019-11-09 08:55:09 -08:00
Brent Royal-Gordon
37d3ce7b95 Merge pull request #28177 from brentdax/diagnostics-in-your-diagnostics
[NFC] [DiagnosticEngine] Improve output for malformed diagnostic messages
2019-11-08 23:03:46 -08:00
Brent Royal-Gordon
4f8756d13a [NFC] [DiagnosticEngine] Improve output for malformed diagnostic messages
This is NFC as long as you assume there are no bad diagnostics.
2019-11-08 19:48:34 -08:00
Owen Voorhees
ac05a66938 [Diagnostics] Introduce "Educational Notes" for diagnostics
Educational notes are small pieces of documentation which explain a concept
relevant to some diagnostic message. If -enable-descriptive-diagnostics is
passed, they will be printed after a diagnostic message if available.

Educational notes can be found at /usr/share/doc/diagnostics in a
toolchain, and are associated with specific compiler diagnostics in
EducationalNotes.def.
2019-11-07 13:18:35 -08:00
Varun Gandhi
64401ac92c [NFC] Replace StringMap<char, A> with StringSet<A> (#27986) 2019-10-31 12:46:58 -07:00
Owen Voorhees
8a6711769e [Diagnostics] Refactor DiagnosticConsumer interface
DiagnosticInfo now holds all the information needed to consume
a diagnostic, so remove unneeded parameters from handleDiagnostic.
2019-10-29 13:52:12 -07:00
Jordan Rose
5f2695808d Merge pull request #26830 from owenv/diag_child_notes_refactor
[Diagnostics][NFC] Optionally add notes as explicit children of an error/warning
2019-10-02 14:34:33 -07:00
Slava Pestov
b1ffa19c7b AST: Refine recursive property checks on type alias types 2019-09-24 17:39:53 -04:00
Robert Widmann
38bde33067 Merge pull request #27172 from CodaFi/aliasing-artifacts-and-noise-reduction-techniques
Kill validateDeclForNameLookup Harder
2019-09-18 15:00:51 -07:00
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -07:00
Robert Widmann
5e34169aca Separate computing interface types and underlying types
Computing the interface type of a typealias used to push validation forward and recompute the interface type on the fly.  This was fragile and inconsistent with the way interface types are computed in the rest of the decls.  Separate these two notions, and plumb through explicit interface type computations with the same "computeType" idiom.  This will better allow us to identify the places where we have to force an interface type computation.

Also remove access to the underlying type loc.  It's now just a cache location the underlying type request will use.  Push a type repr accessor to the places that need it, and push the underlying type accessor for everywhere else.  Getting the structural type is still preferred for pre-validated computations.

This required the resetting of a number of places where we were - in many cases tacitly - asking the question "does the interface type exist".  This enables the removal of validateDeclForNameLookup
2019-09-17 08:20:55 -07:00
Owen Voorhees
000294f5b1 [Diagnostics][NFC] Optionally add notes as explicit children of an error/warning
Add a new type of diagnostic transaction, CompoundDiagnosticTransaction.
The first diagnostic emitted inside the transaction will become the parent of the subsequent notes.
DiagnosticConsumers may opt in to consuming these child notes alongside the parent
diagnostic, or they can continue to consider them seperately.

Moved PrintingDiagnosticConsumer and a couple of diagnostics to the new
system as a proof of concept.
2019-09-16 17:33:40 -07:00
Jordan Rose
94f1d2c159 Merge pull request #26612 from owenv/formatted_fixits
[Diagnostics][NFCI] Introduce Structured fix-its
2019-09-05 17:51:42 -07:00
Owen Voorhees
68e6065c8e [Diagnostics][NFC] Introduce Structured fix-its
These are defined with macros like errors/warnings/notes, and
make use of format strings and diagnostic arguments. The intent
is to leverage diagnostic arguments in the future to disambiguate
ambiguously spelled types.

Ported a few miscellaneous fix-its to the new system
2019-09-05 10:43:25 -07:00
Rintaro Ishizaki
242699f933 [IDE] Disable constraint system diagnostics during code completion
It seems disabling diagnstics doesn't introduce any regression.

rdar://problem/50679428
2019-08-30 15:25:11 -07:00
Owen Voorhees
486c7b883d [Diagnostics][NFC] Add support for using the %select format specifier with StringRef args
Get rid of some redundant availability diagnostics as a result.
2019-08-26 11:37:29 -07:00
Owen Voorhees
e7a1a1cc3d Add -debug-diagnostic-names frontend flag
This flag adds diagnostic names to the end of their messages, e.g. 'error: cannot convert value of type '[Any]' to specified type '[Int]' [cannot_convert_initializer_value]'. It's intended to be used for debugging purposes when working on the compiler.
2019-08-05 18:54:21 -07:00
Pavel Yaskevich
b1e0980887 [AST] DiagnosticEngine: use references to replace string arguments 2019-07-24 18:14:17 -07:00
Pavel Yaskevich
eafa51d934 [AST] DiagnosticEngine: retain strings used in tentative diagnostic arguments
If diagnostics are produced as part of a transaction, let's copy
strings associated with arguments into a separate long(er) term
storage which is going to be cleaned up when diagnostic is actually
emit to the consumers.
2019-07-24 16:59:38 -07:00
Owen Voorhees
89eaa1e612 [Diagnostics] Desugar syntax sugared types if they have unresolved types
If a syntax sugared type like Array had an unresolved type, it used to print as `[_]` in diagnostics, which could be confusing.
Instead, desugar these unresolved types before printing, so Array, for example, prints as `Array<_>`.
Currently this only applies to Array, Dictionary, and Optional.
2019-07-03 08:11:31 -07:00
Jordan Rose
cb6d47ef24 Show 'some' type origins in diagnostics, like 'aka' for sugared types (#25624)
Currently only works for types that are /just/ a 'some' type, not in a
nested position. Also won't show them for opaque types with different
requirements, to avoid noise when it's not strictly necessary. This
does mean that 'some P' vs. 'some P & Q' won't get the origin part.

Part of rdar://problem/50346954
2019-06-28 20:42:47 -07:00
Owen Voorhees
9d07d06886 [Diagnostics]: Qualify Type arguments to diagnostics if there are name collisions
If a diagnostic argument list contains two or more types which are distinct but have the same name, make sure they are qualified when printed
2019-06-26 19:13:40 -07:00
Michael Gottesman
69335f02c3 [diagnostics] Add the llvm option swift-diagnostics-assert-on-warning to cause the diagnostics engine to assert upon triggering a warning.
This is an option only intending to help compiler developers triage/track down
why a warning is being emitted in a quick manner. It will only be in asserts
builds since it is an LLVM option.
2019-05-22 19:18:35 -07:00