Commit Graph

594 Commits

Author SHA1 Message Date
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
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
Doug Gregor
340e4d8f8a Simplify parsing and representation of extension declarations.
Now that we don't have generic parameter lists at arbitrary positions
within the extended type of an extension declaration, simplify the
representation of the extended type down to a TypeLoc along with a
(compiler-synthesized) generic parameter list.

On the parsing side, just parse a type for the extended type, rather
than having a special grammar. We still reject anything that is not a
nominal type (of course), but it's simpler just to call it a type.

As a drive-by, fix the crasher when extending a type with module
qualification, rdar://problem/20900870.

Swift SVN r28469
2015-05-12 16:26:13 +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
Dmitri Hrybenko
f46f16ae82 stdlib: implement new print() API
rdar://20775683

Swift SVN r28309
2015-05-08 01:37:59 +00:00
Doug Gregor
2653a6569b Eliminate ModuleExpr; DeclRefExpr is good enough for anyone.
Swift SVN r28285
2015-05-07 21:10:53 +00:00
Chris Lattner
37f5452d15 require -> guard.
Swift SVN r28223
2015-05-06 22:53:38 +00:00
John McCall
71198a2869 Test error-coverage diagnostics more completely.
Fix an assert-on-valid caused by a broken getSourceRange()
implementation and a missing diagnostic caused by a broken
walker implementation.

Swift SVN r28142
2015-05-05 00:30:51 +00:00
Chris Lattner
7927a230ae remove compiler support for let/else. This simplifies PBD back to being
an unconditional binding, yay.


Swift SVN r28101
2015-05-03 22:13:02 +00:00
Devin Coughlin
d04cc58c6c Sema: Refine availability context in IfStmt guard conditions following #available()
Loosen restrictions on where #available() can appear in IfStmt guards and refine the
context for guard StmtConditionElements following an availability check.

This enables #available() to be combined with if let optional binding:

if #available(iOS 8.0, *),
   let x = someIOS8API() {
  // Do more iOS 8 stuff
}

and

if let x = someIOS7API() where #available(iOS 8.0, *),
   let y = someIOS8API() {
  // Do more iOS 8 stuff
}

Swift SVN r28096
2015-05-03 20:27:29 +00:00
John McCall
5c171fd448 Parsing, type-checking, SILGen, and IRGen for try!.
Swift SVN r28085
2015-05-02 08:03:15 +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
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
5248ededee Rework the AST representation of CollectionExprs to maintain
a list of their elements, instead of abusing TupleExpr/ParenExpr
to hold them.

This is a more correct representation of what is going on in the
code and produces slightly better diagnostics in obscure cases.

However, the real reason to fix this is that the ParenExpr's that
were being formed were not being installed into the "semantic"
view of the collection expr, not getting type checked correctly,
and led to nonsensical ParenExprs.  These non-sensical ParenExprs
blocked turning on AST verification of other ones.

With this fixed, we can finally add AST verification that 
IdentityExpr's have sensible types.



Swift SVN r27850
2015-04-28 01:09:10 +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 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 Willmore
d4db635e3d Add object literal syntax and _{Color,Image}LiteralConvertible protocols
Add syntax "[#Color(...)#]" for object literals, to be used by
Playgrounds for inline color wells etc. The arguments are forwarded to
the relevant constructor (although we will probably change this soon,
since (colorLiteralRed:... blue:... green:... alpha) is kind of
verbose). Add _ColorLiteralConvertible and _ImageLiteralConvertible
protocols, and link them to the new expressions in the type checker.
CSApply replaces the object literal expressions with a call to the
appropriate protocol witness.

Swift SVN r27479
2015-04-20 12:55:56 +00:00
Doug Gregor
e75b556d35 Walk the existential value of an OpenExistentialExpr.
Swift SVN r27171
2015-04-09 15:51:06 +00:00
Chris Lattner
c17a3a48fa fix the ASTWalker to walk into the where/else clauses of a refutable PBD,
fixing a crash on the testcase caused by lack of autoclosure contextualization.


Swift SVN r27060
2015-04-07 04:46:54 +00:00
Chris Lattner
fb87132f72 significantly simplify the BoolPattern AST representation and logic surrounding it.
The SILGen code could be further simplified, but this is progress at least.  NFC.


Swift SVN r27011
2015-04-05 04:52:38 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Roman Levenstein
941e5b6a58 [patternmatch-silgen] Improve silken and diagnostics for switches on bools and tuples of bools.
This patch introduces a new kind of pattern for matching bool literals, i.e. true and false. Essentially, it is very similar to a pattern for matching enum elements, but simpler. Most of the code is just a boiler plate code copy/pasted from the code for enum element patterns. The only different thing is the emitBoolDispatch function, which emits a SIL code for matching bools.

With this patch, we don't get any false non-exhaustive switch diagnostics for switches on bools anymore. And we have a lot of radars complaining about it. For example rdar://16514545 and rdar://20130240.

