Commit Graph

1357 Commits

Author SHA1 Message Date
Slava Pestov
91dffc9d44 Sema: Use AnyFunctionType::printParams() to print argument lists instead of printing a tuple type
Once the '@escaping' bit is removed from TupleTypeElt, it no longer makes
sense to print argument lists as if they were TupleTypes or ParenTypes,
since function types are '@escaping' by default inside tuples but not
in argument lists.

Instead, print ArrayRef<AnyFunctionType::Param> directly. For now this
introduces some awkward usages of AnyFunctionType::decomposeInput();
these will go away once the AST is changed to represent the argument list
as a list of expressions and not a single tuple expression.
2019-04-15 00:22:29 -04:00
Suyash Srijan
072e84acd6 [CSSimplify] Reject key path if root type is AnyObject (#23820)
Detect situations where `AnyObject` is attempted to be used as a root type of the key path
early and diagnose via new diagnostics framework.
2019-04-14 12:18:35 -07:00
Pavel Yaskevich
16b65018b4 Merge pull request #23436 from xedin/keypath-dynamic-lookup
[SE-0252][TypeChecker] Keypath Dynamic Member Lookup
2019-04-05 00:10:53 -07:00
Slava Pestov
560d3ad529 Sema: Simplify simplifyLocator() 2019-04-02 20:37:01 -04:00
Slava Pestov
6bb36b5c01 Sema: Subscript default arguments
Fixes <https://bugs.swift.org/browse/SR-6118>.
2019-04-02 20:37:01 -04:00
Slava Pestov
93b205e2b9 Sema: Simplify coerceParameterListToType() 2019-04-01 22:41:16 -04:00
Pavel Yaskevich
8f880545cd [TypeChecker] Add ReferenceWritableKeyPath support to keypath dynamic member lookup 2019-04-01 12:41:55 -07:00
Pavel Yaskevich
2c82882b8f [ConstraintSystem] Move unviable keypath dynamic member check into performMemberLookup 2019-04-01 12:40:39 -07:00
Slava Pestov
1467f554f5 AST: Remove ArgumentShuffleExpr 2019-03-31 01:36:19 -04:00
Pavel Yaskevich
1ee66cd653 Merge pull request #23500 from theblixguy/fix/SR-9267
[CSDiag] Improving the fix-it for defining computed variables
2019-03-25 11:02:45 -07:00
Suyash Srijan
5a8e1fa955 [cs] extract computed property fix-it into separate method 2019-03-25 00:07:41 +00:00
Suyash Srijan
9750762b75 [csdiag] missing function call failure here as a backup 2019-03-23 02:11:13 +00:00
Suyash Srijan
1b62039c76 [cssimplify] add a fix for contextual type conversion for function type 2019-03-22 23:40:43 +00:00
Suyash Srijan
cad60ba08b [csdiag] offer a fix-it to turn a stored property into a computed property if needed 2019-03-22 21:21:17 +00:00
Slava Pestov
d470e9df4d AST: Split off ArgumentShuffleExpr from TupleShuffleExpr
Right now we use TupleShuffleExpr for two completely different things:

- Tuple conversions, where elements can be re-ordered and labels can be
  introduced/eliminated
- Complex argument lists, involving default arguments or varargs

The first case does not allow default arguments or varargs, and the
second case does not allow re-ordering or introduction/elimination
of labels. Furthermore, the first case has a representation limitation
that prevents us from expressing tuple conversions that change the
type of tuple elements.

For all these reasons, it is better if we use two separate Expr kinds
for these purposes. For now, just make an identical copy of
TupleShuffleExpr and call it ArgumentShuffleExpr. In CSApply, use
ArgumentShuffleExpr when forming the arguments to a call, and keep
using TupleShuffleExpr for tuple conversions. Each usage of
TupleShuffleExpr has been audited to see if it should instead look at
ArgumentShuffleExpr.

In sequent commits I plan on redesigning TupleShuffleExpr to correctly
represent all tuple conversions without any unnecessary baggage.

Longer term, we actually want to change the representation of CallExpr
to directly store an argument list; then instead of a single child
expression that must be a ParenExpr, TupleExpr or ArgumentShuffleExpr,
all CallExprs will have a uniform representation and ArgumentShuffleExpr
will go away altogether. This should reduce memory usage and radically
simplify parts of SILGen.
2019-03-21 02:18:41 -04:00
Pavel Yaskevich
688042becf [Diagnostics] Add inaccessible member diagnostic 2019-03-18 13:48:08 -07:00
Pavel Yaskevich
852169a5f5 [ConstraintSystem] Split unviable lookup result storage into candidates & reasons
That makes it easy to process unviable choices the same way as viable
ones and request rejection reasons only when necessary.
2019-03-14 22:20:20 -07:00
Pavel Yaskevich
2e14bec250 [Diagnostics] Add out-of-order argument diagnostic 2019-03-04 20:03:54 -08:00
Pavel Yaskevich
5dd5454a75 [CSSimplify] Determine if argument is out-of-order while matching labels
Instead of rerouting out-of-order into re-labeling during diagnostics,
let's do that as part of the label matching algorithm.
2019-03-04 20:03:30 -08:00
Pavel Yaskevich
9999a47197 [Diagnostics] Add closure parameter destructuring diagnostic 2019-03-04 11:37:43 -08:00
Pavel Yaskevich
aeaa26d926 [CSDiagnostics] Add missing arguments failure
Currently only supports closures, but could be easily expanded
to other types of situations e.g. function/member calls.
2019-02-26 13:29:35 -08:00
Joe Groff
bb67cf815c Merge pull request #21355 from technicated/tuple-keypaths-2
Tuple KeyPaths
2019-02-25 12:56:05 -08:00
Suyash Srijan
34f8670d2a [CS] Use fixes to diagnose instance member on type (or vice versa) access (#21830)
This PR migrates instance member on type and type member on instance diagnostics handling to use the new diagnostics framework (fixes) and create more reliable and accurate diagnostics in such scenarios.
2019-02-22 16:57:26 -08:00
technicated
91f0ca2ff9 Removed some now-unnecessary diagnostic / check
unsupported_keypath_tuple_element_reference
expr_keypath_unimplemented_tuple
2019-02-18 10:19:43 +01:00
Andrea Tomarelli
ede47cafbd Partial AST & Sema implementation of TKP 2019-02-18 09:04:42 +01:00
Pavel Yaskevich
df0616a206 [CSDiag] Mark all sub-expressions which are about to be re-typechecked
Currently that has been limited only to expressions which aren't
flagged as `TCC_ForceRecheck`, but it should be extended to all
sub-expressions, otherwise we might produce invalid diagnostics
in `PreCheckExpression`.
2019-01-25 12:04:07 -08:00
David Ungar
a8abaadd65 Minor 2019-01-17 17:37:24 -08:00
David Ungar
6ec471e6eb Format 2019-01-17 11:16:39 -08:00
David Ungar
584c157796 WIP move info to KnownProtocols.def, unformatted 2019-01-17 11:15:58 -08:00
Slava Pestov
e99607c421 Sema: Use ConstraintKind::Bind where possible instead of ::Equal
Solving Bind is a little easier than Equal. The only remaining uses of Equal
are in the .member syntax and keypaths; if we can refactor those, we might be
able to simplify LValue handling in the type checker in general.
2019-01-14 14:55:16 -05:00
Pavel Yaskevich
6791ef3624 Merge pull request #21756 from xedin/rdar-36989788
[Diagnostics] Diagnose missing members via fixes
2019-01-10 10:36:17 -08:00
Slava Pestov
e276b12d9a Sema: Remove unreachable code from CSDiag 2019-01-10 08:44:18 -05:00
Pavel Yaskevich
74a8ee177e [Diagnostics] Diagnose missing members via fixes
Try to fix constraint system in a way where member
reference is going to be defined in terms of its use,
which makes it seem like parameters match arguments
exactly. Such helps to produce solutions and diagnose
failures related to missing members precisely.

These changes would be further extended to diagnose use
of unavailable members and other structural member failures.

Resolves: rdar://problem/34583132
Resolves: rdar://problem/36989788
Resolved: rdar://problem/39586166
Resolves: rdar://problem/40537782
Resolves: rdar://problem/46211109
2019-01-09 17:29:49 -08:00
Pavel Yaskevich
06a7ad63f8 [Diagnostics] Diagnose subscript operator misuse via fixes
Fix to use subscript operator instead of spelled out name helps
to produce a solution, that makes it much easier to diagnose
problems precisely and provide proper fix-its, it also helps to
diagnose ambiguous cases, and stacks up nicely with other errors.
2019-01-08 12:06:40 -08:00
Pavel Yaskevich
35202ab5b0 [TypeChecker] Always emit a fallback error if type-check failed without producing one
Sometimes constraint solver fails without producing any diagnostics,
it could happen during different phases e.g. pre-check, constraint
generation, or even while attempting to apply solution. Such behavior
leads to crashes down the line in AST Verifier or SILGen which are
hard to diagnose.

Let's guard against that by tracking if solver produced any diagnostics
upon its failure and if no errors were or are scheduled to be produced,
let's produce a fallback fatal error pointing at affected expression.

Resolves: rdar://problem/38885760
2019-01-07 10:42:00 -08:00
Pavel Yaskevich
09cb803e79 [CSDiag] Always attempt to erase open existentials after re-typecheck
All of the open existentials should be removed, along with their
opaque value expressions, after sub-expression type-check. Because
diagnostics might pick next sub-expression from constraint and its
anchor could point to sub-expression which has only opaque value
without enclosing open existential, which is going to trip up sanitizer.

Resolves: rdar://problem/46544601
2018-12-21 00:34:27 -08:00
Slava Pestov
2f61230627 Sema: Remove vestigial rvalue varargs code path 2018-12-16 01:02:56 -05:00
Pavel Yaskevich
9ecc0abb29 [CSDiag] FailureDiagnosis needs to account for the fact that expressions are sanitized
After calling `get{Possible}Type{s}WithoutApplying` types have to be
re-cached afterwards because sanitizer (run as part of the constraint
generator) can mutate AST to e.g. re-introduce member references.

Resolves: rdar://problem/46497155
2018-12-13 20:31:50 -08:00
Joe Groff
20a2f3ea9f Merge pull request #21244 from jckarter/archetype-subclasses
Split subclasses out of ArchetypeType.
2018-12-12 11:49:48 -08:00
Joe Groff
f1648a1b3e Split subclasses out of ArchetypeType.
Context archetypes and opened existential archetypes differ in a number of details, and this simplifies the overlapping storage of the kind-specific fields. This should be NFC; for now, this doesn't change the interface of ArchetypeType, but should allow some refinements of how the special handling of certain archetypes are handled.
2018-12-12 08:55:56 -08:00
Pavel Yaskevich
9818b55266 [CSDiagnostics] Add MissingCall failure
It's used to diagnose cases when function/method are used as
a property instead of being called.
2018-12-11 18:44:41 -08:00
Pavel Yaskevich
138105bd98 [CSDiag] Verify that @autoclosure param has function type before casting
When parameter refers to something undefined its type is going to
be `ErrorType`, so diagnostic path needs to make sure that parameter
has a valid function type before trying to extract result from it.

Resolves: rdar://problem/46377919
2018-12-03 18:20:41 -08:00
Michael Gottesman
e379ab9beb Merge pull request #20557 from brentdax/this-is-why-swift-is-a-memory-safe-language
Fix lookupDirect() use-after-scope bugs
2018-11-14 00:01:10 -08:00
Brent Royal-Gordon
270ad33a72 Fix lookupDirect() use-after-scope bugs
In #7530, NominalTypeDecl::lookupDirect() started returning TinyPtrVector instead of ArrayRef so that it wouldn’t be returning a pointer into a mutable data structure. Unfortunately, some callees assigned its return value into an ArrayRef; C++ happily converted the TinyPtrVector to an ArrayRef and then treated the TinyPtrVector as out-of-scope, so the ArrayRef would now point to an out-of-scope object. Oops.
2018-11-13 16:31:59 -08:00
Pavel Yaskevich
c1dba165a9 [CSDiag] Diagnose KeyPath tuple access as unsupported even when sugared
Follow-up for [SR-9213](https://bugs.swift.org/browse/SR-9213)
2018-11-12 12:57:22 -08:00
Pavel Yaskevich
2ad754d470 Merge pull request #20152 from xedin/add-autoclosure-flag-to-param-decl
[AST/Sema] Associate `@autoclosure` flag with parameter declaration
2018-11-10 14:53:31 -08:00
Suyash Srijan
21f97a55b4 Uses isa instead of is for type check 2018-11-10 20:10:43 +00:00
Pavel Yaskevich
6b62ac83e1 [CSDiag] Switch expression diagnostics to check @autoclosure from parameter flags
There is only one place where we need to do that - `typeCheckArgumentChildIndependently`
2018-11-10 11:59:28 -08:00
Suyash Srijan
7d32a749d6 Access kind only if currentType is not null and simplify check for tuple 2018-11-10 18:46:16 +00:00
Suyash Srijan
15ebc07421 Fixes incorrect diagnostic when using keypath with tuples 2018-11-10 17:19:09 +00:00