581 Commits

Author SHA1 Message Date
John McCall
3d3f1a7d7e Parsing/AST/Sema support for rethrows, and fix bugs with
throws/rethrows override and conformance checking.

Swift SVN r27508
2015-04-20 23:39:12 +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
Joe Pamer
37d65f4202 Start tracking SourceLoc data for function "throws" annotations and eliminate the (now unnecessary) "Throws" bit from AbstractFunctionDecls.
Swift SVN r26955
2015-04-03 21:45:30 +00:00
Chris Lattner
3282e2035f Fix <rdar://problem/20364082> Incorrect fixit "if let x: T = ..." => "if let x?: T = ..."
Previously we would emit one diagnostic for the "you need a ?" and one for the "you can't use
a type annotation" errors.  This doesn't work with Xcode because if you apply one, the other
gets clobbered.  Merge these into one diagnostic that performs the removal and the insert.



Swift SVN r26902
2015-04-02 21:47:43 +00:00
Chris Lattner
b183b5818f Make pattern tuple labels consistent with tuple expr labels: it isn't
valid to use _ as a label.


Swift SVN r26832
2015-04-01 22:26:24 +00:00
Chris Lattner
5829c14997 remove some fairly terrifying parsing logic where we would eat
default tuple element values in patterns, and then just drop it
on the floor.  Fortunately, it looks like no code in the testsuite
was actually using this.


Swift SVN r26829
2015-04-01 22:14:24 +00:00
Chris Lattner
b02da0ae31 Add tuple element label information to TuplePatterns. Before we had no way
to represent them, and just dropped them on the ground. Now we parse them,
persist them in the AST, and "resolve" them from the expr grammar, but still
drop them on the ground.  This is progress towards fixing: rdar://20135489


Swift SVN r26828
2015-04-01 22:11:32 +00:00
Chris Lattner
6ee641719c tuple patterns can never contain varargs, so remove the parsing
logic from parsePattern.  Unfortunately, parameter lists (which have their
own parsing logic) still lean on the Pattern data structures, so we can't 
remove this from TuplePattern yet.


Swift SVN r26804
2015-04-01 05:38:35 +00:00
Chris Lattner
9bdb4ea395 inline method into its only caller, NFC.
Swift SVN r26803
2015-04-01 05:29:34 +00:00
Joe Pamer
eee40fc53f Add basic parsing, sema and mangling support for throwing function types. Next up, metadata and serialization support, as well as more tests.
Swift SVN r26767
2015-03-31 18:55:19 +00:00
Chris Lattner
21b2e9e057 add parser and AST representation support for where/else clauses on let/var decls, some highlights:
- Enhance PBD with a whereExpr/elseStmt field to hold this.
- Start parsing the pattern of let/var decls as a potentially refutable pattern.  It becomes 
  a semantic error to use a refutable pattern without an 'else' (diagnostics not in place yet).
- Change validatePatternBindingDecl to use 'defer' instead of a goto to ensure cleanups on exit.
- Have it resolve the pattern in a PBD, rewriting it from expressions into pattern nodes when valid.
- Teach resolvePattern to handle TypedPatterns now that they can appear (wrapping) refutable patterns.
- Teach resolvePattern to handle refutable patterns in PBD's without initializers by emitting a diagnostic
  instead of by barfing, fixing regressions on validation tests my previous patch caused, and fixing
  two existing validation test crashers.

Sema, silgen, and more tests coming later.




Swift SVN r26706
2015-03-29 22:08:44 +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
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
Chris Lattner
7373917e7e Implement support for parsing typed matching patterns. Not used yet.
Swift SVN r26173
2015-03-16 00:18:54 +00:00
Chris Lattner
a0d02cdcdd Several minor changes:
- Strength reduce isAtStartOfBindingName() to just check for 
   identifier or _ and inline into its two callers.
 - Rename Token::isIdentifierOrNone to isIdentifierOrUnderscore.
 - Teach InVarOrLetPattern about matching patterns, so that the
   parser knows when it is parsing an expression as a matching
   pattern but is not yet inside a let/var pattern.
 - Use newfound knowledge of matching patterns to refine handling
   of unexpected let/var when parsing an expression, but not in a
   pattern context, slightly improving QoI in invalid cases.



Swift SVN r26172
2015-03-15 23:36:05 +00:00
Chris Lattner
8e32687702 simplify the parser code for matching patterns by folding some simple methods
into their only call sites, NFC.



Swift SVN r26170
2015-03-15 23:08:52 +00:00
Chris Lattner
d7c26d8758 Speculatively land the grammar change for <rdar://problem/20167393> revise typed-pattern grammar to make refutable patterns a superset of irrefutable ones
This is still a subject of discussion on swift-dev, but it seems like clearly the right
way to go to me.  If it turns out that this isn't a good direction, I'll revert this and 
subsequent patches built on top of it.



