Commit Graph

1181 Commits

Author SHA1 Message Date
swift-ci
fd87ebc401 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-23 07:13:34 -07:00
Robert Widmann
d86551de67 Lift Requirement and Parameter Accessors up to GenericSignature
Start treating the null {Can}GenericSignature as a regular signature
with no requirements and no parameters. This not only makes for a much
safer abstraction, but allows us to simplify a lot of the clients of
GenericSignature that would previously have to check for null before
using the abstraction.
2021-07-22 23:27:05 -07:00
swift-ci
cdf7a9314f Merge remote-tracking branch 'origin/main' into rebranch 2021-07-22 21:54:12 -07:00
Rintaro Ishizaki
6c4eaa121d [CodeCompletion] Handle "unsafe" global actor isolation
For 'unsafe' global actor isolation, implicit "async" happens only if
* The context adopted concurrency feature
* Not '-warn-concurrency' specified

rdar://80907499
2021-07-22 15:17:20 -07:00
swift-ci
94817d06b4 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-20 09:13:59 -07:00
Rintaro Ishizaki
a14ba63d6a Merge pull request #38487 from rintaro/ide-completion-callargchunk 2021-07-20 09:11:52 -07:00
Rintaro Ishizaki
5559d9406f [CodeCompletion] NFC: rename CallParameter* to CallArgument*
Since these chunks are for call sites, the correct term is "argument".
2021-07-19 16:30:12 -07:00
swift-ci
bfeb8e4de7 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-19 10:34:31 -07:00
Hamish Knight
63c6f987de Merge pull request #38447 from hamishknight/fewer-substitutions-for-you 2021-07-19 18:14:09 +01:00
Hamish Knight
f90befe441 [CodeCompletion] Use substGenericArgs in getTypeOfMember
For a GenericFunctionType, use `substGenericArgs`
instead of `subst`, as the latter would form a bad
generic signature if there were UnresolvedTypes
present in the base type, causing the GSB to blow
up when attempting to canonicalize it.

rdar://80635105
2021-07-19 11:26:07 +01:00
swift-ci
9c09c7fb37 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-16 17:54: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
swift-ci
e0e2634b84 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-06 09:35:07 -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
Doug Gregor
80b6fbde88 Merge pull request #38186 from DougGregor/actors-and-global-actors
Semantic tweaks to (global) actors to bring them in line with the accepted proposals
2021-06-30 19:02:12 -07:00
Alex Hoppen
39e92db1b1 Merge pull request #38049 from ahoppen/pr/keypath-completion
[CodeCompletion] Migrate key path completion to be solver based
2021-06-30 22:03:44 +02:00
Doug Gregor
9ec20776c9 [SE-0306] Make actors semantically "final".
Treat actors as being semantically `final` throughout the type checker.
This allows, for example, a non-`required` initializer to satisfy a
protocol requirement.

We're leaving the ABI open for actor inheritance should we need it.

Addresses rdar://78269551.
2021-06-30 10:59:49 -07:00
Alex Hoppen
d64b8ecea6 [CodeCompletion] Migrate key path completion to be solver based
This commit essentially consistes of the following steps:
- Add a new code completion key path component that represents the code completion token inside a key path. Previously, the key path would have an invalid component at the end if it contained a code completion token.
- When type checking the key path, model the code completion token’s result type by a new type variable that is unrelated to the previous components (because the code completion token might resolve to anything).
- Since the code completion token is now properly modelled in the constraint system, we can use the solver based code completion implementation and inspect any solution determined by the constraint solver. The base type for code completion is now the result type of the key path component that preceeds the code completion component.

This resolves bugs where code completion was not working correctly if the key path’s type had a generic base or result type. It’s also nice to have moved another completion type over to the solver-based implementation.

Resolves rdar://78779234 [SR-14685] and rdar://78779335 [SR-14703]
2021-06-25 23:19:35 +02:00
Alex Hoppen
6725e2b850 [CodeComplete] Mark results as not recommended if global actor context doesn't match
Annotate cross-actor references to global actors as `async` and mark them as not-recommended if they must be executed on a different actor than the current context is on.

