Commit Graph

1014 Commits

Author SHA1 Message Date
Alex Hoppen
ad5dc2d76f [CodeComplete] Fix crash when completing inside a result builder containing a variable initialized with nil
Resolves rdar://78017503
2021-05-14 17:21:26 +02:00
Doug Gregor
220e29d674 Reinstate "async let", with "spawn let" as an alias. 2021-05-07 00:13:56 -07:00
Pavel Yaskevich
2f44f5bcd6 [ConstraintSystem] Extract logic that identifies application based on its argument node 2021-05-05 11:00:57 -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
Doug Gregor
5d8174da57 [Concurrency] Introduce spawn let 2021-04-29 22:42:40 -07: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
Nathan Hawes
f75f5fe78d Merge pull request #36879 from nathawes/track-match-call-result
[ConstraintSystem] Record parameter bindings in solutions (NFC)
2021-04-18 06:10:23 +10:00
Nathan Hawes
c57c403ffa [ConstraintSystem] Record parameter bindings in solutions (NFC)
This saves us from needing to re-match args to params in CSApply and is also
useful for a forthcoming change migrating code completion in argument position
to use the solver-based typeCheckForCodeCompletion api.

rdar://76581093
2021-04-16 18:32:06 +10:00
Doug Gregor
cdb7de19bf [Concurrency] References to global-actor functions have global-actor-qualified type.
When referencing a function that is on a global actor, e.g.,

    @MainActor func doSomething() -> Int

the result of that reference is a global-actor-qualified function type, e.g.,

    @MainActor () -> Int

Part of rdar://76030136.
2021-04-16 00:26:39 -07:00
Pavel Yaskevich
d57c112845 [ConstraintSystem] NFC: Replace isOperatorBindOverload with isOperatorDisjunction 2021-04-14 10:34:17 -07:00
Pavel Yaskevich
c9a289e1b5 [ConstraintSystem] Add a method to determine whether disjunction represents an operator 2021-04-13 15:43:15 -07:00
Slava Pestov
77e9025eea Sema: Don't score a solution higher if there's a sync-vs-async mismatch with a 'reasync' function
This fixes a performance regression with the reasync '&&', '||' and '??'
operators.

Also arguably it makes sense anyway since 'reasync' functions can in
fact be called from synchronous functions, so the solution should not
be considered worse.

We don't actually want to be able to overload a synchronous function
with a 'reasync' function anyway; the whole point of 'reasync' is to
avoid the need for such overloading.

Fixes rdar://problem/76254445.
2021-04-08 21:26:42 -04: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
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
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
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
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
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
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
Pavel Yaskevich
56c96c6b50 [CSBindings] Use all equivalence chain members while interring transitive protocols
Currently inference logic only checked direct equivalence class members
associated with a "work-in-progress" type variable, but each member can
have local equivalences as well that need to be accounted for.

Resolves: rdar://75978086
2021-03-30 13:39:12 -07:00
Slava Pestov
8b4d58988d Sema: Fix effect checking issues with 'async let' and string interpolation 2021-03-29 23:49:33 -04:00
Doug Gregor
52096a640e SE-0302: Rename ConcurrentValue/@concurrent to Sendable/@Sendable. 2021-03-18 23:48:21 -07:00
Pavel Yaskevich
3c731d8748 [TypeChecker] Add a flag to disable Double<->CGFloat implicit conversion 2021-03-17 00:18:19 -07:00
Pavel Yaskevich
8c4a0dcd74 [ConstraintSystem] Simplify handling of implicit conversions in getArgumentInfo 2021-03-17 00:18:11 -07:00
Pavel Yaskevich
8c6017687a [ConstraintSystem] Limit new implicit conversion to only Double <-> CGFloat 2021-03-17 00:18:10 -07:00
Pavel Yaskevich
9d9a8d6a26 [ConstraintSystem] Start using implicit conversion to/from CGFloat
Add logic to `matchTypes` to insert an implicit conversion to/from
CGFloat type when two nominal types are matched and one of them is
of `CGFloat` type.
2021-03-17 00:18:09 -07:00
Pavel Yaskevich
2b935bab7c [ConstraintSystem] Add conversion restriction to cover implicit conversion from/to CGFloat 2021-03-17 00:18:08 -07:00
Pavel Yaskevich
4ca67f6d27 [ConstraintSystem] Teach getFunctionArgApplyInfo about inout expressions
Currently `getFunctionArgApplyInfo` expects a locator with `ApplyArgToParam`
element to identify location of the argument. `InOutExpr` could only be used
in argument positions but it doesn't have the same locator format as non-inout
arguments, so `getFunctionArgApplyInfo` needs to do some digging in the AST
to retrieve that information.