Note, that this patch fixes the non-exhaustive switch diagnostics without changing the internal representation of bools. Implementing bool as an enum would have the same effect when it comes to these diagnostics and we would get this diagnostics fix for free, i.e. without any code committed here. But implementing bools-as-enums is an ongoing work and I'm investigating its performance implications. If we become confident that bool-as-enum does not have a negative impact on performance and decide to merge it, then we can revert this patch as it would not be necessary anymore. But if we decide to skip the enum-as-bool approach to its performance issues, then we would have at least fixed the false non-exhaustive diagnostics for bools by means of this patch.

Swift SVN r26650
2015-03-27 22:43:47 +00:00
John McCall
08d3460a19 Implement throw expressions. Untested.
Tests tomorrow for this and 'catch', I promise. :)

Swift SVN r26432
2015-03-23 08:10:15 +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
Doug Gregor
c0d783fe40 Start serializing the reference components of extension declarations.
Specifically, start serializing the generic parameter list, even
though we basically throw it away during deserialization.

Swift SVN r26318
2015-03-19 22:09:59 +00:00
Chris Lattner
79e0fe7438 remove some #if 0 code I accidentally left in.
Swift SVN r26233
2015-03-17 20:42:48 +00:00
Chris Lattner
59c22383fb Rework PatternBindingDecl to maintain a list of pattern/initexpr pairs inside of it.
Previously, a multi-pattern var/let decl like:
  var x = 4, y = 17

would produce two pattern binding decls (one for x=4 one for y=17).  This is convenient
in some ways, but is bad for source reproducibility from the ASTs (see, e.g. the improvements
in test/IDE/structure.swift and test/decl/inherit/initializer.swift).

The hardest part of this change was to get parseDeclVar to set up the AST in a way
compatible with our existing assumptions. I ended up with an approach that forms PBDs in 
more erroneous cases than before.  One downside of this is that we now produce a spurious
  "type annotation missing in pattern"
diagnostic in some cases.  I'll take care of that in a follow-on patch.





Swift SVN r26224
2015-03-17 16:14:18 +00:00
Argyrios Kyrtzidis
68bd67fc12 [Parse/AST] Introduce an AST node for editor placeholders in expression contexts.
If the placeholder is a typed one, parse its type string into a TypeRepr,
resolve it during typechecking and set it as the type for the associated EditorPlaceholderExpr.

Swift SVN r26215
2015-03-17 01:53:02 +00:00
John McCall
0802e85975 Implement the naked 'do' statement.
For now, we assume that 'while' after the braces starts
a do/while rather than being an independent statement.
We should disambiguate this, or better, remove do/while.

Tests later.

Swift SVN r26079
2015-03-13 01:58:42 +00:00
John McCall
dd48c25d3f Parse 'try' expressions.
We parse 'try' as if it were a unary operator allowed on an
arbitrary element of an expr-sequence, but sequence-folding
constrains it to never appear on the RHS of most operators.

We do allow it on the RHS of an assignment or conditional
operator, but not if there's anything to the right which
was not parsed within the RHS.

We do this for assignments so that
  var x = try whatever
and
  x = try whatever
both work as you might expect.

We do this for conditionals because it feels natural to
allow 'try' in the center operand, and then disallowing it
in the right operand feels very strange.

In both case, this works largely because these operators are
assumed to be very low-precedence; there are no standard
operators which would parse outside the RHS.  But if you
create one and use 'try' before it, we'll diagnose it.

Swift SVN r26052
2015-03-12 18:59:21 +00:00
Chris Lattner
9ac6c23c1d rename IsaPattern -> IsPattern to follow source syntax, NFC.
Swift SVN r25951
2015-03-10 20:09:02 +00:00
Chris Lattner
de808d1603 Progress on: <rdar://problem/19382878> Introduce new x? pattern
This introduces a new pattern, spelled "x?" which is sugar for
matching ".Some(x)".  It also changes the parser slightly so that
_ (the discard expr) is parsed as a unary expr instead of as an
expr.  This allows it to have postfix ? after it, which is important
in pattern contexts to support "case _?:".



Swift SVN r25907
2015-03-10 01:00:23 +00:00
Argyrios Kyrtzidis
944e20949a [AST/IDE] Use TypeReprs to keep track of the type components in an ExtensionDecl.
This allows preserving type info and proper annotation of the extension's type components.

