Commit Graph

117 Commits

Author SHA1 Message Date
Anthony Latsis
06a5670c8f Basic: Untie swift::SourceLoc from llvm::SMLoc
Storing a `llvm::SMLoc` is a superfluous indirection, and getting rid of
it enables us to unconditionally import `SourceLoc` into Swift.
2025-07-11 18:48:42 +01: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
Ryan Mansfield
7c97328569 Fix -Wreorder-ctor warning in DiagnosticVerifier.cpp. 2025-02-18 16:24:28 -05:00
Becca Royal-Gordon
0466d5c0ca Handle diagnostic verifier locations concretely
This commit makes a number of adjustments to how the diagnostic verifier handles source buffers and source locations. Specifically:

• Files named by `-verify-additional-file` are read as late as possible so that if some other component of the compiler has already loaded the file, even in some exotic way (e.g. ClangImporter’s source buffer mirroring), it will use the same buffer.
• Expectation source locations now ignore virtual files and other trickery; they are based on the source buffer and physical location in the file.

Hopefully this will make `-verify-additional-file` work better on Windows. As an unintended side effect, it also changes how expectations work in tests that use `#sourceLocation()`.
2025-02-11 12:05:17 -08:00
Ben Barham
d72f5b12c4 Update StringRef::equals references to operator==
`equals` has been deprecated upstream, use `operator==` instead.
2024-06-27 19:14:06 -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
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -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
Michael Gottesman
fa1558a175 [frontend] Add an option called -verify-additional-prefix to add additional check prefixes to the DiagnosticVerifier.
This enables one to use varying prefixes when checking diagnostics with the
DiagnosticVerifier. So for instance, I can make a test work both with and
without send-non-sendable enabled by adding additional prefixes. As an example:

```swift
// RUN: %target-swift-frontend ... -verify-additional-prefix no-sns-
// RUN: %target-swift-frontend ... -verify-additional-prefix sns-

let x = ... // expected-error {{This is always checked no matter what prefixes I added}}
let y = ... // expected-no-sns-error {{This is only checked if send non sendable is disabled}}
let z = ... // expected-sns-error {{This is only checked if send non sendable is enabled}}
let w = ... // expected-no-sns-error {{This is checked for a specific error when sns is disabled...}}
// expected-sns-error @-1 {{and for a different error when sns is enabled}}
```

rdar://114643840
2023-08-30 13:40:17 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Anthony Latsis
3998fdf0c4 DiagnosticVerifier: Optimize CapturedFixItInfo::getLineColumnRange for intra-line source ranges 2023-03-08 13:18:22 +03:00
Anthony Latsis
d2911437c0 DiagnosticVerifier: Use zeros instead of LineColumnRange::NoValue 2023-03-08 13:18:16 +03:00
Anthony Latsis
14b70f306b DiagnosticVerifier: Default expected fix-it start line to the diagnostic's 2023-03-08 12:10:27 +03:00
Anthony Latsis
8306f870ec DiagnosticVerifier: Default expected fix-it end line to start line 2023-03-08 12:10:27 +03:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Becca Royal-Gordon
cdcd726f92 Add fixit alternation to -verify
You can now put `||` between two fix-its to indicate that the test succeeds if either of them is present. This is meant for situations where a fix-it might vary slightly in different subtests or test configurations.

Also fixes a bug in the diagnostic verifier where "expected-whatever" would search beyond the same line for its opening "{{", potentially finding one many lines away and giving a bad diagnostic and poor recovery behavior.
2022-03-04 10:28:42 -08:00
swift-ci
ad903094c0 Merge pull request #41386 from beccadax/your-library-is-overdue
Weaken some type checks for @preconcurrency decls
2022-03-01 16:13:59 -08:00
Rintaro Ishizaki
1ee91db867 [DiagnosticVerifier] Define LineColumnRange::NoValue 2022-02-19 16:53:57 -08:00
Becca Royal-Gordon
5330653f3d Improve -verify’s wrong diagnostic kind diagnosis
If, for instance, an error is emitted as a warning instead, the verifier now detects this and emits a single diagnostic saying that the warning was found but had the wrong kind, instead of emitting one diagnostic saying the error was missing and another saying the warning was unexpected.

