Commit Graph

618 Commits

Author SHA1 Message Date
Robert Widmann
84a07b99ae [NFC] VarDecls in Pattern Binding Initializers Have No Overload Type
Extend #27668 by declining to validate the type of variables
bound by a pattern binding initializer when computing an effective
overload type while rooted at that initializer.
2019-10-16 10:24:37 -07:00
Robert Widmann
0082ba5abc Remove VarDecl::markInvalid
Inline the interface type reset into its callers and make sure they're
also setting the invalid bit - which this was not doing before.
Unfortunately, this is not enough to be able to simplify any part of var
decl validation.
2019-10-14 12:46:39 -07:00
Pavel Yaskevich
773ac24bc9 [ConstraintSystem] Detect and diagnose type mismatch failures of inout parameters
Currently absence of `subtyping` is the only problem detected and diagnosed specifically
for `inout` parameters, but there could be type mismatches in `inout` positions as well
 and we can use `argument-to-parameter mismatch fix to detect and diagnose them.
2019-10-10 17:06:13 -07:00
Hamish Knight
ec45b24b63 Use hasAppliedSelf in getFunctionArgApplyInfo
`callee->hasCurriedSelf()` isn't the correct check
here when we have an argument mismatch for the
self parameter in a curried application.
2019-10-03 15:26:31 -07:00
Robert Widmann
75670c1727 Merge pull request #27436 from CodaFi/signed-sealed-delivered
[NFC] Adopt TypeBase-isms for GenericSignature
2019-09-30 15:50:42 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
Hamish Knight
b6b492d76a [CS] Rename LocatorPathElt::Requirement
Rename to LocatorPathElt::ProtocolRequirement in
order to help avoid confusion with
LocatorPathElt::AnyRequirement.
2019-09-29 14:19:57 -07:00
Pavel Yaskevich
10b1baebb2 Merge pull request #27362 from xedin/port-missing-args
[Diagnostics] Port missing argument(s) diagnostics
2019-09-25 21:08:54 -07:00
Slava Pestov
b1ffa19c7b AST: Refine recursive property checks on type alias types 2019-09-24 17:39:53 -04:00
Robert Widmann
f053f9c480 Port getInterfaceType() patterns in libSema 2019-09-23 16:49:29 -07:00
Pavel Yaskevich
ee8c78eef5 [Diagnostics] Tailored diagnostic when single tuple used instead of N distinct arguments
Diagnose cases when instead of multiple distinct arguments
call got a single tuple argument with expected arity/types:

```swift
func foo(_: Int, _: Int) {}
foo((0, 1)) // expected 2 arguments, got 1 tuple with 2 elements
```
2019-09-23 13:00:37 -07:00
Robert Widmann
b135928125 Drop CheckingWithValidSignature from the validation state machine
Now that the generic signature is computable on demand, this predicate is doubly useless.  All of the callers intended to ask "hasInterfaceType" anyways.
2019-09-20 22:22:49 -07:00
Robert Widmann
321d9b76e7 Remove a dead cycle check 2019-09-20 20:38:38 -07:00
Hamish Knight
58459e7439 [CS] Allow simplification of key path subscript arg locators (#27194)
[CS] Allow simplification of key path subscript arg locators
2019-09-17 14:28:59 +01:00
Robert Widmann
e0a41b19cb Break some cycles
Computing the generic signature changes the way that cycles appear in the compiler.  For now, break these cycles.  We should investigate each place where hasComputedGenericSignature() is used in service of breaking cycles.  See rdar://55263708
2019-09-16 12:50:24 -07:00
Hamish Knight
176969ddde [CS] Allow simplification of key path subscript arg locators
This allows a few fixes to properly emit
diagnostics for key path subscript argument
contextual failures.

Resolves SR-11476.
2019-09-15 21:39:32 +01:00
Hamish Knight
26dab57edd [CS] NFC: Inline recomputeSummaryFlags 2019-09-15 21:39:32 +01:00
Hamish Knight
4af9744fe3 [CS] NFC: Move simplifyLocator out of CSDiag
We eventually want to get rid of CSDiag, but
`simplifyLocator` is definitely something we want
to keep around.
2019-09-15 21:39:32 +01:00
Pavel Yaskevich
b898eaf326 [Diagnostics] Tailored diagnostics for reference equality operator mismatches 2019-09-13 22:35:52 -07:00
Pavel Yaskevich
90d725f701 [Diagnostics] Add special ambiguity diagnostics for operators
In cases when all of the fixed solutions have only one problem in
common - different overloads of a certain operator, let's
produce a tailored diagnostic and suggest matching partial
overloads along side diagnostic notes which point to each choice.
2019-09-13 22:35:52 -07:00
Pavel Yaskevich
8a4fcaa4ba [Diagnostics] Don't diagnoses missing Equatable in pattern-matching of invalid expressions
If expression is incorrect it most likely wouldn't be able to satisfy
`Equatable` or other requirements of `~=` operator overloads, but
at the same time the main problem is related to `case` expression
itself so let's not diagnose missing conformances.
2019-09-13 22:35:52 -07:00
Pavel Yaskevich
93b39c9c23 [Diagnostics] Port pattern-matching mismatch diagnostic
Port diagnostics associated with implicit use of `~=` operator
which is used in `case` statements.
2019-09-13 22:35:50 -07:00
Slava Pestov
de4b63defc Sema: Refactor typeCheckCheckedCast() a bit
This removes all calls to typesSatisfyConstraint() except for the
isConvertibleTo() check at the beginning, in the process making the
analysis a little bit more accurate.
2019-09-12 16:37:53 -04:00
Doug Gregor
c109f9058f [Type checker] Minor crash avoidance tweaks. 2019-09-11 21:05:43 -07:00
Hamish Knight
c745c17c38 Revert naming changes to getCalleeLocator & getChoiceFor
In addition, add a document comment to `getCalleeLocator` to clarify
its semantics.
2019-09-09 22:08:52 +01:00
Hamish Knight
67ee821123 [CS] Allow getCalleeLocator to find key path component callees
In order to do this we need it to take a ConstraintLocator argument so
we can tell which component we want the callee for. To make it clear
that we're looking for a callee at the anchor, also rename the member
to getAnchormostCalleeLocator.
2019-09-09 14:14:35 +01:00
Hamish Knight
8e0ec8df66 [CS] Allow getCalleeLocator to look through optional chaining 2019-09-05 22:25:25 +01:00
Hamish Knight
ee562b9379 [CS] Don't create new locator when simplifying to anchor (#26989)
[CS] Don't create new locator when simplifying to anchor
2019-09-02 20:37:30 +01:00
Pavel Yaskevich
5210e9b7c2 Revert "[AST] Paren'd reference to an IUO function crashes the compiler in SILGen" 2019-09-02 11:02:01 -07:00
Hamish Knight
fdbc21911b [CS] Don't create new locator when simplifying to anchor
We can directly use the version of `simplifyLocator` that works on
an anchor and path array ref instead.
2019-09-02 18:09:47 +01:00
Suyash Srijan
fc9fef2cf3 [CS] Be more defensive in isIUOWrappedInParens() check 2019-08-29 20:38:57 +01:00
Suyash Srijan
b32386bcac [CS] If locator points to a function call, then compare the fn and semanticFn, otherwise fall back to paren check
This is because otherwise we would have false positives, like 'Foo(Bar())' where Foo's init accepts a non-optional Bar and Bar's init returns an IUO
2019-08-29 01:12:32 +01:00
Suyash Srijan
a2daa11109 Merge branch 'master' into fix/SR-10492 2019-08-28 23:48:08 +01:00
Suyash Srijan
32cfd5bd19 [CS] Only check if the decl has a function type 2019-08-27 23:46:45 +01:00
Suyash Srijan
67971488dd [CS] Only check for the presence of a paren expr 2019-08-27 23:04:20 +01:00
Suyash Srijan
b33c5208c1 [CS] Extract the check into a separate lambda 2019-08-27 22:54:02 +01:00
Suyash Srijan
06607644f2 [CS] Move the check to resolveOverload() 2019-08-27 22:50:37 +01:00
Hamish Knight
ef1d5ab373 [CS] Look at the fn's rvalue type in getCalleeLocator
This makes sure we correctly resolve to the initialiser decl rather than
an lvalue local variable of a metatype in the included test case.
2019-08-27 15:59:08 +01:00
Slava Pestov
2dbeeb0d3f AST: Make SubstFlags::UseErrorType the default behavior
We've fixed a number of bugs recently where callers did not expect
to get a null Type out of subst(). This occurs particularly often
in SourceKit, where the input AST is often invalid and the types
resulting from substitution are mostly used for display.

Let's fix all these potential problems in one fell swoop by changing
subst() to always return a Type, possibly one containing ErrorTypes.

Only a couple of places depended on the old behavior, and they were
easy enough to change from checking for a null Type to checking if
the result responds with true to hasError().

Also while we're at it, simplify a few call sites of subst().
2019-08-22 01:07:50 -04:00
Hamish Knight
a0919f73b0 [CS] Use subclasses to expose locator element info
Instead of adding specific accessors directly to
ConstraintLocator::PathElement, add subclasses that expose these
accessors.
2019-08-19 11:58:49 +01:00
Doug Gregor
da267bf7ca [Constraint system] Switch TypeVariables to a SetVector.
There were a few places where we wanted fast testing to see whether a
particular type variable is currently of interest. Instead of building
local hash tables in those places, keep type variables in a SetVector
for efficient testing.
2019-08-16 14:13:15 -07:00
Slava Pestov
19d283d9dc AST: Replace ImplicitlyUnwrappedOptionalAttr with Decl::{is,set}ImplicitlyUnwrappedOptional() 2019-08-15 18:41:41 -04:00
Pavel Yaskevich
746cad564f Merge pull request #26459 from xedin/diag-conversion-to-specified-type
[ConstraintSystem] Add a fix to ignore contextual type mismatch
2019-08-14 12:58:09 -07:00
Doug Gregor
be73a9d641 [Function builders] Add one-way constraints when applying function builders
When we transform each expression or statement in a function builder,
introduce a one-way constraint so that type information does not flow
backwards from the context into that statement or expression. This
more closely mimics the behavior of normal code, where type inference
is per-statement, flowing from top to bottom.

This also allows us to isolate different expressions and statements
within a closure that's passed into a function builder parameter,
reducing the search space and (hopefully) improving compile times for
large function builder closures.

For now, put this functionality behind the compiler flag
`-enable-function-builder-one-way-constraints` for testing purposes;
we still have both optimization and correctness work to do to turn
this on by default.
2019-08-13 12:38:46 -07:00
Pavel Yaskevich
e7bff97929 [Diagnostics] NFC: Temporarily move couple of auxiliary functions to ConstraintSystem
Functions like `isRawRepresentable*` and `conformsToKnownProtocol`
have to be be shared between CSDiag and new diagnostics framework
until relevant code is removed from the former.
2019-08-13 11:55:08 -07:00
Pavel Yaskevich
45aec3c6ad [ConstraintSystem] NFC: Extract logic related to forming locator for argument info retrieval 2019-07-31 00:52:00 -07:00
Pavel Yaskevich
259ede3577 [ConstraintSystem] NFC: Refactor getCalleeLocator to avoid creating unnecessary locator 2019-07-31 00:00:21 -07:00
Pavel Yaskevich
32040ebd65 [ConstraintSystem] NFC: Refactor getArgumentInfo to accept ConstraintLocator 2019-07-31 00:00:21 -07:00
Pavel Yaskevich
29d1f6a705 [ConstraintSystem] Don't allow overwrites while collecting argument info
Currently, because argument info has been collected based solely
on anchor, it would be possible to overwrite labels for expressions
like `foo[0](x)` since `ApplyExpr` uses its function expression as
a key for argument information cache, which leads to errors while
attempting optimizations based on that information.
2019-07-31 00:00:21 -07:00
Pavel Yaskevich
e2dd9da5e3 [ConstraintSystem] NFC: Move argument info handling into constraint system 2019-07-31 00:00:21 -07:00