Swift SVN r25309
2015-02-16 08:36:16 +00:00
Joe Pamer
527a9a8825 Use "isa" instead of "dyn_cast" when checking for type identity.
Swift SVN r24945
2015-02-04 06:30:07 +00:00
Joe Pamer
f86324ac8a Prevent error recovery for type expressions from crashing the compiler. This has come up fairly often during recent testing. (rdar://problem/19543299 and rdar://problem/19673269)
Swift SVN r24943
2015-02-04 06:07:40 +00:00
Chris Lattner
763bb6386f Implement parser, AST representation, type checker, etc support for generalized
if-let statements (also while and var, of course) that include multiple bindings
and where clauses.

SILGen support still remains, it currently just asserts on the new constructs.



Swift SVN r24239
2015-01-07 07:03:02 +00:00
Chris Lattner
f3ed7e93e1 Completely redesign our AST representation of capturelists. Formerly,
a capture list hung off the CaptureExpr it was associated with.  This made
sense lexically (since a capture list is nested inside of the closure) but
not semantically.  Semantically, the capture list initializers are evaluated
outside the closure, the variables are bound to those values, then the closure
captures the newly bound values.

To directly represent this, represent captures with a new CaptureListExpr node,
which contains the ClosureExpr inside of it.  This correctly models the semantic
relationship, and makes sure that AST walkers all process the initializers of the
capture list as being *outside* of the closure.

This fixes rdar://19146761 and probably others.


Swift SVN r23756
2014-12-06 04:36:11 +00:00
Devin Coughlin
b07fd30315 Change ASTWalker to preserve AbstractFunctionDecl body kinds when walking.
This commit changes ASTWalker to preserve AbstractFunctionDecl body kinds. When
walking over an AbstractFunctionDecl, ASTWalker calls setBody() on the
declaration to update the body after traversal. Prior to this commit, setBody()
would unconditionally set the body kind to BodyKind::Parsed --- that is,
traversing the AST would change the body kind to Parsed. In some cases, this
modified a body kind from TypeChecked to Parsed, causing a small number of
standard library functions to be type checked twice. This behavior also
interferes with the creation of type refinement contexts for variable accessor
functions (coming in a future commit).

This commit adds an additional parameter to setBody() that allows callers to
provide a body kind (this defaults to Parsed) and changes ASTWalker to preserve
the body kind when walking a AbstractFunctionDecl.



Swift SVN r22607
2014-10-08 18:56:57 +00:00
Devin Coughlin
0d7996f4ee Add parsing of availability query expressions (#os(...))
This patch adds a new 'pound_os' token, a new case for it in parseExprPostfix, and parsing of platform version constraints, e.g., OSX >= 10.10. 

It also adds enough type checking and SILGen to get the parsing tests to run without triggering "Unimplemented" assertions.


Swift SVN r21865
2014-09-11 02:59:05 +00:00
Argyrios Kyrtzidis
7049168e4b [IDE] Annotate the explicit result type of a closure.
Swift SVN r21808
2014-09-09 16:53:33 +00:00
Devin Coughlin
ab563d6ef1 Add availability query expression (#os(...))to the AST
This commit adds a new expression (AvailabilityQueryExpr) and a single kind of
specification for when a block of code or function is available
(VersionConstraintAvailabilitySpec). We may add more kinds of specifications
in the future. At the moment, the AvailabilityQueryExpr allows only a
single platform to be queried; I will add support for multiple platforms
in a later commit.

This commit contains just the added AST nodes; no parsing, type checking, etc.
I’ve added assert(false && “Unimplemented”) for places where support for
AvailabilityQueryExpr will need to be added later.



Swift SVN r21760
2014-09-06 02:11:02 +00:00
Jordan Rose
9418b9cfd4 [Type Checker] Try harder to synthesize enum Equatable conformance on demand.
If either parameter to == has a known concrete type at constraint generation
time, see if that type is a nominal that can derive its conformance to
Equatable. If so, do so, and then add that == to the overload set.
(It may already be there, but that's okay -- it will get uniqued later.)

This isn't perfect because it relies on one of the parameters to == having
a concrete type /before/ constraint solving. There are plenty of reasons
why that wouldn't happen. But this at least fixes the common case, and
breaking the expression up into multiple lines is a less distasteful
workaround than replacing (x == .Value) with !(x != .Value). I've added a
test case that should work but doesn't that we can revisit later.

rdar://problem/18073705

Swift SVN r21557
2014-08-29 01:10:06 +00:00
Doug Gregor
344ecfd3f9 Add a new 'fail' statement to the AST for failing from an initializer.
The spelling of the 'fail' statement is simply 'return nil', but
distinguishing it in the AST clarifies intent for SILGen.

Swift SVN r21310
2014-08-20 17:22:36 +00:00
Doug Gregor
a0bc9274db Change parsing and representation of extensions to accommodate generic parameters.
The eventual goal for extensions of generic types is to require them
to specify their generic parameters, e.g.,

  extension Array<T> { ... }

rather than today's

  extension Array { ... }

Start parsing (optional) generic parameters here, and update the
representation of ExtensionDecl to accomodate this new grammar
production. Aside from the parser changes, there's no intended
functionality change here.

Swift SVN r20682
2014-07-29 19:17:00 +00:00
Doug Gregor
5a08a69ebc Remove NewArrayExpr entirely; reject "new" expressions in the parser.
Swift SVN r19293
2014-06-27 15:57:48 +00:00
Joe Groff
9a190ea59e AST: Remove unneeded expression nodes for __inout_conversion and __writeback_conversion.
We no longer need this language feature. The Sema support is still skeletally kept in place because removing it seems to totally break pointer conversions; I need to work with Joe and Doug to figure out why that's the case.

Swift SVN r19289
2014-06-27 04:23:35 +00:00