Commit Graph

455 Commits

Author SHA1 Message Date
Xi Ge
dfc48c8aee [CodeComplete] Add type relation descriptor when completing return statement. rdar://22788321
Swift SVN r32125
2015-09-21 21:18:26 +00:00
Xi Ge
9335511c0d [Parser] Better recovery from parsing errors in RepeatStmt so that indentation works. rdar://22713926
Swift SVN r32053
2015-09-18 00:39:49 +00:00
Xi Ge
e726cf0ee6 [Parser] Return statement should not expect expression when the following token is one of #if, #elseif, #endif and #else. rdar://21729212
Swift SVN r31897
2015-09-11 18:11:13 +00:00
Xi Ge
ef3b45871b [CodeComplete] Complete arguments of call expressions.
When users invoke code completion at an argument position, we suggest argument names,
if required however not specified, or a list of argument values. These values are annotated
with their type relation to the expected argument types, so that
Xcode can prioritize those values that apply over those that do not.
This also fixes: rdar://21727063

Swift SVN r31505
2015-08-26 22:01:25 +00:00
Dmitri Hrybenko
3f7d64c532 Diagnose invalid arguments for '#if _runtime()'
rdar://problem/20117677

Swift SVN r31336
2015-08-19 16:55:39 +00:00
Joe Groff
0b1283b1c9 Have 'defer' statements cons up func decls instead of closure literals.
The defer body func is only ever fully applied, so SILGen can avoid allocating a closure for it if it's declared as a 'func', making it slightly more efficient at -Onone.

Swift SVN r30638
2015-07-25 21:28:06 +00:00
Doug Gregor
f00e5bc6ab Allow a variadic parameter anywhere in the parameter list.
Requiring a variadic parameter to come at the end of the parameter
list is an old restriction that makes no sense nowadays, and which we
had all thought we had already lifted. It made variadic parameters
unusable with trailing closures or defaulted arguments, and made our
new print() design unimplementable.

Remove this restriction, replacing it with a less onerous and slightly
less silly restriction that we not have more than one variadic
parameter in a given parameter clause. Fixes rdar://problem/20127197.

Swift SVN r30542
2015-07-23 18:45:29 +00:00
Jordan Rose
4cdac3fc4c Don't add variables declared in 'guard let' to a SourceFile's Decls.
These variables really are local variables -- they have have a
TopLevelCodeDecl as their DeclContext rather than the SourceFile.
Treating them as global variables caused crashes in serialization.