Resolves rdar://75902598
2021-06-17 23:13:55 +02:00
Rintaro Ishizaki
f553826ab2 [CodeCompletion] Don't modify CodeCompletionResult in place for cached results
Instead, allocate new `CodeCompletionResult` in the current sink.
2021-06-09 13:05:41 -07:00
Rintaro Ishizaki
5d5b93df8e [CodeCompletion] Make lookupCodeCompletionResultsFromModule() only accept
SourceFile as the decl context.
2021-06-08 16:06:10 -07:00
Rintaro Ishizaki
4617bbbebd [CodeCompletion] Apply 'ExprAtFileScope' when emitting keywords 2021-06-08 15:39:53 -07:00
Rintaro Ishizaki
1855e1a143 [CodeCompletion] Add flairs to cached items
* Starting a statement with a protocol name is rare
* Starting a statemnet at top-level of non-script file is invalid

rdar://77934897
2021-06-08 14:09:39 -07:00
Rintaro Ishizaki
a2b59688b0 [CodeCompletion] Add decl context dependent 'Flair' to decl keywords
* 'super' in a overriding decl is "common".
* type decl introducers (e.g. 'struct', 'enum') at top-level in library
  files are "common"
* type decl introducers in 'protocol' are invalid, hence "rare"
* top-level only decl introducer (e.g. 'import', 'extension') are invalid
  at non-top-level, hence "rare"
* nested types in function bodies are "rare"
* member only decls (e.g. 'subscript', 'deinit') are invalid in function
  body, hence "rare"
* some modifiers (e.g. 'public', 'private', 'override') are invalid for
  local decls, hence "rare"

