Commit Graph

276 Commits

Author SHA1 Message Date
Doug Gregor
dccf3155f1 SE-0022: Implement parsing, AST, and semantic analysis for #selector. 2016-01-26 21:12:04 -08:00
Doug Gregor
fd3f03f3be Remove UnresolvedConstructorExpr.
UnresolvedConstructorExpr is not providing any value here; it's
essentially just UnresolvedDotExpr where the name refers to an
initializer, so use that instead. NFC
2016-01-20 17:09:02 -08:00
Doug Gregor
5f07f6b12f Remove all vestiges of UnresolvedSelectorExpr. NFC 2016-01-20 17:09:01 -08:00
John McCall
1f3b3142b4 Distinguish conformance and superclass generic requirements.
As part of this, use a different enum for parsed generic requirements.

NFC except that I noticed that ASTWalker wasn't visiting the second
type in a conformance constraint; fixing this seems to have no effect
beyond producing better IDE annotations.
2016-01-11 16:07:37 -08:00
Chris Lattner
95f07f02b9 rename AST/Parameter.h to AST/ParameterList.h now that Parameter is gone. 2016-01-03 14:47:44 -08:00
Chris Lattner
6afe77d597 Eliminate the Parameter type completely - now ParameterList is just
an overblown array of ParamDecl*'s that also keeps track of parenlocs
and has helper methods.
2016-01-03 14:45:38 -08:00
Chris Lattner
b170b700f8 move the rest of the state out of Parameter and into ParamDecl,
in prep for Parameter going away.  NFC.
2016-01-01 15:27:53 -08:00
Chris Lattner
5e8c9a3444 Revert "remove the Parameter::isTypeImplicit hack and replace it with something more"
This reverts commit 277a62a0d6.  It broke
the stdlib build, and my attempt to solve it a different way isn't working.
2016-01-01 15:02:00 -08:00
Chris Lattner
4479b46ef0 move the TypeLoc for a parameter out of Parameter and onto ParamDecl. NFC. 2016-01-01 14:13:13 -08:00
Chris Lattner
277a62a0d6 remove the Parameter::isTypeImplicit hack and replace it with something more
principled (NFC).
2016-01-01 13:47:55 -08:00
Chris Lattner
cc3f173040 remove variadics, default args etc, from tuple patterns, and simplify
the Pattern::clone interface now that the complexity isn't needed.
This also removes support for serializing this state.
2015-12-31 20:12:12 -08:00
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Chris Willmore
c99c02b5a6 Transform EditorPlaceholderExpr into trap if executed in playground
mode (take 2)

Allow untyped placeholder to take arbitrary type, but default to Void.
Add _undefined<T>() function, which is like fatalError() but has
arbitrary return type. In playground mode, merely warn about outstanding
placeholders instead of erroring out, and transform placeholders into
calls to _undefined(). This way, code with outstanding placeholders will
only crash when it attempts to evaluate such placeholders.

When generating constraints for an iterated sequence of type T, emit

    T convertible to $T1
    $T1 conforms to SequenceType

instead of

    T convertible to SequenceType

This ensures that an untyped placeholder in for-each sequence position
doesn't get inferred to have type SequenceType. (The conversion is still
necessary because the sequence may have IUO type.) The new constraint
system precipitates changes in CSSimplify and CSDiag, and ends up fixing
18741539 along the way.

(NOTE: There is a small regression in diagnosis of issues like the
following:

    class C {}
    class D: C {}
    func f(a: [C]!) { for _: D in a {} }

It complains that [C]! doesn't conform to SequenceType when it should be
complaining that C is not convertible to D.)

<rdar://problem/21167372>

(Originally Swift SVN r31481)
2015-12-10 22:05:16 -08:00
Xi Ge
264e91d3c4 [SourceKit] Allow SourceEntityWalker to visit generic type parameters of type decls.
This unlocks SourceKit's "find related identifiers" request on generic type params. rdar://22356526
2015-12-03 15:12:16 -08:00
Wisdom Omuya
5510d4b1ad fix typo in ASTWalker 2015-12-03 13:33:05 -05:00
Dmitri Hrybenko
2e51d23875 Un-ifdef object literals
Swift SVN r32880
2015-10-25 07:50:53 +00:00
Doug Gregor
07bec981d8 Introduce FixedTypeRepr to handle those few cases where we need a Type in a TypeRepr.
This TypeRepr should be used sparingly, where we have some fixed type
that cannot otherwise be expressed in the language. It's better than
faking up an IdentTypeRepr.

