Commit Graph

15871 Commits

Author SHA1 Message Date
Pavel Yaskevich
8269522f86 Merge pull request #28837 from xedin/rdar-56340587
[ConstraintSystem] Delay constraint generation for single-statement closure body
2020-01-16 00:29:11 -08:00
Brent Royal-Gordon
0c478b6be6 Revert "Merge pull request #28665 from CodaFi/the-phantom-menace"
This reverts commit 43a3ab7e35, reversing
changes made to 4f39d9c749.

# Conflicts:
#	include/swift/AST/Attr.def
#	lib/AST/Attr.cpp
#	lib/Serialization/Deserialization.cpp
#	lib/Serialization/ModuleFormat.h
#	lib/Serialization/Serialization.cpp
2020-01-15 15:28:42 -08:00
Pavel Yaskevich
4eda04297f [CSGen] Unify handling of single- and multi-statement closures
Both multi- and single-statement closures now behave the same way
when it comes to constraint generation, because the body is opened
only once contextual type becomes available or it's impossible
to find one e.g. `_ = { 1 }`.
2020-01-15 14:19:54 -08:00
Pavel Yaskevich
d0e20ebade Merge pull request #29209 from xedin/rdar-56221372
[ConstraintSystem] Fix `getArgumentExpr` to check number of tuple ele…
2020-01-15 08:55:23 -08:00
Pavel Yaskevich
b633ef2da4 Merge pull request #29208 from xedin/dont-attempt-duplicate-supertypes
[CSBindings] Avoid inferring duplicate bindings from supertypes
2020-01-15 00:15:18 -08:00
Doug Gregor
3651defcfa [Solver] When LLVM stats are disabled, don't adjust their values.
Fixes rdar://58549337
2020-01-14 22:12:43 -08:00
Varun Gandhi
f5cb50c1a8 [Sema] Implicitly tuple a pattern if applicable.
Fixes rdar://problem/58425942.
2020-01-14 21:14:56 -08:00
Pavel Yaskevich
d318b5d0f6 [ConstraintSystem] Fix getArgumentExpr to check number of tuple elements before access
Fix `getArgumentExpr` to not assume that constraint system
always asks for index that exists in an argument tuple,
because sometimes arguments could be synthesized (such
arguments do not have corresponding expression).

Resolves: rdar://problem/56221372
2020-01-14 17:44:32 -08:00
Pavel Yaskevich
97d747002c [CSBindings] Avoid inferring duplicate bindings from supertypes
If there is `subtype` relationship between two type variables
binding inference algorithm attempts to infer supertype bindings
transitively, but it doesn't check whether some of the new types
are already included in the set, which leads to duplicate solutions.
2020-01-14 17:31:57 -08:00
Pavel Yaskevich
0aadb7c6a5 [CSDiag] NFC: Move findResolvedMemberRef to ConstraintSystem.cpp
This method is used by diagnostics and CSApply at this point.
2020-01-14 12:51:58 -08:00
Pavel Yaskevich
c6a5f59946 [ConstraintSystem] Attempt types linked via subtyping in reverse order (supertypes first)
If there is a subtype relationship between N types we have to make
sure that type chain is attempted in reverse order because we can't
infer bindings transitively through type variables and attempting
it in any other way would miss potential bindings across the chain.
2020-01-14 00:09:33 -08:00
Pavel Yaskevich
25433b3805 [CSGen] Use getType when refering to closure parameters in expression context 2020-01-14 00:09:33 -08:00
Pavel Yaskevich
ad52afa4bb [ConstraintSystem] Add pair-wise differentiation of key path dynamic member overloads
Single type of keypath dynamic member lookup could refer to different
member overlaods, we have to do a pair-wise comparison in such cases
otherwise ranking would miss some viable information e.g.
`_ = arr[0..<3]` could refer to subscript through writable or read-only
key path and each of them could also pick overload which returns `Slice<T>`
or `ArraySlice<T>` (assuming that `arr` is something like `Box<[Int]>`).
2020-01-14 00:09:33 -08:00
Pavel Yaskevich
c3153e020d [CSRanking] Account for that fact that some bindings can be type holes 2020-01-14 00:09:33 -08:00
Pavel Yaskevich
22e12e86a8 [ConstraintSystem] Switch to pair-wise type binding differentiation for ranking
Instead of trying to hold a "global" set of type variable differences
let's use pair-wise comparison instead because in presence of generic
overloads such would be more precise.

