Commit Graph

100 Commits

Author SHA1 Message Date
Alex Hoppen
640cfac61c [CodeComplete] Compute type relations for global cached results
Computing the type relation for every item in the code completion cache is way to expensive (~4x slowdown for global completion that imports `SwiftUI`). Instead, compute a type’s supertypes (protocol conformances and superclasses) once and write their USRs to the cache. To compute a type relation we can then check if the contextual type is in the completion item’s supertypes.

This reduces the overhead of computing the type relations (again global completion that imports `SwiftUI`) to ~6% – measured by instructions executed.

Technically, we might miss some conversions like
- retroactive conformances inside another module (because we can’t cache them if that other module isn’t imported)
- complex generic conversions (just too complicated to model using USRs)

Because of this, we never report an `unrelated` type relation for global items but always default to `unknown`.

But I believe this change covers the most common cases and is a good tradeoff between accuracy and performance.

rdar://83846531
2022-03-01 09:16:23 +01:00
Alex Hoppen
190ee6ecc7 [CodeCompletion] Replace includes of CodeCompletion.h by more specific ones 2022-02-23 17:08:26 +01:00
Rintaro Ishizaki
7ef93b2a67 [Basic] Move copyCString to Basic/StringExtras.
Also, use StringRef.copy() instead of copyString().
2022-02-18 11:34:45 -08:00
Rintaro Ishizaki
5ab84ae242 [CodeCompletion] Precompute and cache "filter name"
Filter name for completion item is always used. Also, for cached items,
they are used multiple times for filtering. So precomputing and caching
it improves performance.

rdar://84036006
2022-02-18 11:34:45 -08:00
Rintaro Ishizaki
33ee4d609f [CodeCompletion] 'ContextFreeCodeCompletionResult' factory method
Convert 'ContextFreeCodeCompletionResult' constructor overloads to
'create()' factory methods. This is the consistent interface with
'CodeCompletionString'. NFC
2022-02-18 09:58:26 -08:00
Rintaro Ishizaki
7893f74142 Merge pull request #41384 from rintaro/ide-completion-actorkind-rdar79733313
[CodeCompletion] Add a symbol kind for actors
2022-02-16 15:55:47 -08:00
Alex Hoppen
6bc0de94a2 [SourceKit] Compute code completion type relation when wrapping a ContextFreeCodeCompletionResult in a CodeCompletionResult
[CodeCompletion] Make ExpectedTypeContext a class with explicit getters/setters

This simplifies debugging because you can break when the possible types are set and you can also search for references to `setPossibleType` to figure out where the expected types are being set.
2022-02-16 20:28:13 +01:00
Rintaro Ishizaki
d9011e06b2 [CodeCompletion] Add a symbol kind for actors
rdar://79733313
2022-02-15 13:14:46 -08:00
Alex Hoppen
50eafca5bf [Code Completion] Extract CodeCompletionResultTypeRelation to a top-level type
Preliminary work to compute the type relation when constructing a contextual code completion result.
2022-02-08 15:04:38 +01:00
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
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
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
Rintaro Ishizaki
73be942082 [CodeCompletion] NFC: Make enums in CodeCompletionResult scoped 2021-11-11 11:30:04 -08:00
swift-ci
102e1cebc1 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-22 15:53:25 -07:00
Rintaro Ishizaki
1656eed597 Revert "[CodeCompletion] Provide known module source file information"
This effectively reverts commit f8751d466e.
2021-09-22 10:06:19 -07:00
swift-ci
86a715d70e Merge remote-tracking branch 'origin/main' into rebranch 2021-08-30 17:15:00 -07:00
Ben Barham
8ae8f1d204 [Completion] Remove unused DocWords
The various keyword/recommended/etc fields were parsed and added to
completions, but never actually plumbed through SourceKit. Since they're
still unused and the implementation is not particularly lightweight,
just remove for now.

Resolves rdar://82464220
2021-08-28 14:05:01 +10:00
swift-ci
d21e7e0aba Merge remote-tracking branch 'origin/main' into rebranch 2021-08-11 13:32:56 -07:00
Rintaro Ishizaki
ed1db1bed2 [CodeCompletion] Explain why results aren't recommended
* Implement 'getDiagnosticSeverity()' and 'getDiagnosticMessage()' on
  'CodeCompletionResult'
* Differentiate 'RedundantImportIndirect' from 'RedundantImport'
* Make non-Sendable check respects '-warn-concurrency'

