Commit Graph

15871 Commits

Author SHA1 Message Date
Luciano Almeida
64f8a6bd42 [CSDiagnostics] Renaming ContextualFailure CoerceExpr method naming 2020-01-06 14:37:27 -03:00
Luciano Almeida
d9cfbd3e55 [CSDiag] Remove obsolete code block in visitCoerceExpr 2020-01-05 18:39:55 -03:00
swift_jenkins
d62e2bc3cc Merge remote-tracking branch 'origin/master' into master-next 2020-01-05 13:19:01 -08:00
Holly Borla
52a736ebec Merge pull request #29000 from hborla/unresolved-member-expr-diagnostics
[ConstraintSystem] Finish porting unresolved member reference failures.
2020-01-05 13:16:35 -08:00
Holly Borla
94bbb8f76e [ConstraintSystem] Finish porting unresolved member reference failures.
This covers member failures where the error is at the declaration, so
the result of member lookup is "already diagnosed".
2020-01-05 11:33:02 -08:00
Luciano Almeida
f145264fc7 [tests] Fix parser recover tests 2020-01-05 00:23:15 -03:00
Luciano Almeida
a1bf54af51 [CSDiagnostics] Extract diagnostic for CoerceExpr to function 2020-01-04 23:41:14 -03:00
Luciano Almeida
49e8eee3e5 [CSDiagnostics] Handle CoercionExpr empty path in ContextualMismatch 2020-01-04 15:59:13 -03:00
Luciano Almeida
533d9acf73 [CSSimplify] Fallback to contextual mismatch in repair failures for CoerceExpr 2020-01-04 15:54:46 -03:00
swift_jenkins
1a0a1672ff Merge remote-tracking branch 'origin/master' into master-next 2020-01-03 21:19:08 -08:00
Doug Gregor
64b691fb30 Merge pull request #29005 from DougGregor/functional-pattern-checking
[Type checker] Make typeCheckPattern() a functional request
2020-01-03 21:14:31 -08:00
Doug Gregor
61ac2534e7 [Type checker] Make coercePatternToType return the new Pattern.
Rather than mutating the parameter pattern in place and separately
return whether an error occurred, return the new pattern or NULL if an
error occurred. While here, switch over to ContextualPattern for the
input.

And get rid of that infernal "goto".
2020-01-03 17:27:55 -08:00
Doug Gregor
cc11fc6838 [Type checker] Introduce a request for computing the type of a pattern.
Compute the "raw" type of a pattern via a request, caching the result
of TypeChecker::typeCheckPattern(). Retain typeCheckPattern() as the
general entrypoint for performing this computation so that other code
doesn't need to change yet.
2020-01-03 16:14:48 -08:00
Doug Gregor
033f9c7927 [Type checker] Introduce "contextual patterns".
Contextual pattern describes a particular pattern with enough
contextual information to determine its type. Use this to simplify
TypeChecker::typeCheckPattern()'s interface in a manner that will
admit request'ification.
2020-01-03 15:41:21 -08:00
swift_jenkins
0f07bd9e65 Merge remote-tracking branch 'origin/master' into master-next 2020-01-03 14:39:26 -08:00
Slava Pestov
5a582a6dd5 Merge pull request #28988 from slavapestov/enclosing-self-type-check-expression-crash
Sema: Fix crash-on-invalid with 'enclosing self' property wrappers
2020-01-03 17:34:28 -05:00
Robert Widmann
96b3b9f0f4 [NFC] Hide SourceFile::Decls
In preparation for installing some stable paths infrastructure here,
hide access to the array of top-level decls.
2020-01-03 14:14:00 -08:00
Slava Pestov
41a00e5780 Sema: Fix crash-on-invalid with 'enclosing self' property wrappers
The diagnostic is still terrible, but at least we shouldn't crash.

Fixes one manifestation of <rdar://problem/57726880>.

I also filed <https://bugs.swift.org/browse/SR-11989> to track improving
the diagnostic.
2020-01-03 15:06:42 -05:00
Doug Gregor
9c8351b206 [Type checker] Make typeCheckPattern() functional.
Make TypeChecker::typeCheckPattern() return the computed type, rather
than returning an "error" flag. More importantly, make it functional,
so that it doesn't set the type it computes on the pattern.

