Commit Graph

18963 Commits

Author SHA1 Message Date
Pavel Yaskevich
dd67132fd9 Merge pull request #36793 from xedin/rdar-52204608
[Diagnostics] Contextual mismatch should be attached to the closure i…
2021-04-07 14:07:56 -07:00
Pavel Yaskevich
df8113b5dd [Diagnostics] Contextual mismatch should be attached to the closure if its body is empty/implicit
If there is a contextual mismatch associated with a closure body,
make sure that the diagnostic is attached to the closure even
if the body is empty or implicit.

Resolves: rdar://52204608
2021-04-07 10:06:34 -07:00
Pavel Yaskevich
583d617254 Merge pull request #36786 from xedin/partial-note-crash-objc-optionals
[Diagnostics] Fix crash while trying to print candidates for a option…
2021-04-07 10:04:48 -07:00
Luciano Almeida
a028a0dc2c [CSGen] Removing code that was only necessary for failure diagnostics 2021-04-06 23:40:23 -03:00
Evan Wilde
59a218a50a Merge pull request #36763 from etcwilde/ewilde/fix-try-await-fix-it
[Concurrency] Fix try-await fix-it
2021-04-06 18:30:05 -07:00
Pavel Yaskevich
a16d557fd0 [Diagnostics] Fix crash while trying to print candidates for a optional @objc method reference 2021-04-06 16:20:57 -07:00
Slava Pestov
75dcd346d5 Merge pull request #36761 from slavapestov/for-await-concrete-conformance-fix
Sema: Fix effects checking of 'for await' with a concrete conformance
2021-04-06 18:06:28 -04:00
Evan Wilde
8e63412e61 Emit 'try' before 'await' in fix-it
Actually put the try fix-it before the await if it is available.
2021-04-06 09:58:59 -07:00
Evan Wilde
fdbaedc568 Plumb await location through to diagnostics
We want to be able to put the `try` before the `await`, so we need to
make it available where we emit the diagnostics and fix-its.
The easiest way to do that was through the context object.
2021-04-06 09:58:59 -07:00
Holly Borla
95f8ed8807 Merge pull request #36711 from hborla/property-wrapper-availability-inference
[Property Wrappers] Fix availability inference of synthesized property wrapper setters
2021-04-06 09:30:06 -07:00
Doug Gregor
87cbb88a08 Merge pull request #36771 from DougGregor/infer-type-from-property-wrapper 2021-04-06 08:01:00 -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
Doug Gregor
1f33aa9586 Infer a type's actor isolation from the property wrappers it uses.
Fixes rdar://76252310.
2021-04-05 23:13:52 -07:00
Evan Wilde
54a0e1901d Merge pull request #36757 from etcwilde/ewilde/fix-conditional-effects-simple-display
Stop simple_display from crashing
2021-04-05 17:29:06 -07:00
Holly Borla
0a5de7a659 [Property Wrappers] Implement availability inference for the _modify accessor
of a wrapped property.
2021-04-05 15:59:53 -07:00
Holly Borla
1efb638681 [Sema] Add a helper function to get the innermost declaration with an
@available annotation.
2021-04-05 15:39:10 -07:00
Slava Pestov
d6db99a442 Sema: Fix effects checking of 'for await' with a concrete conformance
AsyncSequence is only polymorphic over 'throws' effects, not 'async',
because it is @rethrows and not @reasync. So the logic here was wrong,
and it would incorrectly conclude that a 'for await' with a concrete
conformance did not require the outer function to be 'async'.

Fixes rdar://problem/75436909.
2021-04-05 18:26:36 -04:00
Evan Wilde
8b27425f80 Stop simple_display from crashing
All code-paths in simple-display led to the llvm_unreachable being hit.
Returning from the switch-cases lets us not do that, which is good.
2021-04-05 10:34:34 -07:00
Pavel Yaskevich
1d8c2a10c6 Merge pull request #36545 from xedin/rdar-75476311
[ConstraintSystem] Bind external closure parameter type to a concrete…
2021-04-05 10:04:42 -07:00
Robert Widmann
a5a79f23c0 Merge pull request #36721 from CodaFi/resoulver
[NFC] Move Some Type Resolution Methods from TypeChecker to TypeResolution
2021-04-04 23:15:19 -07:00
Pavel Yaskevich
225e2dbeed [ConstraintSystem] Bind external closure parameter type to a concrete contextual type
Performance optimization.

