Commit Graph

244 Commits

Author SHA1 Message Date
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
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
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
Xi Ge
2e6b2b5bee test: update SourceKit/CodeComplete/complete_override.swift 2021-11-23 21:43:40 -08: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
Rintaro Ishizaki
7e7b2c3557 [CodeCompletion] Annotate override completions
* "description" for override completion is now annotatable
* "description" doesn't include attributes and decl introducer, but it
  includes generic paramters, effects specifiers, result type clause,
  and generic where clauses
* "name" now only include the name and the parameter names
* "sourcetext" should be the same

rdar://63835352
2021-09-02 12:12:26 -07:00
Doug Gregor
b2dee32b00 Enable async let without the experimental flag 2021-07-26 16:14:34 -07:00
Rintaro Ishizaki
90b3f6ec57 [CodeCompletion] Fix a test case after CodeComletionString::getName() obsoletion
Since 7c24d19, sorted result from SourceKit for 'foo(a: Int)' and
'foo(a: String)' is non-deterministic. Update the test case.

rdar://80729544
2021-07-19 14:10:22 -07:00
David Ungar
9e7eb2fb7d Disable failing test. 2021-07-17 10:30:28 -07:00
Rintaro Ishizaki
18dc9c1c27 [CodeCompletion] Remove CodeComletionString::getName()
`CodeCompletioString::getName()` was used only as the sorting keys in
`CodeCompletionContext::sortCompletionResults()` which is effectively
deprecated. There's no reason to check them in `swift-ide-test`. Instead,
check `printCodeCompletionResultFilterName()` that is actually used for
filtering.
2021-07-16 13:24:19 -07:00
Varun Gandhi
02afb9d49b [ModuleInterface] Print full type if ambiguous for extensions.
The patch introduces a new setting instead of changing existing settings
because the generated interfaces in the IDE have slightly different
requirements; the extended type there is unconditionally not printed
qualified (even if it is ambiguous). This is likely because the
ambiguity heuristic is very weak; it doesn't even do name lookup.
Simplifying that logic would be nice, but then we'd need to update
a bunch of IDE/print* tests and end up with more more visual clutter
in the IDE.

Introducing the new setting means we can change the behavior for
swiftinterface files without affecting the behavior for IDE interfaces.

Fixes rdar://79093752.
2021-06-11 20:04:43 -07:00
Doug Gregor
5004a5447b [Concurrency] Make "self" parameter of actor-isolated functions 'isolated'.
The notion of "actor-isolated" currently exists at the declaration level.
For functions, it is going to be captured in the function type itself,
where 'self' is declared to be 'isolated'. Model isolation both
ways: the 'self' of a method that is isolated to an actor instance
will be 'isolated' as well.

We are still using declaration-based checking of actor isolation.
However, by mirroring this information we can move more incrementally
over to doing checking based on 'isolated' parameters.
2021-06-07 23:59:38 -07:00
Rintaro Ishizaki
3cbc6e7c18 Merge pull request #37591 from rintaro/ide-completion-cache-rdar78315441
[CodeCompletion] Don't check 'InvalidAsyncContext' for imported globals
2021-05-21 23:21:23 -07:00
Doug Gregor
3fe712dfda [SE-0313] Enable nonisolated by default. 2021-05-21 15:17:43 -07:00
Rintaro Ishizaki
0ce1faa6c7 [CodeCompletion] Don't check 'InvalidAsyncContext' for imported globals
'InvalidAsyncContext' depends on the decl context. That may case
"sticky" not-recommended If it's cached for a non-async context.

To workaround this, stop checking 'InvalidAsyncContext' when collecting
completion items for caching. Also consistently use the 'SourceFile' as
the decl context to avoid decl context specific behavior.

rdar://78315441
2021-05-21 15:16:36 -07:00
Rintaro Ishizaki
8d63f298c1 [CodeCompletion] Don't suggest argument labels from unapplicable overload
When matching an argument to a parameter list, if there is no matching
parameter, the argument list is not applicable to the parameters. In
such case, code completion should not suggest argument labels of the
function.

rdar://77867723
2021-05-17 13:39:43 -07:00
Rintaro Ishizaki
861bbcc5d6 Merge pull request #37330 from rintaro/ide-completion-rdar75620636
[CodeCompletion] Make object literals optional
2021-05-10 13:47:10 -07:00
Rintaro Ishizaki
da96ef1f51 [CodeCompletion] Make object literals optional
For example, non-Darwin platforms probably don't want
`#colorLiteral(red:green:blue":alpha:)` and `#imageLiteral(named:)`.
Add an completion option to include them, which is "on" by default.

rdar://75620636
2021-05-07 16:27:13 -07:00
Rintaro Ishizaki
72f16df99d [CodeCompletion] Reset 'hasSingleExpressionBody' when setting function body
Previously, completing inside non single expression body might cause a
crash if you had done any completion with single expression in the same
body.

