Commit Graph

6605 Commits

Author SHA1 Message Date
Simon Barinka
06af7494e9 [SourceKit] Report type decl info instead of hidden inits 2023-08-02 23:40:08 +02:00
Simon Barinka
d0cf2e4bf3 [SourceKit] Fix formatting issues 2023-08-01 13:26:14 +02:00
Simon Barinka
e32a20a55c [SourceKit] Report init info instead of the type decl info
Addresses PR review comments.
2023-08-01 12:51:39 +02:00
Simon Barinka
fcd084f9dd [SourceKit] Report cursor info information for literals
Adds literals support for the CursorInfo request.
Previously CursorInfo just returned error for literals.
Implements issue #57725
2023-07-30 14:22:08 +02:00
Ben Barham
5d9ce6fcb2 [SourceKit] Compilation fixes for SourceKit on rebranch 2023-07-28 09:03:28 -07:00
Ben Barham
5334e719e3 [SwiftScan] Update getOptionName usage
`getOptionName()` now returns a `StringRef`, so we can use `empty()`
instead of a `strlen` check.
2023-07-28 09:03:28 -07:00
Ben Barham
e0ad141add [Tools] Add missing header to MockPlugin 2023-07-28 09:03:28 -07:00
Evan Wilde
669285fd17 Merge pull request #65534 from stephank/fix/cmake-3.25
build: fix accidental cmake expansions
2023-07-24 09:44:14 -07:00
Saleem Abdulrasool
72337efc3b build: adjust application of flags for LLVM issue (#67455)
The flags were meant to be applied to the C++ code not the Swift code.
Adjust the configuration to apply the flags properly.
2023-07-21 13:23:27 -07:00
Hiroshi Yamauchi
627175fe4c Fix a build issue with swift-inspect
Update the version of swift-argument-parser used by swift-inspect to
be compatible with the package description version.

Add compiler flags for a LLVM bug workaround.
2023-07-21 04:36:15 -07:00
Saleem Abdulrasool
bc9e90d318 swift-inspect: ensure that we eject any injected code
We would previously fail to eject the injected code on a failure.  This
would prevent a future introspection into the process as well as leave
the file open with an incremented retain count in the kernel space which
would prevent the file from being deleted.

In the future, when the application is able to treat the injected code
as a resource, this resource would be temporarily extracted, but would
no longer be possible to delete until a reboot (with a registration of
the deletion) due to the retained code.

Take the opportunity to rename some functions to take advantage of
labelled parameters and trailing function syntax.  This makes the code a
small amount easier to read.
2023-07-19 07:51:12 -07:00
Saleem Abdulrasool
255beb3d0e Merge pull request #67334 from compnerd/66973
swift-inspect: clean up incorrect casts introduced in #66973
2023-07-18 07:15:58 -07:00
Saleem Abdulrasool
c6fbff4c94 Merge pull request #67336 from compnerd/lambda-calculus
swift-inspect: correct some escaping binding for RemoteMirror
2023-07-18 07:15:35 -07:00
Stéphan Kochen
7b460ce495 build: fix accidental cmake expansions
As of CMake 3.25, there are now global variables `LINUX=1`, `ANDROID=1`,
etc. These conflict with expressions that used these names as unquoted
strings in positions where CMake accepts 'variable|string', for example:

- `if(sdk STREQUAL LINUX)` would fail, because `LINUX` is now defined and
  expands to 1, where it would previously coerce to a string.

- `if(${sdk} STREQUAL "LINUX")` would fail if `sdk=LINUX`, because the
  left-hand side expands twice.

In this patch, I looked for a number of patterns to fix up, sometimes a
little defensively:

- Quoted right-hand side of `STREQUAL` where I was confident it was
  intended to be a string literal.

- Removed manual variable expansion on left-hand side of `STREQUAL`,
  `MATCHES` and `IN_LIST` where I was confident it was unintended.

Fixes #65028.
2023-07-17 21:50:50 +02:00
Saleem Abdulrasool
1b538f55ef swift-inspect: correct some escaping binding for RemoteMirror
Adjust the pointer handling for the callback and adjust the code to
ensure that we properly form memory references to the function for the
callback.
2023-07-17 10:58:18 -07:00
Saleem Abdulrasool
8794df84e9 swift-inspect: correct invalid memory usage introduced in #66973
Clean up the incorrect memory binding in swift-inspect introduced in
PR#66973.  This fixes the incorrect memory usage to mutate the `context`
parameter.
2023-07-17 10:16:26 -07:00
Saleem Abdulrasool
9fb9561f67 swift-inspect: clean up incorrect casts introduced in #66973
Clean up some casts that would cause warnings on Windows introduced in
PR #66973.  Rewrite some of the path computation for the DLL path to
avoid some unnecessary conversions.  Split out some of the merged guards
to allow for split diagnostic emissions.
2023-07-17 09:51:38 -07:00
Saleem Abdulrasool
aad2b6e3e0 Merge pull request #66973 from hjyamauchi/dump-arrays
Improve the dump-arrays performance on Windows
2023-07-15 17:09:11 -07:00
Steven Wu
e66d8b6efb [SwiftScan] Fix a typo in SwiftScan C header
Fix a typo in SwiftScan C Header.
2023-07-14 16:27:24 -07:00
Hiroshi Yamauchi
af890f3cbf Improve the dump-arrays performance on Windows
Use the HeapWalk API for heap iteration instead of the
Heap32First/Next API, which was known to be slow. Since HeapWalk only
works locally, it requires using a remote thread and a DLL.
2023-07-14 16:13:10 -07:00
swift-ci
bfc8407112 Merge pull request #67278 from mikeash/swift-demangle-warn-empty-input
[swift-demangle] Warn when passed an empty argument.
2023-07-13 12:41:48 -07:00
Mike Ash
d797473ea2 [swift-demangle] Warn when passed an empty argument.
We already have a warning when a single _ is passed, which catches the case where someone passes _$someMangledName and the shell expands it as a variable. But sometimes people do this without the leading underscore. Detect and warn about that case too.
2023-07-13 10:09:46 -04:00
Ben Barham
6e93ac1627 Merge pull request #66958 from DavidGoldman/main
Add source.request.index_to_store to sourcekitd
2023-07-12 13:53:33 -07:00
David Goldman
af81adb63c sourcekitd source.request.index_to_store fixes - new test and minor changes 2023-06-30 15:55:43 -04:00
David Goldman
d618233166 Add source.request.index_to_store to sourcekitd
This requests performs an index store index of the given file using the
given index store path and index unit output path. All other options are
derived from the index store related compiler flags.

This will allow IDEs like Xcode to index the file directly inside of
sourcekitd and potentially reuse an already built AST.
2023-06-28 14:24:20 -04:00
Holly Borla
725374e0d8 [Macros] Implement attached extension macros. 2023-06-27 21:22:12 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -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
Ben Barham
93ec785d92 Merge pull request #66907 from bnbarham/fix-reuse-test
[CursorInfo] Pass primary path to allow comparing previous ASTs
2023-06-26 10:50:51 -07:00
Alex Hoppen
22d34d9b14 Merge pull request #58978 from ahoppen/pr/no-deadlock-cancellation-bigger-change
[SoruceKit] Audit SwiftASTManager to prevent deadlocks
2023-06-26 13:11:08 +02:00
Ben Barham
ab95dba720 [CursorInfo] Pass primary path to allow comparing previous ASTs
Update the cursor requests to also pass in their primary file. Snapshots
should be compared using this file, not the input buffer name. This
fixes AST re-use when the AST is usable with snapshots.

Resolves rdar://110344363.
2023-06-23 20:00:19 -07:00
Ben Barham
1d7c534228 Merge pull request #66839 from bnbarham/reuse-cursor-ast
[CursorInfo] Re-use already built ASTs ahead of currently building ones
2023-06-23 09:05:47 -07:00
Alex Hoppen
453f6cdeee [SoruceKit] Audit SwiftASTManager to prevent deadlocks
- Ensure that no callbacks are called when either of these mutexes are held:
  - `SwiftASTConsumer::CancellationRequestCallbackAndIsCancelledMtx`
  - `ASTBuildOperation::DependencyStampsMtx`
    - Exception: We allow calls to `getBuferStamp` because that doesn’t claim any locks)
    - No change was necessary here
  - `ASTBuildOperation::ConsumersAndResultMtx`
  - `ASTBuildOperation::CacheMtx`
    - No change was necessary here
  - `ASTBuildOperation::ScheduledConsumersMtx`
    - Make sure we always inform the consumers asynchronously, even if the operation was already cancelled when the consumer got enqueued by introducing `ConsumerNotificationQueue`
