Commit Graph

347 Commits

Author SHA1 Message Date
Doug Gregor
49aa0e966f Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's
contents in the SourceManager, has always been optional. However, the
effectively every SourceFile actually does have a buffer ID, and the
vast majority of accesses to this information dereference the optional
without checking.

Update the handful of call sites that provided `nullopt` as the buffer
ID to provide a proper buffer instead. These were mostly unit tests
and testing programs, with a few places that passed a never-empty
optional through to the SourceFile constructor.

Then, remove optionality from the representation and accessors. It is
now the case that every SourceFile has a buffer ID, simplying a bunch
of code.
2024-09-16 21:46:42 -07:00
Doug Gregor
b272a05ea9 Merge pull request #76363 from DmT021/wp/print-diagnostic-groups
[Diagnostics] Add -print-diagnostic-groups flag
2024-09-11 13:04:07 -07:00
Dmitrii Galimzianov
a8b71ea97f Add -print-diagnostic-groups flag
This change adds the `-print-diagnostic-groups` flag as described by SE-0443.
2024-09-11 13:34:42 +02:00
Alexis Laferrière
8d28ed4fa9 Merge pull request #76269 from xymus/public-module-name
Diagnostics: Intro the public module name concept to hide support modules from clients
2024-09-09 16:57:12 -07:00
Doug Gregor
08e339b7b4 Merge pull request #74466 from DmT021/wp/no-warning-as-error
[Diagnostics] Add -no-warning-as-error to except a specific warning from being treated as an error
2024-09-09 09:35:05 -07:00
Dmitrii Galimzianov
28883b6654 [Diagnostics] Add -[no-]warning-as-error flags for precise control over warning behavior
This commit adds new compiler options -no-warning-as-error/-warning-as-error which allows users to specify behavior for exact warnings and warning groups.
2024-09-07 01:14:43 +02:00
Alexis Laferrière
c60fea3aac Sema: Use clearer param name in getPublicModuleName
Use onlyIfImported instead of mustBeVisible.
2024-09-05 12:45:13 -07:00
Alexis Laferrière
bc9babbbea Diagnostics: Use public module name in diagnostics 2024-09-04 16:21:37 -07:00
Allan Shortlidge
4420ea853b Sema: Check availability of conformance type witnesses.
The type satisfying a protocol requirement must be at least as available as the
associated type for the requirement.

Resolves rdar://134093006
2024-08-22 15:23:21 -07:00
Slava Pestov
b601c294ac AST: Replace remaining uses of Type::transform() with transformRec() 2024-08-12 16:05:43 -04:00
Holly Borla
5fa35b5c3e [Concurrency] Compute the source of actor isolation in ActorIsolationRequest. 2024-08-04 18:48:57 -07:00
Steven Wu
30737eb396 [Caching] Support swift style diagnostics for swift caching
Add support for swift style diagnostics for swift caching. This includes
pre-populate the GeneratedSourceInfo with macro name so it doesn't need
to infer from an ASTNode, which the caching mechanism cannot preserve.

Still leave the default diagnostic style to LLVM style because replaying
swift style diagnostics is still very slow and including parsing source
file using swift-syntax.

