Commit Graph

1031 Commits

Author SHA1 Message Date
Robert Widmann
1491eb0ca3 [NFC] Drop Some Superfluous Null Signature Guards 2021-07-22 23:27:06 -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
Hamish Knight
d4c25f55c2 [AST] Reject GenericFunctionType in TypeBase::getTypeOfMember
Remove the default argument for the `memberType`
parameter and enforce that GenericFunctionType is
not passed. Also add a defaulted overload for the
property case, as they should never have a
GenericFunctionType interface type.
2021-07-20 14:11:31 +01:00
Pavel Yaskevich
d1e12785ed [Diagnostics] Diagnose ambiguous solutions with warnings like regular ambiguities
If solutions either have no fixes at all or all of the are warnings,
let's use `diagnoseAmbiguity` to diagnose such cases as-if there are
no fixes at all.

Resolves: rdar://79657350
2021-07-08 22:06:12 -07:00
Pavel Yaskevich
001884e268 Merge pull request #38235 from xedin/rdar-79757320
[Diagnostics] Ignore result type failures if one side is a hole
2021-07-06 13:52:07 -07:00
Robert Widmann
c64427fb6c Construct AutoClosureExpr With Deeper Parent Contexts
AutoClosureExprs created by the constraint system used to be constructed
with the decl context of the constraint system itself. This meant that
autoclosures in expressions nested in closures would initially be
parented onto any enclosing functions rather than the deepest closure
context. When we ran capture analysis and lookup from inside of the body
of these nascent values, we would fail to find declarations brought into
scope by those parent closures. This is especially relevant when
pre-typechecked code is involved since captures for those declarations
will be forced before their bodies have been recontextualized. See
issue #34230 for why we need to force things so early.

The attached test case demonstrates both bugs: The former a bogus lookup
through the parent context that would incorrectly reject this otherwise
well-formed code. The latter is a crash in SILGen when the capture
computation would fail to note $0.

Use the decl context of the solution application target, which is always
going to be the deepest user-written closure expression available to us,
and therefore the deepest scope that can introduce capturable variables.

rdar://79248469
2021-07-06 10:55:10 -07:00
Pavel Yaskevich
aea8d246b5 [ConstraintSystem] Resolve dependent member as a hole if base is one
Instead of preserving unresolved dependent member types, let's resolve
them as holes if their base has been determined to be one.
2021-07-02 12:57:21 -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
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
Holly Borla
939a861fe1 [ConstraintSystem] Add a constraint locator path element for tuple types,
which will provide context for tuple element mismatch diagnostics.
2021-06-23 19:18:11 -07:00
Luciano Almeida
0e8b7ceb18 [SR-13239] Adjust error message to split inferrence source into notes 2021-06-18 10:56:04 -03:00
Luciano Almeida
1903681554 [SR-12239] Adjusting ambiguit check to use solution argument binding to map arg to param 2021-06-18 10:56:04 -03:00
Luciano Almeida
2e4ea3b94c [Sema] Adjusments from review in SR-13239 and for variadic closure case 2021-06-18 10:56:04 -03:00
Luciano Almeida
c02f30f5c1 [Sema] Diagnose generic parameter contextual inference ambiguity between function call result and closure argument 2021-06-18 10:56:03 -03:00
Pavel Yaskevich
2b207e8f07 [Diagnostics] Augment "expected parameter" note with an argument type
Currently ambiguity notes attached to a candidate only mention
expected type and its position. To improve clarify of such notes
it's useful to print argument type as well since it's not always
clear what it is at the first glance at the code.

Resolves: SR-14634
Resolves: rdar://78224323
2021-05-26 12:58:35 -07:00
Hamish Knight
46fa6e5721 [AST] Improve BinaryExpr
Abstract away the TupleExpr gunk and expose
`getLHS` and `getRHS` accessors. This is in
preparation for completely expunging the use
of TupleExpr as an argument list.
2021-05-19 14:48:01 +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
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