Commit Graph

1541 Commits

Author SHA1 Message Date
Doug Gregor
aafd24bfed Prefer diagnostic group names for diagnostic categories over the ad hoc ones 2025-02-27 19:40:23 -08:00
Slava Pestov
a6a96da558 AST: Source range of FuncDecl/ConstructorDecl should include the thrown type
When a function declaration has a body, its source range ends at the
closing curly brace, so it includes the `throws(E)`. However, a
protocol requirement doesn't have a body, and due to an oversight,
getSourceRange() was never updated to include the extra tokens
that appear after `throws` when the function declares a thrown
error type. As a result, unqualified lookup would fail to find a
generic parameter type, if that happened to be the thrown type.

Fixes rdar://problem/143950572.
2025-02-10 09:17:40 -05:00
Alex Hoppen
e2235e201c Merge pull request #78421 from ahoppen/add-sourcekit-plugin
[SourceKit] Add mechanism to load plugins for request handling into SourceKit
2025-01-15 12:42:10 -08:00
Doug Gregor
8bb5bbedbc Implement an unsafe expression to cover uses of unsafe constructs
Introduce an `unsafe` expression akin to `try` and `await` that notes
that there are unsafe constructs in the expression to the right-hand
side. Extend the effects checker to also check for unsafety along with
throwing and async operations. This will result in diagnostics like
the following:

    10 |   func sum() -> Int {
    11 |     withUnsafeBufferPointer { buffer in
    12 |       let value = buffer[0]
       |                   |     `- note: reference to unsafe subscript 'subscript(_:)'
       |                   |- warning: expression uses unsafe constructs but is not marked with 'unsafe'
       |                   `- note: reference to parameter 'buffer' involves unsafe type 'UnsafeBufferPointer<Int>'
    13 |       tryWithP(X())
    14 |       return fastAdd(buffer.baseAddress, buffer.count)

These will come with a Fix-It that inserts `unsafe` into the proper
place. There's also a warning that appears when `unsafe` doesn't cover
any unsafe code, making it easier to clean up extraneous `unsafe`.

This approach requires that `@unsafe` be present on any declaration
that involves unsafe constructs within its signature. Outside of the
signature, the `unsafe` expression is used to identify unsafe code.
2025-01-10 10:39:14 -08:00
Allan Shortlidge
77141c5bc5 SourceKit: Adopt SemanticAvailableAttr in SwiftDocSupport.cpp. 2025-01-07 07:31:29 -08:00
Alex Hoppen
b6c94aecc3 [SourceKit] Add mechanism to load plugins for request handling into SourceKit
This allows us to load plugins into the sourcekitd service to handle requests (currently only used for code completion). This allows us to implement parts of sourcekitd in Swift and outside of the compiler repository, making it easier to iterated on them because the compiler doesn’t need to be rebuilt.
2025-01-03 15:24:52 +01:00
Ian Anderson
cdb42c3535 [ClangImporter] clang's -iframework comes before builtin usr/local/include, but Swift's -Fsystem comes after
When Swift passes search paths to clang, it does so directly into the HeaderSearch. That means that those paths get ordered inconsistently compared to the equivalent clang flag, and causes inconsistencies when building clang modules with clang and with Swift. Instead of touching the HeaderSearch directly, pass Swift search paths as driver flags, just do them after the -Xcc ones.

Swift doesn't have a way to pass a search path to clang as -isystem, only as -I which usually isn't the right flag. Add an -Isystem Swift flag so that those paths can be passed to clang as -isystem.

rdar://93951328
2024-12-23 22:15:52 -08:00
Ben Barham
8111fe9343 Merge pull request #78262 from bnbarham/skip-non-wmo-diag
[Embedded] Do not produce `cannot_specialize_class` for live issues
2024-12-20 10:40:07 -08:00
Becca Royal-Gordon
08e2a4ddae Type check ABI decls
Sema now type-checks the alternate ABI-providing decls inside of @abi attributes.

Making this work—particularly, making redeclaration checking work—required making name lookup aware of ABI decls. Name lookup now evaluates both API-providing and ABI-providing declarations. In most cases, it will filter ABI-only decls out unless a specific flag is passed, in which case it will filter API-only decls out instead. Calls that simply retrieve a list of declarations, like `IterableDeclContext::getMembers()` and friends, typically only return API-providing decls; you have to access the ABI-providing ones through those.

As part of that work, I have also added some basic compiler interfaces for working with the API-providing and ABI-providing variants. `ABIRole` encodes whether a declaration provides only API, only ABI, or both, and `ABIRoleInfo` combines that with a pointer to the counterpart providing the other role (for a declaration that provides both, that’ll just be a pointer to `this`).

Decl checking of behavior specific to @abi will come in a future commit.

Note that this probably doesn’t properly exercise some of the new code (ASTScope::lookupEnclosingABIAttributeScope(), for instance); I expect that to happen only once we can rename types using an @abi attribute, since that will create distinguishable behavior differences when resolving TypeReprs in other @abi attributes.
2024-12-19 15:49:34 -08:00
Ben Barham
a2fda1d9f3 [Embedded] Do not produce cannot_specialize_class for live issues
SourceKit explicitly disables WMO, silence the diagnostic in this case
(but leave it enabled for explicit non-WMO builds otherwise).
2024-12-19 15:31:41 -08:00
Kuba (Brecka) Mracek
8792efedf0 Merge pull request #77115 from kubamracek/embedded-mangling-prefix
[Mangling] [NFC] Prepare for a new mangling prefix for Embedded Swift: $e
2024-12-03 08:10:49 -08:00
Kuba Mracek
9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00
Allan Shortlidge
c5398e17d3 AST: Introduce Decl::getDeprecatedAttr().
It replaces `DeclAttr::getDeprecated()` as the designated way to query for the
attribute that makes a decl deprecated.
2024-12-02 07:35:58 -08:00
Allan Shortlidge
2358712870 AST/Sema: Remove DeclAttr::isUnavailable().
Update callers to use `Decl::isUnavailable()` instead.
2024-12-02 07:35:58 -08:00
Allan Shortlidge
1dc7aa5b7b AST: Introduce Decl::isUnavailable().
Replace calls to `AvailableAttr::isUnavailable()` with `Decl::isUnavailable()`.
2024-12-02 07:35:58 -08:00
Allan Shortlidge
ad7383499b Merge pull request #77758 from tshortli/available-attr-conveniences
AST: `AvailableAttr` cleanup
2024-11-21 13:03:07 -08:00
Allan Shortlidge
36230cd9c6 AST: Use an accessor to get the PlatformKind from an AvailableAttr. 2024-11-21 09:10:36 -08:00
Hamish Knight
4946c799af [AST] Remove ModuleDecl::addFile
Rather than exposing an `addFile` member on
ModuleDecl, have the `create` members take a
lambda that populates the files for the module.
Once module construction has finished, the files
are immutable.
2024-11-17 14:17:20 +00:00
Hamish Knight
309c02410b [IDE] Avoid relying on after-the-fact use of addFile
We shouldn't be attempting to append SourceFiles
to the module after-the-fact for syntactic macro
expansion, refactor things such that the SourceFile
is created alongside the ModuleDecl.
2024-11-17 14:17:20 +00:00
Doug Gregor
24a12ebc34 Renable GeneratedSourceInfo::Attribute to GeneratedSourceInfo::AttributeFromClang 2024-11-15 09:02:49 -08:00
Doug Gregor
989c73d014 Ensure that buffers containing Clang swift_attr attributes are parsed as attributes
Previously, they were being parsed as top-level code, which would cause
errors because there are no definitions. Introduce a new
GeneratedSourceInfo kind to mark the purpose of these buffers so the
parser can handle them appropriately.
2024-11-13 21:19:37 -08:00
Hamish Knight
499fe6dc48 Merge pull request #77072 from hamishknight/complete-options
[IDE] Pass LangOptions to `ide::isSourceInputComplete`
2024-10-30 20:17:47 +00:00
swift-ci
e4ff9e578e Merge remote-tracking branch 'origin/main' into rebranch 2024-10-21 11:26:28 -07:00
Ben Barham
6b3cc32328 [CursorInfo] Take a copy of USR when resolving cursor info
Resolving cursor info is async and can occur after the request has been
deleted, make sure to take a copy of the `USR` (which is part of that
request).

Resolves rdar://137320169.
2024-10-18 16:44:05 -07:00
Hamish Knight
81dc7d87ed [Parse] Remove TypeChecker and SIL options parameter from ParserUnit
Providing these is a bit of a layering violation,
the parser shouldn't care about these options (there
does seem to be one current use of `TypeCheckerOpts`
in the parser for designated operator types, but
that's a legacy feature that was never officially
supported).
2024-10-17 14:04:34 +01:00
swift-ci
e5f97d79c5 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-30 07:15:01 -07:00
nate-chandler
ba8f8ea282 Merge pull request #76526 from nate-chandler/general-coro/20240906/1
[CoroutineAccessors] Initial framing.
2024-09-30 07:04:04 -07:00
swift-ci
f00e29868e Merge remote-tracking branch 'origin/main' into rebranch 2024-09-28 08:15:47 -07:00
Allan Shortlidge
07b84fccfb AST: Introduce ModuleDecl::isClangHeaderImportModule() convenience. 2024-09-27 12:00:03 -07:00
Nate Chandler
091368ba21 [CoroutineAccessors] Added read.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Nate Chandler
98a2e6a7df [CoroutineAccessors] Added modify.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
swift-ci
56bd686ccf Merge remote-tracking branch 'origin/main' into rebranch 2024-09-19 18:58:28 -07:00
Slava Pestov
4bb8f46d6d Merge pull request #76536 from slavapestov/small-subst-cleanups
Tiny optimization and cleanups
2024-09-19 21:36:51 -04:00
swift-ci
ae4fee5d4e Merge remote-tracking branch 'origin/main' into rebranch 2024-09-19 13:54:31 -07:00
Slava Pestov
abbc37e41d IDE: Replace a couple of getTypeOfMember() calls 2024-09-19 12:54:27 -04:00
Doug Gregor
5b2520e379 Remove IfConfigDecl from the AST
The swift-syntax tree retains information about the parsed #if
regions. Drop it from the semantic AST.
2024-09-18 20:51:54 -07:00
swift-ci
5039a2d86c Merge remote-tracking branch 'origin/main' into rebranch 2024-09-18 10:55:29 -07:00
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
Ben Barham
a7b50f357f Merge remote-tracking branch 'origin/main' into manual-main-merge
Conflicts:
  - `lib/Driver/ToolChains.cpp` conflicting with the `addAllArgs` rename
    for multiple options
2024-09-16 13:53:18 -07:00
Doug Gregor
8b91a922cb Only consider the active clauses of IfConfigDecls in placeholder expansion
This is another step toward the removal of IfConfigDecl
2024-09-07 23:31:13 -07:00
swift-ci
763c61f92f Merge remote-tracking branch 'origin/main' into rebranch 2024-08-30 18:13:35 -07:00
Jim M. R. Teichgräber
f2e57d8c76 [SourceKit] Add optional declarations array to interface gen request (#75802)
Introduces the new DeclarationsArrayBuilder and adds it to the
EditorConsumer. Declaration info always includes a kind, offset, and
length, and includes a USR where applicable.
As the USR is already available for editor.open.interface type requests,
this doesn't compute any new information, it just exposes more of what's
there already.
2024-08-30 18:04:12 -07:00
swift-ci
f624072420 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-29 03:33:30 -07:00
Hamish Knight
1cb0f8fdd5 [AST] Rename isPrivateStdlibDecl -> isPrivateSystemDecl
This better reflects what we're actually checking
here.
2024-08-28 18:31:51 +01:00
swift-ci
88e671860c Merge remote-tracking branch 'origin/main' into rebranch 2024-08-12 23:33:59 -07:00
Kuba (Brecka) Mracek
2941f24da3 Merge pull request #75308 from kubamracek/embedded-indexing-non-wmo
[embedded] Don't produce PerfDiags when in non-WMO mode (e.g. when building during indexing)
2024-08-12 23:29:30 -07:00
swift-ci
30a2b71979 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-12 16:14:01 -07:00
Alex Hoppen
01f3be2c6b Merge pull request #75842 from ahoppen/ast-consumer-failed-pure-virtual
[SourceKit] Make `SwiftASTConsumer::failed` pure virtual
2024-08-12 16:13:19 -07:00
Alex Hoppen
84c0d13b30 [SourceKit] Make SwiftASTConsumer::failed pure virtual
Previously, if a semantic tokens request or diagnostic request failed, we wouldn’t return any response.
2024-08-12 12:46:11 -07:00
Kuba Mracek
a2644683d7 [SourceKit] Add missing failed() override in computeDiagnostics, fix missing propagation of errors 2024-08-12 12:44:35 -07:00