Swift SVN r32372
2015-10-01 18:30:51 +00:00
Xi Ge
ec4e469062 [CodeComplete] Introduce code completion expr to better preserve the context of the code completion token in ASTs.
Swift SVN r31908
2015-09-11 22:59:12 +00:00
Chris Willmore
9c1f3e907a Revert "Transform EditorPlaceholderExpr into trap if executed in playground mode."
This reverts commit r31481, which apparently needed some parallel
changes to SourceKit and broke the build as a result.

Swift SVN r31483
2015-08-26 05:28:04 +00:00
Chris Willmore
0addd80bb3 Transform EditorPlaceholderExpr into trap if executed in playground mode.
Allow untyped placeholder to take arbitrary type, but default to Void.
Add _undefined<T>() function, which is like fatalError() but has
arbitrary return type. In playground mode, merely warn about outstanding
placeholders instead of erroring out, and transform placeholders into
calls to _undefined(). This way, code with outstanding placeholders will
only crash when it attempts to evaluate such placeholders.

<rdar://problem/21167372> transform EditorPlaceholderExpr into fatalError()

Swift SVN r31481
2015-08-26 04:50:55 +00:00
Jordan Rose
2801d47e59 Add Parse and Sema support for 'try?'.
rdar://problem/21692467

Swift SVN r31030
2015-08-05 22:17:25 +00:00
Jordan Rose
953424072e Guard "object literals" feature with SWIFT_ENABLE_OBJECT_LITERALS.
This is not a feature we're releasing at the moment, so provide a way
to turn it off.

rdar://problem/21935551

Swift SVN r30966
2015-08-04 00:16:52 +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
John McCall
a0ee7b2772 Don't look through 'try!' in getSemanticsProvidingExpr().
To support this, make 'try' and 'try!' no longer IdentityExprs
and give them a common base class to simplify the sorts of
analyses and transformations that do want to treat them
as identity-like.

Note that getSPE() still looks through normal 'try', since
the overwhelming proportion of clients will consider it
semantically equivalent to the undecorated expression.

Change getValueProvidingExpr() to look through try!, since
it's allowed to return something with slightly different
semantics, and use it in the unused-result diagnostic.

Fixes a large number of bugs, mostly uncaught, with SILGen
peepholes that use getSPE() and therefore were accidentally
looking through try!.  <rdar://21515402>

Swift SVN r30224
2015-07-15 19:34:18 +00:00
Xi Ge
57489ceb0f [SyntaxHighlighting] Give ASTWalker the option to walk into generic params of function decls.
Therefore, generic params can also benefit from syntax highlighting and semantic annotation
in SourceKit. rdar://20529255

Swift SVN r30220
2015-07-15 18:28:09 +00:00
Chris Lattner
c114dc9abc generalize ASTWalker to allow clients to visit TypeLocs, not just TypeReprs.
NFC, since nothing is using this functionality yet.


Swift SVN r29983
2015-07-08 18:46:36 +00:00
Chris Willmore
52d441ba61 Have a bit per PatternBindingEntry saying whether the corresponding
initializer has been type-checked, rather than a bit for the entire
PatternBindingDecl.

<rdar://problem/21057425> Crash while compiling attached test-app.

Swift SVN r29049
2015-05-27 01:31:28 +00:00
Argyrios Kyrtzidis
a6f143b87e [AST] Add AST walking for the TypeLoc of IsPattern.
Fixes rdar://21032179

Swift SVN r28822
2015-05-20 04:06:38 +00:00
John McCall
3740e9b2b7 Rely on ASTVisitor::visit for Decl visiting in the
AST walker and provide some guidance for implementers
in the file comment.

Swift SVN r28790
2015-05-19 21:45:12 +00:00
John McCall
155507d722 Teach ASTWalker to walk some more implicit expressions and
declarations generated by the type-checker.

Unfortunately, it's not possible to directly check this
because the verifier is itself based on ASTWalker.  But I'm
going to add an assertion to SILGen in a follow-up that
assumes that TypeCheckError has visited every ApplyExpr,
and since SILGen already walks most of the AST with its
own custom walker, that will check this well enough.

Swift SVN r28732
2015-05-19 00:54:27 +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
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