If there is a concrete contextual type we could use, let's bind
it to the external type right away because internal type has to
be equal to that type anyway (through `BindParam` on external type
i.e. <internal> bind param <external> conv <concrete contextual>).

```swift
func test(_: ([String]) -> Void) {}

test { $0 == ["a", "b"] }
```

Without this optimization for almost all overloads of `==`
expect for one on `Equatable` and one on `Array` solver would
have to repeatedly try the same `[String]` type for `$0` and
fail, which does nothing expect hurts performance.

Resolves: rdar://19836070
Resolves: rdar://19357292
Resolves: rdar://75476311
2021-04-02 22:11:03 -07:00
Slava Pestov
f1831fb16a Sema: Teach rethrows checking about 'nil' default arguments
In Swift 5.4, this worked:

  func foo(_: (() throws -> ())? = nil) rethrows {}
  foo()  // no 'try' needed

However, this was an accident, because this was also accepted:

  func foo(_: (() throws -> ())? = { throw ... }) rethrows {}
  foo()  // 'try' *should* be required here

This got fixed at some point recently, but since people rely on the
old case working for 'nil', let's add back a check for a 'nil'
default parameter.

Fixes rdar://problem/76169080.
2021-04-02 23:56:59 -04:00
Doug Gregor
d3d2d75b4d Merge pull request #36698 from DougGregor/actor-escaping-isolation
[Actors] Permit non-sendable, escaping closures to be actor-isolated.
2021-04-02 13:01:17 -07:00
Robert Widmann
2c5166dbfa [NFC] Move applyUnboundGenericArguments to TypeResolution 2021-04-02 09:07:29 -07:00
Robert Widmann
fe959c55b2 [NFC] Move resolveTypeInContext to TypeResolution 2021-04-02 09:07:29 -07:00
Doug Gregor
f8cb209c5a Only diagnose references to globals under -warn-concurrency.
Fixes rdar://75996222.
2021-04-02 00:06:48 -07:00
Holly Borla
85e3c7b97e Merge pull request #36696 from hborla/wrapped-parameter-accessor-synthesis
[Property Wrappers] Fix accessor synthesis of wrapped parameters that infer the property wrapper attribute.
2021-04-01 18:14:56 -07:00
Holly Borla
e1de140dbb [Property Wrappers] Intersect the availability of the wrapped/projected value
setter with the availability of the enclosing scope when inferring the
availability of the synthesized setters for an applied property wrapper.
2021-04-01 18:11:05 -07: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
Doug Gregor
5ecb9ebec2 [Actors] Permit non-sendable, escaping closures to be actor-isolated.
Remove the heuristic that escaping closures cannot be actor-isolated.
This is in line with the long term plan for actor isolation, but opens
up some holes in the short term because Sendable closures are not enforced
throughout the Swift ecosystem.