rdar://77934651
2021-06-07 17:52:00 -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
Konrad `ktoso` Malawski
6008b32789 [Distributed] initial distributed support, fixed availability (#37650)
* [Distributed] Initial distributed checking

* [Distributed] initial types shapes and conform to DistributedActor

* [Distributed] Require Codable params and return types

* [Distributed] initial synthesis of fields and constructors

* [Distributed] Field and initializer synthesis

* [Distributed] Codable requirement on distributed funcs; also handle <T: Codable>

* [Distributed] handle generic type params which are Codable in dist func

[Distributed] conformsToProtocol after all

* [Distributed] Implement remote flag on actors

* Implement remote flag on actors

* add test

* actor initializer that sets remote flag

[Distributed] conformances getting there

* [Distributed] dont require async throws; cleanup compile tests

* [Distributed] do not synthesize default implicit init, only our special ones

* [Distributed] properly synth inits and properties; mark actorTransport as _distributedActorIndependent

Also:

- do not synthesize default init() initializer for dist actor

* [Distributed] init(transport:) designated and typechecking

* [Distributed] dist actor initializers MUST delegate to local-init

* [Distributed] check if any ctors in delegation call init(transport:)

* [Distributed] check init(transport:) delegation through many inits; ban invoking init(resolve:using:) explicitly

* [Distributed] disable IRGen test for now

* [Distributed] Rebase cleanups

* [Concurrent] transport and address are concurrent value

* [Distributed] introduce -enable-experimental-distributed flag

* rebase adjustments again

* rebase again...

* [Distributed] distributed functions are implicitly async+throws outside the actor

* [Distributed] implicitly throwing and async distributed funcs

* remove printlns

* add more checks to implicit function test

* [Distributed] resolve initializer now marks the isRemote actor flag

* [Distributed] distributedActor_destroy invoked instead, rather than before normal

* [Distributed] Generate distributed thunk for actors

* [distributed] typechecking for _remote_ functions existing, add tests for remote funcs

* adding one XFAIL'ed task & actor lifetime test

The `executor_deinit1` test fails 100% of the time
(from what I've seen) so I thought we could track
and see when/if someone happens to fix this bug.

Also, added extra coverage for #36298 via `executor_deinit2`

* Fix a memory issue with actors in the runtime system, by @phausler

* add new test that now passes because of patch by @phausler

See previous commit in this PR.
Test is based on one from rdar://74281361

* fix all tests that require the _remote_ function stubs

* Do not infer @actorIndependent onto `let` decls

* REVERT_ME: remove some tests that hacky workarounds will fail

* another flaky test, help build toolchain

* [Distributed] experimental distributed implies experimental concurrency

* [Distributed] Allow distributed function that are not marked async or throws

* [Distributed] make attrs SIMPLE to get serialization generated

* [Distributed] ActorAddress must be Hashable

* [Distributed] Implement transport.actorReady call in local init

* cleanup after rebase

* [Distributed] add availability attributes to all distributed actor code

* cleanup - this fixed some things

* fixing up

* fixing up

* [Distributed] introduce new Distributed module

* [Distributed] diagnose when missing 'import _Distributed'

* [Distributed] make all tests import the module

* more docs on address

* [Distributed] fixup merge issues

* cleanup: remove unnecessary code for now SIMPLE attribute

* fix: fix getActorIsolationOfContext

* [Distributed] cmake: depend on _concurrency module

* fixing tests...

* Revert "another flaky test, help build toolchain"

This reverts commit 83ae6654dd.

* remove xfail

* clenup some IR and SIL tests

* cleanup

* [Distributed] fix cmake test and ScanDependencies/can_import_with_map.swift

* [Distributed] fix flags/build tests

* cleanup: use isDistributed wherever possible

* [Distributed] don't import Dispatch in tests

* dont link distributed in stdlib unittest

* trying always append distributed module

* cleanups

* [Distributed] move all tests to Distributed/ directory

* [lit] try to fix lit test discovery

* [Distributed] update tests after diagnostics for implicit async changed

* [Distributed] Disable remote func tests on Windows for now

* Review cleanups

* [Distributed] fix typo, fixes Concurrency/actor_isolation_objc.swift

* [Distributed] attributes are DistributedOnly (only)

* cleanup

* [Distributed] cleanup: rely on DistributedOnly for guarding the keyword

* Update include/swift/AST/ActorIsolation.h

Co-authored-by: Doug Gregor <dgregor@apple.com>

* introduce isAnyThunk, minor cleanup

* wip

* [Distributed] move some type checking to TypeCheckDistributed.cpp

* [TypeCheckAttr] remove extra debug info

* [Distributed/AutoDiff] fix SILDeclRef creation which caused AutoDiff issue

* cleanups

* [lit] remove json import from lit test suite, not needed after all

* [Distributed] distributed functions only in DistributedActor protocols

* [Distributed] fix flag overlap & build setting

* [Distributed] Simplify noteIsolatedActorMember to not take bool distributed param

* [Distributed] make __isRemote not public

* [Distributed] Fix availability and remove actor class tests

* [actorIndependent] do not apply actorIndependent implicitly to values where it would be illegal to apply

* [Distributed] disable tests until issue fixed

Co-authored-by: Dario Rexin <drexin@apple.com>
Co-authored-by: Kavon Farvardin <kfarvardin@apple.com>
Co-authored-by: Doug Gregor <dgregor@apple.com>
2021-05-28 07:22:03 +09: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
Konrad `ktoso` Malawski
0c75bd2a39 Revert Initial distributed, some issues to be fixed first (#37556)
* Revert "[Distributed] disable tests until issue fixed"

This reverts commit 0a04278920.

* Revert "[Distributed] Initial `distributed` actors and functions and new module (#37109)"

This reverts commit 814ede0cf3.
2021-05-21 19:28:48 +09:00
Rintaro Ishizaki
1114f1b509 Merge pull request #37527 from rintaro/ide-compeltion-hiddenmodule-rdar78232229
[CodeCompletion] Don't suggest underscored module name
2021-05-20 18:23:09 -07:00
Konrad `ktoso` Malawski
814ede0cf3 [Distributed] Initial distributed actors and functions and new module (#37109)
* [Distributed] Initial distributed checking

* [Distributed] initial types shapes and conform to DistributedActor

* [Distributed] Require Codable params and return types

* [Distributed] initial synthesis of fields and constructors

* [Distributed] Field and initializer synthesis

* [Distributed] Codable requirement on distributed funcs; also handle <T: Codable>

* [Distributed] handle generic type params which are Codable in dist func

[Distributed] conformsToProtocol after all

* [Distributed] Implement remote flag on actors

* Implement remote flag on actors

* add test

* actor initializer that sets remote flag

[Distributed] conformances getting there

* [Distributed] dont require async throws; cleanup compile tests

* [Distributed] do not synthesize default implicit init, only our special ones

* [Distributed] properly synth inits and properties; mark actorTransport as _distributedActorIndependent

Also:

- do not synthesize default init() initializer for dist actor

* [Distributed] init(transport:) designated and typechecking

* [Distributed] dist actor initializers MUST delegate to local-init

* [Distributed] check if any ctors in delegation call init(transport:)

* [Distributed] check init(transport:) delegation through many inits; ban invoking init(resolve:using:) explicitly

* [Distributed] disable IRGen test for now

* [Distributed] Rebase cleanups

* [Concurrent] transport and address are concurrent value

* [Distributed] introduce -enable-experimental-distributed flag

* rebase adjustments again

* rebase again...

* [Distributed] distributed functions are implicitly async+throws outside the actor

* [Distributed] implicitly throwing and async distributed funcs

* remove printlns

* add more checks to implicit function test

* [Distributed] resolve initializer now marks the isRemote actor flag

* [Distributed] distributedActor_destroy invoked instead, rather than before normal

* [Distributed] Generate distributed thunk for actors

* [distributed] typechecking for _remote_ functions existing, add tests for remote funcs

* adding one XFAIL'ed task & actor lifetime test

The `executor_deinit1` test fails 100% of the time
(from what I've seen) so I thought we could track
and see when/if someone happens to fix this bug.

Also, added extra coverage for #36298 via `executor_deinit2`

* Fix a memory issue with actors in the runtime system, by @phausler

* add new test that now passes because of patch by @phausler

See previous commit in this PR.
Test is based on one from rdar://74281361

* fix all tests that require the _remote_ function stubs

* Do not infer @actorIndependent onto `let` decls

* REVERT_ME: remove some tests that hacky workarounds will fail

* another flaky test, help build toolchain

* [Distributed] experimental distributed implies experimental concurrency

* [Distributed] Allow distributed function that are not marked async or throws

* [Distributed] make attrs SIMPLE to get serialization generated

* [Distributed] ActorAddress must be Hashable

* [Distributed] Implement transport.actorReady call in local init

* cleanup after rebase

* [Distributed] add availability attributes to all distributed actor code

* cleanup - this fixed some things

* fixing up

* fixing up

* [Distributed] introduce new Distributed module

* [Distributed] diagnose when missing 'import _Distributed'

* [Distributed] make all tests import the module

* more docs on address

* [Distributed] fixup merge issues

* cleanup: remove unnecessary code for now SIMPLE attribute

* fix: fix getActorIsolationOfContext

* [Distributed] cmake: depend on _concurrency module

* fixing tests...

* Revert "another flaky test, help build toolchain"

This reverts commit 83ae6654dd.

* remove xfail

* clenup some IR and SIL tests

* cleanup

* [Distributed] fix cmake test and ScanDependencies/can_import_with_map.swift

* [Distributed] fix flags/build tests

* cleanup: use isDistributed wherever possible

* [Distributed] don't import Dispatch in tests

* dont link distributed in stdlib unittest

* trying always append distributed module

* cleanups

* [Distributed] move all tests to Distributed/ directory

* [lit] try to fix lit test discovery

* [Distributed] update tests after diagnostics for implicit async changed

* [Distributed] Disable remote func tests on Windows for now

* Review cleanups

* [Distributed] fix typo, fixes Concurrency/actor_isolation_objc.swift

* [Distributed] attributes are DistributedOnly (only)

* cleanup

* [Distributed] cleanup: rely on DistributedOnly for guarding the keyword

* Update include/swift/AST/ActorIsolation.h

Co-authored-by: Doug Gregor <dgregor@apple.com>

* introduce isAnyThunk, minor cleanup

* wip

* [Distributed] move some type checking to TypeCheckDistributed.cpp

* [TypeCheckAttr] remove extra debug info

* [Distributed/AutoDiff] fix SILDeclRef creation which caused AutoDiff issue

* cleanups

* [lit] remove json import from lit test suite, not needed after all

* [Distributed] distributed functions only in DistributedActor protocols

* [Distributed] fix flag overlap & build setting

* [Distributed] Simplify noteIsolatedActorMember to not take bool distributed param

* [Distributed] make __isRemote not public

Co-authored-by: Dario Rexin <drexin@apple.com>
Co-authored-by: Kavon Farvardin <kfarvardin@apple.com>
Co-authored-by: Doug Gregor <dgregor@apple.com>
2021-05-21 09:12:29 +09:00
Rintaro Ishizaki
98324f65e6 [CodeCompletion] Suggest explicitly imported modules regaredless 2021-05-20 12:52:49 -07:00
Rintaro Ishizaki
858ecb8413 [CodeCompletion] Don't suggest underscored module name
Underscored modules (e.g. '_Concurrency') are usually not meant be
written explicitly in source code. They are usually implicitly imported
with other modules. Code completion should not suggest them in type and
expression context.

rdar://78232229
2021-05-19 23:09:29 -07:00
Rintaro Ishizaki
5096ab7bc4 [CodeCompletion] Complete type attributes
Complete type attributes after '@' in a type position

rdar://44917341
2021-05-19 20:44:40 -07:00
Hamish Knight
010bcc1feb [CodeComplete] Include expr keywords in argument completion
When completing for an argument expression, make
sure to include keywords that can be used in an
expression position, such as `try`, `await` and
`super`.

rdar://77869845
2021-05-18 17:24:51 +01:00
Slava Pestov
131d3f4bce Sema: Pass down a ModuleDecl instead of a DeclContext to conformsToProtocol()
... and a bunch of follow-up simplifications pushing ModuleDecls further
up, since I couldn't resist the yak shave.
2021-05-17 16:34:18 -04: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
5ea60e8044 Merge pull request #37300 from rintaro/ide-completion-rdar76355581
[CodeCompletion] Complete pattern introducer for 'for'
2021-05-07 18:41:04 -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
b348bf60e1 [CodeCompletion] Complete pattern introducer for 'for'
After 'for', suggest 'try', 'await', 'var' and 'case'.

rdar://76355581
2021-05-06 18:13:43 -07:00
Alex Hoppen
3d1f9b6402 [CodeCompletion] Remove unresolved type from ParsedExpr during operator completion
When doing operator completion, we re-type-check the sequence expression. If we have an unresolve type already applied to `ParsedExpr`, which is the last element of the sequence, the type checker crashes in `validation-test/IDE/crashers_2_fixed/0008-must-conform-to-literal-protocol.swift`, because there are still inactive constraints in the constraint system when it finishes solving.

Previously, we would ignore because we allowed free type variables, which we no longer do since the last commit.
2021-05-06 18:35:00 +02: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
Alejandro Alonso
444c35cf8d Merge pull request #36953 from Azoy/isType-isDeclType
[NFC] Introduce isDecl and getDeclType
2021-04-20 15:33:00 -04:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
Ben Langmuir
fa476b0a8d [completion] Make NotRecommendedReason an enum class 2021-04-19 13:22:13 -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
Alex Hoppen
fd8e34913a Merge pull request #36551 from ahoppen/pr/internal-labels-in-closures
[CodeComplete] Default parameter names of completed closure to internal names
2021-04-06 15:30:26 +02:00
Alex Hoppen
865e80f9c4 [CodeComplete] Default parameter names of completed closure to internal names
If have a function that takes a trailing closure as follows
```
func sort(callback: (_ left: Int, _ right: Int) -> Bool) {}
```
completing a call to `sort` and expanding the trailing closure results in
```
sort { <#Int#>, <#Int#> in
  <#code#>
}
```

We should be doing a better job here and defaulting the trailing closure's to the internal names specified in the function signature. I.e. the final result should be
```
sort { left, right in
  <#code#>
}
```

This commit does exactly that.

Firstly, it keeps track of the closure's internal names (as specified in the declaration of `sort`) in the closure's type through a new `InternalLabel` property in `AnyFunctionType::Param`. Once the type containing the parameter gets canonicalized, the internal label is dropped.

Secondly, it adds a new option to `ASTPrinter` to always try and print parameter labels. With this option set to true, it will always print external paramter labels and, if they are present, print the internal parameter label as `_ <internalLabel>`.

Finally, we can use this new printing mode to print the trailing closure’s type as
```
<#T##callback: (Int, Int) -> Bool##(_ left: Int, _ right: Int) -> Bool#>
```

This is already correctly expanded by code-expand to the desired result. I also added a test case for that behaviour.
2021-04-01 19:14:19 +02:00
Rintaro Ishizaki
8c2e54bbde Merge pull request #36634 from rintaro/ide-completion-rdar75963052
[CodeCompletion] Stop suggesting initializer calls on unresolved member
2021-03-30 09:48:24 -07:00
Alex Hoppen
4faa3973ac Merge pull request #36607 from ahoppen/pr/suggest-self-in-where-clause
[CodeComplete] In where clauses, suggest Self and the current type
2021-03-30 13:17:45 +02:00