- Ensure that all callbacks to `SwiftASTConsumer` (i.e. `requestCancellation` and `handlePrimaryAST`, `failed`, `cancelled`) are performed asyncronously from a queue to avoid deadlocks

rdar://110357502
2023-06-23 16:55:49 +02:00
Alex Hoppen
b91328cb32 Merge pull request #66866 from ahoppen/ahoppen/cursor-info-deadlock
[SourceKit] Fix a potential deadlock when a cursor info request is cancelled while another one is inside a cancellation callback
2023-06-23 16:10:21 +02:00
Ben Barham
037ddc92ee [CursorInfo] Re-use already built ASTs ahead of currently building ones
Resolves rdar://110344363.
2023-06-22 14:12:48 -07:00
Alex Hoppen
35661f2ab6 [SourceKit] Inform consumers about cancellation from a background queue
This fixes a deadlock that could occur when a cursor info request is cancelled while another one is inside the cancellation callback. The schematic deadlock backtrace is

```
sourcekitd::cancelRequest
SourceKit::RequestTracker::cancel -> holds RequestTracker.RequestsMtx
anonymous func in SourceKit::SwiftASTManager::processASTAsync
SourceKit::SwiftASTConsumer::requestCancellation
anonymous func in ASTBuildOperation::addConsumer -> tries to get ASTBuildOperation.ConsumersAndResultMtx

resolveCursor
SourceKit::SwiftASTManager::processASTAsync
SourceKit::SwiftASTConsumer::requestCancellation
anonymous func in ASTBuildOperation::addConsumer
[probably inlined] ASTBuildOperation::requestConsumerCancellation -> holds ASTBuildOperation.ConsumersAndResultMtx
resolveCursor::CursorInfoConsumer::cancelled
anonymous func in SourceKit::SwiftLangSupport::getCursorInfo
anonymous func in handleRequestCursorInfo
reportCursorInfo
anonymous func in sourcekitd::handleRequest -> tries to get RequestTracker.RequestsMtx
```

