Commit Graph

1539 Commits

Author SHA1 Message Date
Alex Hoppen
f5b6103ef7 [SourceKit] Fix a crash that occurred when a document without an associated source file is reopened
When opening a file for the first time, we don’t store a snapshot for it. This could cause a crash when trying to consult its snapshot to see whether an AST can be reused for cursor info.
2021-12-13 16:43:32 +01:00
Alex Hoppen
22f67e89a6 [SourceKit] Explicitly specify frontend action type when creating compiler invocation
Explicitly specify the frontend action to make sure we aren’t loading thes stdlib if the performed action is syntactic only.
2021-12-13 15:32:08 +01:00
Alex Hoppen
63c31033fc [Frontend] Load standard libarary in CompilerInstance::setup
Instead of checking that the stdlib can be loaded in a variety of places, check it when setting up the compiler instance. This required a couple more checks to avoid loading the stdlib in cases where it’s not needed.

To be able to differentiate stdlib loading failures from other setup errors, make `CompilerInstance::setup` return an error message on failure via an inout parameter. Consume that error on the call side, replacing a previous, more generic error message, adding error handling where appropriate or ignoring the error message, depending on the context.
2021-12-13 15:32:08 +01:00
Alex Hoppen
c90c7a2975 [SourceKit] Enqueue SwiftASTConsumers async on a queue
Enqueuing `SwiftASTConsumer`s might be expensive because `getBuildOperationForConsumer` consults the file system. Since all results from the AST build are processed asynchronously anyway, there’s no need to perform the enqueuing  synchronously.

rdar://86289703
2021-12-10 09:11:02 +01:00
Alex Hoppen
4aa911023a Merge pull request #40339 from ahoppen/pr/improve-sourcekit-stamp-handling
[SourceKit] Improvements to stamp handling in SwiftASTManager
2021-12-09 23:53:59 +01:00
Alex Hoppen
e17faa5bcf [SourceKit] Improve memory cost function of ASTBuildOperation 2021-12-08 15:17:13 +01:00
Alex Hoppen
3adb9c2823 [SourceKit] Make FileContent non ref-counted
We never need to have two copies of the same `FileContent` object, so we don’t need a copy constructor and can thus pass it on the stack again, instead of storing it on the heap.
2021-12-08 15:17:13 +01:00
Alex Hoppen
dcbedc65fd [SourceKit] Remove some dupliate computation of realpaths 2021-12-08 15:17:13 +01:00
Alex Hoppen
5f4b1a0b27 [SourceKit] Don't store Stamps in ASTBuildOperation
FileContents already contains the stamps.
2021-12-08 15:17:13 +01:00
Alex Hoppen
a8bfd4fe44 [SourceKit] Store FileContents in ASTBuildOperation instead of snapshots 2021-12-08 15:17:13 +01:00
Alex Hoppen
de25265de0 [SourceKit] Remove ability to specify fixed snapshots to use when building an AST
The feature was never used and just complicated the implementation.
2021-12-08 15:17:13 +01:00
Alex Hoppen
1739c23a9b Merge pull request #40158 from ahoppen/pr/cancel-code-completion
[SourceKit] Support cancellation of code completion like requests
2021-12-07 17:10:05 +01:00
Rintaro Ishizaki
f17671c4a6 Guard a static assert for MSVC
MSVC doens't pack diffrent underlying int types into a bitfield. e.g.

  struct S {
    int a: 1;
    char b: 1;
    int c: 1;
  };

These fields are considered three sparate bitfields.
2021-12-04 00:19:25 -08:00
Rintaro Ishizaki
94a372e8ca [CodeCompletion] Use enums in bit fields as-is
We don't need to convert them from/to integer
2021-12-03 15:33:28 -08:00
Alex Hoppen
177ab6e8e7 [SourceKit] Support cancellation of code completion like requests
Essentially, just wire up cancellation tokens and cancellation flags for `CompletionInstance` and make sure to return `CancellableResult::cancelled()` when cancellation is detected.

rdar://83391488
2021-12-02 13:05:03 +01:00
Alex Hoppen
9042536323 [SourceKit] Move the cancellation flag from TypeCheckerOptions to ASTContext
We need to modify the pointer pointing to the cancellation flag when reusing an ASTContext for code completion. This is not possible by the previous design because `TypeCheckerOptions` was `const`. Moving the cancellation flag to `ASTContext` will also allow other stages of the compiler to honor a cancellation request.
2021-12-02 12:57:34 +01:00
Saleem Abdulrasool
910fbee14e gardening: make c++98-compat-extra-semi an error
This cleans up 90 instances of this warning and reduces the build spew
when building on Linux.  This helps identify actual issues when
building which can get lost in the stream of warning messages.  It also
helps restore the ability to build the compiler with gcc.
2021-11-27 11:40:17 -08:00
Alex Hoppen
ac56bfb34e Merge pull request #40066 from ahoppen/pr/deep-stack
[SourceKit] Use deep stack when parsing in the XPC service
2021-11-15 09:17:03 +01:00
Alex Hoppen
8a6c4b338a Merge pull request #39681 from ahoppen/pr/request-tracker
[SourceKit] Add a request tracker that manages cancellation
2021-11-12 11:54:07 +01:00
Rintaro Ishizaki
73be942082 [CodeCompletion] NFC: Make enums in CodeCompletionResult scoped 2021-11-11 11:30:04 -08:00
Alex Hoppen
772485def3 [SourceKit] Add a request tracker that manages cancellaiton
Previously, `SwiftASTManager` and `SlowRequestSimulator` maintained their own list of in-progress cancellation tokens. With code completion cancellation coming up, there would need to be yet another place to track in-progress requests, so let’s centralize it.