We need an overhaul of top-level variables in script files anyway
(see rdar://problem/20992489&21628526), but this fixes the immediate
issue.

rdar://problem/21928533

Swift SVN r30519
2015-07-23 00:55:36 +00:00
Xi Ge
c783def2f5 [CodeCompletion] Add code completion for platform names inside #available() condition.
The code for generating the code completion string reuses that of the @available attribute.
rdar://21467109

Swift SVN r30346
2015-07-18 00:10:37 +00:00
Slava Pestov
4e26069c8f Parse: Fix EndLoc of #if without #endif in parseDeclIfConfig(), and clean up duplication
Fixes <rdar://problem/19671208>.

Swift SVN r30314
2015-07-17 08:31:21 +00:00
Chris Lattner
ae4aa79866 fix <rdar://problem/18776073> Swift's break operator in switch should be indicated in errors
Swift SVN r30116
2015-07-11 18:30:51 +00:00
Ben Langmuir
b17da688b2 [CodeCompletion] Avoid crash completing switch case at top-level
We always expect to get a pattern, but in top-level completion we forgot
to build the fallback AnyPattern to go in the error result.

rdar://21661308

Swift SVN r30078
2015-07-10 18:58:09 +00:00
Chris Lattner
b075f810ba Reimplement error recovery in C-style for statement, where we'd turn a ClosureExpr
into the body of the for statement.  Instead of ripping the body of the closureexpr
out and putting it into the C Style for, wrap up the closureExpr into a call.  This
avoids breaking AST invariants because the ClosureExpr will be the DeclContext for
anything inside of it.

This fixes <rdar://problem/21679557> compiler crashes on "for{{"
... which was Practical Swift's shortest crasher.



Swift SVN r29916
2015-07-06 06:19:30 +00:00
Chris Lattner
da4ea30b23 Make the parser handle #if directives better when skipping due to error recovery. Previously,
we would blow past a #endif directive, which leads to bad things later.

this will be tested in a forthcoming testcase.


Swift SVN r29915
2015-07-06 05:28:55 +00:00
Chris Lattner
c03c042ad4 fix <rdar://problem/21392677> for/case/in patterns aren't parsed properly
We weren't keeping track of the fact that we were parsing within a matching
pattern context, so we'd fail some patterns.


Swift SVN r29457
2015-06-17 21:33:32 +00:00
Chris Lattner
8e14bbaaa1 fix <rdar://problem/21110580> guard let in top level code doesn't work
We were just not injecting the vardecls into the SourceFile, so unqual name 
lookup couldn't find them later.


Swift SVN r29456
2015-06-17 20:00:05 +00:00
Jordan Rose
de81a3e15f Prefer using known-identifiers to using getIdentifier.
I didn't add anything to the table, just made use of what was already there.
We have plenty of additional calls to getIdentifier that could probably benefit
from this kind of easy access as well.

This commit also removes FOUNDATION_MODULE_NAME and OBJC_MODULE_NAME from
Strings.h. Neither of these is likely to change in the future, and both
already have KnownIdentifiers equivalents in use.

No intended functionality change.

Swift SVN r29292
2015-06-04 04:01:08 +00:00
Ben Langmuir
4c83738657 Address review feedback on r29070
* Make CHECK-NOT lines more robust
* Remove redundant assertion

Swift SVN r29079
2015-05-27 21:25:10 +00:00
Ben Langmuir
8ccaa86806 [CodeCompletion] Complete variables bound by catch
Make sure we build the CatchStmt and DoCatchStmt AST nodes when
code-completing inside the body of a catch so that we can complete the
bindings from the catch.

It's often a good idea to early-exit once we see a code completion
token, but not when we skip building an AST node that provides variable
bindings.  In code completion, we don't have Scope-based lookup, and
rely on having reachable AST nodes for patterns so that we can dig the
out the bindings we need.

Also extend the pattern checking to handle "IsPattern", since we
apparently weren't handling "let x as Foo", and that affects all complex
catch patterns because of an implicit "as ErrorType" or explicit
"as NSError".

rdar://problem/21116164

Swift SVN r29070
2015-05-27 19:01:16 +00:00
Jordan Rose
0c77785020 [Parser] Explicitly reject "try" before a statement with a specific diagnostic.
And for "try return", "try throw", and "try let", get even more specific,
with a fix-it to suggest moving the "try" onto the expression.

rdar://problem/21043120

Swift SVN r28862
2015-05-21 00:12:36 +00:00
Chris Lattner
258f91f60b revert: r28801 - improve the source location information for { and } in a ClosureExpr.
Instead, provide the location of the { in a closure expr to the argument formation as 
part of the datastructure already used to manage implicit closure arguments in the parser.


Swift SVN r28818
2015-05-20 03:19:56 +00:00
Chris Lattner
66916683a2 improve the source location information for { and } in a ClosureExpr, by
actually tracking it. NFC.


Swift SVN r28801
2015-05-20 00:10:04 +00:00
Chris Lattner
b1cd88b5f1 rename the implicitly generated temp variable for 'defer' from tmpClosure to
$tmpClosure.  This is NFC, but should help with rdar://20968266, a debugger
QoI issue.



Swift SVN r28741
2015-05-19 02:22:20 +00:00
Ben Langmuir
882959b60d [CodeCompletion] Remove incorrect special-casing for throw/catch
It's not okay to filter to only ErrorType results, since we may be
trying to chain to an error type result foo.bar.getError().  And the
existing logic had no way to handle results from other modules, so we
were missing key results like 'NSError'.

Eventually we'll want to bring back something like this that handles all
modules, but as a way to bump the priority of ErrorType results rather
than to filter out everything else.

rdar://problem/20985515

Swift SVN r28716
2015-05-18 19:00:04 +00:00
Chris Lattner
e517ad9182 Fix unreachable code handling to properly diagnose things like:
throw x 
whatever()  

as being unreachable after the throw.



Swift SVN r28680
2015-05-17 15:13:35 +00:00
Dmitri Hrybenko
0a1f7c09df Revert "Fix unreachable code handling to properly diagnose things like:"
This reverts commit 28678.  It broke the IDE/complete_exception.swift
test.

Swift SVN r28679
2015-05-17 12:27:57 +00:00
Chris Lattner
5ead9764bd Fix unreachable code handling to properly diagnose things like:
throw x
  whatever()

as being unreachable after the throw.



Swift SVN r28678
2015-05-17 05:56:02 +00:00
Devin Coughlin
c9952640bb Support short-form @available attributes.
Allow availability attributes of the form:

  @available(iOS 8.0, OSX 10.10, *)
  func foo() { }

This form is intended for use by third-party developers when annotating their
own declarations and uses the same syntax as #available(). This annotation
says that on iOS foo() is available on version 8.0 and newer; on OSX it is
available on 10.10; and on any other un-mentioned platform it considered
available on the minimum deployment target and greater. Just like with

For now, we support this form during parsing by synthesizing multiple implicit
long-form @available attributes. So, for example, the above annotation will
synthesize two implicit attributes:

  @available(iOS, introduced=8.0)
  @available(OSX, introduced=10.10)
  func foo() { }

Synthesizing attributes in this way is not ideal -- it makes for a poor Fix-It
experience, among other things -- but it exposes the short-form syntax with
minimal invasiveness.

rdar://problem/20938565

Swift SVN r28647
2015-05-15 23:36:11 +00:00
Devin Coughlin
9f4233bdc1 Move validation of #available() from Sema to Parse
In anticipation of adding short-form @available() annotations, move validation
of #available() platform/version lists out of Sema and into the parser. This
also enables slightly more graceful recovery from errors.

Swift SVN r28637
2015-05-15 20:08:25 +00:00
Ted Kremenek
02041a9e6f Revert "Revert "fix <rdar://problem/20883210> QoI: Following a "let" condition with boolean condition spouts nonsensical errors""
I thought this was the culprit behind the SourceKit test failure, but I was wrong.

Swift SVN r28621
2015-05-15 07:05:55 +00:00
Ted Kremenek
3ab75178de Revert "fix <rdar://problem/20883210> QoI: Following a "let" condition with boolean condition spouts nonsensical errors"
This is causing a regression with 'while ... where', and manifests in the SourceKit tests.

Swift SVN r28616
2015-05-15 06:50:10 +00:00
Chris Lattner
e6344e4ad6 fix <rdar://problem/20883210> QoI: Following a "let" condition with boolean condition spouts nonsensical errors
Swift SVN r28596
2015-05-15 01:14:20 +00:00
Devin Coughlin
561082b08d [Parse] Update comment describing statement condition grammar.
Update the comment describing the statement condition grammar to include
generalized pattern matching with 'case' and #available().

Swift SVN r28573
2015-05-14 18:35:08 +00:00
Chris Lattner
8a7b3f414e Revise the parser and AST representation of #available to be part of StmtCondition
instead of being an expression.

To the user, this has a couple of behavior changes, stemming from its non-expression-likeness.
 - #available cannot be parenthesized anymore
 - #available is in its own clause, not used in a 'where' clause of if/let.

Also, the implementation in the compiler is simpler and fits the model better.  This
fixes:
<rdar://problem/20904820> Following a "let" condition with #available is incorrectly rejected



Swift SVN r28521
2015-05-13 19:00:40 +00:00
Chris Lattner
acf5a426bb as a tiny QoI improvement, parse "#if 0" and recover as if the user
wrote "#if false" while producing an error + fixit.


Swift SVN r28411
2015-05-11 06:07:44 +00:00
Chris Lattner
1fec424301 fix comment typo, nfc.
Swift SVN r28372
2015-05-09 21:51:42 +00:00
Chris Lattner
3814b7003f Implement support for arbitrary pattern matching in for-each statements,
which composes straight-forwardly on top of the existing stuff for if/let
and guard.



Swift SVN r28371
2015-05-09 21:34:35 +00:00
Chris Lattner
47bdbfb694 fix <rdar://problem/20883147> Type annotation for 'let' condition still expected to be optional
Swift SVN r28360
2015-05-09 02:34:01 +00:00
Chris Lattner
58b63193d5 Implement support for 'where' clauses on foreach loops, part of
<rdar://problem/14482451> Allow refutable patterns & 'where' in 'for-each' loops




Swift SVN r28338
2015-05-08 23:57:01 +00:00
Chris Lattner
ddddc88808 simplify some code.
Swift SVN r28249
2015-05-07 00:41:02 +00:00
Chris Lattner
37f5452d15 require -> guard.
Swift SVN r28223
2015-05-06 22:53:38 +00:00
Chris Lattner
0011b3ae21 rename "unless" to "require" and give it an 'else' keyword.
Swift SVN r28059
2015-05-02 00:16:44 +00:00
Chris Lattner
d5073d9e4f rework StmtCondition to be based on patterns initializers and boolean
conditions instead of being wrapped around PatternBindingDecl.  When
let/else goes away, PatternBindingDecl will become a lot simpler.


Swift SVN r28055
2015-05-01 23:33:59 +00:00
Chris Lattner
ec95a37e08 rework the disambiguation logic that determines whether a token stream is
likely to be a c-style for loop or a for-each loop.  NFC except in one recovery
cases where we already spray crazy diagnostics.


Swift SVN r28023
2015-05-01 04:42:56 +00:00
Chris Lattner
2ffb5bb23c diagnose always-true conditions.
Swift SVN r28017
2015-05-01 03:55:08 +00:00
Chris Lattner
2cf3fd3f43 Fix scoping so that the variables parsed in an 'unless' are inserted into the
parent scope.



Swift SVN r27994
2015-04-30 20:59:00 +00:00
Chris Lattner
79ea1e0bf1 In the body of an 'unless', reject uses of any variables bound in the unless.
Swift SVN r27993
2015-04-30 20:08:29 +00:00
Chris Lattner
c6aa041fb9 Add parser/ast/sema/sourcekit/etc support for 'unless' statement.
SILGen support still missing.



Swift SVN r27961
2015-04-30 05:55:11 +00:00
Chris Lattner
31c01eab73 Change the meaning of "if let x = foo()" back to Xcode 6.4 semantics. The compiler
includes a number of QoI things to help people write the correct code.  I will commit
the testcase for it as the next patch.

The bulk of this patch is moving the stdlib, testsuite and validation testsuite to
the new syntax.  I moved a few uses of "as" patterns back to as? expressions in the 
stdlib as well.



Swift SVN r27959
2015-04-30 04:38:13 +00:00
Chris Lattner
aa4f01b228 fix a fixit I accidentally broke and re-adjust a testcase back to the way it was.
Swift SVN r27942
2015-04-29 23:09:47 +00:00