Commit Graph

784 Commits

Author SHA1 Message Date
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
Chris Lattner
59185be7cd Add the ability to write an 'if case' condition. It allows an arbitrary refutable
pattern, and can be chained together in conditions just like our other 'if let' 
constructs.  This only adds functionality, it doesn't change anything yet.


Swift SVN r27932
2015-04-29 21:59:57 +00:00
John McCall
426510cd4e Create an ErrorExpr when expression parsing consumes tokens
but doesn't build anything.

I have no idea why this test case needed to change.

Swift SVN r27897
2015-04-29 00:23:15 +00:00
Chris Lattner
82ef514f99 Reimplement the AST, Sema, and SILGen of defer to be closure based.
Now we bind the defer body into a ClosureExpr and emit it at the point of
the defer.  At any exit points out of the controlled region, we emit a call 
to the closure.

This should cover any problems where expressions cannot be emitted multiple times.
However, this is dramatically more complex than the obvious implementation, so I 
hope this patch can be reverted.



Swift SVN r27767
2015-04-26 17:58:06 +00:00
Chris Lattner
ee96164996 implement parsing, AST, and basic Sema support for 'defer'.
SILGen support and diagnosing jumps out of a defer aren't done
yet.



Swift SVN r27759
2015-04-26 15:16:37 +00:00
Chris Lattner
f71a329afd fix <rdar://problem/17569958> #endif not parsed correctly when occurs as last line in file
Swift SVN r27753
2015-04-26 05:32:04 +00:00
Chris Lattner
a475a3326f implement <rdar://problem/19786845> Warn on "let" and "var" when no data is bound in a pattern
We warn like this:
t.swift:3:12: warning: 'let' pattern has no effect; sub-pattern didn't bind any variables
      case let .Bar: println("bar")
           ^~~ ~~~~



Swift SVN r27747
2015-04-26 04:38:13 +00:00
Chris Lattner
2f15b53fe8 Add support for 'catch {' as a synonym for "catch let error {".
Swift SVN r27702
2015-04-24 18:54:45 +00:00
Chris Willmore
c7c7388cf2 Change do-while to repeat-while.
Change all uses of "do { ... } while <cond>" to use "repeat" instead.
Rename DoWhileStmt to RepeatWhileStmt. Add diagnostic suggesting change
of 'do' to 'repeat' if a condition is found afterwards.

<rdar://problem/20336424> rename do/while loops to repeat/while & introduce "repeat <count> {}" loops

Swift SVN r27650
2015-04-23 22:48:31 +00:00
Chris Lattner
e45c8defce fix <rdar://problem/20489838> QoI: Nonsensical error and fixit if "let" is missing between 'if let ... where' clauses
by tweaking parsing logic to handle a common error case with a nice diagnostic + fixit.  We now produce:

x.swift:4:29: error: binding ended by previous 'where' clause; use 'let' to introduce a new one
if let y? = x where y == 0, z? = x where z == 0 {
                            ^
                            let 



Swift SVN r27452
2015-04-18 05:36:01 +00:00
Chris Lattner
a63120f11a fix <rdar://problem/20457938> typed pattern is not allowed on if/let condition
Swift SVN r27110
2015-04-08 00:28:29 +00:00
Chris Lattner
e62845b9da fix <rdar://problem/20426834> incorrect refutable pattern match issue
We only require one of the patterns in a multi-pattern PBD to be conditional
as part of the swift 1 migation.  Relax the requirements to allow unconditional
bindings next to conditional ones.  This required moving some logic from the parser
to sema time.



Swift SVN r26987
2015-04-04 20:36:16 +00:00
Chris Lattner
8a07a85a91 Progress towards let/else:
- Implement SILGen for conditional multi-pattern PBD's.
 - Have the type checker check where clauses on PBDs.
 - Change the AST to represent complex if/let PBD's with
   composed PBDs instead of breaking them down. For example, 
   represent:
     if let x? = foo(), y? = bar() where x == y {
   as a single PBD in a StmtCondition instead of representing
   it as three entries in the condition.

The later change is good for AST/source fidelity as well as providing
a cheap way to exercise all the logic I'm building.



Swift SVN r26959
2015-04-03 22:46:34 +00:00
John McCall
2560e62b66 Only allow 'throw' expressions at statement positions.
rdar://20385676

Swift SVN r26833
2015-04-01 22:30:53 +00:00
Chris Lattner
b6e13bd1fe - Diagnose conditional PBD's without an else, conditional ones that do have an else,
and refutable pattern bindings without an initializer.
- Enhance ASTDumper to dump where/else clauses on PBDs.
- Merge if/let conditional PBD logic into the mainline logic now that they are all
  potentially conditional (more simplifications coming for this)

add tests for the fixits, which exercise the earlier SourceRange enhancments, e.g.:

x.swift:3:5: error: refutable pattern match can fail; add an else {} to handle this condition
let o? = a
    ^~
           else {}




Swift SVN r26751
2015-03-31 05:31:47 +00:00
Chris Lattner
c6134d913f prune #include
Swift SVN r26705
2015-03-29 22:02:26 +00:00
Arnold Schwaighofer
b9f795699f Revert "add parser and AST representation support for where/else clauses on let/var decls."
It breaks the validation test suite.

This reverts commit r26692.

rdar://20339903

Swift SVN r26700
2015-03-29 13:56:32 +00:00
Chris Lattner
9c53b659ee add parser and AST representation support for where/else clauses on let/var decls.
Sema, silgen, and more tests coming later.


Swift SVN r26692
2015-03-29 06:20:24 +00:00
Chris Lattner
fa90fec707 Teach Pattern::forEachVariable how to handle dig into ExprPatterns
to find variables, enabling it to work with refutable patterns in
addition to nonrefutable ones.  This allows eliminating some special
case code in the parser, NFC.



Swift SVN r26686
2015-03-29 05:28:35 +00:00
Xi Ge
8a64deb828 [codecompletion] auto-completing the catch statement.
When the code completion token is seen after the catch keyword, a set of
visible error types are suggested as completion.

Swift SVN r26519
2015-03-25 04:16:57 +00:00
John McCall
5d2f32bf83 Disallow trailing closures in catch patterns and
fix an assertion with rethrows out of non-exhaustive
catch statements.

Swift SVN r26470
2015-03-24 01:34:50 +00:00
John McCall
a0a16d78d2 Implement the do/catch statement. Tests to follow.
This patch also introduces some SILGen infrastructure for
dividing the function into "ordinary" and "postmatter"
sections, with error-handling-like stuff going into the
final section.  Currently, this is largely undermined by
SILBuilder, but I'm going to fix that in a follow-up.

Swift SVN r26422
2015-03-23 02:08:26 +00:00