Use UnresolvedType as a placeholder for types that need to be
inferred, rather than a null type. This allows us to produce
structural types involving types that need to be inferred.

Note that with this change as-is, we get a number of duplicated
diagnostics, because typeCheckPattern() will be called multiple times
for the same pattern and will emit some diagnostics each time. This
will be addressed in a subsequent commit.
2020-01-03 11:25:05 -08:00
swift_jenkins
dd0a12e971 Merge remote-tracking branch 'origin/master' into master-next 2020-01-03 08:59:01 -08:00
Holly Borla
475b5591ed Merge pull request #28979 from hborla/ambiguous-call-diagnostics
[ConstraintSystem] Start to allow diagnosing ambiguity with fixes for solution sets with more than one fix.
2020-01-03 08:49:30 -08:00
Holly Borla
9e73bb3176 [ConstraintSystem] Start to allow diagnosing ambiguity with fixes
for solution sets with more than one fix.
2020-01-02 23:48:16 -08:00
swift_jenkins
769eb1e228 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 20:59:16 -08:00
Doug Gregor
baa1a735b6 Merge pull request #28986 from DougGregor/for-each-pattern-cleanup
[Type checker] Move for-each pattern checking logic into the solver.
2020-01-02 20:54:02 -08:00
kelvin13
eb79a08a42 (wip) update comparable implementations to match new internal apis 2020-01-02 22:31:21 -06:00
swift_jenkins
e90b4ab8be Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 19:39:07 -08:00
Slava Pestov
1ee4403fb7 Merge pull request #28985 from slavapestov/property-wrapper-modify-transparent
Sema: Don't mark property wrapper 'modify' accessors transparent
2020-01-02 22:25:06 -05:00
swift_jenkins
cd9d23d5c4 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 17:19:15 -08:00
Doug Gregor
79776436d8 Merge pull request #28984 from DougGregor/de-de-virtualize-for-each
[Type checker] Stop devirtualizing the reference to IteratorProtocol.next()
2020-01-02 17:08:59 -08:00
kelvin13
ed2552a694 fix merge conflict and update caseless stdlib enums to use synthesized Comparable 2020-01-02 18:40:50 -06:00
Doug Gregor
2a13b1dff0 [Type checker] Stop coercing patterns while type-checking them.
Detangle the "type check" and "coerce" phases somewhat for pattern type
checking, as a precursor to making the former more functional.
2020-01-02 16:15:42 -08:00
swift_jenkins
add386ded3 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 15:59:15 -08:00
Doug Gregor
716c72cadb Merge pull request #28380 from DougGregor/for-each-in-constraint-solver
[Type checker] Fold more for-each type checking into the constraint solver
2020-01-02 15:43:46 -08:00
Slava Pestov
1337925608 Sema: Don't mark property wrapper 'modify' accessors transparent
There are certain conditions that cause them to reference
non-public properties, in particular if the property
wrapper is implemented via a subscript taking a keypath.

Instead of trying to detect this specific case though (and
possibly missing others), I'm just going to decree that
'modify' is never going to be transparent for property
wrappers.

