Commit Graph

18963 Commits

Author SHA1 Message Date
Pavel Yaskevich
f5e672e985 Merge pull request #37216 from xedin/rdar-70610141
[Diagnostics] Improve diagnostics when passing `async` to a sync parameter
2021-05-05 10:10:05 -07:00
Pavel Yaskevich
0cca70b916 Merge pull request #37260 from xedin/rdar-76475495
[Sema] Suppress concurrency related diagnostics for invalid AST nodes
2021-05-05 10:09:51 -07:00
Pavel Yaskevich
0e9c33e47f [Sema] Suppress concurrency related diagnostics for invalid AST nodes
Expressions that failed type-check can't be correctly analyzed by
effects checker due to missing type and overload choice information.

Resolves: rdar://76475495
2021-05-04 14:25:07 -07:00
Pavel Yaskevich
2898b50b7f Revert "Revert "[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …"" 2021-05-04 11:19:33 -07:00
Pavel Yaskevich
c842773450 [Diagnostics] Re-phrase note about inferred async effect from an operation in a closure body 2021-05-04 10:09:03 -07:00
Pavel Yaskevich
5b897f67da Merge pull request #37221 from apple/revert-36946-rdar-61749633
Revert "[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …"
2021-05-04 09:40:05 -07:00
Slava Pestov
daceb1677a Sema: Allow unavailable conformances to be referenced from unavailable contexts
Relaxes the conformance availability check to match the Swift 5.3 behavior
with unavailable types.

Fixes rdar://problem/75430966.
2021-05-03 23:40:46 -04:00
adrian-prantl
43c5d8954b Merge pull request #37155 from adrian-prantl/75905336-1
Allow functions marked @LLDBDebuggerFunction to bypass actor isolatio…
2021-05-03 18:51:00 -07:00
Pavel Yaskevich
21c161d7ae Merge pull request #37209 from LucianoPAlmeida/nfc-record-hole
[NFC][Sema] Changing API to facilitate recording pontential holes recursively
2021-05-03 12:59:41 -07:00
Pavel Yaskevich
b12d57afac Revert "[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …" 2021-05-03 11:55:25 -07:00
Pavel Yaskevich
886a8ab6b7 [Diagnostics] Improve diagnostics when passing async to a sync parameter
If `async` effect has been inferred from the body of the closure,
let's find out the first occurrence of `async` node and point it out
to make it clear why closure is `async`.

Resolves: rdar://70610141
2021-05-03 11:08:36 -07:00
Pavel Yaskevich
53992d04b6 [ConstraintSystem] NFC: Extract async node identification into a function
It's useful not only for effect determination but for diagnostics as well.
2021-05-03 11:06:59 -07:00
Konrad `ktoso` Malawski
5bbba40fb5 Merge pull request #37194 from ktoso/cleanup
[TaskLocal] remove commented out code
2021-05-03 22:15:09 +09:00
Xi Ge
bbe5b83de9 Parser: teach canImport to take an additional parameter indicating the minimum module version
canImport should be able to take an additional parameter labeled by either version or
underlyingVersion. We need underlyingVersion for clang modules with Swift overlays because they
have separate version numbers. The library users are usually interested in checking the importability
of the underlying clang module instead of its Swift overlay.

Part of rdar://73992299
2021-05-02 17:47:44 -07:00
Luciano Almeida
c069e86f83 [NFC][Sema] Changing API to facilitate recording pontential holes recursively 2021-05-01 23:06:25 -03:00
Ikko Ashimine
97029aa9f9 Fix typo in CSStep.cpp
substition -> substitution
2021-05-02 02:20:20 +09:00
Konrad `ktoso` Malawski
6094f73487 [TaskLocal] remove commented out code 2021-05-01 10:04:00 +09:00
swift-ci
1e544b095f Merge pull request #37176 from DougGregor/remove-debug-dumps 2021-04-30 12:05:21 -07:00
John McCall
cc2863c136 Merge pull request #36878 from rjmccall/custom-executors
Introduce basic support for custom executors
2021-04-30 13:54:02 -04:00
Doug Gregor
8c180498e0 Remove stray debugging statements 2021-04-30 09:21:55 -07:00
Slava Pestov
7a15b7a453 Merge pull request #37157 from slavapestov/gsb-pre-cleanups-redundant-requirements-rewrite
GSB: Preliminary cleanups before redundant requirement algorithm rewrite
2021-04-30 10:19:18 -04:00
swift-ci
e152c14c0a Merge pull request #37162 from DougGregor/spawn-let 2021-04-30 02:19:16 -07:00
John McCall
186c53000d Introduce basic support for custom executors.
- Introduce an UnownedSerialExecutor type into the concurrency library.
- Create a SerialExecutor protocol which allows an executor type to
  change how it executes jobs.
- Add an unownedExecutor requirement to the Actor protocol.
- Change the ABI for ExecutorRef so that it stores a SerialExecutor
  witness table pointer in the implementation field.  This effectively
  makes ExecutorRef an `unowned(unsafe) SerialExecutor`, except that
  default actors are represented without a witness table pointer (just
  a bit-pattern).
- Synthesize the unownedExecutor method for default actors (i.e. actors
  that don't provide an unownedExecutor property).
- Make synthesized unownedExecutor properties `final`, and give them
  a semantics attribute specifying that they're for default actors.
- Split `Builtin.buildSerialExecutorRef` into a few more precise
  builtins.  We're not using the main-actor one yet, though.

Pitch thread:
  https://forums.swift.org/t/support-custom-executors-in-swift-concurrency/44425
2021-04-30 03:11:56 -04:00
Doug Gregor
1fa2d1656d [Concurrency] Don't complain about interpolation variables being mutated.
Implicitly-generated interpolation variables are mutated within the
autoclosures created by a `spawn let`. Don't complain about them being
concurrently accessed, because they aren't.

Fixes rdar://76020473.
2021-04-29 23:32:56 -07:00
Doug Gregor
41f42fabbf [Concurrency] Resyntax 'async let' as 'spawn let'.
This helps track the proposal.
2021-04-29 23:28:16 -07:00
Doug Gregor
5d8174da57 [Concurrency] Introduce spawn let 2021-04-29 22:42:40 -07:00
swift-ci
bf6c673fd3 Merge pull request #36959 from ktoso/wip-task-locals-revisions 2021-04-29 20:50:01 -07:00
Slava Pestov
35a2687afe GSB: Pass down requirement signature protocol to computeGenericSignature() 2021-04-29 23:35:14 -04:00
Adrian Prantl
5fe0c03d5f Allow functions marked @LLDBDebuggerFunction to bypass actor isolation checks
In order to allow LLDB to evaluate expressions inside an actor without spawining
async functions and potentially continue all threads, this relaxes the actor
isolation checks in @LLDBDebuggerFunction functions to allow a synchronous call
into an extension method.

rdar://75905336
2021-04-29 20:13:30 -07:00
Holly Borla
af649e7b41 Merge pull request #37143 from hborla/wrapped-parameter-mutability
[Property Wrappers] Always make sure the storage for a wrapped parameter is immutable.
2021-04-29 19:32:25 -07:00
Robert Widmann
847930bfb7 Don't Force the Interface Type While Checking Sendable
Asking for Sendable conformances on this path is going to lead to
a traversal of the stored properties of the type. If there is an
interface type computation ongoing, as is very likely the case, this
traversal can wind up causing a cycle when it forces the interface type
of a member once again.

Request only the non-structural conformances to break the cycle.

rdar://77189542
2021-04-29 13:11:32 -07:00
Holly Borla
d8b5d7d51d [Property Wrapper] For a wrapped parameter that is implementation detail,
make the backing stroage a let-constant.
2021-04-29 12:33:15 -07:00
Pavel Yaskevich
46bc3b672d Merge pull request #37115 from xedin/disable-only-in-perf
[CSSimplify] Allow overload choices with missing labels to be considered for diagnostics
2021-04-29 10:25:16 -07:00
Konrad `ktoso` Malawski
38a43a481e [TaskLocals] Enforce @TaskLocal may only be used on static props 2021-04-29 21:44:48 +09:00
Konrad `ktoso` Malawski
f0781b1f8b [TaskLocals] prettier API thanks to default inits 2021-04-29 15:48:23 +09:00
Pavel Yaskevich
f36ecf2fa1 [CSSimplify] Allow overload choices with missing labels to be considered for diagnostics
Let's make use of a newly added "disable for performance" flag to
allow solver to consider overload choices where the only issue is
missing one or more labels - this makes it for a much better
diagnostic experience without any performance impact for valid code.
2021-04-28 12:04:57 -07:00
Robert Widmann
fae8d9a713 Merge pull request #37073 from CodaFi/top-billing
[Gardening] Remove An Unused TLCD Checking Entrypoint
2021-04-27 22:57:15 -07:00
Holly Borla
2327f1004c Merge pull request #37093 from hborla/property-wrapper-diagnostic-crash
[Property Wrappers] Fix a diagnostic crash when a parameter has a wrapped value mismatch.
2021-04-27 18:36:07 -07:00
Pavel Yaskevich
957e05cfb1 [Constraint] Allow constraints to be disabled only in "performance" mode 2021-04-27 16:11:47 -07:00
Holly Borla
0248250a51 [Property Wrappers] Fix a diagnostic crash when a parameter has a wrapped value
mismatch.

If there's an error in property wrapper application, the backing property
wrapper type request will return a null type, which would cause the compiler
to crash because most error recovery code expects ErrorType. If the wrapper
application has an error, use the interface type of the parameter instead.
2021-04-27 12:56:52 -07:00
Alex Hoppen
ae21abaead Merge pull request #37034 from ahoppen/pr/subst-generic-params-mismatch
[Sema] Fix crash when retrieving typeContextInfo for a partially bound generic type
2021-04-27 17:19:06 +02:00
Alex Hoppen
af789d508e Merge pull request #37065 from ahoppen/pr/complete-from-constrained-extensions
[CodeComplete] Show completions from constrained protocol extension
2021-04-27 08:14:35 +02:00
Alex Hoppen
b70e91fbff [Sema] Fix crash when retrieving typeContextInfo for a partially bound generic type
In the following test case, we are crashing while building the generic signature of `someGenericFunc`, potentially invoked on `model` in line 11.

```swift
struct MyBinding<BindingOuter> {
  func someGenericFunc<BindingInner>(x: BindingInner) {}
}

struct MyTextField<TextFieldOuter> {
  init<TextFieldInner>(text: MyBinding<TextFieldInner>) {}
}

struct EncodedView {
    func foo(model: MyBinding<String>) {
        let _ = MyTextField<String>(text: model)
    }
}
```

Because we know that `model` has type `MyBinding<TextFieldInner>`, we substitute the `BindingOuter` generic parameter by `TextFieldInner`. Thus, `someGenericFunc` has the signature `<TextFieldInner /* substitutes BindingOuter */, BindingInner>`. `TextFieldInner` and `BindingOuter` both have `depth = 1`, `index = 0`. Thus the verification in `GenericSignatureBuilder` is failing.

After discussion with Slava, the root issue appears to be that we shouldn’t be calling `subst` on a `GenericFunctionType` at all. Instead we should be using `substGenericArgs` which doesn’t attempt to rebuild a generic signature, but instead builds a non-generic function type.

--------------------------------------------------------------------------------

We slightly regress in code completion results by showing two `collidingGeneric` twice in the following case.

```swift
protocol P1 {
  func collidingGeneric<T>(x: T)
}
protocol P2 {
  func collidingGeneric<T>(x: T)
}
class C : P1, P2 {
  #^COMPLETE^#
}
```

Previously, we were representing the type of `collidingGeneric` by a generic function type with generic param `T` that doesn’t have any restrictions. Since we are now using `substGenericArgs` instead of `subst`, we receive a non-generic function type that represents `T` as an archetype. And since that archetype is different for the two function signatures, we show the result twice in code completion.

One could also argue that showing the result twice is intended (or at least acceptable) behaviour since, the two protocol may name their generic params differently. E.g. in

```swift
protocol P1 {
  func collidingGeneric<S>(x: S)
}
protocol P2 {
  func collidingGeneric<T>(x: T)
}
class C : P1, P2 {
  #^COMPLETE^#
}
```

we might be expected to show the following two results
```
func collidingGeneric<S>(x: S)
func collidingGeneric<T>(x: T)
```

Resolves rdar://76711477 [SR-14495]
2021-04-27 08:13:54 +02:00
Rintaro Ishizaki
712e439fe9 Merge pull request #37069 from rintaro/ide-rdar76714968
[CodeCompletion] Peform complete `filterSolutions` in code completion
2021-04-26 18:21:41 -07:00
Robert Widmann
602aa3bd8b [Gardening] Remove An Unused TLCD Checking Entrypoint 2021-04-26 16:42:22 -07:00
Rintaro Ishizaki
848031825e [CodeCompletion] Peform complete filterSolutions in code completion
Not-filtering solutions causes unacceptable slownesses in some cases.
For now, filter solutions as normal typechecking does to restore the
performance.

rdar://76714968
2021-04-26 13:03:32 -07:00
Hamish Knight
ae37545a13 Merge pull request #37062 from hamishknight/sup
[AST] Remove 'is super' bit on ApplyExpr
2021-04-26 12:44:57 -07:00
Pavel Yaskevich
a21f323c16 Merge pull request #36946 from xedin/rdar-61749633
[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …
2021-04-26 12:19:55 -07:00
Alex Hoppen
b99ca7cae9 [CodeComplete] Show completions from constraint protocol extension
Consider the following example.

```swift
protocol FontStyle {}
struct FontStyleOne: FontStyle {}

extension FontStyle where Self == FontStyleOne {
    static var one: FontStyleOne { FontStyleOne() }
}

func foo<T: FontStyle>(x: T) {}
func case1() {
    foo(x: .#^COMPLETE^#)
}
```

With SE-0299 accepted, we should be suggesting `.one`.

For that, we need to consider the extension applied when performing the unresolved dot code completion with a primary archetype that conforms to `FontStyle`.

However, in the following case, which performs an unresolved dot completion on the same base type, we don't want to suggest `.one` because that would require `T == FontStyleOne`, which we can’t assume.

```swift
func case2<T: FontStyle>(x: T) {
    x.#^COMPLETE_2^#
}
```

Since the constraint system cannot tell us how it came up with the archetype, we need to apply a heuristic to differentiate between the two cases.

What seems to work fine in most cases, is to determine if `T` referes to a generic parameter that is visible from the decl context we are completing in (i.e. the decl context we are completing in is a child context of the context that `T` is declared in). If it is not, then `T` cannot be the type of a variable we are completing on. Thus, we are in the first case and we should consider all extensions of `FontStyle` because we can further specialize `T` by picking a more concrete type.
Otherwise `T` may be the type of a variable we are completing on and we should be conservative and only suggest those extensions whose requirements are fulfilled by `T`.

Since this is just a heuristic, there are some corner cases, where we aren’t suggesting constrainted extensions although we should. For example, in the following example the call to `testRecursive` doesn’t use `T` and we should thus suggest `one`. But by the rules described above we detect that `T` is accessible at the call and thus don’t apply extension whose requirements aren’t satisfied.

```swift
func testRecursive<T: FontStyle>(_ style: T) {
  testRecursive(.#^COMPLETE_RECURSIVE_GENERIC^#)
}
```

Similar completion issues also occurred without SE-0299 in more complicated, generic scenarios.

Resolves rdar://74958497 and SR-12973
2021-04-26 20:03:07 +02:00
Pavel Yaskevich
71372bce67 [Diagnostics] Switch to use contextual purpose associated with locator
`ContextualFailure` is the main beneficiary of additional information
associated with `ContextualType` element because it no longer has to
query solution for "purpose" of the contextual information.

Resolves: rdar://68795727
2021-04-26 09:51:25 -07:00