Commit Graph

15871 Commits

Author SHA1 Message Date
Pavel Yaskevich
0170c8949d [CSDiag] NFC: Remove obsolete @dynamicCallable diagnostics 2019-12-06 16:43:18 -08:00
Pavel Yaskevich
21a8b3c57d [Diagnostics] Port tailored diagnostics for missing dynamicallyCall methods 2019-12-06 16:43:18 -08:00
Pavel Yaskevich
328143ad4d [ConstraintSystem] Align @dynamicCallable argument locators with regular calls
Having the same locators for `@dynamicCallable` and the regular calls
make it much easier to produce diagnostics.
2019-12-06 16:43:18 -08:00
Pavel Yaskevich
b0d01de99a [ConstraintSystem] Add a special locator element for implicit @dynamicCallable calls 2019-12-06 16:43:18 -08:00
Pavel Yaskevich
184e238707 [Diagnostics] Improve diagnostics for mutating callAsFunction used on r-value 2019-12-06 16:43:18 -08:00
Robert Widmann
4d0dbe6368 Synthesize semantic members for override matching 2019-12-06 15:55:58 -08:00
Holly Borla
1e013a02cf [ConstraintSystem] Move FailureDiagnostic::getFunctionArgApplyInfo
into `ConstraintSystem`.
2019-12-06 15:43:39 -08:00
Pavel Yaskevich
08baf67677 [ConstraintSystem] Fix a case of too eager force optional unwrap with optional contextual type
If return of optional chaining is assigned to an optional type
or discarded there should be no force optional unwrap attempt
on it because type variable associated with context can be
bound to optional of any depth.

Resolves: rdar://problem/57668873
2019-12-06 15:03:19 -08:00
Robert Widmann
00407857d0 [NFC] Swap CodeCompletion's lookupQualified for TypeChecker's
This call relied on semantic member synthesis, so now it has to go through TypeChecker::lookupQualified.
2019-12-06 14:18:31 -08:00
Robert Widmann
dd51251014 Move semantic member synthesis into the type checker's lookup utilities
Pull these calls out of lookup itself to prevent re-entrancy.  Synthesizing these members can force a conformance check that can ultimately wind up back in lookup.  Pull the forcing out of every single qualified lookup and just install these members in the TypeChecker's entrypoints to lookup.

The upside is we can localize this gross hack, the downside is, of course, that we have to smear it across all of the lookup entrypoints.
2019-12-06 14:17:34 -08:00
Robert Widmann
5599df0748 Resolve CodingKeys before visiting member decls in the primary
Force this check to occur so that the interface types of members can successfully make reference to CodingKeys.  This is an egregious emergent behavior of Codable that currently forces two protocol conformance checks just to synthesize a type witness.  We can definitely get away with just creating the witness up front.