If there are N solutions for a single generic overload we currently
relied on "local" comparison to detect the difference, but it's not
always possible to split the system to do one. Which means higher
level comparisons have to account for "local" (per overload choice)
differences as well otherwise ranking would loose precision.
2020-01-14 00:09:33 -08:00
Pavel Yaskevich
af82e6f11b [TypeChecker] Use special locator while matching function builder body to closure result type 2020-01-14 00:09:33 -08:00
Pavel Yaskevich
cf2cad0cd5 [ConstraintSystem] Add more information retrieval callbacks to getCalleeLocator
`getCalleeLocator` has to be able to:

- Retrieve type for given expression via `getType`;
- Simplify given type via `simplifyType`; and
- Retrieve a selected overload choice for a given locator via `getOverloadFor`.
2020-01-14 00:09:33 -08:00
Pavel Yaskevich
449ef613f3 [CSGen] NFC: Remove obsolete closure handling logic
Since we no longer walk into closures it's possible to remove
`{enter, exit}Closure` and `getClosureParams`.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
1c803a7cac [CSFix] Account for special closure handling in invalid trailing closure fix
Since closures don't get the type assigned right away anymore we
have to fetch it before any of the internal type variables could
be marked as holes.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
36216d5871 [Diagnostics] Pinpoint contextual error location if it's related to a call to closure
For example `let _: B = { A() }()` should point to a closure result
instead of a call.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
65adc18139 [ConstraintSystem] Delay constraint generation from single-statement closure body
Attempt to infer a closure type based on its parameters and body
and put it aside until contextual type becomes available or it
has been determined that there is no context.

Once all appropriate conditions are met, generate constraints for
the body of the closure and bind it the previously inferred type.

Doing so makes it possible to pass single-statement closures as
an argument to a function builder parameter.