e.g.

  func test() {
    test(#^HERE^#)
  }

after that:

  func test() {
    test(arg)
    if #^HERE^#
  }

That was because the `hasSingleExpressionBody` wasn't cleared when
reusing the function for subsequent completions.

This patch just clears it whenever a new parsed body is set to a
function.

rdar://75358153
2021-05-07 13:59:32 -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
Rintaro Ishizaki
75ff9480c2 [CodeCompletion] Boost exact case-sensitive prefix match
When there are symbols 'Label' and 'label', if a user type 'Lab',
'Label' should be prioritized.

rdar://77164709
2021-04-27 22:32:37 -07:00
Alex Hoppen
6085e1dca4 [CodeCompletion] Reset diagnostics when reusing an ASTContext for completion
The diagnosticc engine is keeping track of state which might modify parsing/typechecking behaviour. In the added test case the `fatalErrorOccurred` flag was during the first completion. The flag was still `true` for the second completion, causing parsing/typechecking to behave slightly differently. Because of this, the ExprRewriter failed when applying a constraint system solution, not properly cleaning up its `ExprStack`.

This PR tackles both issues:
1) Reset the `hadError` flags in the diagnostics engine
2) Clean up the `ExprRewriter`’s `ExprStack` when rewriting a target fails.

Either of these changes fixes the crash in the test case but I think both could manifest through different code paths in different scenarios.

Fixes rdar://76051976 [SR-14430]
2021-04-15 13:07:27 +02:00
Slava Pestov
e30ced6069 Disable complete_checkdeps_notifyupdate.swift even harder 2021-02-11 16:05:06 -05:00
Rintaro Ishizaki
a5d5c8dccb [Test] Disable a test case while investigating
rdar://problem/74150023
2021-02-09 12:49:17 -08:00
Rintaro Ishizaki
27dc2cf406 [SourceKit] Add a request kind to notify dependencies are updated 2021-02-05 18:41:26 -08:00
Rintaro Ishizaki
8f8846342f [Tests] Disable a failing test case
While investigating

rdar://problem/72627583
2020-12-23 09:36:44 -08:00
Rintaro Ishizaki
8ef504acf3 Merge pull request #35050 from rintaro/ide-completion-rdar72198530
[CodeCompletion] Annotate 'async' functions/initializers in results
2020-12-18 09:29:07 -08:00
Xi Ge
c0e6204363 test: xfail failing sourcekitd tests in CI
rdar://72466352
2020-12-18 07:19:02 -08:00
Rintaro Ishizaki
4286c44e72 [CodeCompletion/SourceKit] Consolidate some chunk kinds
Consolidate ThrowsKeyword, RethrowsKeyword, and AsyncKeyword to
EffectsSpecifierKeyword.
Abolish 'key.throwsoffset' and 'key.throwslength' as they aren't used.
2020-12-14 12:25:30 -08:00
Ben Barham
68f89d44de [SourceKit] Fix flakey VFS completion tests
These tests relied on timing between completion runs in order to check
that fast completion was working properly for completions in VFS files.
That is, they would assume that two runs happening one after another
without a sleep inbetween would always run fast completion.

However, that's not necessarily the case and there have been cases where
a dependency check happens despite its interval being fairly long
(multi-second).

This change emulates the same behaviour by changing the interval
between 0/100, which should prevent any timing issues.

Resolves rdar://72144331
2020-12-11 09:22:24 +10:00
Ben Barham
34ff514ab1 [SourceKit] Fix flakey completion tests
A previous change updated the checkdep tests to move the sleep before
copying over files. This fixed cases where the modification time would
be the same second as the dependency check. Unfortunately this
introduced a slightly different form of flakiness - if the sleep went
too long, the completion that was meant to re-use the AST would see that
it's time to check dependencies and thus skip the fast completion path.

One fix for that would be to add a smaller sleep before, a longer sleep
after, and increase the dependency check time. That increases the
runtime of the tests even further though, so instead just update the
timestamps manually to be in the past/future in order to invoke the path
we want to test. This also allows a 0 dependency check time (ie. always
check), which makes the tests even faster.

Resolves rdar://71861446
2020-12-10 14:51:55 +10:00
Rintaro Ishizaki
055dc66d3b [Frontend] Recover missing input file by dummy input buffer.
Also, continue trying opening files even if any of primary files are
missing so that the caller can know all files failed to open.

rdar://problem/33757793
2020-12-04 15:23:29 -08:00
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Rintaro Ishizaki
84f0c5723a [CodeCompletion] Calculate type relation when adding type annotation
Calculate and set the type relation in each result building logic which
knows the actual result type.

