Commit Graph

2350 Commits

Author SHA1 Message Date
Alex Hoppen
fd72674a57 [Code Completion] Split code completion results into context free part that can be cached and contextual part displayed to the user
This allows makes the distinction between cachable and non-cachable properties cleaner and allows us to more easily compute contextual information (like type relations) for cached items later.
2022-01-27 10:40:47 +01:00
Alex Hoppen
bad96793f8 [Code Completion] Extract NotRecommendedReason and CodeCompletionResultKind to top-level types
Preliminary work to split `CodeCompletionResult` into a context-free and contextual part.
2022-01-20 16:26:30 +01:00
Mishal Shah
0bf1389863 Merge pull request #40907 from apple/rebranch
Update swift:main to support llvm-project:stable/20211026 changes (Rebranch merge)
2022-01-19 23:36:38 -08:00
Ben Barham
7337e3bac2 Merge pull request #40566 from bnbarham/synthesized-harmony
[IDE] Only consider synthesized extensions when in the same module
2022-01-19 14:32:13 -08:00
swift-ci
7f6db10594 Merge remote-tracking branch 'origin/main' into rebranch 2022-01-14 04:35:17 -08:00
Alex Hoppen
7aa472c556 [CodeComplete] Make SourceKit::CodeCompletion::Completion store a reference to the underlying swift result instead of extending that type
Previously, when creating a `SourceKit::CodeCompletion::Completion`, we needed to copy all fields from the underlying `SwiftResult` (aka `swift::ide::CodeCompletionResult`). The arena in which the `SwiftResult` was allocated still needed to be kept alive for the references stored in the `SwiftResult`.

To avoid this unnecessary copy, make `SourceKit::CodeCompletion::Completion` store a reference to the underlying `SwiftResult`.
2022-01-11 14:41:36 +01:00
Alex Hoppen
ee99666f91 [CodeComplete] Return result sink as code completion results
Previously the code completion methods just returned an `ArrayRef` that pointed into the result sink that contained the results but no effort was made to actually keep that that result sink alive, e.g. when transforming results in `transformAndForwardResults`.

Instead, return the `CodeCompletionResultSink` from the code compleiton methods now and adopt that sink from the inner results created in `transformAndForwardResults`.
2022-01-11 14:41:35 +01:00
Ben Barham
bf0bcfa8e1 [IDE] Only consider synthesized extensions when in the same module
Only declarations in the same module as synthesized extension's target
are placed within a synthesized extension. We should thus not add
"::SYNTHESIZED::" to the USR if the given declaration is in a different
and.

As an example, `Foundation` adds a method `components(separatedBy:)` to
`String` through an extension on `StringProtocol`. But since it is
within `Foundation` and not `Swift` it will *not* be in a synthesized
extension of `String` or `StringProtocol`. So it should not have
"::SYNTHESIZED::" added and should also not being in the `String` group.

Resolves rdar://71355632.
2021-12-24 09:17:41 +10:00
swift-ci
bea22f7f05 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-22 15:15:13 -08:00
Saleem Abdulrasool
b6d2c5bc9a Revert "build: add a workaround for CMake[>=3.22] and SourceKit"
This reverts commit 1e5df70d89.

