Commit Graph

15871 Commits

Author SHA1 Message Date
Suyash Srijan
f8dace593c [Typechecker] Fix a crash related to use of invalid @autoclosure parameter 2019-12-17 03:24:09 +00:00
swift_jenkins
130bff9a5c Merge remote-tracking branch 'origin/master' into master-next 2019-12-16 18:00:02 -08:00
Hamish Knight
56265a26bf [CS] Resolve callees for key path dynamic members (#28807)
[CS] Resolve callees for key path dynamic members
2019-12-16 17:52:22 -08:00
swift_jenkins
aae37dcce1 Merge remote-tracking branch 'origin/master' into master-next 2019-12-16 17:20:37 -08:00
Suyash Srijan
66c2429cba [Typechecker] Fix a few regressions with @autoclosure (#28677)
* [Typechecker] Introduce a new request to check the structure of @autoclosure

* Revert "[Typechecker] Introduce a new request to check the structure of @autoclosure"

This reverts commit 3b1d4308bd3444230bfc7d031f7ccfa3b366a038.

* [Typechecker] Fix a few regressions related to use of @autoclosure
2019-12-17 01:07:43 +00:00
swift_jenkins
04c1567708 Merge remote-tracking branch 'origin/master' into master-next 2019-12-16 14:09:55 -08:00
Dan Zheng
c842fee0a4 [AutoDiff upstream] Add @transpose(of:) attribute.
The `@transpose(of:)` attribute registers a function as a transpose of another
function. This patch adds the `@transpose(of:)` attribute definition, syntax,
parsing, and printing.

Resolves TF-827.

Todos:
- Type-checking (TF-830, TF-1060).
- Enable serialization (TF-838).
- Use module-qualified names instead of custom qualified name syntax/parsing
  (TF-1066).
2019-12-16 12:23:08 -08:00
Robert Widmann
7dd429b67f [NFC] Refactor buildSubscript a bit
Have callers resolve the SelectedOverload instead of the callee.  Then make the error paths more apparent, and flush Optional<SelectedOverload> wherever it can be found.
2019-12-16 11:31:14 -08:00
Robert Widmann
1534b3659d [NFC] Const-qualify SelectedOverload's members 2019-12-16 11:28:54 -08:00
swift_jenkins
ac5af153b2 Merge remote-tracking branch 'origin/master' into master-next 2019-12-16 10:20:30 -08:00
Pavel Yaskevich
a96c40d23b Merge pull request #28783 from xedin/cut-down-fn-retypecheck-in-visit-applye-expr
[CSDiag] Remove obsolete function diagnostics from `visitApplyExpr`
2019-12-16 10:09:05 -08:00
Hamish Knight
cefc03f0e2 [CS] Resolve callees for key path dynamic members
Change the locator for the applicable fn
constraint for the inner subscript reference in an
implicit `outer[dynamicMember: \Inner.[0]]` expr
such that it uses the member locator with a
KeyPathDynamicMember element.

Then add a case to `getCalleeLocator` to handle
these locators. We also need to handle this
specially in `getArgumentInfoLocator` due to the
fact that the argument labels for the inner
subscript reference correspond to those written
by the user for the outer subscript reference.

Resolves SR-11933.
Resolves rdar://problem/57824025.
2019-12-16 10:04:24 -08:00
Xi Ge
03fab30ee0 Merge branch 'master' into tbdgen-ld-hide 2019-12-14 20:57:05 -08:00
swift_jenkins
9013f38fcd Merge remote-tracking branch 'origin/master' into master-next 2019-12-14 20:00:27 -08:00
Doug Gregor
9f85ce33b7 Merge pull request #28796 from DougGregor/leave-optimization-to-the-optimizers
[Constraint application] Stop optimizing casts in the AST.
2019-12-14 19:48:19 -08:00
Xi Ge
5e30d0e02b sema: diagnose bad interactions between @available and @_originallyDefinedIn 2019-12-14 18:34:14 -08:00
Doug Gregor
cb69e00b83 [Constraint application] Stop optimizing casts in the AST.
Constraint application was rewriting conditional casts (as?) and
forced casts (as!) into coercions (as) at the AST level when it
determined that there was a coercion. Stop doing that: it's the
optimizer's job to remove such casts.
2019-12-14 16:03:15 -08:00
Doug Gregor
f9eb34a5fa [Constraint solver] Switch coercion to be solution-based.
Rather than spinning up a new constraint system when performing an "as"
coercion, perform the coercion with the known solution, because we
already did all of the work to figure out how to perform the coercion.
2019-12-14 16:03:15 -08:00
swift_jenkins
fd390dfa5c Merge remote-tracking branch 'origin/master' into master-next 2019-12-14 08:00:41 -08:00
Slava Pestov
0a89228d11 Merge pull request #28788 from slavapestov/csapply-protocol-operator-cleanup
Sema: Clean up handling of protocol operators with concrete operands
2019-12-14 10:46:52 -05:00
Pavel Yaskevich
2db14a9148 [CSDiag] NFC: Remove obsolete function diagnostics from visitApplyExpr 2019-12-13 22:50:46 -08:00
Pavel Yaskevich
d77e34925f [ConstraintSystem] Lift a restriction on fixing of non-function calls on Any/AnyObject
Detect and diagnose situations where call is attempted directly on
`Any` or `AnyObject` or member calls with `AnyObject` base which
didn't match.
2019-12-13 22:50:04 -08:00
Pavel Yaskevich
a9106cafca [ConstraintSystem] Account for missing unwrap(s) in call to optional Objective-C members 2019-12-13 22:50:04 -08:00
Slava Pestov
594044a049 Sema: Clean up handling of protocol operators with concrete operands
In this case we would "devirtualize" the protocol requirement call
by building the AST to model a direct reference to the witness.

Previously this was done by recursively calling typeCheckExpression(),
but the only thing this did was recover the correct substitutions
for the call.

Instead, we can just build the right SubstitutionMap directly.
Unfortunately, while we serialize enough information in the AST
to devirtualize calls at the SIL level, we do not for AST Exprs.

This is because SIL devirtualization builds a reference to the
witness thunk signature, which is an intermediate step between
the protocol requirement and the witness. I get around this by
deriving the substitutions from walking in parallel over the
interface type of the witness, together with the inferred type
of the call expression.
2019-12-14 01:02:33 -05:00
swift_jenkins
51c9955050 Merge remote-tracking branch 'origin/master' into master-next 2019-12-13 21:40:17 -08:00
Doug Gregor
448a14e15f Merge pull request #28789 from DougGregor/playground-transform-iuo
[Playground transform] Retain ! expressions when logging variables.
2019-12-13 21:30:45 -08:00
Doug Gregor
8fdfbaaba5 [Playground transform] Retain ! expressions when logging variables.
When a force-value expression (!) is encountered while logging
variables, retain the force-value expression rather than dropping it.
This allows logging involving implicitly unwrapped optionals.

Fixes rdar://problem/56098581.
2019-12-13 15:58:54 -08:00
swift_jenkins
59fa47cc7a Merge remote-tracking branch 'origin/master' into master-next 2019-12-13 15:20:06 -08:00
Slava Pestov
ff294bdfb1 Merge pull request #28780 from slavapestov/sr-75-cleanups
A handful of cleanups in preparation for building curry thunks in Sema
2019-12-13 18:10:26 -05:00
swift_jenkins
d27b9fd05f Merge remote-tracking branch 'origin/master' into master-next 2019-12-13 14:40:35 -08:00
Hamish Knight
f1e690c07e Merge pull request #28775 from hamishknight/dynamic-lookup-attr-req
Requestify hasDynamicMemberLookupAttribute for Sema too
2019-12-13 14:40:13 -08:00
Slava Pestov
7626f9de4f AST: Small cleanups
- Allow AbstractClosureExpr to be created with null body
- Split up ParameterList::CloneFlags::Inherited
2019-12-13 15:39:47 -05:00
Slava Pestov
4a7b35dc6b Sema: Compute captures correctly for closures without source locations
Soon we'll be synthesizing more implicit autoclosures in CSApply, and
this case comes up.
2019-12-13 15:39:47 -05:00
Slava Pestov
db357d95a9 Sema: Remove unused 'locator' parameter in a few places 2019-12-13 15:39:47 -05:00
Slava Pestov
a9249287a1 Sema: Remove some dead code from CSDiag 2019-12-13 15:35:38 -05:00
swift_jenkins
e0d0bd61de Merge remote-tracking branch 'origin/master' into master-next 2019-12-13 12:00:52 -08:00
Pavel Yaskevich
5ba2e59c63 Merge pull request #28752 from xedin/simplify-potential-binding
[ConstraintSystem] Record originator constraint for each type variable binding
2019-12-13 11:50:02 -08:00
Hamish Knight
36cecb4015 Requestify hasDynamicMemberLookupAttribute for Sema too
Previously we had a request for this in
IDETypeChecking, but this wasn't used for queries
made from Sema. Move the request into Sema, and
move `hasDynamicMemberLookupAttribute` onto
TypeBase.
2019-12-13 11:04:00 -08:00
swift_jenkins
33b051b2ec Merge remote-tracking branch 'origin/master' into master-next 2019-12-13 10:20:13 -08:00
Pavel Yaskevich
fb764969c0 Merge pull request #28770 from xedin/rdar-57843297
[Diagnostics] Upon keypath result contextual mismatch try to match ob…
2019-12-13 10:12:27 -08:00
Pavel Yaskevich
47c7b9b910 [Diagnostics] Upon keypath result contextual mismatch try to match object types
If there was a mismatch between last component type and contextual
key path result type, let's try to re-match the types with all optionals
stripped off. In cases where the problem is optionality difference
e.g. `[Int] vs. [Int]?` that propagates contextual information to
the last component which facilitates better diagnostics.

Resolves: rdar://problem/57843297
2019-12-13 00:50:54 -08:00
swift_jenkins
8753c13fbb Merge remote-tracking branch 'origin/master' into master-next 2019-12-12 22:40:06 -08:00
Holly Borla
0b0dfe8b81 Merge pull request #28764 from hborla/remove-unused-func-csdiag
[CSDiag] Remove diagnoseClosureExplicitParameterMismatch.
2019-12-12 22:35:16 -08:00
Holly Borla
5ec28a6116 [CSDiag] Remove diagnoseClosureExplicitParameterMismatch. 2019-12-12 20:47:00 -08:00
swift_jenkins
e359fef156 Merge remote-tracking branch 'origin/master' into master-next 2019-12-12 18:19:55 -08:00
Dan Zheng
bb1052ca3e [AutoDiff upstream] Upstream @derivative attribute type-checking. (#28738)
The `@derivative` attribute registers a function as a derivative of another
function-like declaration: a `func`, `init`, `subscript`, or `var` computed
property declaration.

The `@derivative` attribute also has an optional `wrt:` clause specifying the
parameters that are differentiated "with respect to", i.e. the differentiation
parameters. The differentiation parameters must conform to the `Differentiable`
protocol.

If the `wrt:` clause is unspecified, the differentiation parameters are inferred
to be all parameters that conform to `Differentiable`.

`@derivative` attribute type-checking verifies that the type of the derivative
function declaration is consistent with the type of the referenced original
declaration and the differentiation parameters.

The `@derivative` attribute is gated by the
`-enable-experimental-differentiable-programming` flag.

Resolves TF-829.
2019-12-12 18:18:18 -08:00
Pavel Yaskevich
c4b74a3984 [ConstraintSystem] Remove getSourceKind() from PotentialBinding
There was a single place where it was used to determine whether
a binding comes from an argument conversion constraint. Since
constraint locator is part of the binding now it's possible to
use it instead and remove unused accessor.
2019-12-12 16:48:40 -08:00
Pavel Yaskevich
87beea3c40 [ConstraintSystem] Use binding as a source of type variable assignment
Since `binding` has all of the required information now it's possible
to use its `locator` as a source of type variable assignment
(`Bind` constraint) in `TypeVariableBinding::attempt` which helps
to improve diagnostics.
2019-12-12 12:42:30 -08:00
Pavel Yaskevich
382013f788 [Diagnostics] Convert missing @escaping diagnostic to contextual failure
This gives diagnostic access to both sides of a conversion/binding
which makes it easier to diagnose errors associated with generic parameters.
2019-12-12 12:42:25 -08:00
Pavel Yaskevich
cc50b46345 [Diagnostics] Preserve raw from/to types in contextual mismatch diagnostic
This is useful in some situations where access to type variable(s)
helps to diagnose the problem properly e.g. if it's a conversion
to generic parameter.
2019-12-12 12:42:19 -08:00