CodeCompletionResultBuilder couldn't know the actual result type. From
the declaration alone, it cannot know the correct result type because it
doesn't know how the declaration is used (e.g. calling? referencing by
compound name? curried?)
2020-09-16 22:04:50 -07:00
Nathan Hawes
a1ef6e4dac Merge pull request #33749 from nathawes/new-member-completion
[CodeCompletion] Update member completion to handle ambiguous and invalid base expressions
2020-09-09 18:51:22 -07:00
Rintaro Ishizaki
77b4f75608 [SourceKit] Reorgantize code completion options
* Abolish 'reuseastcontext' per-request option
* Add 'MaxASTContextReuseCount' global configuration
2020-09-03 19:30:05 -07:00
Nathan Hawes
3850417035 [Test][CodeCompletion] Consistently check for the 'unknown' type relation when there's no expected type.
The tests were matching the previous implementation's output, which sometimes produced 'unknown' and sometimes 'unrelated' in cases where there was no expected type from the context.
2020-09-01 13:25:37 -07:00
Nathan Hawes
03b5296f70 [test] Update code completion test with improved type relation result. 2020-08-28 22:24:24 -07:00
Rintaro Ishizaki
bf5fb4d2bb [CodeCompletion] Don't update VFS content hash map after each completion
This was not needed. The list of depenencies should not be changed
during fast-completion sessions.

This was also harmful because it calls stat(2) for all the dependency
files.

rdar://problem/67773257
2020-08-26 09:56:36 -07:00
Rintaro Ishizaki
dd6046ba16 [CodeCompletion] Stop recording interface hash when searching CC token 2020-08-14 10:33:53 -07:00
Rintaro Ishizaki
facabd8010 Merge pull request #33200 from rintaro/ide-completion-rdar66301353
[CodeCompletion] Fix issue in dependency checking for the editing file
2020-07-30 14:02:03 -07:00
Rintaro Ishizaki
2f4dcf3e2f [CodeCompletion] Fix issue in dependency checking for the editing file
'SM.getCodeCompletionBufferID()' returns the buffer ID of the previous
code completion. 'CI.getCodeCompletionFile()->getBufferID()' always
returns the original source buffer ID of the current file in the main
module. The latter is needed for excluding buffer ID for dependency checking.

rdar://problem/66301353
2020-07-30 09:27:58 -07:00
Argyrios Kyrtzidis
324ccb576e [SourceKit] Fix issue where CompletionCheckDependencyInterval is set to 0 when the global config request is sent
Fixes rdar://66309544
2020-07-29 21:44:09 -07:00
Rintaro Ishizaki
e953e523a0 [CodeCompletion] Fast completion inside function builder function
`PreCheckFunctionBuilderRequest` applies `PreCheckExpression` to the
expressions inside the function body. Previously it used to receive only
`AnyFunctionRef` (`FunctionDecl` or `ClosureExpr`) as the parameter.
However, when fast-completion kicks-in, it replaces the body of the
function, then tries to call `PreCheckFunctionBuilderRequest` again, with
the same function decl as before. It used to return cached "Success"
result, but it didn't actually apply `PreCheckExpression`. So any
`UnresolvedDeclRefExpr` remained unresolved.

In this patch, make `PreCheckFunctionBuilderRequest` receive "body" of the
function as well, so it doesn't return the cached result for the *previous*
body.

rdar://problem/65692922
2020-07-16 23:38:49 -07:00
Rintaro Ishizaki
17be66c3d6 [PlaceholderExpansion] Omit return type in closure signature
Return type in the closure signature is often redundant when expanding
placeholders, because the type of the clossures are usually inferred
from the context (i.e. calling function), users don't need to write the
return type explicitly.

They are not only redundant, but also sometimes harmful when the return
type is a generic parameter or its requirement. Actually, there is no
correct spelling in such cases.

So omit the return type and the parentheses around the parameter clause.

rdar://problem/63607976
2020-07-09 14:37:17 -07:00
Rintaro Ishizaki
bdfe1b1b08 [Parse] Avoid delayed member parsing for type decl with missing brace
Cache empty member list so that 'IterableDeclContext::loadAllMembers()'
doesn't perform delayed member parsing.

Fixes: rdar://problem/63921896
2020-06-04 14:34:22 -07:00
Rintaro Ishizaki
17b681bf20 [SourceKit] Disable complete_build_session.swift test file while investigating 2020-06-03 11:11:31 -07:00
Rintaro Ishizaki
ad51f4f1a8 [CodeCompletion] Fix non-determinisc failures in dependency check test cases
Sleep a few seconds to ensure the timestamp of the modified files are
different from the last completion.

rdar://problem/62923248
2020-05-27 08:58:14 -07:00
Rintaro Ishizaki
6116f7d528 [CodeCompletion] Disable fast-completion dependecy checking test cases
while investigating.

rdar://problem/62923248
2020-05-20 09:07:00 -07:00
Dmitri Gribenko
b6d0ef5c81 Remove support for a broken std::regex in libstdc++ 4.8
Out of all operating systems ever supported by Swift, only Ubuntu 14.04
had libstdc++ 4.8, and Swift has sunset support for Ubuntu 14.04 for a
while now.
2020-05-19 17:20:55 +02:00