Commit Graph

767 Commits

Author SHA1 Message Date
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
Doug Gregor
a4301cc95b [Type checker] Transform multi-statement closures via function builders.
When calling a function whose parameter specifies a function builder
with a multi-statement closure argument, transform the closure into
a single expression via the function builder. Should the result
type checker, replace the closure body with the single expression.
2019-06-11 17:34:44 -07:00
Pavel Yaskevich
00e30dd53c Merge pull request #25291 from xedin/refactor-open-generic
[ConstraintSystem] Refactor openGeneric/openFunctionType
2019-06-07 22:42:24 -07:00
Pavel Yaskevich
c1087b9ab7 [ConstraintSystem] Remove boolean flags from openGeneric/openFunctionType 2019-06-06 11:56:49 -07:00
Hamish Knight
356b3b4150 [Sema] Don't assume member refs have base types
- Add a precondition on `doesDeclRefApplyCurriedSelf` to expect
a member decl, and rename it to make the precondition explicit.

- Don't assume that not having a base type means this isn't a member
reference, as member references to static operators don't have base
types.

Resolves SR-10843.
2019-06-06 17:03:47 +01:00
Pavel Yaskevich
ae68558dae [ConstraintSystem] Generalize and extract opening function params/result into substGenericArgs 2019-06-05 16:50:47 -07:00
Pavel Yaskevich
d86ccc9741 [ConstraintSystem] Fix regression in partial application of initializers
Correct a regression related to use of partially applied initializers,
which should be rejected only if it happens in a delegation chain.

Resolves: [SR-10837](https://bugs.swift.org/browse/SR-10837)
Resolves: rdar://problem/51442825
2019-06-05 12:13:50 -07:00
Pavel Yaskevich
24d6a3c484 [ConstraintSystem] Remove skipGenericRequirements flag from openGeneric 2019-06-05 10:33:07 -07:00
Pavel Yaskevich
930f74a023 [ConstraintSystem] Remove unused inner declaration context parameter from openGeneric* 2019-06-04 18:00:22 -07:00
Pavel Yaskevich
ef1e5425d4 [ConstraintSystem] Extract logic for opening generic parameters into its own method 2019-06-04 17:50:44 -07:00
Pavel Yaskevich
72c6dbb336 [ConstraintSystem] Separate parameter label removal from generic function opening 2019-06-04 14:26:07 -07:00
Hamish Knight
623a6adee0 [AST] Add ValueDecl::getNumCurryLevels 2019-05-31 23:10:48 +01:00
Hamish Knight
dcabcb36b4 [AST][Sema] Add ValueDecl::hasCurriedSelf
Use this function to replace various places where the logic is
duplicated.

In addition, isolate the logic where subscripts are treated as having
curried self parameters to CalleeCandidateInfo, as their interface types
don't have a curried self, but get curried with self by
CalleeCandidateInfo. Ideally we'd fix this by having a subscript's
interface type be curried with self, but given that most of this CSDiag
logic should be going away, this may not be necessary.
2019-05-31 15:53:26 +01:00
Pavel Yaskevich
c30845fa74 [ConstraintSystem] Detect and diagnose missing generic arguments
Introduce a fix to detect and diagnose situations when omitted
generic arguments couldn't be deduced by the solver based on
the enclosing context.

Example:

```swift
struct S<T> {
}

_ = S() // There is not enough context to deduce `T`
```

Resolves: rdar://problem/51203824
2019-05-29 16:39:41 -07:00
Pavel Yaskevich
91dbcfdfcc [ConstraintSystem] Deplay opening generic requirements until after contextual self has been applied
While computing a type of member via `getTypeOfMemberReference`
let's delay opening generic requirements associated with function
type until after self constraint has been created, that would give
a chance for contextual types to get propagated and make mismatch
originated in generic requirements much easier to diagnose.

Consider following example:

```swift
struct S<T> {}

extension S where T == Int {
  func foo() {}
}

func test(_ s: S<String>) {
  s.foo()
}
```

`foo` would get opened as `(S<$T>) -> () -> Void` and contextual `self`
type is going to be `S<String>`, so applying that before generic requirement
`$T == Int` would make sure that `$T` gets bound to a contextual
type of `String` and later fails requirement constraint `$T == Int`.

This is much easier to diagnose comparing to `$T` being bound to
`Int` right away due to same-type generic requirement and then
failing an attempt to convert `S<String>` to `S<Int>` while simplifying
self constraint.

Resolves: rdar://problem/46427500
Resolves: rdar://problem/34770265
2019-05-24 11:33:30 -07:00