Commit Graph

265 Commits

Author SHA1 Message Date
fwcd
9a86d2ecd2 Add diagnostic categories indicating deprecations and non-usage 2021-05-08 16:19:59 +02:00
fwcd
204827c6ab Update default value for unknown diagnostic IDs 2021-05-08 16:04:56 +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
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
Doug Gregor
14a311b36e [Global actors] Check calls to global-actor-qualified functions, not references
Check actor isolation of calls to functions with global-actor-qualified
type. This closes a pre-existing loophole where a value of
global-actor-qualified function type could be called from any context.
Paired with this, references to global-actor-qualified function
declarations will get global-actor-qualified function type whenever
they are referenced within an experience, i.e., whenever we form a
value of that type. Such references can occur anywhere (one does not
need to be on the actor), and carrying the global actor along with the
function type ensures that they can only be called from the right
actor. For example:

    @MainActor func onlyOnMainActor() { ... }

    func callIt(_ fn: @MainActor () -> Void) {
      fn() // error: not on the main actor, so cannot synchronously call
           // this wasn't previously diagnosed
    }

    func passIt() {
      callIt(onlyOnMainActor)  // okay to pass the function
                               // used to be an error
    }

While here, fix up some broken substitution logic for
global-actor-qualified function types and "override" actor isolation.
2021-04-16 00:26:39 -07:00
Alex Hoppen
e4f4b89427 Merge pull request #36591 from ahoppen/pr/no-nullptr-sugared-types
[Diags] Add check for null when printing type for diags
2021-03-31 12:23:56 +02:00
Doug Gregor
9d8fde8c18 [Concurrency] Remove actorIndependent(unsafe) isolation.
Don't treat `actorIndependent(unsafe)` as its own kind of isolation.
It was only really used as a bring-up hack to break the isolation model,
but shouldn't be in the user model of the language and causes
complications to the implementation.
2021-03-26 08:27:36 -07:00
Alex Hoppen
f25c53a234 [Diags] Add check for null when printing type for diags
IIUC we should never have `ParenType`s that wrap a `nullptr` type. Adding an assertion to catch that situation. In the meantime check for null types in the `DiagnosticsEngine` to prevent a crash.

Fixes rdar://75740683
2021-03-25 23:04:08 +01: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
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
Hassan
1b0e8f9cec [Localization] Make localization producer handle printing diagnostics IDs 2021-03-14 17:38:34 +02:00
Hassan
dc5a4bd1ec [Localization] Print diagnostic ID name from localization 2021-03-14 17:37:55 +02:00
Becca (née Brent) Royal-Gordon
93ffb88219 Merge pull request #36125 from beccadax/behave-yourself
[NFC] Allow errors to be conditionally emitted as warnings
2021-03-04 17:13:03 -08:00
Doug Gregor
3e6b3695f5 Model "unsafe" global actor isolation.
With "unsafe" global actor isolation, we only enforce actor isolation
when interacting with other explicitly-isolated code. This allows some
code to be annotated with, e.g., `@MainActor(unsafe)` so that users
who opt into concurrency get proper diagnostics, but existing code
does not change.
2021-03-03 17:59:01 -08:00
Becca Royal-Gordon
313235a1b1 [NFC] Reorganize DiagnosticState::determineBehavior()
This makes it a little easier to reason abut what’s going on while also fixing a small, currently-unexercisable flaw that would have previously occurred if you used limitBehavior(DiagnosticBehavior::Warning) and emitted a remark.
2021-03-03 15:32:52 -08: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
Michael Gottesman
4c9e1b662b [ast] Fix a memory error in Diagnostic Emission.
Specifically, we were storing pointers into a SmallVector. When the small vector
resized, the pointers were no longer valid resulting in memory
corruption. Was triggered by my work adding capture diagnostics.
2021-01-30 21:50:03 -08:00
Varun Gandhi
f9570b2d34 [NFC] Pass full convention printing boolean for types etc.
When -experimental-print-full-convention is set, we should be printing
the full convention in diagnostics, doc comments etc.
2021-01-25 18:47:39 -08:00
Luciano Almeida
b9dec7da4c [test] Adjusting tests for generic parameters that are now being aka on diagnostics 2021-01-14 17:44:52 -03:00
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