rdar://56844567
2019-12-06 14:14:13 -08:00
Hamish Knight
0c1330dd9e [CS] Resolve callees for callAsFunction .member exprs (#28604)
[CS] Resolve callees for callAsFunction `.member` exprs
2019-12-06 13:34:23 -08:00
Holly Borla
f9a1ab28f4 [ConstraintSystem] Port tuple type mismatches to the new framework 2019-12-06 13:12:57 -08:00
Doug Gregor
d23ab39a6f Merge pull request #28589 from DougGregor/wrapper-type-default-init-crash
[Property wrappers] Fix crash due to wrapped type/wrapper type confusion
2019-12-06 11:30:33 -08:00
Hamish Knight
8a83440ce1 [CS] Resolve callees for callAsFunction ".member" exprs
Apply the same checks as ApplyExprs to
UnresolvedMemberExprs in getCalleeLocator to
resolve callees in cases where they're used with
`callAsFunction` in addition to a weird edge case
where we currently allow them with constructor
calls, e.g:

```
struct S {
  static let s = S.self
}

let x: S = .s()
```

Arguably we should be representing ".member()"
expressions with an UnresolvedMemberExpr + CallExpr,
which would avoid the need to apply these special
cases, and reject the above syntax for not using
an explicit ".init". Doing so will likely require
a bit of hacking in CSGen though.

Resolves SR-11909.
2019-12-06 11:21:37 -08:00
swift-ci
fed5ff9440 Merge pull request #28606 from DougGregor/function-builders-pound-diag 2019-12-06 00:56:38 -08:00
Doug Gregor
36f67b2af1 [Property wrappers] Be sure to record the original value initializer! 2019-12-05 23:29:38 -08:00
Doug Gregor
6022b3838f [Function builders] Handle #warning and #error
Fixes rdar://problem/53209000.
2019-12-05 23:24:41 -08:00
Doug Gregor
f51119ad6b [Property wrappers] Sync up implicit "nil" initialization defaulting.
Perform implicit "nil" initialization for a wrapped property only when
the memberwise initializer's parameter is of the wrapped type.
2019-12-05 22:04:18 -08:00
Hamish Knight
40750c01fd [CS] Use different locators for nested 'wrappedValue' lookups
With the new way of caching overloads in the
constraint system, we no longer allow different
overloads to be resolved for the same locator in
the same scope.

Adjust the property wrapper logic
so that it appends Member locator elements for
nested lookups.
2019-12-05 14:47:52 -08:00
Hamish Knight
a97328dcbf [CS] Use a MapVector to cache resolved overloads
Rather than maintaining a linked list of overload
choices, which must be linearly searched each time
we need to lookup an overload at a given callee
locator, use a MapVector which can be rolled back
at the end of a scope.

Remove ResolvedOverloadSetListItem in favor of
using SelectedOverload, which avoids the need to
convert between them when moving from
ConstraintSystem to Solution.
2019-12-05 14:47:52 -08:00
Pavel Yaskevich
cafa338ae3 Merge pull request #28594 from xedin/rdar-50420029
[ConstraintSystem] Guard against infinite recursion in key path dynam…
2019-12-05 14:34:10 -08:00
swift-ci
b7d0264bc1 Merge pull request #28591 from DougGregor/nsobject-protocol-conformance 2019-12-05 13:10:59 -08:00
Pavel Yaskevich
1d393ebdd4 [ConstraintSystem] Guard against infinite recursion in key path dynamic member lookup
It's possible to construct subscript member responsible for key path
dynamic member lookup in a way which is going to be self-recursive
and an attempt to lookup any non-existent member is going to trigger
infine recursion.

Let's guard against that by making sure that the base type of the
member lookup is different from root type of the key path.

Resolves: rdar://problem/50420029
Resolves: rdar://problem/57410798
2019-12-05 12:42:17 -08:00
Pavel Yaskevich
d8997c6223 Merge pull request #28573 from xedin/remove-closure-handling-from-csdiag
[Diagnostics] Port last remaining closure expression diagnostics
2019-12-05 11:37:22 -08:00
Doug Gregor
345d1f420e Fix typo in comment 2019-12-05 11:36:21 -08:00
Doug Gregor
3fb77ea447 Provide a custom diagnostic for conformance to NSObjectProtocol
Swift classes cannot meaningfully conform to NSObjectProtocol.
Inheriting from NSObject is the appropriate fix, so suggest that.
Fixes rdar://problem/32543753.
2019-12-05 11:10:27 -08:00
Brent Royal-Gordon
63ec1cf5af Introduce a separate #filePath, remove -pound-file
This makes the path behavior more first-class. The feature is now hidden behind an experimental flag, -enable-experimental-concise-pound-file.
2019-12-04 16:35:13 -08:00
Pavel Yaskevich
5c56eea904 [CSDiag] Remove obsolete logic related to closure expression handling 2019-12-04 14:24:41 -08:00
Pavel Yaskevich
bbe0c098ba [ConstraintSystem] Avoid member lookup if base type is a "hole"
Member lookup on a "hole" is not going to produce any results
and it makes sense to detect early and short-circuit the constraint.
2019-12-04 14:23:12 -08:00
Pavel Yaskevich
805a5e9a1e [Diagnostics] Extend missing argument(s) diagnostic to support closure returns
If return type is a function, it's possible to return a closure
which can have some of its arguments unused in the body e.g.

`let _: () -> ((Int) -> Void) = { return { } }`

In this case resulting closure has to use its only parameter or
explictly ignore it by declaring `_ in`.
2019-12-04 14:22:46 -08:00
Hamish Knight
66afe772d5 [CS] Fix resolution of key path component callees (#28569)
[CS] Fix resolution of key path component callees
2019-12-04 13:43:07 -08:00
Pavel Yaskevich
3116d6ef8a Merge pull request #28539 from xedin/remove-constraint-handling-from-csdiag
[Diagnostics] Port diagnostics related to ambiguities and constraints
2019-12-04 12:15:26 -08:00
Hamish Knight
7e1a963cce [CS] Fix resolution of key path component callees
Previously we were just searching for a resolved
overload with the same component index and anchor
for the key path. However unfortunately that found
dynamic member lookup overloads in certain cases,
leading to an incorrect mutability capability.

Change the logic such that it uses the callee
locator for a given key path component, ensuring
we only match against the "direct" callee, and
not any dynamic members it might be also referring
to.

Resolves SR-11896.
2019-12-04 11:47:35 -08:00
Hamish Knight
e5ea69c0fc [CS] Fix key path dynamic member IUOs (#28562)
[CS] Fix key path dynamic member IUOs
2019-12-04 10:57:43 -08:00
Pavel Yaskevich
1be60a7c56 [ConstraintSystem] NFC: While diagnosing operator ambiguity use Identifier::is to compare names 2019-12-04 10:40:20 -08:00
Rintaro Ishizaki
12fd2078e2 Merge pull request #28319 from rintaro/ide-completion-rdar49697202
[CodeCompletion] Suggest the property name in its didSet clause
2019-12-04 09:47:48 -08:00
Varun Gandhi
e7be41d0cb Merge pull request #27479 from varungandhi-apple/vg-track-clang-function-types
Track Clang function types in the AST
2019-12-04 08:47:35 -08:00
Hamish Knight
d328b1b32a [CS] Correctly set key path component types
Previously we missed caching component types in
one case, and cached the wrong type in another.
Make both cases use cacheExprTypes to cache the
correct component types.
2019-12-04 08:43:06 -08:00
Hamish Knight
ef6a240372 [CS] Fix key path dynamic member IUOs
Previously we were only handling IUO unwrapping in
visitKeyPathExpr, but not for callers that were
building their own property and subscript
components such as dynamic member lookup.

Move the IUO unwrapping logic into
buildKeyPath[Property/Subscript]Component,
and adjust their signatures to allow them to
append multiple components. Also add
buildKeyPathOptionalForceComponent to allow more
convenient adding of an optional force component.

Resolves SR-11893.
2019-12-04 08:43:06 -08:00
Hamish Knight
c1849ba621 [CS] Refactor visitKeyPathExpr a little
Rather than setting `baseTy` for each component,
just set it for the last component in the
iteration. In addition, remove the `component`
variable, which no longer serves a purpose.
Finally, cache all the component types at the end
of the loop.
2019-12-04 08:43:06 -08:00
Hamish Knight
92a6302dcc [CS] Don't throw away unresolved key path components
When originally implemented (a5ca6ccd61),
we used to append the set `component` to
`resolvedComponents`, however that appears to have
been refactored away at some point, leaving a couple
of dead assignments. Restore the old behaviour by
just appending the components.
2019-12-04 08:43:05 -08:00
Rintaro Ishizaki
ad4b9df3c0 [CodeCompletion] Suggest the property name in its didSet clause
Previously, property names are hidden in the whole range of the
declarations. Now, it's only hidden in its own initializer range.

rdar://problem/49697202
2019-12-03 18:12:47 -08:00
Robert Widmann
371526bdea Add a high-level request to type check a file 2019-12-03 17:16:14 -08:00
Robert Widmann
b7537cf434 Merge pull request #28434 from CodaFi/rialto-repls
[NFC] Refactor @_dynamicReplacement Checking
2019-12-03 17:11:52 -08:00
Rintaro Ishizaki
83c1e7bf4a Merge pull request #28433 from rintaro/ide-completion-secondpassend
[CodeCompletion] Stop using temporary Lexer in the second pass
2019-12-03 17:08:58 -08:00
Robert Widmann
72e80c21f1 Bump the module format version
We've changed *what* is serialized by changing the way
@_dynamicReplacement is type checked, but not *how* it's
serialized.  Bump the format so there aren't strange incompatibilities
because of this.
2019-12-03 15:30:05 -08:00
Robert Widmann
4e36fc0bd5 Replace semantic usages of DynamicReplacementAttr with the request
Complete the refactoring by splitting the semantic callers for the original decl of a dynamically replaced declaration.

There's also a change to the way this attribute is validated and placed.  The old model visited the attribute on any functions and variable declarations it encountered in the primary.  Once there, it would strip the attribute off of variables and attach the corresponding attribute to each parsed accessor, then perform some additional ObjC-related validation.

The new approach instead leaves the attribute alone.  The request exists specifically to perform the lookups and type matching required to find replaced decls, and the attribute visitor no longer needs to worry about revisiting decls it has just grafted attributes onto.  This also means that a bunch of parts of IRGen and SILGen that needed to fan out to the accessors to ask for the @_dynamicReplacement attribute to undo the work the type checker had done can just look at the storage itself.  Further, syntactic requests for the attribute will now consistently succeed, where before they would fail dependending on whether or not the type checker had run - which was generally not an issue by the time we hit SIL.
2019-12-03 15:30:04 -08:00
Robert Widmann
c60b661c29 Add a request for replaced decls
Add DynamicallyReplacedDeclRequest to ValueDecl and plumb the request through to TypeCheckAttr where it replaces TypeChecker::findReplacedDynamicFunction.
2019-12-03 15:30:04 -08:00
Pavel Yaskevich
94b4052321 [CSDiag] NFC: Remove all of the obsolete diagnoseGeneral*Failures logic 2019-12-03 12:07:16 -08:00