In theory there are some edge cases we could handle better by doing two separate passes—one to detect exact expectation matches and remove them, another to detect near-misses and diagnose them—but in practice, I think the text + diagnostic location is likely to be unique enough to keep this from being a problem. (I would hesitate to do wrong-line diagnostics in the same pass like this, though.)
2022-02-18 13:27:59 -08:00
Anthony Latsis
2128678d56 DiagnosticVerifier: Support line offsets in fix-it verification ranges 2022-02-18 04:42:57 +03:00
Anthony Latsis
4ebd9c0131 [NFC] DiagnosticVerifier: Remove redundant variable 2022-01-31 05:04:49 +03:00
Anthony Latsis
91fedd9b8a Verifier: Support line numbers in fix-it verification 2022-01-31 05:04:49 +03:00
Anthony Latsis
d5087ee329 [NFC] DiagnosticVerifier: Cache computed column numbers for actual fix-its 2022-01-31 05:04:33 +03:00
Anthony Latsis
011ce73e0c DiagnosticVerifier: Fix no-op range assignment in DiagnosticVerifier::handleDiagnostic 2022-01-31 05:04:33 +03:00
Anthony Latsis
99b8ae09d0 [NFC] DiagnosticVerifier: Use a dedicated struct for fix-it column-based ranges 2022-01-31 05:04:22 +03:00
Anthony Latsis
8e4ea9b01a [NFC] DiagnosticVerifier: Move 'getColumnNumber' into SourceManager 2022-01-31 05:04:09 +03:00
Evan Wilde
0aafd09835 F_None was renamed OF_None
This patch updates usages of F_None to OF_None, as LLVM changed that in
commit 3302af9d4c39642bebe64dd60a3aa162fefc44b2.
2021-06-23 10:36:39 -07:00
Becca Royal-Gordon
1f713074ac [NFC] Fix issues with -verify mode
This commit fixes two weird bugs in -verify mode:

1. SourceLocs from the wrong SourceManager could be passed through a ForwardingDiagnosticConsumer into the DiagnosticVerifier.

2. -verify-additional-file did not error out correctly when the file couldn’t be opened.

No tests, as we only have basic tests for the diagnostic verifier.
2021-03-25 16:02:29 -07:00
Brent Royal-Gordon
5036a55550 [Frontend] Allow additional files for diagnostic verifier
This change adds a frontend flag, -verify-additional-file, which can be used to pass extra files directly to the diagnostic verifier. These files are not otherwise considered to be Swift source files; they are not compiled or even properly parsed.

This feature can be used to verify diagnostics emitted in non-source files, such as in module interfaces or header files.
2021-01-11 15:59:25 -08:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Owen Voorhees
45bc578ae5 [SourceManager] Rename line and column APIs for clarity 2020-05-21 12:54:07 -05:00
Matt Davis
feb03ebcd7 [DiagnosticVerifier] Explicit convert a StringRef into a std::string.
The newer llvm StringRef library has removed the implicit StringRef to
std::string conversion.  (See: llvm/llvm-project@adcd026)