While at it, also support cancelling requests before they are scheduled, eliminating the need for a `sleep` in a test case.

The current implementaiton leaks tiny amounts of memory if a request is cancelled after if finishes. I think this is fine because it is a pretty nieche case and the leaked memory is pretty small (a `std::map` entry pointing to a `std::function` + `bool`). Alternatively, we could require the client to always dispose of the cancellation token manually.
2021-11-10 22:11:02 +01:00
Ben Barham
f6db91e3f9 [SourceKit] Ignore references without a location
A keypath using dynamic member lookup results in various `KeyPathExpr`
that have components with no location. Ignore these and any other
references that have a missing location.

Resolves rdar://85237365
2021-11-10 14:52:46 +10:00
Alex Hoppen
3a96cc7c51 [SourceKit] Use a deep stack to perform syntactic parsing
Othwerise we were performing the syntactic parsing on a background queue that had a reduced stack size which could result in stack overflows.

rdar://84474387
2021-11-09 18:36:09 +01:00
Alex Hoppen
86a1bfd340 Merge pull request #39631 from ahoppen/pr/cancel-completion-infrastructure
[CodeCompletion] Refactor how code completion results are returned to support cancellation
2021-11-09 13:35:18 +01:00
Ben Barham
fd7d59daa6 [CursorInfo] Add a synthesized field
Mark implicit declarations with a `synthesized` field, since while we
still want them to have a cursor info result (eg. for their USR to find
possible overrides), it's likely that clients will want to treat them
differently to results that have a real location in source.

An alternative could be to remove the location entirely, but:
  - the module name would also have to be removed to prevent wasted
    lookups in the generated interface
  - having the location could still be useful as the location that
    caused the synthesized declaration (though at the moment only
    synthesized initializers have a location)

Resolves rdar://84990655
2021-11-05 15:52:10 +10:00
Alex Hoppen
c9f5331804 [SourceKit] Pass CompletionContext by reference to CompletionInstance 2021-10-29 12:00:12 +02:00
Alex Hoppen
95ae8a41cc [SourceKit] Make completion-like helper functions static 2021-10-28 11:10:31 +02:00
Alex Hoppen
70e3c99edd [SourceKit] Remove performCompletionLikeOperation
All users of `performCodeCompletionLikeOperation` have been migrated to dedicated methods on `CompletionInstance`.
2021-10-28 11:10:30 +02:00
Alex Hoppen
163ccf9184 [SourceKit] Move invocation of code completion second pass for code completion from SoruceKit to CompletionInstance 2021-10-28 11:10:30 +02:00
Alex Hoppen
367c9819ef [SourceKit] Move invocation of code completion second pass for ConformingMethodList from SoruceKit to CompletionInstance 2021-10-28 11:10:30 +02:00
Alex Hoppen
ab257bbda3 [SourceKit] Move invocation of code completion second pass for TypeContextInfo from SoruceKit to CompletionInstance
The invocation of the code completion second pass should be implementation detail of `CompletionInstance`. Create a method on `CompletionInstance` that correctly invokes the second pass and just reutnrs the type context info results to the caller.
2021-10-28 11:10:30 +02:00
Alex Hoppen
b6e03e3d98 [CodeCompletion] Make sure callback is always called from performOperation
We had some situations left that neither returned an error, nor called the callback with results in `performOperation`. Return an error in these and adjust the tests to correctly match the error.
2021-10-28 11:10:30 +02:00
Alex Hoppen
2fcb24e716 [CodeCompletion] Refactor how code completion results are returned to support cancellation
This refactors a bunch of code-completion methods around `performOperation` to return their results via a callback only instead of the current mixed approach  of indicating failure via a return value, returning an error string as an inout parameter and success results via a callback. The new guarantee should be that the callback is always called exactly once on control flow graph.

Other than a support for passing the (currently unused) cancelled state through the different instance, there should be no functionality change.
2021-10-28 11:10:30 +02:00
Ben Barham
157c742cac Merge pull request #39851 from bnbarham/always-add-module-name
[CursorInfo] Always add module name to response
2021-10-28 09:05:59 +10:00
Ben Barham
8128450690 [CursorInfo] Always add module name to response
To simplify clients, have the cursorinfo result be consistent whether
requesting a symbol within the current module or not, ie. do not skip
adding the module name.

