Commit Graph

581 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
effd0d00c6 Merge pull request #26302 from xedin/remove-label-mismatch-from-lookup
[Diagnostics] Don't filter overload set candidates based on labels in lookup
2019-07-26 10:34:23 -07:00
Pavel Yaskevich
654c1ae219 [ConstaintSystem] Adjust getEffectiveOverloadType to ignore Optional.init 2019-07-25 00:36:00 -07:00
Doug Gregor
8355f3d270 [Constraint graph] Move constraint uniquing into gatherConstraints().
Simplify the interface to gatherConstraints() by performing the
uniquing within the function itself and returning only the resulting
(uniqued) vector of constraints.
2019-07-25 02:26:49 -04:00
Pavel Yaskevich
783add0ea4 [CSDiagnostics] Split no exact match diagnostic into three choices
1. If this is a special name avoid printing it because
   printing kind is sufficient;

2. If all of the labels match, print a full name;

3. If labels in different choices are different, it means
   that we can only print a base name.
2019-07-22 12:32:17 -07:00
Pavel Yaskevich
caf266f4b1 [CSDiagnostics] Use special error message when call didn't match exactly
For multiple solutions with fixes for the same call, replace
`ambiguous reference` diagnostic with the one that explicitly
mentions that there are no exact matches, and provide partially
matched candidates as notes.
2019-07-22 11:20:56 -07:00
Pavel Yaskevich
9550d10037 [Diagnostics] Add a diagnostic for single parameter tuple splat
Diagnose situation when a single "tuple" parameter is given N arguments e.g.

```swift
func foo<T>(_ x: (T, Bool)) {}
foo(1, false) // foo exptects a single argument of tuple type `(1, false)`
```
2019-07-16 11:06:42 -07:00
Slava Pestov
7434e37605 Sema: Fix crash with circular property initial values
Fixes <rdar://45313700>, <https://bugs.swift.org/browse/SR-9015>.
2019-06-27 23:13:46 -04:00
Slava Pestov
bd95c7d4ef Sema: Remove a bit of dead code concerning DynamicSelfType 2019-06-27 23:13:45 -04:00
Slava Pestov
590ef2bdd3 AST: Remove TypeBase::eraseDynamicSelfType() 2019-06-27 16:37:03 -04:00
Slava Pestov
5826db5d56 AST: Add AbstractFunctionDecl::hasDynamicSelfResult() and use it
This calculates a result directly from the function's result type
instead of checking a bit that was previously set by the type
checker. Also, always returns true for constructors to simplify
some callers.
2019-06-26 01:10:12 -04:00
Slava Pestov
bf71e074b9 Sema: Small cleanup for simplifyTypeImpl() 2019-06-26 01:10:11 -04:00
John Holdsworth
83bee5911e More additional tests 2019-06-26 01:10:11 -04:00
John Holdsworth
b799304fca Resolve failing constraint for subscripts returning Self 2019-06-26 01:10:11 -04:00
John Holdsworth
c1c1801448 CovariantReturnConversionExpr required. 2019-06-26 01:10:11 -04:00
John Holdsworth
bd4f49c1b5 Revert some tidy-ups. 2019-06-26 01:10:11 -04:00
John Holdsworth
f3e2282f65 Tidy-up 2019-06-26 01:10:11 -04:00
John Holdsworth
b3512298f1 Remove debug messages 2019-06-26 01:10:11 -04:00
John Holdsworth
498280d324 Seems to work 2019-06-26 01:10:11 -04:00
John Holdsworth
444027667c Some progress 2019-06-26 01:10:11 -04:00
John Holdsworth
97f102c74b Story so far 2019-06-26 01:10:11 -04:00
Pavel Yaskevich
b72b3cbf0d Merge pull request #25721 from theblixguy/fix/SR-10992
[ConstraintSystem] Fix crash on function conversion reliant on conditional conformance
2019-06-24 16:52:35 -07:00
Suyash Srijan
376fea12a8 [ConstraintSystem] Adds a new overload for getConstraintLocator that automatically gets the summary flags 2019-06-24 21:51:57 +01:00
Hamish Knight
e1f8af2389 Merge remote-tracking branch 'upstream/master' into a-couple-of-tangents 2019-06-18 19:09:06 +01:00
Hamish Knight
a3ead02902 Merge remote-tracking branch 'upstream/master' into a-couple-of-tangents 2019-06-13 14:46:55 +01:00
Hamish Knight
40d2f51780 [CS] Don't retrieve an overload choice for x[](y)
Previously we returned a subscript member locator for an apply of a
subscript expr, which is incorrect because the callee is the function
returned from the subscript rather than the subscript itself.
2019-06-13 13:51:50 +01:00
John McCall
b4cdbc05a6 Move the core builder-transform logic into its own file. 2019-06-11 18:58:11 -07:00
Doug Gregor
e08f1fbe18 [DSL] Clean up assignment of types to synthesized TypeExprs.
The implicit TypeExprs for function builders were getting inconsistently set
types, which would sometimes be the metatype and sometimes not be the
metatype, leading to a crash in the new test code.
2019-06-11 17:34:45 -07:00
John McCall
999d98acb1 Fix treatment of single-line getters with function builders.
rdar://50561122
2019-06-11 17:34:45 -07:00
John McCall
952eb9d8f9 Allow function-builder attributes on funcs and computed vars.
rdar://50150690
2019-06-11 17:34:45 -07:00
Doug Gregor
5d0d8d97ae [Constraint solver] Capture/roll back type mappings generated while solving.
When we perform constraint generation while solving, capture the
type mappings we generate as part of the solver scope and solutions,
rolling them back and replaying them as necessary. Otherwise, we’ll
end up with uses of stale type variables, expression/parameter/type-loc
types set twice, etc.

Fixes rdar://problem/50390449 and rdar://problem/50150314.
2019-06-11 17:34:45 -07:00
John McCall
83b5b2fa7d Support if-else chains on function builders.
A substantial amount of this patch goes towards trying to get at least
minimal diagnostics working, since of course I messed up the rule a few
times when implementing this.

rdar://50149837
2019-06-11 17:34:45 -07:00
Doug Gregor
7475bcd2ff [Function builders] Prescan closure bodies for a 'return' statement.
Since we short-circuit in the function builder application when we
hit something we cannot translate, relying on that visitor to
detect 'return' statements (which disable the application) is bogus.
Use a separate, earlier visitor to find 'return' statements consistently.

Fixes rdar://problem/50266341.
2019-06-11 17:34:45 -07:00
Doug Gregor
b7bbf4ca1a [Function builders] Allow uses of generic function builders.
Use the opened type from the callee declaration to open up references to
generic function builders that contain type parameters. This allows general
use of generic function builders.
2019-06-11 17:34:45 -07:00
Doug Gregor
ac47c9d500 [Function builders] Diagnose unhandled closure constructs within the type checker 2019-06-11 17:34:44 -07:00
Doug Gregor
c98f01705c [DSL] Allow function builders to opt in to "if" statements.
If a function builder contains a buildIf function, then "if" statements
will be supported by passing an optional of the "then" branch.
"if" statements with an "else" statement are unsupported at present.
2019-06-11 17:34:44 -07:00
Doug Gregor
ffd160162f [DSL] Allow function builders to opt in to "do" support via buildDo(). 2019-06-11 17:34:44 -07:00
Doug Gregor
6a3739ac65 Ensure that we use the right closure context for constraint generation. 2019-06-11 17:34:44 -07:00