rdar://76129658
2021-08-10 17:11:14 -07:00
Rintaro Ishizaki
f8751d466e [CodeCompletion] Provide known module source file information
* 'CodeCompletionContext' now has 'requiresSourceFileInfo()' flag
* When 'true', 'SourceFiles' is populated.
* 'SourceFiles' is a list of pairs of a known module source
  file path and its up-to-date-ness
* Clients (i.e. 'CodeCompletionConsumer') can retrieve it from
  'CodeCompletionContext' in 'handleResults'
* Each completion item now has 'SourceFilePath' property
* C-APIs to get those informations
2021-08-10 17:11:14 -07:00
Evan Wilde
2c04be2724 llvm::StringRef compare_lower -> compare_insensitive
The `compare_lower` API was replaced with `compare_insensitive` in llvm
commit 2e4a2b8430aca6f7aef8100a5ff81ca0328d03f9.

git clang-format ran.

(cherry picked from commit aca2de95ee)
2021-07-02 10:55:17 -07:00
Evan Wilde
42ff140171 llvm::StringRef equals_lower -> equals_insensitive
The `equals_lower` API was replaced with `equals_insensitive` in llvm
commit 2e4a2b8430aca6f7aef8100a5ff81ca0328d03f9 and
3eed57e7ef7da5eda765ccc19fd26fb8dfcd8d41.

Ran git clang-format.

(cherry picked from commit e21e70a6bf)
2021-07-02 10:55:17 -07:00
Evan Wilde
0919c2cd70 StringRef ends/startswith-lower -> insensitive
Updating StringRef startswith and endswith API to use insensitive rather
than lower.

(cherry picked from commit 1b8b39e6de)
2021-07-02 10:55:17 -07:00
Rintaro Ishizaki
154cd88c86 [CodeCompletion] Use 'Flair' to describe "is argument labels" 2021-06-07 17:25:01 -07:00
Rintaro Ishizaki
6dd5d9482f [CodeCompletion] Introduce "Flair" in code completion
To describe fine grained priorities.

Introduce 'CodeCompletionFlair' that is a set of more descriptive flags for
prioritizing completion items. This aims to replace '
SemanticContextKind::ExpressionSpecific' which was a "catch all"
prioritization flag.
2021-06-07 17:25:01 -07:00
Rintaro Ishizaki
3c2433c942 [CodeCompletion] Prioritize call argument pattern
struct Foo {
    init(_ arg1: String, arg2: Int) {}
    init(label: Int) {}
  }
  func test(strVal: String) {
    _ = Foo(<HERE>)
  }

In this case, 'strVal' was prioritized because it can use as an argument
for 'init(_:arg2:)'. However, argument labels are almost always
preferable, and if the user actually want 'strVal', they can input a few
characters to get it at the top. So we should always prioritize call
argument patterns.

rdar://77188260
2021-04-29 13:23:15 -07:00
Ben Langmuir
be7b5a7179 [completion] Clarify and simplify not-recommended state
Combine IsNotRecommended with NotRecommendedReason and improve the names
of the existing cases to more clearly identify the cases they apply to.
Now all not-recommended completions are required to have a reason.
2021-04-19 09:43:28 -07:00
Ben Langmuir
222e2c7f4c Lift ImportDepth utility out of SourceKit into IDE (NFC) 2021-03-09 13:52:56 -08:00
Brent Royal-Gordon
f71923778b Add -testable-import-module frontend flag
This is just like -import-module, but it does an @testable import. Simple, right?

Fixes rdar://66544654.
2020-10-09 18:59:20 -07:00
Brent Royal-Gordon
b440ab7331 [NFC] Move several types/functions to Import.h
To help consolidate our various types describing imports, this commit moves the following types and methods to Import.h:

* ImplicitImports
* ImplicitStdlibKind
* ImplicitImportInfo
* ModuleDecl::ImportedModule
* ModuleDecl::OrderImportedModules (as ImportedModule::Order)
* ModuleDecl::removeDuplicateImports() (as ImportedModule::removeDuplicates())
* SourceFile::ImportFlags
* SourceFile::ImportOptions
* SourceFile::ImportedModuleDesc