Fixes <rdar://problem/57609867>.
2020-01-02 18:30:37 -05:00
Doug Gregor
7fa84b592e [Type checker] Move for-each pattern checking logic into the solver. 2020-01-02 15:29:44 -08:00
Doug Gregor
40e599e962 [Type checker] Move for-each application logic into constraint system.
Move the various "application" logic for the for-each loop out of the
visitor in TypeCheckStmt and into the constraint system's handling of
for-each bindings.
2020-01-02 15:09:23 -08:00
Doug Gregor
97b5a0d5fb [Type checker] Stop devirtualizing the reference to IteratorProtocol.next().
Rather than having the type checker look for the specific witness to
next() when type checking the for-each loop, which had the effect of
devirtualizing next() even when it shouldn't be, leave the formation
of the next() reference to SILGen. There, form it as a witness
reference, so that the SIL optimizer can choose whether to
devirtualization (or not).
2020-01-02 14:39:00 -08:00
Doug Gregor
f22a7e2880 [AST] Drop makeIterator reference from ForEachStmt.
Rather than having the type checker form the ConcreteDeclRef for
makeIterator, have SILGen do it, because it's fairly trivial.
Eliminates some redundant state from the AST.
2020-01-02 13:29:13 -08:00
swift_jenkins
b9fde199f0 Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 13:19:16 -08:00
Pavel Yaskevich
6261324440 Merge pull request #28980 from xedin/remove-obsolete-csdiag-listener
[CSDiag] NFC: Remove obsolete `CalleeListener` callback
2020-01-02 13:08:15 -08:00
Doug Gregor
9be16b2185 [Type checker] Move conformance resolution during application into Solution.
While this doesn't completely use the solution's set of known conformances,
it moves the logic for handling the lookup into the right place.
2020-01-02 13:06:09 -08:00
swift_jenkins
a376fdaa9d Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 12:19:11 -08:00
Rintaro Ishizaki
046c9148ec [CodeCompletion] Use getBodySourceRange() instead of getSourceRange()
To check if the completion is happening in the AFD body.
Otherwise, local variables are sometimes not suggested because the body
and its range is from another file.

rdar://problem/58175106
2020-01-02 12:18:47 -08:00
Rintaro Ishizaki
9cd3072dd4 Merge pull request #28949 from rintaro/ide-completion-rdar52105899
[CodeCompletion] Evaluate 'PatternBindingEntryRequest' before checking the init
2020-01-02 12:14:47 -08:00
Doug Gregor
bbcaf8c669 [Type checker] Introduce value witness constraints.
Introduce a new kind of constraint, the "value witness" constraint,
which captures a reference to a witness for a specific protocol
conformance. It otherwise acts like a more restricted form of a "value
member" constraint, where the specific member is known (as a
ValueDecl*) in advance.

The constraint is effectively dependent on the protocol
conformance itself; if that conformance fails, mark the type variables
in the resolved member type as "holes", so that the conformance
failure does not cascade.

Note that the resolved overload for this constraint always refers to
the requirement, rather than the witness, so we will end up recording
witness-method references in the AST rather than concrete references,
and leave it up to the optimizers to perform devirtualization. This is
demonstrated by the SIL changes needed in tests, and is part of the
wider resilience issue with conformances described by
rdar://problem/22708391.
2020-01-02 12:06:23 -08:00
Pavel Yaskevich
43f1e9ba60 [CSDiag] NFC: Remove obsolete CalleeListener callback
Since closure handling has been ported to new diagnostic framework
`CalleeListener` callback is no longer used.
2020-01-02 11:06:09 -08:00
swift_jenkins
81c0ed297a Merge remote-tracking branch 'origin/master' into master-next 2020-01-02 10:19:08 -08:00
Doug Gregor
c5a655e35b [Type checker] Fold more for-each type checking into the constraint solver.
The type checking of the for-each loop is split between the constraint
solver (which does most of the work) and the statement checker (which
updates the for-each loop AST). Move more of the work into the constraint
solver proper, so that the AST updates can happen in one place, making use
of the solution produced by the solver. This allows a few things, some of
which are short-term gains and others that are more future-facing:

* `TypeChecker::convertToType` has been removed, because we can now either
use the more general `typeCheckExpression` entry point or perform the
appropriate operation within the constraint system.
* Solving the constraint system ensures that everything related to the
for-each loop full checks out
* Additional refactoring will make it easier for the for-each loop to be
checked as part of a larger constraint system, e.g., for processing entire
closures or function bodies (that’s the futurist bit).
2020-01-02 09:55:39 -08:00
Rintaro Ishizaki
091c36bc82 [CodeCompletion] Evaluate 'PatternBindingEntry' before checking the init
If a completion happens in an 'PatternBindingInitializer' context for
'TypedPattern' without any 'VarDecl', e.g.:

    let _: Int = <COMPLETION>

it crashes because 'typeCheckPatternBinding()' requires that the
'TypedPattern' has the type.

rdar://problem/52105899
2019-12-25 16:30:52 -08:00
Robert Widmann
ebac915ef4 [NFC] Drop bogus closure interface type reset 2019-12-25 17:03:03 -05:00