Commit Graph

1181 Commits

Author SHA1 Message Date
Rintaro Ishizaki
4df17c5bd2 [CodeCompletion] Stop suggesting initializer calls on unresolved member
For example, for

  class C {
    class D: C {
        init() {}
    }
  }
  let _: C = .#^HERE^#

We used to suggest 'D()' (not just 'D') because it was invalid without
initialization. However, after SE-0287, it can be valid. For example, if
'D' has:

  extension C.D {
    static var staticC: C { ... }
  }

Users can write:

  let _: C = .D.staticC

So we should not suggest constructor calls. Also, this is consistent with
normal type name completion. Users still can get initializer completions
by adding '(' after the type name.

Although initialization call completion with type names was convenient
in some cases, it's too annoying when we have unrelated member types
like:

  enum MyEnum {
    typealias Content = Int
    case value(Content)
  }

We don't want `.Content(bitPattern)` etc for implicit member completion
for 'MyEnum' context type.

rdar://75963052
2021-03-29 15:37:13 -07:00
Alex Hoppen
943d7ee621 [CodeComplete] In where clauses, suggest Self and the current type
Fixes rdar://70058225
2021-03-26 17:43:35 +01:00
Doug Gregor
9d8fde8c18 [Concurrency] Remove actorIndependent(unsafe) isolation.
Don't treat `actorIndependent(unsafe)` as its own kind of isolation.
It was only really used as a bring-up hack to break the isolation model,
but shouldn't be in the user model of the language and causes
complications to the implementation.
2021-03-26 08:27:36 -07:00
Rintaro Ishizaki
3434463368 [CodeCompletion] Factor out actor isolation analysis 2021-03-24 15:53:37 -07:00
Rintaro Ishizaki
b2174da15b [CodeCompletion] Update for actor isolation
For cross actor references:
* Annotate with 'async'
* "Not recommended" if there're non-'Sendable' arguments or return types

rdar://72200120
2021-03-24 15:52:44 -07:00
Rintaro Ishizaki
c991347160 [IDE] Explicitly specify 'SerializedOK=false' to 'getRawComment()'
This ensures that we don't try getRawComment() from serialized locations

rdar://problem/75010520
2021-03-18 17:30:36 -07:00
Ben Langmuir
222e2c7f4c Lift ImportDepth utility out of SourceKit into IDE (NFC) 2021-03-09 13:52:56 -08:00
Doug Gregor
5013d20b86 Merge pull request #35784 from DougGregor/se-0296 2021-02-05 20:10:48 -08:00
Doug Gregor
238290cdc4 [SE-0296] Enable async/await by default.
Always parse `async` and `await`, allowing the definition and use of
asynchronous functions without the "experimental concurrency" flag.

Note that, at present, use of asynchronous functions requires one to
explicitly import or link against the `_Concurrency` library. We'll
sort this out in a follow-up change.

Tracked by rdar://73455330.
2021-02-05 09:51:46 -08:00
shreyaa-sharmaa
2b11d7acc7 Task SR-14138 Replace std::transform with llvm::transform 2021-02-04 12:58:33 +05:30
Rintaro Ishizaki
b856c15513 [CodeCompletion] Mark async calls "NotRecommended" in non-async context
rdar://problem/72198532
2021-01-13 11:46:54 -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
Rintaro Ishizaki
4c38ec5a4a Merge pull request #35069 from rintaro/ide-completion-rdar72199413
[Parse/CodeCompletion] Implement effects specifier completion
2020-12-15 13:11:18 -08:00
Rintaro Ishizaki
4284a51589 [Parse/CodeCompletion] Implement effects specifier completion
Rewrote and rename 'parseAsyncThrows' to 'parseEffectsSpecifiers'.
Implemented 'CodeCompletionCallbacks::completeEffectsSpecifier()'
2020-12-14 12:38:15 -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
Rintaro Ishizaki
5a7af5c673 [CodeCompletion][NFC] Rename addAsyncThrows to addEffectsSpecifiers 2020-12-14 12:24:44 -08:00
Rintaro Ishizaki
be7466eb3f [CodeCompletion] Annotate 'async' functions/initializers in results
Similar to how it shows "throws" today.