Swift SVN r26168
2015-03-15 22:54:45 +00:00
Chris Lattner
bf73cc23f1 fix <rdar://problem/20167543> "for var x = ..." not parsed as a foreach loop
This was because the ambiguity between c-style and foreach loops wasn't being
properly handled.  Use the canParsePattern() logic to handle this in full 
generality.

Since that logic was unused, dust it off and clean it up a bit.  Similarly,
remove some old vestigates of default argument parsing in tuples and 
old-syntax array handling.



Swift SVN r26164
2015-03-15 21:43:04 +00:00
Chris Lattner
27ef444db5 Remove the "isLet" parameter from the pattern parsing logic. It was (almost)
duplicated by the InVarOrLetPattern state in the Parser object.  Beef 
InVarOrLetPattern up so that we can remove it.

NFC except that we now reject pointless let patterns in foreach loops,
similar to how we reject var patterns inside of let patterns.



Swift SVN r26163
2015-03-15 21:06:37 +00:00
Chris Lattner
20f8f09ea8 Land: <rdar://problem/19382905> improve 'if let' to support refutable patterns and untie it from optionals
This changes 'if let' conditions to take general refutable patterns, instead of
taking a irrefutable pattern and implicitly matching against an optional.

Where before you might have written:
  if let x = foo() {

you now need to write:
  if let x? = foo() {
    
The upshot of this is that you can write anything in an 'if let' that you can
write in a 'case let' in a switch statement, which is pretty general.

To aid with migration, this special cases certain really common patterns like
the above (and any other irrefutable cases, like "if let (a,b) = foo()", and
tells you where to insert the ?.  It also special cases type annotations like
"if let x : AnyObject = " since they are no longer allowed.

For transitional purposes, I have intentionally downgraded the most common
diagnostic into a warning instead of an error.  This means that you'll get:

t.swift:26:10: warning: condition requires a refutable pattern match; did you mean to match an optional?
if let a = f() {
       ^
        ?

I think this is important to stage in, because this is a pretty significant
source breaking change and not everyone internally may want to deal with it
at the same time.  I filed 20166013 to remember to upgrade this to an error.

In addition to being a nice user feature, this is a nice cleanup of the guts
of the compiler, since it eliminates the "isConditional()" bit from
PatternBindingDecl, along with the special case logic in the compiler to handle
it (which variously added and removed Optional around these things).




Swift SVN r26150
2015-03-15 07:06:22 +00:00
Chris Lattner
9ac6c23c1d rename IsaPattern -> IsPattern to follow source syntax, NFC.
Swift SVN r25951
2015-03-10 20:09:02 +00:00
Xi Ge
c0bf1f54ff [CodeCompletion] Further support the context-sensitivity of
auto-completing @attributes. By delaying the handling of code completion token after the entire decl being parsed, we know
what are the targets of the attribute to finishe, thus, only suggesting those applicable attributes.

Swift SVN r25938
2015-03-10 18:40:39 +00:00
Chris Lattner
c049068523 use Tok.isAny a bit more consistently in this file to simplify this code, NFC.
Swift SVN r25932
2015-03-10 17:03:18 +00:00
Chris Lattner
b63567e06e val got renamed to let, update internal function names. NFC.
Swift SVN r25931
2015-03-10 16:58:21 +00:00
Chris Lattner
db187f2183 Enhance VarPattern to capture a bit indicating whether the pattern was a var or let.
Previously we only used this information in the parser, but Sema needs to know as well.

NFC except in -dump-ast.



Swift SVN r25914
2015-03-10 06:07:56 +00:00
Xi Ge
32e9a0aca7 [CodeCompletion] Making the code completion of attributes
context-sensitive. The first step is to recommend parameter-applicable
attributes only when the code completion token is found inside a
param decl.

Swift SVN r25810
2015-03-06 23:20:17 +00:00
Doug Gregor
ac93e35b01 Address Chris's review comments on @autoclosure(escaping).
Swift SVN r25251
2015-02-12 21:20:59 +00:00
Doug Gregor
954b4e4d83 Implement @autoclosure(escaping).
Addresses rdar://problem/19499207.

Swift SVN r25249
2015-02-12 21:09:47 +00:00
Denis Vnukov
0d84be65de Fix for rdar://problem/19605567, Fuzzing Swift: abort() in Verifier::checkSourceRanges(...)
Correct start/end locations of constructor arguments and class body in erroneous scenarios.



Swift SVN r24769
2015-01-28 01:05:36 +00:00
Denis Vnukov
196d500439 Fix for rdar://problem/19563867, Fuzzing Swift: Parser::parseTopLevel() crashes in Verifier::walkToPatternPost(swift::Pattern*):
a vararg subpattern of a TuplePattern should be a TypedPattern

Check for a vararg subpattern to be a typed pattern seemed to be missing in closure arguments parsing.



Swift SVN r24733
2015-01-26 21:11:32 +00:00
Doug Gregor
b642c555be Allow one to change the argument labels of curried function parameters.
Curried function parameters (i.e., those past the first written
parameter list) default to having argument labels (which they always
have), but any attempt to change or remove the argument labels would
fail. Use the fact that we keep both the argument labels and the
parameter names in patterns to generalize our handling of argument
labels to address this problem.

The IDE changes are due to some positive fallout from this change: we
were using the body parameters as labels in code completions for
subscript operations, which was annoying and wrong.

Fixes rdar://problem/17237268.

Swift SVN r24525
2015-01-19 22:15:14 +00:00
Chris Lattner
407bad1445 remove @autoclosure as a type attribute. Recognize it in a parameter
list and produce a nice fixit, so that people using it have an obvious
upgrade path.


Swift SVN r24075
2014-12-22 20:14:56 +00:00
Chris Lattner
86c3c50157 Implement support for parsing declattrs on parameters. The only tricky
case is where there is no argument name, because declattrs and typeattrs
can be juxtaposed.



Swift SVN r24045
2014-12-19 23:42:12 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Doug Gregor
51c1433ddd Add magic "literal" __DSO_HANDLE__ to refer to the DSO handle.
__DSO_HANDLE__ can be used as a callee-side default
argument. Addresses rdar://problem/17878114.


Swift SVN r21440
2014-08-25 16:33:54 +00:00
Chris Lattner
61715b1da7 Remove some dead code: pattern parsing is now never used for argument lists,
so inout can't appear there and we don't need to propagate an "isArgumentList"
bool down through pattern parsing.  NFC.



Swift SVN r20835
2014-07-31 17:46:08 +00:00
Chris Lattner
bc2071a66f make 'inout' be a keyword, to match var and let.
Swift SVN r20829
2014-07-31 16:36:56 +00:00
Chris Lattner
a2beb62f85 fix <rdar://problem/16786168> Functions currently permit 'var inout' parameters
fix <rdar://problem/17867059> ` upgrade logic should be removed




Swift SVN r20817
2014-07-31 06:18:42 +00:00
Doug Gregor
ff92b5f007 Remove -[no]implicit-objc-with.
Toggling this option causes funny things to happen, and there's no
point in keeping it.

Swift SVN r20565
2014-07-25 22:13:46 +00:00
Doug Gregor
795f568898 Start diagnosing the use of '`' rather than '#', with a Fix-It.
<rdar://problem/16891828>.

Swift SVN r17982
2014-05-13 00:03:05 +00:00
Doug Gregor
1efd9fba5b Start accepting '#' in addition to '`' to mark a keyword argument <rdar://problem/16891828>.
Update the standard library, tests, diagnostics, and Fix-Its.

Swift SVN r17981
2014-05-13 00:03:04 +00:00
Argyrios Kyrtzidis
a5eeb9617a [Parser] Create ParamDecls even for unnamed parameters.
This preserves more of source info (e.g. API name location) and simplifies things since
we don't have to construct ParamDecls for the unnamed parameters later on.

Swift SVN r17828
2014-05-10 18:23:47 +00:00
Doug Gregor
ac579592a6 Complain about first keyword arguments in methods/initializers that start with "with".
... with Fix-Its to remove the "with", of course. Only do this under
-implicit-objc-with.

Swift SVN r17755
2014-05-09 01:40:52 +00:00
Argyrios Kyrtzidis
717966f579 [Parser] Emit error + fixit if 'inout' appears after the parameter.
Swift SVN r17518
2014-05-06 01:39:35 +00:00
Argyrios Kyrtzidis
dfa772de8b [AST] Set the source range of ParamDecl as the argument+parameter range and keep track of its parent pattern.
Swift SVN r17441
2014-05-05 15:14:31 +00:00
Chris Lattner
502e663e23 inline parsePatternIdentifier into its only caller, and simplify the result.
Swift SVN r17407
2014-05-04 23:14:15 +00:00
Doug Gregor
eb7a9144a8 Bring keyword arguments to subscripts.
Subscript declarations were still encoding the names of index
variables in the subscript type, which unintentionally made them
keyword arguments. Bring subscript declarations into the modern day,
using compound names to encode the subscript argument names, which
provides consistency for the keyword-argument world
<rdar://problem/14462349>. Note that arguments in subscripts default
to not being keyword arguments, which seems like the right default.

We now get keyword arguments for subscripts, so one can overload
subscripts on the names of the indices, and distinguish at the call
site. Under -strict-keyword-arguments, we require strictness here as well.

The IRGen/IDE/SILGen test updates are because the mangling of common
subscripts changed from accidentally having keyword arguments to not
having keyword arguments.

Swift SVN r17393
2014-05-04 19:31:09 +00:00
Chris Lattner
8f444a4a61 simplify some parsing logic by using Token::isIdentifierOrNone more,
and rearrange some closure parsing logic to tidy it up, NFC.


Swift SVN r17363
2014-05-04 04:42:53 +00:00