Resolves: SR-11628
Resolves: rdar://problem/56340587
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
59c749124d [CSBindings] Prefer closure type binding over disjunction
Even if contextual closure type has type variables inside
prefer it over disjunction because it provides a lot of
contextual information early which helps to solve the system
faster.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
b868d1cfb7 [ConstraintSystem] Account for unapplied curried self while trying to retrieve function builder type for parameter 2020-01-14 00:09:32 -08:00
Pavel Yaskevich
141c987bb9 [ConstraintSystem] Add accessor to type var to determine if it represents a closure type 2020-01-14 00:09:32 -08:00
Pavel Yaskevich
9257b29465 [ConstraintSystem] Clarify DefaultClosureType constraint and add its own simplify method 2020-01-14 00:09:32 -08:00
Pavel Yaskevich
9dc2dfde98 [ConstraintSystem] Allow single-statement closures be used with function builders
While resolving closure use contextual locator information to
determine whether given contextual type comes from a "function builder"
parameter and if so, use special `applyFunctionBuilder` to open
closure body instead of regular constraint generation.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
66db166922 [ConstraintSystem] Introduce new DefaultClosureType constraint
This constraint connects type variable representing a closure
expression to its inferred type and behaves just like regular
`Defaultable` constraint expect for type inference where it's
used only if there are no contextual bindings available.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
b7523d745c [ConstraintSystem] Introduce resolveClosure method to generate constraints for closure body
In preparation to change the way closures are handled in constraint system
let's introduce a special method which is responsible for generation of
constraints for closure body and connecting it to the rest of the
constraint system when contextual type becomes available.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
92556e8f0d [ConstraintSystem] Introduce a mapping from closures to their inferred types
In preparation to change type-checking behavior of closures
we need to introduce a special mapping from closure expressions
to their inferred types (based on parameters/result and body).
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
465a948e67 [ConstraintSystem] Add a separate constraint generation for closure body
Separate closure from top-level constraint generation because
its body shouldn't be considered when it comes to parent/weight
computation, otherwise top expression in body is going to get
disconnected from the closure.
2020-01-14 00:09:32 -08:00
Pavel Yaskevich
8f68a68c70 [ConstraintSystem] Augment getCalleeLocator with getType callback
This is necessary for ambiguity diagnostics because none of the
solutions are applied back to the constraint system which means
that `getCalleeLocator` needs an ability to query information
from different sources e.g. constraint system and/or solution.
2020-01-14 00:09:32 -08:00
swift-ci
8f4c364244 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-14 00:03:21 -08:00
Suyash Srijan
29268e2a34 [PropertyWrappers] Fix a bug with class property wrapper access control (#29023)
* [PropertyWrappers] Class property wrapper cannot have an open init, so make sure to consider that when looking for suitable wrapper inits

* [PropertyWrappers] Extract the access control check into a separate static method
2020-01-14 07:53:48 +00:00
swift-ci
4f2181524c Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-13 19:03:55 -08:00
Slava Pestov
b9dfd408e7 Merge pull request #29173 from slavapestov/enum-raw-value-not-equatable-fix
Sema: Fix crash when synthesizing RawRepresentable conformance with non-Equatable raw type
2020-01-13 21:48:35 -05:00
swift-ci
1b83dcb298 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-13 16:44:05 -08:00
Pavel Yaskevich
20443ad923 Merge pull request #29166 from xedin/port-array-dict-literal-diagnostics
[Diagnostics] Port diagnostics for array/dictionary literals
2020-01-13 16:40:32 -08:00
Slava Pestov
1dd527ef4e Sema: Fix crash when synthesizing RawRepresentable conformance with non-Equatable raw type
The error recovery logic around derived conformances is a little bit
tricky. Make sure we don't crash if a type explicitly provides a
RawValue type witness that is not equatable, but omits the witnesses
for init(rawValue:) and the rawValue property.

Fixes <rdar://problem/58127114>.
2020-01-13 19:07:06 -05:00
swift-ci
da3943ae2b Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-13 14:43:23 -08:00
Harlan Haskins
e23e77b6a5 Allow function builder attrs on vars without bodies in interfaces (#29165)
The check for whether or not we can use a function builder on a property
checked whether the attached getter had a body, which is not always true for
module interfaces. Just disable that part of the check when compiling a
module interface.

rdar://58535753
2020-01-13 14:41:01 -08:00
Pavel Yaskevich
83744d9d39 [Diagnostics] Use ´isa instead of dyn_cast` because array/dictionary expr in unused 2020-01-13 12:53:30 -08:00
Pavel Yaskevich
2164476bf5 [Diagnostics] Port diagnostics related to dictionary literal use 2020-01-13 12:41:07 -08:00
Pavel Yaskevich
f2942ebb56 [Diagnostics] Port diagnostics related to array literal use 2020-01-13 11:54:59 -08:00
swift-ci
dcb4ee0582 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-12 12:23:31 -08:00
Dan Zheng
1486d6b346 NFC: Add GenericSignature::getCanonicalSignature. (#29105)
Motivation: `GenericSignatureImpl::getCanonicalSignature` crashes for
`GenericSignature` with underlying `nullptr`. This led to verbose workarounds
when computing `CanGenericSignature` from `GenericSignature`.

Solution: `GenericSignature::getCanonicalSignature` is a wrapper around
`GenericSignatureImpl::getCanonicalSignature` that returns the canonical
signature, or `nullptr` if the underlying pointer is `nullptr`.

Rewrite all verbose workarounds using `GenericSignature::getCanonicalSignature`.
2020-01-12 12:17:41 -08:00
swift-ci
52c5ecd291 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-10 16:23:41 -08:00
Rintaro Ishizaki
8fe4c0795b Merge pull request #28944 from rintaro/ide-completion-rdar58175106
[CodeCompletion] Use getBodySourceRange() instead of getSourceRange()
2020-01-10 16:21:07 -08:00
Arnold Schwaighofer
0c99cd9734 Merge remote-tracking branch 'origin/master' into master-rebranch 2020-01-10 08:00:41 -08:00
Doug Gregor
946eee9cf8 Merge pull request #29102 from DougGregor/function-builder-via-constraint-system
[Constraint solver] Use a constraint system to apply all function builders
2020-01-09 23:42:32 -08:00
Doug Gregor
142b3ad538 [Constraint system] Minor fixes / test updates for function builders. 2020-01-09 16:33:13 -08:00