Commit Graph

15871 Commits

Author SHA1 Message Date
Pavel Yaskevich
2fa4fbb7a9 Merge pull request #30646 from xedin/rdar-60225883
[CSApply] Support dynamic member lookup as component of key path dyna…
2020-03-26 09:33:12 -07:00
Pavel Yaskevich
f75996839a Revert "[ConstraintSystem] Accept trailing closure if multiple defaulted parameters after last function parameter" 2020-03-26 09:19:57 -07:00
Holly Borla
da715f87c5 [Diagnostics] Support diagnosing references to operators without argument
application in MissingConformanceFailure::diagnoseAsAmbiguousOperatorRef
2020-03-26 08:40:32 -07:00
Pavel Yaskevich
95be170e46 [CSApply] Support dynamic member lookup as component of key path dynamic member lookup
Previously solution application only supported references to
key path dynamic member lookup as components but it should support both kinds.

Resolves: rdar://problem/60225883
Resolves: [SR-12313](https://bugs.swift.org/browse/SR-12313)
2020-03-25 15:21:52 -07:00
David Ungar
db141af397 Merge pull request #30639 from davidungar/rdar-60840456-custom-attr-on-extension
Start lookup *outside* of D when D is, e.g. an ExtensionDecl
2020-03-25 15:12:48 -07:00
swift-ci
3e32a4cd57 Merge pull request #30641 from dan-zheng/fix-typo 2020-03-25 13:28:10 -07:00
Pavel Yaskevich
b73b7c20c4 Merge pull request #30592 from xedin/fallback-diag-for-holes
[ConstraintSystem] Avoid applying invalid solution with fixes
2020-03-25 11:54:08 -07:00
Dan Zheng
7d1341e21c [Sema] NFC: fix typo.
`let` stored -> `let` stored property
2020-03-25 18:40:38 +00:00
David Ungar
44cc14a051 Start lookup *outside* of D when D is, e.g. an ExtensionDecl, since the attribute is outside of it. 2020-03-25 11:17:13 -07:00
Dan Zheng
e5cb871428 [AutoDiff upstream] Add flag-gated AdditiveArithmetic derivation. (#30628)
Add `AdditiveArithmetic` derived conformances for structs, gated by the
`-enable-experimential-additive-arithmetic-derivation` flag.

Structs whose stored properties all conform to `AdditiveArithmetic` can derive
`AdditiveArithmetic`:
- `static var zero: Self`
- `static func +(lhs: Self, rhs: Self) -> Self`
- `static func -(lhs: Self, rhs: Self) -> Self`
- An "effective memberwise initializer":
  - Either a synthesized memberwise initializer or a user-defined initializer
    with the same type.

Effective memberwise initializers are used only by derived conformances for
`Self`-returning protocol requirements like `AdditiveArithmetic.+`, which
require memberwise initialization.

Resolves TF-844.
Unblocks TF-845: upstream `Differentiable` derived conformances.
2020-03-25 10:31:50 -07:00
Pavel Yaskevich
5f328ad003 [ConstraintSystem] Don't increase SK_Fix score when looking through holes
`SK_Fix` was used to indicate that solver has encountered a hole
along the current path but since there is `SK_Hole` now, increasing
`SK_Fix` no longer makes sense.
2020-03-25 09:34:00 -07:00
Pavel Yaskevich
7410c09c56 [CSGen] No longer allow _ allow to be a hole directly
Problems related to incorrect use of `_` where previously diagnosed
by syntactic diagnostics which meant that it could only happen on
type-checked AST. This is no longer a case so we don't have to allow
incorrect uses of `_` to form solution without any fixes.
2020-03-25 08:33:36 -07:00
Dan Zheng
07596cbc9b [AutoDiff upstream] Relax @differentiable for protocol witnesses. (#30629)
Previously, all witnesses of a `@differentiable` protocol requirement were
required to have the same attribute (or one with superset parameter indices).

However, this leads to many annotations on witnesses and is not ideal for
usability. `@differentiable` attributes are really only significant on
public witnesses, so that they are clearly `@differentiable` at a glance (in
source code, interface files, and API documentation), without looking through
protocol conformance hierarchies.

Now, only *public* witnesses of `@differentiable` protocol requirements are
required to have the same attribute (or one with superset parameter indices).
For less-visible witnesses, an implicit `@differentiable` attribute is created
with the same configuration as the requirement's.

Resolves TF-1117.
Upstreams #29771 from tensorflow branch.
2020-03-25 08:13:27 -07:00
Pavel Yaskevich
972de2e657 Merge pull request #30627 from LucianoPAlmeida/SR-12382-improve-pointer-conversion-mismatch-diag
[SR-12382] Improve optional pointer conversion mismatch diagnostics
2020-03-25 02:22:59 -07:00
Luciano Almeida
829152bdb4 [CSDiagnostics] Handle optional Inout to typed pointer conversion diagnostics on generic mismatch 2020-03-25 01:51:30 -03:00
Pavel Yaskevich
4b3d075fb7 [ConstraintSystem] Produce fallback diagnostic on mismatch between fixes/holes
If score indicates that a solution should have at least one fix
but it doesn't let's attempt to produce a fallback diagnostic inline.
2020-03-24 16:51:44 -07:00
Pavel Yaskevich
16c1f50eda [ConstraintSystem] Diagnose incorrect use of _ during constraint generation
`_` or discard assignment expression should only be used on the left-hand
side of the assignment expression. Incorrect uses are easy to detect during
constraint generation which also allows us to avoid complications related
to other diagnostics when `_` is used incorrectly.
2020-03-24 16:51:44 -07:00
Pavel Yaskevich
da2023c9a0 [ConstraintSystem] Score solutions based on number of holes
Introduce `SK_Hole` which is used to count a number of "holes" in
a given solution. It is used to distinguish solutions with fewer holes.

Also it makes it possible to check whether a solution has holes but
no fixes, which is an issue and such solution shouldn't be applied
to AST.
2020-03-24 16:51:44 -07:00
Pavel Yaskevich
786bad422a [ConstraintSystem] Avoid applying invalid solution with fixes
If solution score indicates that there should be a fix but
none where recorded fail solution application and produce
a fallback diagnostic to pin-point a problem.

Resolves: rdar://problem/60663007
2020-03-24 16:51:44 -07:00
Pavel Yaskevich
465b0e193a [ConstraintSystem] Diagnose more cases of invalid nil use during constraint generation
Move check for `nil` destination of conditional casts to `visitNilLiteral` and
add support for `nil?` which wasn't previously detected.
2020-03-24 14:57:27 -07:00
Robert Widmann
a9e11e3130 [NFC] Separate Taking Redundant Conformance Diagnostics From The Lookup Table 2020-03-24 12:40:11 -07:00
marcrasi
1be86adbfc [AutoDiff] forbid derivative registration using @differentiable (#30001)
Delete `@differentiable` attribute `jvp:` and `vjp:` arguments for derivative
registration. `@derivative` attribute is now the canonical way to register
derivatives.

Resolves TF-1001.
2020-03-24 00:41:27 -07:00
Slava Pestov
c2a913e4d7 Sema: Fix interface type vs archetype mixup with generic typealiases
Fixes <rdar://problem/60081992>.
2020-03-23 19:01:26 -04:00
Anthony Latsis
8f306261ea Merge pull request #30574 from AnthonyLatsis/code-complete-broken-conf-no-static
[CodeCompletion] Add overlooked 'isDeclVisibleInLookupMode' check when collecting value requirements
2020-03-24 01:26:41 +03:00
Robert Widmann
89b8163824 Merge pull request #30585 from CodaFi/untapped-potential
Register Conformances as Potential Member Constraints
2020-03-23 14:33:07 -07:00
Hamish Knight
de4669055a Add direct operator lookup requests (#30584)
Add direct operator lookup requests
2020-03-23 12:09:23 -07:00
Anthony Latsis
cf43a564a2 [CodeCompletion] Check visibility in lookup mode when collecting value requirements 2020-03-23 21:40:41 +03:00
Robert Widmann
bafd707429 Register Conformances as Potential Member Constraints
Unwind a hack whose stated purpose was to register a potential member
edge from an extension to the extended type. In reality, this only
registered a plain member dependency on 'deinit'. This edge is
insufficient in isolation to cause a rebuild of a dependent file in the
case where a type and its extension live in separate files. However, we
appear to have been saved by the redundancy in edge registration because the
lookup for the extended type will register a top-level or nominal
dependency (for an unqualified or qualified reference respectively). The
worry there is if a protocol conformance edge *should* flip a previously
private nominal dependency edge to a cascading edge. In such a case, the
old code would not have been able to make the cascading edge promotion,
and we would have potentially miscompiled by not rescheduling dependent
jobs.
2020-03-23 11:20:05 -07:00
Hamish Knight
b179a3966b [CS] A couple of minor cleanups (#30582)
[CS] A couple of minor cleanups
2020-03-23 10:39:38 -07:00
Anthony Latsis
667bec0f21 Merge pull request #30578 from AnthonyLatsis/memb-fail-qoi
[DiagQoI] Improve fallback fixits for static member on instance errors
2020-03-23 19:31:10 +03:00
Hamish Knight
9656a0491e Allow OperatorLookupDescriptor to hold a file or module 2020-03-23 09:17:58 -07:00
Hamish Knight
e71d921e43 [CS] Re-introduce some assertions
These FIXMEs appear to now be outdated.

This commit also adds an additional assertion in
`bindTypeVariable`.
2020-03-22 22:58:48 -07:00
Hamish Knight
c74a7512f7 [CS] NFC: Remove OverloadChoiceKind::BaseType
This doesn't appear to be used any more.
2020-03-22 22:51:58 -07:00
Anthony Latsis
572f0544a2 [DiagQoI] Improve fallback fixits for static member on instance error 2020-03-23 08:27:55 +03:00
Robert Widmann
c136a0b190 [NFC] Remove SourceFile's Operator Lookup Entrypoints
Now that this is requestified, the extra level of indirection serves no
purpose.
2020-03-21 11:19:46 -07:00
Doug Gregor
aacdd3a27d Merge pull request #30537 from DougGregor/roop-sr10950_prop_wrap_autoclosure
[Property wrappers] Fix handling of @autoclosure in init(wrappedValue:)
2020-03-20 23:12:18 -07:00
Anthony Latsis
7e21d7b5eb Merge pull request #30423 from AnthonyLatsis/se-0267-additions
[SE-0267] Improvements (Ep. 1)
2020-03-21 08:59:13 +03:00
Anthony Latsis
3825656261 [Sema] Tidy up checkContextualRequirements() 2020-03-21 05:47:54 +03:00
Robert Widmann
076a24709b Merge pull request #30544 from CodaFi/standard-operating-procedure
[NFC] Define LookupOperatorRequest and Friends
2020-03-20 17:34:38 -07:00
Robert Widmann
9d6d672494 Rename LookupPrecedenceGroupRequest to ValidatePrecedenceGroupRequest
Make way for a new kind of name lookup request for operators
2020-03-20 15:47:36 -07:00
Rintaro Ishizaki
0b1dbbda5f Merge pull request #30525 from rintaro/ide-completion-rdar57622639
[LookupVisibleDecls] Tweak unquialified lookup
2020-03-20 15:32:36 -07:00
Rintaro Ishizaki
021cbbb668 Merge pull request #30530 from AnthonyLatsis/member-lookup-protocols
[CodeCompletion] Optimize member lookup in protocols being conformed to
2020-03-20 13:17:24 -07:00
Roopesh Chander
9c2dca7d6a [Property wrappers] Fix handling of @autoclosure in init(wrappedValue:)
If the 'wrappedValue:' parameter is an escaping autoclosure, and a
struct property is marked with that property wrapper, the memberwise
initializer of the struct is now synthesized with an escaping
autoclosure for that property.
2020-03-20 12:20:52 -07:00
Rintaro Ishizaki
80848682cc [LookupVisibleDecls] Tweak unquialified lookup
- Show static var decls in non-qualified metatype lookup
- Show enum element decls in non-qualified metatype lookup
- Never show initializers in non-qualified lookup
- Perform instance lookups in lazy var initializer
- Perform non-qualified metatype lookup inside static func

rdar://problem/57622639
2020-03-20 10:44:24 -07:00
Anthony Latsis
be4ad49b56 Address suggestions 2020-03-20 20:31:44 +03:00
Pavel Yaskevich
d673ed0989 Merge pull request #30519 from xedin/rdar-52204414
[ConstraintSystem] Don't allow explicit closure result to be implicitly converted to `Void`
2020-03-20 09:36:17 -07:00
Anthony Latsis
137ef220f6 [CodeCompletion] Optimize member lookup in protocols being conformed to 2020-03-20 18:12:07 +03:00
Pavel Yaskevich
4876996b8c Merge pull request #30510 from HassanElDesouky/SR-12309-FollowUp
[CSGen] Diagnose `nil` with any number of parentheses
2020-03-20 00:13:50 -07:00
Pavel Yaskevich
89933c67da [ConstraintSystem] Don't allow explicit closure result to be implicitly converted to Void
It's allowed to convert a single statement closure from `(...) -> T` to `(...) -> Void`
_only_ if there is no explicit `return` in the body.

Resolves: [SR-12277](https://bugs.swift.org/browse/SR-12277)
Resolves: rdar://problem/52204414
2020-03-19 16:59:17 -07:00
Pavel Yaskevich
0ebdba06b5 [ConstraintSystem] Add a new locator element - type for body of a closure 2020-03-19 13:48:07 -07:00