This commit is large and intentionally kept mechanical—nothing interesting to see here.
2020-10-09 18:57:07 -07:00
Varun Gandhi
d3369f7711 [NFC] Rename ImportFilterKind cases to be clearer. 2020-09-23 12:50:20 -07:00
Ben Barham
4f5d4d80bb [Gardening] Add re-usable copy* utility methods to use in code completion
Various copy* methods were re-implemented in a bunch of files, move them
to CodeCompletion.h so they can be re-used everywhere that needs them.
2020-09-10 11:42:33 +10:00
Ben Langmuir
cf87ad805f [gardening] Move filter name printing alongside other completion methods 2020-08-25 10:39:19 -07:00
Ben Langmuir
6480bfaad2 [gardening] Move FuzzyStringMatcher to libIDE 2020-08-25 10:39:08 -07:00
Martin Boehme
d806ba53f6 Give OptionSet an initializer_list constructor.
This makes it easier to specify OptionSet arguments.

Also modify appropriate uses of ModuleDecl::ImportFilter to take
advantage of the new constructor.
2020-06-22 06:57:29 +02:00
Rintaro Ishizaki
7086ffb79f [CodeCompletion] Annotated result type
Introduced 'TypeAnnotationBegin' chunk kind for grouping the result type
name chunks.

rdar://problem/62617558
2020-05-11 22:56:22 -07:00
Rintaro Ishizaki
75a0c9f819 [CodeCompletion] Add 'IsSystem' flag to code completion result item
'key.is_system: 1' is added if the associated declaration is from a
system module.

rdar://problem/62617558
2020-05-11 12:24:36 -07:00
Ben Langmuir
37b98af4e6 [CodeCompletion] Pre-expand closures in argument completion
When completing a single argument for a trailing closure, pre-expand the
closure expression syntax instead of using a placeholder. It's not valid
to pass a non-closure anyway.

rdar://62189182
2020-05-06 01:56:41 -04:00
Rintaro Ishizaki
e9c438cdd5 [CodeCompletion] Dont mark type mismatching items 'not recommended'
func foo() {}
let a: Int = #^HERE^#

Previously, we marked 'foo()' as 'NotRecommented' because 'Void' doesn't
have any member hence it cannot be 'Int'. But it wass confusing with
'deprecated'.

Now that we output 'typerelation' which is 'invalid' in this case. So clients
can deprioritize results, or even filter them out.

rdar://problem/57726512
2020-05-05 10:40:05 -07:00
Daniel Sweeney
ea526c6383 Converting ModuleDecl::ImportedModule from std::pair to a dedicated struct. (#31360) 2020-04-30 20:26:03 -07:00
Hamish Knight
453667f659 [Frontend] Validate ImplicitImportModuleNames early
Check whether the user has provided a valid
identifier when parsing the options. Also make
ImplicitImportModuleNames a private member of
FrontendOptions to prevent mutation after being
parsed.
2020-04-20 13:20:35 -07:00
Rintaro Ishizaki
773a464e83 [CodeCompletion] Add an option to emit annotated description 2020-04-07 00:46:14 -07:00
Rintaro Ishizaki
979906cce2 [CodeCompletion] Don't manually handle Equal opeerator 2020-04-06 13:49:43 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Brent Royal-Gordon
f8df2f66fd Add mechanism for per-SourceFile overlays
When a “separately imported overlay” is added to a SourceFile, two things happen:

1. The direct import of the underlying module is removed from getImports*() by default. It is only visible if the caller passes ImportFilterKind:: ShadowedBySeparateOverlay. This means that non-module-scoped lookups will search _OverlayModule before searching its re-export UnderlyingModule, allowing it to shadow underlying declarations.

2. When you ask for lookupInModule() to look in the underlying module in that source file, it looks in the overlays instead. This means that UnderlyingModule.foo() can find declarations in _OverlayModule.
2020-02-18 11:07:12 -08:00
swift-ci
23021d96fc Merge remote-tracking branch 'origin/master' into master-rebranch 2020-02-06 11:04:29 -08:00
Rintaro Ishizaki
cc8d4965f8 [CodeCompletion] Ensure cached results have 'unknown' type relation 2020-02-05 17:05:23 -08:00
swift_jenkins
29b0fb925e Merge remote-tracking branch 'origin/master' into master-next 2019-12-19 14:40:17 -08:00
Rintaro Ishizaki
62c44126b6 [SourceKit] Reuse compiler instance between multiple completion
- Introduce ide::CompletionInstance to manage CompilerInstance
- `CompletionInstance` vends the cached CompilerInstance when:
-- The compiler arguments (i.e. CompilerInvocation) has has not changed
-- The primary file is the same
-- The completion happens inside function bodies in both previous and
   current completion
-- The interface hash of the primary file has not changed
- Otherwise, it vends a fresh CompilerInstance and cache it for the next
  completion

rdar://problem/20787086
2019-12-18 21:52:20 -08:00