rdar://128615572
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
Konrad `ktoso` Malawski
54229549b3 [Distributed] Offer fixit for import Distributed when it is required (#72948) 2024-04-12 18:05:32 -07:00
Kavon Farvardin
0ce97b8503 Diagnostics: noformat modifier for Type
Sometimes, quotes or an "aka" for a type are not desirable in a
diagnostic, such as one describing a Requirement. This modifier
suppresses such additional formatting a Type in a diagnostic.
2024-04-09 13:51:57 -07:00
Michael Gottesman
806cd7940e [region-isolation] Fix actor isolated parameters to get an actor isolated error instead of a task isolated error.
Now that we actually know the region that non transferrable things belong to, we
can use this information to give a better diagnostic here.

A really nice effect of this is that we now emit that actor isolated parameters
are actually actor isolated instead of task isolated.
2024-03-10 22:08:40 -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
Doug Gregor
81ffafdc6a Merge pull request #70602 from ApolloZhu/macro/expression-as-default-argument
[Macros] Expression macro as caller-side default argument
2024-02-14 16:10:11 -08:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05:00
Apollo Zhu
b09a22a9a0 Somewhat working
Test shadowed variable of same type

Fully type check caller side macro expansion

Skip macro default arg caller side expr at decl primary

Test macro expand more complex expressions

Set synthesized expression as implicit

Add test case for with argument, not compiling currently

Test with swiftinterface

Always use the string representation of the default argument

Now works across module boundary

Check works for multiple files

Make default argument expression work in single file

Use expected-error

Disallow expression macro as default argument

Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
2024-02-06 15:02:11 -08:00
Slava Pestov
d9c82b1b04 Sema: Clean up printing of generic signatures in missing witness diagnostics
Instead of stripping out requirements, let's pass the right PrintOptions.
2024-02-05 17:13:02 -05:00
Holly Borla
11cb94faa5 [Concurrency] Use .limitBehaviorUntilSwiftVersion for concurrency diagnostics
that are suppressed or downgraded until Swift 6.

There are a few benefits to using a `UntilSwiftVersion` diagnostic engine API,
including the diagnostic wrapping to communicate that the mistake will be an
error in Swift 6, and to include the mistake in the frontend statistic for
Swift 6 errors.
2024-01-31 17:08:01 -08:00
Holly Borla
50945efe6d [Diagnostics] Add InFlightDiagnostic::limitBehaviorUntilSwiftVersion to
downgrade or suppress errors until a specified language version.
2024-01-30 19:50:32 -08:00
Holly Borla
32038d9261 [Statistics] Add a frontend counter for Swift 6 errors diagnosed via
`warnUntilSwiftVersion(6)`.
2024-01-29 19:58:48 -08:00
Holly Borla
d60a06760b Merge pull request #71050 from hborla/global-actor-unsafe
[Concurrency] Deprecate `@GlobalActor(unsafe)` in favor of `@preconcurrency @GlobalActor`
2024-01-22 16:52:56 -08:00
Holly Borla
47afd21d85 [Concurrency] Remove ActorIsolation::GlobalActorUnsafe. 2024-01-21 21:05:33 -08:00
Hamish Knight
3f4b45b012 [AST] Remove SerializedLocalDeclContext
It's not clear that its worth keeping this as a
base class for SerializedAbstractClosure and
SerializedTopLevelCodeDecl, most clients are
interested in the concrete kinds, not only whether
the context is serialized.
2024-01-18 12:03:52 +00:00
Doug Gregor
89bda715ce Merge pull request #69840 from DougGregor/macro-role-metaprogramming
[Macros] Macro-metaprogram macro roles
2023-11-14 11:51:50 -08:00
Doug Gregor
b53026d8d4 [Macros] Macro-metaprogram macro roles
Introduce X-macros for the various macro roles, and use them to
macro-metaprogram a lot of boilerplate involved with introducing new
macro roles.
2023-11-13 22:37:54 -08:00
Kavon Farvardin
b55c4f1fc9 [nfc] allow ErrorTypeRepr to store a ZeroArgDiagnostic
There are sometimes parsing stuations where we don't want to
emit a parsing error, because of feature guarding. For
example, if a Feature involves new syntax for a type, we
must be able to parse both the true and false sides of an
ifdef guarding that new syntax based on a Feature flag.
2023-11-13 15:49:46 -08:00
Sophia Poirier
4c9a726183 nonisolated(unsafe) to opt out of strict concurrency static checking for global variables 2023-10-26 16:22:28 -07:00
Holly Borla
a6d078b820 [Concurrency] Use the 'nonisolated' terminology instead of 'independent'.
This commit is NFC; it's mostly renames.
2023-09-08 13:28:55 -07:00
Ben Barham
18cb5f4f3d [Diagnostics] Update in_macro_expansion note for attached macros
Use the attached atttribute's location as the location of the macro,
rather than the location of the declaration it's attached to. Also add
the kind and name of that declaration to the note itself.
2023-07-25 16:03:52 -07:00
Becca Royal-Gordon
325ab9118e [NFC] Adopt new features in availability diagnostics
Allows the removal of a helper function.
2023-07-19 13:08:12 -07:00
Becca Royal-Gordon
2ab1e05c68 [NFC] Add new DiagnosticEngine Decl features
Implements several enhancements to DiagnosticEngine’s handling of Decl arguments:

• All Decl classes, not just ValueDecls, are now valid to use as arguments.
• There is built-in logic to handle accessors by printing a phrase like `getter for 'foo'`, so this no longer has to be special-cased for each diagnostic.
• `%kind` can be used to insert the descriptive kind before a name; `%kindonly` inserts only the descriptive kind. This can eliminate kind/name argument pairs.
• `%base` can insert only the base name, leaving out any argument labels; `%kindbase` combines `%kind` and `%base`.

This PR is marked NFC because there are no intentional uses of these changes yet.
2023-07-19 13:06:51 -07:00
Holly Borla
725374e0d8 [Macros] Implement attached extension macros. 2023-06-27 21:22:12 -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
Allan Shortlidge
a971a0c980 AST: Add convenience for limiting diags to warnings in swiftinterfaces.
Sometimes it's useful to be more lenient when type checking swiftinterfaces
since restrictions that could be dropped in the future will manifest in
resilient libraries being incompatible with older compilers otherwise.
2023-06-15 11:17:34 -07:00
Hamish Knight
5dd258f99f [Diags] Avoid emitting fix-its for generated code
Drop fix-its produced in generated buffers, such
as for macro expansions, as these aren't directly
actionable by the user.

rdar://108231633
2023-05-23 11:37:40 +01:00
Hamish Knight
100244a0c3 Avoid computing generated source notes on child notes
This could cause us to double up on the same note
for nested macro expansions, as we'd generate the
note, then when recursing back through the function
we'd compute the same note again. Also remove the
seemingly unused `lastBufferID` param.
2023-05-02 16:21:44 +01:00
Rajveer
c34f099c7d Improved out-of-place binding diagnostic and reflecting 'var' or 'let' binding pattern
Fixes Issue #63993
2023-03-19 19:26:58 +05:30
Allan Shortlidge
fb03b4aa04 Sema: Relax availability checking for @MainActor.
The `@MainActor` global actor constraint on a declaration does not carry an
inherent ABI impact and therefore use of this constraint should not be limited
to OS versions where Swift concurrency is available.

Resolves rdar://105610970
2023-03-16 14:23:36 -07:00
Ellie Shin
7d23db3646 Create PackageUnit class, and Package entries to DeclContext / ASTHierarchy
Previously enum AccessLimitKind was
added to distinguish access scopes b/t package and public while keeping
DeclContext null but it proved to be too limiting. This PR creates package specific entries for DeclContext and
ASTHierarchy. It create a new class PackageUnit that can be set as the parent DeclContext of ModuleDecl. This PR
contains addition of such entries but not the use of them; the actual use of them will be in the upcoming PRs.

Resolves rdar://106155600
2023-03-02 13:20:51 -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
Holly Borla
a3caacd309 [Macros] Initial implementation of conformance macros. 2023-02-23 20:43:11 -08:00
Doug Gregor
7ea0e3f096 Switch GeneratedSourceInfo ranges over to CharSourceRange.
Macro expansion buffers, along with other generated source buffers,
need more precise "original source ranges" that can be had with the
token-based `SourceRange`. Switch over to `CharSourceRange` and provide
more thoughtfully-determined original source ranges.
2023-02-11 11:23:26 -08:00
Holly Borla
f04f512184 [Macros] Add a new macro role for attached peer macros. 2023-02-10 14:38:22 -08:00
Richard Wei
81943b2b11 [Macros] Clean up MacroExpansionDecl (#63486)
- Remove the `Rewritten` field and `setRewritten()`. Make `getRewritten()` invoke the request.
- Rename fields `Macro` and `MacroLoc` to `MacroName` and `MacroNameLoc` respectively as well as their getters to match those in `MacroExpansionExpr`.
2023-02-07 14:57:02 +08:00
Holly Borla
f6f57a8099 [Macros] Rename "synthesized member macros" to "member macros". 2023-01-26 21:52:36 -08:00
Holly Borla
8b9be30783 [Macros] Add a new macro role for synthesized member macros. 2023-01-22 21:19:21 -08:00