This does not actually impact the build, so revert it to reduce the
complexity in the build.
2021-12-22 10:15:26 -08:00
swift-ci
ba0c98ff08 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-21 22:33:02 -08:00
Rintaro Ishizaki
473ecd8c80 Merge pull request #40645 from rintaro/sourcekit-compilerserver
[SourceKit] Add a request to generate object files in SourceKit
2021-12-21 22:29:11 -08:00
Rintaro Ishizaki
7c92a8e555 [SourceKit] Add a request to generate object files in SourceKit
Add 'request.compile'
2021-12-21 14:35:38 -08:00
swift-ci
f25c7addf6 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-21 09:53:19 -08:00
Rintaro Ishizaki
2795a19ed6 Merge pull request #40163 from rintaro/ide-completion-enumbitfield
NFC: [CodeCompletion] Use enums in bit fields as-is
2021-12-21 09:40:00 -08:00
Alex Hoppen
c1542bf80e [SourceKit] Guard static assert by _MSC_VER 2021-12-21 11:56:03 +01:00
swift-ci
41ef4e8c9d Merge remote-tracking branch 'origin/main' into rebranch 2021-12-20 09:15:08 -08:00
Alex Hoppen
669e3f34a6 Merge pull request #40155 from ahoppen/pr/improve-module-search-path-lookup
[Serialization] Improve module loading performance
2021-12-20 18:09:17 +01:00
swift-ci
3321e4715d Merge remote-tracking branch 'origin/main' into rebranch 2021-12-17 16:15:07 -08:00
Rintaro Ishizaki
2c7cbe9748 [SourceKit] Initialize llvm in SourceKit
Preparation for code generation in SourceKit
2021-12-17 10:19:53 -08:00
swift-ci
09c4a37ac9 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-15 16:44:42 -08:00
Ben Barham
65ef8020de [CodeComplete] Add option to add calls with no defaults (or not)
Now that arguments are marked up with whether they have a default or
not, clients may not need the extra call (that has no default
arguments). Add an option to allow not adding this item.

Resolves rdar://85526214.
2021-12-15 13:30:57 +10:00
swift-ci
7ff906d730 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-14 04:53:37 -08:00
Alex Hoppen
4fc9d015de Merge pull request #40107 from ahoppen/pr/load-stdlib-in-setup
[Frontend] Load standard libarary in CompilerInstance::setup
2021-12-14 13:45:23 +01:00
Alex Hoppen
fe7878ecce [Serialization] Improve module loading performance
When looking for a Swift module on disk, we were scanning all module search paths if they contain the module we are searching for. In a setup where each module is contained in its own framework search path, this scaled quadratically with the number of modules being imported. E.g. a setup with 100 modules being imported form 100 module search paths could cause on the order of 10,000 checks of `FileSystem::exists`. While these checks are fairly fast (~10µs), they add up to ~100ms.

To improve this, perform a first scan of all module search paths and list the files they contain. From this, create a lookup map that maps filenames to the search paths they can be found in. E.g. for
```
searchPath1/
  Module1.framework

searchPath2/
  Module1.framework
  Module2.swiftmodule
```
we create the following lookup table
```
Module1.framework -> [searchPath1, searchPath2]
Module2.swiftmodule -> [searchPath2]
```
2021-12-14 12:44:13 +01:00
swift-ci
60fc05af03 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-13 10:54:40 -08:00
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
swift-ci
6aa71465d0 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-10 05:33:50 -08:00
Alex Hoppen
5a6341bd65 Merge pull request #40493 from ahoppen/pr/enqueue-consumer-on-background-queue
[SourceKit] Enqueue `SwiftASTConsumer`s async on a queue
2021-12-10 14:23:47 +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
swift-ci
1c8c75ac62 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-09 17:08:58 -08:00
Ben Barham
9dabad41b6 Merge pull request #40491 from apple/revert-40353-pr/no-semantic-info-if-not-requested
Revert "[SourceKit] Don't build an AST if no semantic info is requested"
2021-12-10 10:39:40 +10: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
a5b3f83223 Revert "[SourceKit] Don't build an AST if no semantic info is requested" 2021-12-09 21:20:43 +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
swift-ci
8abc3941d1 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-07 08:14:19 -08: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
swift-ci
fcc173765f Merge remote-tracking branch 'origin/main' into rebranch 2021-12-04 09:33:47 -08: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
Saleem Abdulrasool
1e5df70d89 build: add a workaround for CMake[>=3.22] and SourceKit
The switch between compilers causes problems due to new flags being used
for building.  This adds a workaround to avoid the search path
re-ordering which breaks the build with a newer CMake.
2021-12-03 16:26:38 -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
swift-ci
ee8f9ee1f3 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-03 15:14:24 -08:00
Connor Wakamo
b553a92718 Merge pull request #40235 from cwakamo/eng/PR-85511244-fix-some-SourceKit-CMake-issues
[CMake] Fix a couple SourceKit CMake issues.

This addresses <rdar://problem/85511244>.
2021-12-03 15:09:00 -08:00