Commit Graph

6605 Commits

Author SHA1 Message Date
Augusto Noronha
e2c8b761cd [NFC][RemoteInspection] Add an opaque AddressSpace field to RemoteAddress
Add an extra opaque field to AddressSpace, which can be used by clients
of RemoteInspection to distinguish between different address spaces.

LLDB employs an optimization where it reads memory from files instead of
the running process whenever it can to speed up memory reads (these can
be slow when debugging something over a network). To do this, it needs
to keep track whether an address originated from a process or a file. It
currently distinguishes addresses by setting an unused high bit on the
address, but because of pointer authentication this is not a reliable
solution. In order to keep this optimization working, this patch adds an
extra opaque AddressSpace field to RemoteAddress, which LLDB can use on
its own implementation of MemoryReader to distinguish between addresses.

This patch is NFC for the other RemoteInspection clients, as it adds
extra information to RemoteAddress, which is entirely optional and if
unused should not change the behavior of the library.

Although this patch is quite big the changes are largely mechanical,
replacing threading StoredPointer with RemoteAddress.

rdar://148361743
(cherry picked from commit 58df5534d2)
(cherry picked from commit 8f3862b5e7)
2025-07-11 16:36:40 -07:00
Hamish Knight
0c8468e0ee [SourceKit] Print backticks if needed in printDisplayName
Ensure we print raw identifier names with backticks for e.g the
document structure request.

rdar://152524780
2025-06-25 19:52:09 +01:00
John Hui
a2bd6cafd9 Merge pull request #82171 from j-hui/j-hui/6.2/jump-to-def-for-macro-expanded-clang-imports
🍒 [6.2] [SourceKit] Support location info for macro-expanded Clang imports
2025-06-13 04:10:37 -07:00
John Hui
c94955b571 [SourceKit] Support location info for macro-expanded Clang imports
Currently, when we jump-to-definition for decls that are macro-expanded
from Clang imported decls (e.g., safe overloads generated by
@_SwiftifyImport), setLocationInfo() emits a bongus location pointing to
a generated buffer, leading the IDE to try to jump to a file that does
not exist.

The root cause here is that setLocationInfo() calls getOriginalRange()
(earlier, getOriginalLocation()), which was not written to account for
such cases where a macro is generated from another generated buffer
whose kind is 'AttributeFromClang'.

This patch fixes setLocationInfo() with some refactoring:

-   getOriginalRange() is inlined into setLocationInfo(), so that the
    generated buffer-handling logic is localized to that function. This
    includes how it handles buffers generated for ReplacedFunctionBody.

-   getOriginalLocation() is used in a couple of other places that only
    care about macros expanded from the same buffer (so other generated
    buffers not not relevant). This "macro-chasing" logic is simplified
    and moved from ModuleDecl::getOriginalRange() to a free-standing
    function, getMacroUnexpandedRange() (there is no reason for it to be
    a method of ModuleDecl).

-   GeneratedSourceInfo now carries an extra ClangNode field, which is
    populated by getClangSwiftAttrSourceFile() when constructing
    a generated buffer for an 'AttributeFromClang'. This could probably
    be union'ed with one or more of the other fields in the future.

rdar://151020332
(cherry picked from commit 44aba1382d)
2025-06-12 18:24:04 -07:00
Pavel Yaskevich
38ce1c230e [CodeCompletion] Implement completions in using declaration's specifier position
(cherry picked from commit 816ea9fda6)
2025-06-04 13:16:55 -07:00
Hamish Knight
1d56f2e789 [SourceKit] Properly handle cursor info range for macro expansions
Make `getOriginalLocation` work with source ranges, and adjust the
cursor info logic to map the range into the original buffer. This
fixes the case where we were using bogus range lengths for macro
expansion decls.