One significant effect of this change is that we will now, statically,
fail to detect many cases where actor isolation can be broken.
2021-03-31 23:22:56 -07:00
Slava Pestov
df6ad7ffad Merge pull request #36679 from uuttff8/Remove-unused-DeclContext-parameter-from-canDecompose
Remove unused DeclContext
2021-04-01 01:28:04 -04:00
Holly Borla
2a4cc912b6 [Property Wrappers] Fix accessor synthesis of wrapped parameters that infer
the property wrapper attribute.
2021-03-31 18:38:41 -07:00
Holly Borla
ad3568e52e Merge pull request #36344 from hborla/property-wrapper-parameter-revision
[SE-0293] Implement revision #3 of property wrapper parameters
2021-03-31 15:49:01 -07:00
Doug Gregor
d66382d8be Merge pull request #36676 from DougGregor/unsafe-concurrency-attrs
[Concurrency] Introduce "unsafe" @Sendable and @MainActor parameter attributes
2021-03-31 15:41:10 -07:00
Pavel Yaskevich
1e9ae59869 Merge pull request #36681 from xedin/revert-implicit-conversion-flag
Revert "[TypeChecker] Add a flag to disable Double<->CGFloat implicit…
2021-03-31 15:36:39 -07:00
Saleem Abdulrasool
c03c3b266d Merge pull request #36592 from drexin/wip-remove-codable-enum-flag
[Frontend] Remove enable-experimental-enum-codable-derivation flag
2021-03-31 15:04:32 -07:00
Slava Pestov
48b729d2f2 Merge pull request #36641 from slavapestov/more-reasync-fixes
More 'reasync' fixes
2021-03-31 15:43:59 -04:00
Pavel Yaskevich
8e401d2413 Merge pull request #36657 from xedin/rdar-75978086
[CSBindings] A couple of adjustments to transitive protocol inference
2021-03-31 12:31:13 -07:00
Pavel Yaskevich
ed8491c15b Revert "[TypeChecker] Add a flag to disable Double<->CGFloat implicit conversion"
This reverts commit 3c731d8748.
2021-03-31 11:10:21 -07:00
Josh Learn
a6da8a8899 Support constant diagnostics on constructors
This change includes a fix to allow the diagnostics
for constantness in function arguments to work properly
for constructors. This change also includes some minor
code cleanup in the constantness diagnostic pass.
2021-03-31 11:06:55 -07:00
Pavel Yaskevich
f00c578761 Merge pull request #34401 from xedin/implicit-cgfloat-conversion
[DNM][TypeChecker] Implement Double <-> CGFloat implicit conversion
2021-03-31 10:20:28 -07:00
Doug Gregor
f02a01e4f2 Add @_unsafeMainActor corresponding to @MainActor 2021-03-31 09:40:41 -07:00
Doug Gregor
b68f8555b3 [Concurrency] Introduce "unsafe" @Sendable and @MainActor parameters.
Introduce the notion of "unsafe" @Sendable parameters, indicated by the
hidden @_unsafeSendable parameter attribute. Closure arguments to such
parameters are treated as @Sendable within code that has already
adopted concurrency, but are otherwise enert, allowing them to be
applied to existing concurrency-related APIs to smooth the transition
path to concurrency.

Additionally, introduce the notion of an "unsafe" @MainActor closure,
for cases where we have determined that the closure will execute on
the main actor but it (also) isn't part of the type system.

Pattern-match uses of the Dispatch library's DispatchQueue to infer
both kinds of "unsafe" as appropriate, especially (e.g.) matching the pattern

  DispatchQueue.main.async { ... }

to treat the closure as unsafe @Sendable and @MainActor, allowing such
existing code to better integrate with concurrency.

Implements rdar://75988966.
2021-03-31 09:40:03 -07:00
Holly Borla
a11e2455b0 [Property Wrappers] Fixes and tests for inaccessible and unavailable
parameter wrappers.
2021-03-31 09:29:46 -07:00
Holly Borla
833a665027 [Property Wrappers] Correct the source location of applied property
wrapper expressions in property wrapper parameter thunks, and add
SILGen tests for property wrapper parameters in inlinable functions.
2021-03-31 09:29:46 -07:00
Holly Borla
a15f4233a2 [Property Wrappers] Implement implementation-detail property wrappers for
parameters.
2021-03-31 09:29:46 -07:00
Doug Gregor
e0bd26942e Cleanup check for whether a context uses concurrency features 2021-03-31 09:03:14 -07:00
Anton Kuzmin
1faff5e049 Remove unused DeclContext 2021-03-31 14:48:06 +03:00
Ben Barham
7a17592df8 Merge pull request #36616 from bnbarham/infer-completionhandlerasync
[ClangImporter] Add @completionHandlerAsync for imported decls
2021-03-31 18:31:18 +10:00
Doug Gregor
46f167bc54 Merge pull request #36644 from DougGregor/further-global-actor-inference
[Actor inference] Extend global actor inference
2021-03-30 23:14:17 -07:00