rdar://110357502
2023-06-22 21:31:42 +02:00
Alex Hoppen
b66dfadea5 [SourceKit] When AST-based cursor info is cancelled, don’t run solver-based cursor info
Running solver-based cursor info in the callback that is informed about cancellation extends the window for a deadlock.
2023-06-22 21:29:08 +02:00
Saleem Abdulrasool
d3249ac3e2 sourcekitd: adjust the definition of SOURCEKIT_PUBLIC
The API surface for sourcekitd is exported through libAPI and
libService.  Use the `sourcekitd_EXPORTS` macro (reflecting the CMake
default behaviour of `_EXPORTS` macros) to provide a proper definition
of the macro on Windows.  This is not related to MSVC but to PE/COFF
which uses this to define the ABI boundary for the symbol.

This is helpful in partially repairing the ARM64 build of sourcekitd.
2023-06-21 14:59:58 -04:00
Rintaro Ishizaki
13a29a0e20 Merge pull request #66689 from rintaro/macros-serialization-pluginopts
[Macros] Update plugin search options serialization
2023-06-16 15:06:03 -07:00
Rintaro Ishizaki
6fa0c14dfb [Macros] Make 'PluginSearchOption' a external union
Create a 'Kind' enum so that deserialization can use the kind instead of
a string option name.
2023-06-16 11:59:19 -07:00
Hamish Knight
8e66001174 Merge pull request #66676 from hamishknight/interface-error 2023-06-16 10:24:20 +01:00
Rintaro Ishizaki
706985df82 [Macros] Update plugin search options serialization
Previously plugin search options were serialized for each option kind.
Instead serialize them in the order specified.
2023-06-15 17:32:59 -07:00
Hamish Knight
a9f9bd1394 [SourceKit] Record module loading errors when generating interfaces
Record up to two errors emitted when we fail to
load a module for interface generation, and include
these errors in the message we pass back to the
editor. This should help us better pin down the
reason why interface generation failed.

rdar://109511099
2023-06-15 23:55:07 +01:00
Rintaro Ishizaki
5791a2cb37 [Macros] Plugin search options group
'load-plugin-library', 'load-plugin-executable', '-plugin-path' and
'-external-plugin-path' should be searched in the order they are
specified in the arguments.

Previously, for example '-plugin-path' used to precede
'-external-plugin-path' regardless of the position in the arguments.
2023-06-14 15:46:39 -07:00
Artem Chikin
92d9e61d1a [Dependency Scanning] Emit header dependencies of binary Swift module dependencies in output and provide libSwiftScan API to query it 2023-06-12 15:01:41 -04:00
Holly Borla
fc24471ff7 Merge pull request #66532 from hborla/suppress-expansion-in-macro-argument
[Macros] Use source locations to determine whether to suppress macro expansions.
2023-06-12 11:18:25 -07:00
Steven Wu
b1f99b8e93 [CAS] swift dependency scanning using CAS for compiler caching (#66366)
Teach swift dependency scanner to use CAS to capture the full dependencies for a build and construct build commands with immutable inputs from CAS.

This allows swift compilation caching using CAS.
2023-06-12 10:55:53 -07:00
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
Doug Gregor
bb7af04883 Merge pull request #66460 from ahoppen/ahoppen/sourcekitd-exports
[SourceKit] Add barrier-related functions to sourcekitdInProc-darwin.exports
2023-06-08 12:53:42 -07:00
Alex Hoppen
fc662b1487 [SourceKit] Add barrier-related functions to sourcekitdInProc-darwin.exports 2023-06-08 11:08:29 -07:00