rdar://151411756
2025-05-29 20:49:44 +01:00
Hamish Knight
26517a1239 [SourceKit] Handle CustomAttrs arguments for placeholder expansion
Introduce a new ASTWalker option for walking CustomAttrs and use it
for the placeholder scanner to ensure we can expand placeholders in
attribute arguments.
2025-05-22 20:17:17 +01:00
Hamish Knight
5823154444 [SourceKit] Handle macro arguments in placeholder expansion
Allow macro argument placeholders to expand into trailing closures.

rdar://150550747
2025-05-22 20:17:17 +01:00
Alex Hoppen
b3d9155b7d Merge pull request #81605 from ahoppen/6.2/allow-disabling-implicit-cancellation
[6.2][SourceKit] Allow passing `cancel_on_subsequent_request: 0` for all requests that use a OncePerASTToken
2025-05-22 07:36:51 +02:00
Ben Barham
03ca9ea0a5 [SourceKit] Remove diagnostics path calculation
The diagnostic group documentation now point to the swift.org URL rather
than the toolchain path, so it no longer needs to be passed all the way
through sourcekitd.

Resolves rdar://151500502.

(cherry picked from commit 381684a389)
2025-05-19 14:48:46 -07:00
Alex Hoppen
5bd9e439ee [SourceKit] Allow passing cancel_on_subsequent_request: 0 for all requests that use a OncePerASTToken
We need this option for `collectVariableType` (aka inlay type hints) but since I’m at it, I’m adding an option to disable the implicit request cancellation for all requests that have it since we don’t want it in LSP at all.

Prerequisite to fixing https://github.com/swiftlang/sourcekit-lsp/issues/2021 / rdar://145871554, need to adopt this option in SourceKit-LSP.
2025-05-19 13:45:50 +02:00
Michael Gottesman
e92e9dff0c Make Feature a struct enum so we can put methods on it.
Just noticed this as I was looking at making other changes.

(cherry picked from commit 3ff9463957)
2025-05-14 16:07:04 -07:00
Ben Barham
d829fcf2eb Merge exported modules with the same public name in generated interface
If a module has the same `public-module-name` as the module being
generated and its import is exported, merge it into the same generated
interface.

Fix various always-imported modules from being printed while here and
update all the tests that checked for them.

Resolves rdar://137887712.