Resolves rdar://77003299
2021-10-22 12:35:53 +10:00
Zoe Carver
401f334b90 Merge pull request #38675 from zoecarver/lazy-importer-namespaces
[cxx-interop] Lazily import members of clang namespaces and records via requests.
2021-10-21 09:04:52 -07:00
zoecarver
b8e52a7ad2 [cxx-interop] Lazily import members of Clang namespaces and records via requests.
Also adds a ClangImporter request zone and move some requests into it.
2021-10-20 14:52:43 -07:00
Alex Hoppen
2f19d1847f [SourceKit] Add a dedicated request to retrieve the diagnostics of a file
Currently, SourceKit always implicitly sends diagnostics to the client after every edit. This doesn’t match our new cancellation story because diagnostics retrieval is no request and thus can’t be cancelled.

Instead, diagnostics retrieval should be a standalone request, which returns a cancellation token like every other request and which can thus also be cancelled as such.

The indented transition path here is to change all open and edit requests to be syntactic only. When diagnostics are needed, the new diagnostics request should be used.

rdar://83391522
2021-10-13 21:28:18 +02:00
swift-ci
3f8fea8508 Merge remote-tracking branch 'origin/main' into rebranch 2021-10-06 10:17:29 -07:00
Alex Hoppen
5e9ff15960 Merge pull request #39540 from ahoppen/pr/simulate-long-request
[SourceKit] Add option to simulate a long-running request
2021-10-05 11:59:47 +02:00
Meghana Gupta
f458d9b490 Fix unnecessary one-time recompile of stdlib with -enable-ossa-flag (#39516)
* Fix unnecessary one-time recompile of stdlib with -enable-ossa-flag

This includes a bit in the module format to represent if the module was
compiled with -enable-ossa-modules flag. When compiling a client module
with -enable-ossa-modules flag, all dependent modules are checked for this bit,
if not on, recompilation is triggered with -enable-ossa-modules.

* Updated tests
2021-10-04 18:46:40 -07:00
Alex Hoppen
fa0ead5dc1 [SourceKit] Add option to simulate a long-running request
This allows us to remove the dependency on a slow-to-typecheck example for a `sourcekitd-test`.
2021-10-04 21:43:53 +02:00
swift-ci
c51550f30e Merge remote-tracking branch 'origin/main' into rebranch 2021-09-30 15:11:41 -07:00
Alex Hoppen
b0678ca524 Merge pull request #39494 from ahoppen/pr/sourcekit-cancellation-tokens
[SourceKit] Allow explicit cancellation of requests with a cancellation token
2021-09-30 17:01:53 +02:00
Alex Hoppen
7d5ee83a61 [SourceKit] Allow explicit cancellation of requests with a cancellation token
The key changes here are
- To keep track of cancellation tokens for all `ScheduledConsumer`s in `SwiftASTManager`
- Generate unique request handles for all incoming requests (`create_request_handle `), use these request handles as cancellation tokens and return them from the `sourcekitd_send_request` methods
- Implement cancellation with `sourcekitd_cancel_request` as the entry point and `SwiftASTManager::cancelASTConsumer` as the termination point

Everything else is just plumbing the cancellation token through the various abstraction layers.

rdar://83391505
2021-09-30 11:45:24 +02:00
Rintaro Ishizaki
fa04717bf5 Merge pull request #39395 from rintaro/sourcekit-completion-inits
[CodeCompletion] Remove two completion options from LangOptions
2021-09-29 09:52:51 -07:00
Alex Hoppen
4521c99d56 Merge pull request #38782 from ahoppen/pr/sourcekit-cancellation
[SourceKit] Support cancellation of requests while an AST is being built
2021-09-28 20:08:14 +02:00
Alex Hoppen
7a80034e35 [SourceKit] Support cancellation of requests while an AST is being built
This commit refactors the way ASTs are being built in SourceKit and how `SwiftASTConsumer`s are served by the built ASTs. `SwiftASTManager.h` should give an overview of the new design.

This commit does not change the cancellation paradigm in SourceKit (yet). That is, subsequent requests with the same `OncePerASTToken` still cancel previous requests with the same token. But while previously, we were only able to cancel requests that haven’t started an AST build yet, we can now also cancel the AST build of the to-be-cancelled requests.

With this change in place, we can start looking into explicit cancellation of requests or other cancellation paradigms.
2021-09-23 11:53:45 +02:00
Rintaro Ishizaki
afc24dfd4b [CodeCompletion] Remove two completion options from LangOptions
"add inits to toplevel" and "call pattern heuristics" are only used in
code completion. Move them from LangOptions to CodeCompletionContext so
that they don't affect compiler arguments.
2021-09-22 16:49:50 -07:00
swift-ci
102e1cebc1 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-22 15:53:25 -07:00