This patch also uses a StringRef to compare another StringRef
eliminating the need to perform a StringRef to std::string conversion.
I am concerned that StringRef's are being stored in
ExpectedEducationalNotes, but as long as the StringRef does not out live
the definition this is totally cool then.
2020-04-11 09:29:58 -07:00
Owen Voorhees
456081715e Merge pull request #30947 from owenv/verifier-asan-fix
[DiagnosticVerifier] Fix ASAN issue in the verifier
2020-04-10 11:25:51 -05:00
Owen Voorhees
20d3afc439 [DiagnosticVerifier] Fix ASAN issue where Twine was stored to a temporary 2020-04-10 04:53:05 -07:00
Owen Voorhees
cfbedd81c4 [DiagnosticVerifier] Add support for asserting presence of edu notes 2020-04-09 18:18:25 -07:00
omochimetaru
a07b35ab03 [Diagnostics] Improve {{none}} fix-it verifier (#30791)
* [Diagnostics] Improve {{none}} fix-it verifier

* split two conditions

* define "none" constant

* support plural

* use Twine and add comment for replacement range

* check if {{none}} is at the end

* use noneMarkerStartLoc

* update second {{none}} error message

Co-Authored-By: Owen Voorhees <owenvoorhees@gmail.com>

* update test case for second {{none}}

* fix test case for new {{none}} check

* Use named struct

* set const

Co-authored-by: Owen Voorhees <owenvoorhees@gmail.com>
2020-04-09 15:32:14 -07:00
Owen Voorhees
d6a2910f41 Update DiagnosticVerifier.cpp 2020-04-01 15:12:30 -07:00
Owen Voorhees
2c2850d7eb Merge branch 'master' into verifier-wording-fix 2020-04-01 17:05:24 -05:00
Owen Voorhees
465bab002f [DiagnosticVerifier] Make Diagnostic Verifier a DiagnosticConsumer subclass
Update DiagnosticVerifier to respect color flags

Improve DiagnosticVerifier test coverage

verifier updates to support new llvm stable branch
2020-03-28 12:29:53 -07:00
Owen Voorhees
768c4385cf [DiagnosticVerifier] More accurate wording when printing diagnostics from external sources 2020-03-21 15:11:46 -07:00
omochimetaru
3ccec26390 [Diagnostics] Fix range of fix-its in verify mode 2020-03-19 18:47:57 +09:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Martin Boehme
f81ef9cf1e Prepend "diagnostic produced by Clang:" to Clang diagnostics. 2020-03-02 14:56:42 +01:00
Martin Boehme
45503abcdf Move struct Result directly above verifyFile(). 2020-03-02 14:56:42 +01:00
Martin Boehme
c164fca37b If -verify mode saw unexpected diagnostics, print diagnostics from all files.
As an example of how this is useful, consider the case where
ClangImporter fails with

  "unexpected error produced: could not build C module 'ctypes'"

It would be useful to know what the underlying Clang error was that
caused building the module to fail, but so far, `-verify` mode would not
output that; to get the error, it would be necessary to run the compiler
invocation again without `-verify`.

This change causes any remaining diagnostics that weren't in the input file
to be output if there were unexpected diagnostics in `-verify` mode.

I haven't added any tests for this because I didn't find a place that
contains tests for the `-verify` functionality itself (as opposed to
tests that use `-verify` mode). I think the large number of tests that
run with `-verify` should at least ensure, however, that this change
does not regress anything.
2020-03-02 14:56:42 +01:00
Owen Voorhees
0a239d568a Update diag_deprecated_string_interpolation to use column offsets in -verify mode instead of FileCheck 2019-09-03 11:09:36 -07:00
Owen Voorhees
3a2547ce0c [Diagnostics][NFC] Allow column specification in -verify mode
To check the column a diagnostic is emitted at, use
expected-error@+x:y, or expected-error@:y to specify
a column without a line offset
2019-08-29 20:11:55 -07:00
Harlan Haskins
42e1c2f07a [test] Add expected-remark to DiagnosticVerifier 2019-05-01 18:22:43 -07:00
Jordan Rose
f6c7973911 Teach -verify-apply-fixes to handle overlapping fix-its (#23970)
...by coalescing duplicates and dropping conflicts. Both cases can
happen with "expected-error 2 {{...}}": we might get multiple fix-its
providing the same new message, or one message might have diverged
into two, giving us incompatible changes.
2019-04-12 13:19:54 -07:00