(cherry picked from commit ddddc667c8)
2025-05-02 12:52:44 -07:00
Allan Shortlidge
8f2d5a759e Merge pull request #80321 from tshortli/warnings 2025-03-30 16:14:21 -07: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
Allan Shortlidge
8c54a354e3 SourceKit: Fix an unused variable warning in XPCService.cpp. 2025-03-28 12:33:40 -07:00
Dave Lee
115b2b7bcb [swift-inspect] Use decimal format for Task ID (#80309)
Use decimal to display Task IDs. This matches changes being done else where to use decimal consistently for Task IDs. For example https://github.com/swiftlang/swift/pull/80154 and https://github.com/swiftlang/llvm-project/pull/10308.
2025-03-27 12:39:19 -07:00
Becca Royal-Gordon
775bdacefc [NFC] Extract Decl::getExplicitObjCName()
Create a helper method which looks for an `@objc` attribute with an explicit name and returns it, and adopt it in various existing places.
2025-03-26 10:47:12 -07:00
Anthony Latsis
631a04e56c Merge pull request #80159 from AnthonyLatsis/danaus-plexippus-5
Sema: Extend adoption mode for `AsyncCallerExecution` to storage declarations
2025-03-26 04:40:58 +00:00
Dylan Sturgeon
2c8e337f25 Merge pull request #80074 from dylansturg/objc_enum_refs
The Error enum synthesized declarations, e.g. the struct and its static accessors, should generally appear to be identical to the underlying Clang definitions. There are some specific use cases where the synthesized declarations are necessary though.

I've added an option for USR generation to override the Clang node and emit the USR of the synthesized Swift declaration. This is used by SwiftDocSupport so that the USRs of the synthesized declarations are emitted.

Fixes 79912
2025-03-25 11:21:21 +00:00
Anthony Latsis
6512aa1f5a AST: Introduce and use ValueDecl::isAsync 2025-03-25 02:07:03 +00:00
Anthony Latsis
3d3b1ca50a [NFC] AST: Turn getParameterList into a method on ValueDecl 2025-03-19 18:49:15 +00:00
Hamish Knight
b60fe39dc2 [SourceKit] Change bundle ID from com.apple to org.swift
rdar://146840864
2025-03-12 10:29:28 +00:00
Evan Wilde
eeee0dfddd CMake: option to disable swift in swift
Adding `SWIFT_ENABLE_SWIFT_IN_SWIFT` option to enable or disable the
parts of Swift that require a Swift compiler to build. This is meant for
bootstrapping compilers on new platforms and is not guaranteed to result
in a compiler that will pass the test suite.

This option is on by default so that folks won't forget.
If the option is off, the resulting compiler does not include the Swift
optimizer sources in SwiftCompilerSources nor does the resulting
compiler have swift macro support.
2025-03-06 13:32:49 -08:00
Ben Barham
ce8458ee67 Merge pull request #79530 from bnbarham/load-service-from-file
[SourceKit] Do not hardcode the XPC service name
2025-03-04 09:33:36 -08:00
Konrad `ktoso` Malawski
92ead521b8 [Concurrency] Fix swift-inspect and remote mirror build (#79715) 2025-03-04 07:04:42 +09:00
Ben Barham
652da5555f [SourceKit] Do not hardcode the XPC service name
Write the service name into a resource file rather than have it
hardcoded, allowing it to be updated post-build if necessary.
2025-02-28 21:19:45 -08:00
Doug Gregor
aafd24bfed Prefer diagnostic group names for diagnostic categories over the ad hoc ones 2025-02-27 19:40:23 -08:00
Konrad `ktoso` Malawski
f55964df26 [Concurrency] Initial steps for startSynchronously for Task (#79608)
* [Concurrency] Initial steps for startSynchronously for Task

* [Concurrency] Rename to _startSynchronously while in development

* [Concurrency] StartSynchronously special executor to avoid switching

* startSynchronously bring back more info output

* [Concurrency] startSynchronously with more custom executor tests

* add missing ABI additions to test for x86

* [Concurrency] gyb generate _startSynchronously

* [Concurrency] %import dispatch for Linux startSynchronously test

* [Concurrency] Add TaskGroup.startTaskSynchronously funcs

* [Concurrency] DispatchSerialQueue does not exist on linux still
2025-02-27 02:34:33 -08:00
Mike Ash
b3a430d175 [swift-inspect] On Darwin, don't try to inspect processes that don't have Swift.
When we locate libswiftCore.dylib in the remote process, check for failure and give up immediately if we don't find one. If the process doesn't have Swift, there's no point in trying to inspect anything in it.

rdar://143978694
2025-02-24 14:37:43 -05:00
Steven Wu
c42268e7f1 Merge pull request #79301 from cachemeifyoucan/eng/PR-144623388
[BridgingHeader] Fix auto-chaining when only dependency has bridging header
2025-02-13 11:35:39 -08:00
Steven Wu
719edaf7e2 [BridgingHeader] Fix auto-chaining when only dependency has bridging header
When enable bridging header auto chaining, it is possible for the
compilation to have a PCH file input for the bridging header from a
binary swift module dependency. In this case, we should not report a
bridging header for current module as bridging header can be leaking out
through swiftinterface file.

To fully distinguish the PCH files passed in through different
situation, here are the situations:
* If no chaining is used, only `-import-objc-header` option is used and
  it can be used to pass either a header file or a PCH file depending if
  GeneratePCH job is requested or not.
* If chaining is enabled, `-import-objc-header` is only used to pass the
  header file and `-import-pch` is used to pass PCH file. Chaining mode
  requires PCH generation if bridging header is used.

rdar://144623388
2025-02-12 07:30:14 -08:00
Hamish Knight
d260bd8ddb [build-script] Remove Xcode generation support
This was quite brittle and has now been superseded
by swift-xcodegen. Remove the CMake/build-script
logic for it, leaving the option behind to inform
users to switch to using xcodegen instead.
2025-02-12 12:19:21 +00:00
Slava Pestov
17d8c820dc Merge pull request #79220 from slavapestov/fix-rdar143950572
AST: Source range of FuncDecl/ConstructorDecl should include the thrown type
2025-02-10 13:49:37 -05: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
Steven Wu
9d59044bb1 [BrdigingHeader] Auto bridging header chaining
Add ability to automatically chaining the bridging headers discovered from all
dependencies module when doing swift caching build. This will eliminate all
implicit bridging header imports from the build and make the bridging header
importing behavior much more reliable, while keep the compatibility at maximum.

For example, if the current module A depends on module B and C, and both B and
C are binary modules that uses bridging header, when building module A,
dependency scanner will construct a new header that chains three bridging
headers together with the option to build a PCH from it. This will make all
importing errors more obvious while improving the performance.
2025-02-05 09:41:04 -08:00
eeckstein
71015c674b Merge pull request #78980 from eeckstein/fix-swift-demangle
swift-demangle: don't require the $-prefix for embedded symbols
2025-01-29 07:18:27 +01:00
Saleem Abdulrasool
18fa490721 Merge pull request #78827 from andrurogerz/swift-inspect-cmake
[swift-inspect] use CMake FetchContent to fetch ArgumentParser when not provided
2025-01-28 14:40:34 -08:00
Erik Eckstein
1f36fa5c0b swift-demangle: don't require the $-prefix for embedded symbols
Support demangling `swift-demangle e4main8MyStructV3fooyyFAA1XV_Tg5` (note the missing $-prefix)
2025-01-28 17:35:53 +01:00
Alastair Houghton
ab8e561583 Merge pull request #78516 from al45tair/eng/PR-124913332
[Backtracing] Implement API per SE-0419
2025-01-28 10:48:33 +00:00
Alex Hoppen
d5a6ff2d3a Merge pull request #78686 from ahoppen/explicit-enum-type
[SourceKit] Explicitly specify the type of enums in CodeCompletinSwiftInterop.h
2025-01-24 22:28:07 -08:00
Saleem Abdulrasool
bfd09996ad Merge pull request #78821 from compnerd/tradewars
SourceKit: correct the macro definitions to avoid warnings on Windows
2025-01-23 15:29:35 -08:00
Andrew Rogers
92dea69b7e [swift-inspect] build swift-argument-parser as shared lib when fetched remotely 2025-01-22 15:53:07 -08:00
Andrew Rogers
7b1c4dc461 [swift-inspect] clarify CMake use block() to scope ArgumentParser properties 2025-01-22 15:20:23 -08:00
Saleem Abdulrasool
c9019d6a9c swift-inspect: mark some conformances as retroactive
This silences a couple of warnings in the swift-inspect build.
2025-01-22 15:17:12 -08:00
Andrew Rogers
b0bae6355b [swift-inspect] clarify CMake properties set for ArgumentParser 2025-01-22 14:52:07 -08:00
Andrew Rogers
ba9be84a8a [swift-inspect] update CMake documentation 2025-01-22 14:50:40 -08:00
Andrew Rogers
9792a07b66 [swift-inspect] bump swift-argument-parser version to 1.5.0 2025-01-22 14:30:23 -08:00
Andrew Rogers
509a07767b [swift-inspect] use FetchContent to fetch ArgumentParser in CMake build 2025-01-22 14:29:50 -08:00
Saleem Abdulrasool
1d2eb3bc2c SourceKit: correct the macro definitions to avoid warnings on Windows
This silences a large number of warnings due to
`-Winconsistent-dllimport`. While it is possible to support the library
to be built statically, that is not currently supported by the build
system, so simply leave that unsupported for decoration.

An option here for ELF targets would be to use
`__attribute__((__visibility__("default")))` and enable hidden
visibility by default enabling a small bit of optimization.
2025-01-22 14:00:46 -08:00