Introduced CodeCompletionStringChunk::ChunkKind::AsyncKeyword

rdar://problem/72198530
2020-12-14 11:03:24 -08:00
Rintaro Ishizaki
82eca57e13 [CodeCompletion] Complete 'await' in expression position
rdar://problem/72199267
2020-12-11 11:53:32 -08:00
Richard Wei
de2dbe57ed [AutoDiff] Bump-pointer allocate pullback structs in loops. (#34886)
In derivatives of loops, no longer allocate boxes for indirect case payloads. Instead, use a custom pullback context in the runtime which contains a bump-pointer allocator.

When a function contains a differentiated loop, the closure context is a `Builtin.NativeObject`, which contains a `swift::AutoDiffLinearMapContext` and a tail-allocated top-level linear map struct (which represents the linear map struct that was previously directly partial-applied into the pullback). In branching trace enums, the payloads of previously indirect cases will be allocated by `swift::AutoDiffLinearMapContext::allocate` and stored as a `Builtin.RawPointer`.
2020-11-30 15:49:38 -08:00
Nathan Hawes
240a26244d [CodeCompletion] Rename isSingleExpressionBody to isImplicitSingleExpressionReturn for clarity
This bool was true only for single-expression closure and function bodies that
do not have an explicit `return` in the source. Rename it and its associated
methods, to avoid confusion with the hasSingleExpressionBody methods on
ClosureExpr and AbstractFuncDecl. Those don't care whether the expression was
explicitly written in the source or not.
2020-11-19 13:33:57 +11:00
Nathan Hawes
ca7fb37aba [CodeCompletion][Sema][Parse] Migrate unresolved member completion to the solver-based completion implementation
Following on from updating regular member completion, this hooks up unresolved
member completion (i.e. .<complete here>) to the typeCheckForCodeCompletion API
to generate completions from all solutions the constraint solver produces (even
those requiring fixes), rather than relying on a single solution being applied
to the AST (if any). This lets us produce unresolved member completions even
when the contextual type is ambiguous or involves errors.

Whenever typeCheckExpression is called on an expression containing a code
completion expression and a CompletionCallback has been set, each solution
formed is passed to the callback so the type of the completion expression can
be extracted and used to lookup up the members to return.
2020-11-13 15:37:14 -08:00
Pavel Yaskevich
51bd8d93d6 Merge pull request #34510 from maustinstar/sr-11711
[SR-11711]  [Parse] Single-expression implicit returns within #if declarations
2020-11-05 21:14:44 -08:00
Rintaro Ishizaki
d221f14215 [CodeCompletion] Deduplicate results in ExprContextInfo
Using canonical types. Otherwise 'Optional<T>' and 'T?' aren't
considered the same.

Also, for example, the expected context types are 'T?' and 'T', don't
get results from 'T' twice.

rdar://problem/71063455
2020-11-05 11:32:16 -08:00
maustinstar
f6c9769bf0 Statement setter for last element 2020-11-03 22:20:23 -05:00
maustinstar
37b17338e5 [SR-11711] Single-expression returns for #if declarations within functions 2020-11-03 12:47:39 -05:00
Ben Barham
95ae19255e [CodeCompletion] Do not include decl in own (string interp) initializer
Strings are a single token, so the previous check would treat
completions inside string interpolations as being outside of the
initializer.

Grab the end of the token from the Lexer, but wrap in a context check to
avoid performing that for every declaration found in the lookup.

Resolves rdar://70833348
2020-11-03 16:42:28 +10:00
Ben Barham
4cf7426698 [CodeCompletion] Do not include decl completion in its own initializer
`::lookupVisibleDecls` had an inline consumer in order to remove
"unusable" results. Refactor this method, moving the consumer (now
`UsableFilteringDeclConsumer`) to allow its use when looking up top
level module declarations.

Also use the `AccessFilteringDeclConsumer` in preference to a condition
in `addVarDecl`.

Resolves rdar://56755598
2020-11-02 08:49:05 +10:00
Nathan Hawes
62a5fb1698 [CodeCompletion] Dedupe completion results if multiple lookups were made.
Solver-based member completion performs a lookup per solution, but if the base
types in each solution are variations of the same generic (e.g. Array<Int>,
Array<String>), we can end up with the same result appearing twice (e.g. count)
2020-10-26 15:41:24 -07:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Brent Royal-Gordon
e843a16649 Merge pull request #33935 from brentdax/these-imports-are-testing-my-patience
Add -testable-import-module frontend flag (+ refactoring)
2020-10-11 12:49:09 -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
Nathan Hawes
a91cede79b [Parse][CodeCompletion] Don't special case code completion when forming single-expression closures/function bodies (NFC)
Code completion used to avoid forming single expression closures/function
bodies when the single expression contained the code completion expression
because a contextual type mismatch could result in types not being applied
to the AST, giving no completions.

Completions that have been migrated to the new solver-based completion
mechanism don't need this behavior, however. Rather than trying to guess
whether the type of completion we're going to end up performing is one of
the ones that haven't been migrated to the solver yet when parsing, instead
just always form single-expression closures/function bodies (like we do for
regular compilation) and undo the transformation if and when we know we're
going to perform a completion kind we haven't migrated yet.

Once all completion kinds are migrated, the undo-ing code can be removed.
2020-10-09 16:02:13 -07:00
Varun Gandhi
d3369f7711 [NFC] Rename ImportFilterKind cases to be clearer. 2020-09-23 12:50:20 -07:00
Rintaro Ishizaki
d669247cd1 Merge pull request #33978 from rintaro/ide-completion-settyperelation
[CodeCompletion] Calculate type relation when adding type annotation
2020-09-17 13:59:52 -07:00
Rintaro Ishizaki
ee7f4ad3ae [CodeCompletion] Merge shouldUseFunctionReference to addCompoundFunctionName 2020-09-16 22:49:48 -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
Doug Gregor
25cd671ed5 [Code completion] Test and fix 'static func' for function builder methods. 2020-09-16 15:12:12 -07:00
Doug Gregor
51baa57c51 [Code completion] Add doc comments for function builder build functions
Add brief documentation comments to each of the code completions
produced for a build* function in a code completion.
2020-09-16 12:59:04 -07:00
Doug Gregor
20ab640e56 [Function builders] Add code completion for build* functions.
When performing code completion inside the declaration of a type with
the function builder attribute, also include completions for all of
the possible "build" functions.
2020-09-16 11:55:09 -07:00
Slava Pestov
1298f71554 Merge pull request #33922 from slavapestov/sil-parser-overhaul
SILParser: Fix for removal of parse-time name lookup
2020-09-12 08:11:26 -04:00
Slava Pestov
dbdbbff743 SILParser: Overhaul to not rely on parse-time lookup 2020-09-11 20:05:47 -04:00
Doug Gregor
3c49e46f4f Merge pull request #33906 from DougGregor/concurrency-actors
[Concurrency] Basic support for actor classes and actor isolation
2020-09-11 15:10:45 -07:00
Brent Royal-Gordon
cff4ddf13a [NFC] Adopt new ImportPath types and terminology
# Conflicts:
#	lib/IDE/CodeCompletion.cpp
2020-09-10 19:07:49 -07:00
Ben Barham
107ba0bab4 Merge pull request #33884 from bnbarham/completion-copy-cleanup
[Gardening] Add re-usable copy* utility methods to use in code completion
2020-09-11 08:22:28 +10:00
Doug Gregor
22a350b1ac [Concurrency] Add parsing support for actor classes.
Introduce the "actor class" syntax. Ensure that it is only used for
root classes or classes that inherit from other actor classes.
2020-09-09 20:46:30 -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
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
Nathan Hawes
b15c1fd349 [CodeCompletion] Deduplicate the two isMemberCompletion functions in ParseExpr.cpp and ParseDecl.cpp
Also:
- propagate the Solution -> Result rename to Solution parameter of deliverDotExprResults
- fixup header comment in CodeCompletionTypeChecking.h
2020-09-09 12:14:53 -07:00
Nathan Hawes
7a06792e5d [CodeCompletion] Remove unused field in CodeCompletionCallbacksImpl (NFC) 2020-09-08 17:31:43 -07:00