Resolves: rdar://75146811
2021-03-16 20:12:34 -07:00
David Zarzycki
b80ca8e8eb Merge pull request #36234 from davezarzycki/pr36234
[AST] NFC: Make ExtInfo param Optional<>
2021-03-12 13:47:22 -05:00
Anthony Latsis
79c0d93b86 Sema: Fix dynamic Self behavior for a «super» base expression 2021-03-09 19:20:43 +03:00
Anthony Latsis
8242d843cd NFC, Sema: Further propagate the locator through to doesStorageProduceLValue 2021-03-09 17:01:50 +03:00
Anthony Latsis
42e510c260 NFC, Sema: Derive base expr from locator in getTypeOfMemberReference 2021-03-09 17:01:45 +03:00
David Zarzycki
c0ec6c3235 [AST] NFC: Make ExtInfo param Optional<>
While it is very convenient to default the ExtInfo state when creating
new function types, it also make the intent unclear to those looking to
extend ExtInfo state. For example, did a given call site intend to have
the default ExtInfo state or does it just happen to work? This matters a
lot because function types are regularly unpacked and rebuilt and it's
really easy to accidentally drop ExtInfo state.

By changing the ExtInfo state to an optional, we can track when it is
actually needed.
2021-03-09 05:57:39 -05:00
Doug Gregor
9ccf206feb [Concurrency] Tune overloading to to allow sync overloads in async contexts.
The existing overloading rules strongly prefer async functions within
async contexts, and synchronous functions in synchronous contexts.
However, when there are other differences in the
signature, particularly parameters of function type that differ in
async vs. synchronous, the overloading rule would force the use of the
synchronous function even in cases where the synchronous function
would be better. An example:

    func f(_: (Int) -> Int) { }
    func f(_: (Int) async -> Int) async { }

    func g(_ x: Int) -> Int { -x }

    func h() async {
      f(g) // currently selects async f, want to select synchronous f
    }

Effect the semantics change by splitting the "sync/async mismatch"
score in the constraint system into an "async in sync mismatch" score
that is mostly disqualifying (because the call will always fail) and a
less-important score for "sync used in an async context", which also
includes conversion from a synchronous function to an asynchronous
one. This way, only synchronous functions are still considered within
a synchronous context, but we get more natural overloading behavior
within an asynchronous context. The end result is intended to be
equivalent to what one would get with reasync:

  func f(_: (Int) async -> Int) async { ... }

Addresses rdar://74289867.
2021-03-02 23:14:08 -08:00
Pavel Yaskevich
b487b6956b [ConstraintSystem] Delay inference until let's clear that type variable attempt is successful
Currently bindings where inferred on every `bindTypeVariable` call,
but that's wasteful because not all binds are always correct. To
avoid unnecessary inference traffic let's wait until re-activated
constraints are simplified and notify binding inference about new
fixed type only if all of them are successful.
2021-03-01 10:52:29 -08:00
Pavel Yaskevich
654ec0d511 [ConstraintSystem] NFC: Modernize SK_NonDefaultLiteral inference 2021-03-01 10:52:29 -08:00
Slava Pestov
b007800aca Merge pull request #36170 from slavapestov/requirement-get-protocol-decl
AST: Factor out a new Requirement::getProtocolDecl() utility method
2021-02-26 11:19:32 -05:00
Holly Borla
b7a170cd77 [NFC][ConstraintSystem] Rename applyPropertyWrapperParameter. 2021-02-25 18:35:14 -08:00
Holly Borla
db387273f6 [ConstraintSystem] Don't allow dollar prefixes in argument labels unless
the parameter has an attached property wrapper.
2021-02-25 18:35:14 -08:00
Holly Borla
31f7b1ac75 [ConstraintSystem] Change the type of an unapplied function reference
when it has property wrapper parameters.

The property wrapper type will be replaced with either the wrapped-value
or projected-value type, depending on the argument label/parameter name,
and CSApply will build a thunk to construct the property wrapper and call
the function.
2021-02-25 18:35:13 -08:00
Holly Borla
19a4f93586 [Property Wrappers] Teach the constraint system to build init(projectedValue:)
calls.
2021-02-25 18:35:13 -08:00
Slava Pestov
53e06d69b5 AST: Factor out a new Requirement::getProtocolDecl() utility method 2021-02-25 17:21:18 -05:00
Pavel Yaskevich
df7af0078f [CSBindings] Separate inference storage from final product usable by the solver
`PotentialBindings` lost most of its responsibilities,
and are no longer comparable. Their main purpose now
is binding and metadata tracking (introduction/retraction).

New `BindingSet` type is something that represents a set
of bindings at the current step of the solver.
2021-02-24 10:37:20 -08:00
Pavel Yaskevich
c44a92ae0b [ConstraintSystem] Implement new rule for static member lookup in generic contexts
Instead of requiring result type of the member to conform to declaring protocol,
as originally proposed by SE-0299, let's instead require `Self` to be bound to
some concrete type in extension that declares a static member.

This would make sure that:

1. Members are only visible on a particular type;
2. There is no ambiguity regarding what base of the member chain is going to be.
2021-02-23 11:33:11 -08:00
Pavel Yaskevich
74d2a6c700 [ConstraintSystem] Limit static member reference on protocol metatype to leading dot syntax only
Do not allow references to a static members with explicitly specified
protocol metatype base, limit that to leading dot syntax only.
2021-02-23 11:33:11 -08:00
Pavel Yaskevich
9a584550d2 [ConstraintSystem] Ignore optionals when looking for a concrete base of a static member ref on protocol metatype 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
d1ab178471 [ConstraintSystem] Diagnose conformance failure with base of a static member lookup
Produce a tailored diagnostic when it has been established that
base type of a static member reference on protocol metatype doesn't
conform to a required protocol.
2021-02-23 11:33:10 -08:00