Commit Graph

443 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
8336419844 Include completion source location information compound DeclNames.
When one spells a compound declaration name in the source (e.g.,
insertSubview(_:aboveSubview:), keep track of the locations of the
base name, parentheses, and argument labels.
2016-01-25 14:13:13 -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
Chris Lattner
302e8cd12f Add a TypeExpr::getInstanceType() helper method, NFC. 2016-01-19 22:52:26 -08:00
Chris Lattner
5a4464fbca Fix <rdar://19935319> QoI: poor diagnostic initializing a variable with a non-class func
It is a common point of confusion that property initializers cannot access self, so
produce a tailored diagnostic for it.

Also, when building implicit TypeExprs for the self type, properly mark them implicit.
2016-01-18 22:37:22 -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
Slava Pestov
a1a0573cf0 Sema: Remove dead code, NFC 2015-12-14 13:29:51 -08: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
2f670a8134 [CodeCompletion] Fix an assertion violation. rdar://23306548
When creating a SequenceExpr, we should always have an odd number of
elements.
2015-12-09 12:31:07 -08: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
John McCall
d1554f9fcc Track and verify how an l-value expression is used in the AST.
I'll use this information in a follow-up commit.

Swift SVN r32292
2015-09-29 00:07:10 +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 Lattner
c8990c5f66 Enhance ArrayExpr to keep track of the locations of its commas, NFC.
Swift SVN r31695
2015-09-04 22:16:23 +00:00
Chris Willmore
5d7004a0e1 hasSingleExpressionBody() returns true for void-coercion closures
Have ClosureExpr::hasSingleExpressionBody() return true even after the
closure has been coerced to return Void, i.e., { E } has been rewritten
as { E; () }. This fixes some implicit-self diagnostics, and probably
others.

Revision to r31654 for 22441425.

Swift SVN r31665
2015-09-03 09:36:37 +00:00
Chris Lattner
0c288e0829 introduce a new UnresolvedTypeConversionExpr implicit conversion node for
conversions to and from UnresolvedType.  This will allow UnresolvedType to be
used more aggressively and predictably by CSDiags.  This is NFC, but used in
the next patch.


Swift SVN r31318
2015-08-18 23:41:11 +00:00
Chris Lattner
6ea6d2d6f5 add a new LiteralExpr::shallowClone method, to be used by upcoming work. NFC.
Swift SVN r31268
2015-08-17 17:46:32 +00:00
Chris Lattner
402dcbc782 rename forEachChildExpr to forEachImmediateChildExpr, since that is
what it does, and add a more general forEachChildExpr that walks the
entire expr tree.  Allow both of these to mutate the expr in question
by allowing the lambda to return a new expr.

NFC, this is needed by subsequent work.



Swift SVN r31267
2015-08-17 17:38:16 +00:00
Slava Pestov
e5cb73fe41 SILGen: Clean up ErasureExpr lowering, NFC
This is a step towards partially-applying methods that return Self
on existentials.

- We model opening of both existential values and metatypes with
  OpenExistentialExpr, but erasure had two forms, ErasureExpr and
  MetatypeErasureExpr. Combine them into one, since both Sema and
  SILGen have similar code paths for each.

- If the source type of an ErasureExpr is a closed existential,
  have Sema emit an OpenExistentialExpr, and remove SILGen's
  openExistentialForErasure() path, which mostly duplicates
  openExistentialImpl().

- There was one difference between openExistentialForErasure() and
  openExistentialImpl(). The former would emit the opaque value in
  +0 context, and the latter in a +1 with initialization. The
  previous patch ensures that visitOpaqueValueExpr() generates
  equivalent code in both cases.

Swift SVN r31261
2015-08-16 16:45:48 +00:00
Jordan Rose
74c634524e Pull 'try' et al inside RebindSelfInConstructorExprs.
And give a proper warning when you use 'try?' in a non-failable init.

And do the right thing when trying to SILGen 'try?' delegating to a
failable throwing init.

And make sure DI understands that this is, in fact, an initialization.

More rdar://problem/21692467

Swift SVN r31060
2015-08-06 21:02:43 +00:00
Jordan Rose
6b12b9130e Disallow nesting 'self.init' or 'super.init' inside other expressions.
In addition to being confusing, it makes it harder to implement
'try? self.init(...)' properly. (Next commit!)

Swift SVN r31034
2015-08-05 22:17:41 +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
Chris Willmore
0c9de6edef Diagnose ambiguous overload resolution correctly in more cases.
Take expression depth and preorder traversal index into account when
deciding which unresolved overload to complain about, rather than giving
up if there are two exprs with the same number of overloads. Don't
consider solutions with fixes when emitting ambiguous-system
diagnostics.

Swift SVN r30931
2015-08-02 11:38:12 +00:00
Chris Lattner
0001dc27bb remove support for the experiemental "character literals" feature.
Swift SVN r30509
2015-07-22 22:35:19 +00:00
Devin Coughlin
c1caddae62 Remove experimental support for treating unavailable symbols as optional.
This has always been off by default and is a language direction we have decided not to
pursue.

Swift SVN r30355
2015-07-18 01:56:25 +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
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 Lattner
1df3190253 add a helper function to enumerate the immediate children of an expr node.
Swift SVN r29772
2015-06-28 17:21:31 +00:00
Jordan Rose
8b3d4acccd Allow enum elements with string raw values to default to the name of the element.
Just like enums with integer raw values can get autoincrementing case values,
enums with string raw values get the name of the element. The name is /not/
prefixed with the enum type because the purpose is presumably to interoperate
with a string-based system, which may require either writing or printing the
raw value as a string.

If an enum's raw type is both integer literal convertible and string literal
convertible, the integer side wins. That is, elements without raw values
will get auto-incremented integer values, rather than string values, and will
produce an error if an auto-incremented value cannot be generated.

rdar://problem/15819953

Swift SVN r29542
2015-06-22 00:28:23 +00:00
Joe Groff
d7b9ae72aa Sema: Require '.init' when constructing from a dynamic metatype.
This makes it clearer that expressions like "foo.myType.init()" are creating new objects, instead of invoking a weird-looking method. The last part of rdar://problem/21375845.

Swift SVN r29375
2015-06-14 19:50:06 +00:00
Joe Groff
bebfa969bd Sema: Allow 'x.init' references on metatype expressions.
If 'x.init' appears as a member reference other than 'self.init' or 'super.init' within an initializer, treat it as a regular static member lookup for 'init' members. This allows a more explicit syntax for dynamic initializations; 'self.someMetatype()' looks too much like it's invoking a method. It also allows for partial applications of initializers using 'someMetatype.init' (though this needs some SILGen fixes, coming up next). While we're in the neighborhood, do some other correctness and QoI fixes:

- Only lookup initializers as members of metatypes, not instances, and add a fixit (instead of crashing) to insert '.dynamicType' if the initializer is found on an instance.
- Make it so that constructing a class-constrained archetype type correctly requires a 'required' or protocol initializer.
- Warn on unused initializer results. This seems to me like just the right thing to do, but is also a small guard against the fact that 'self.init' is now valid in a static method, but produces a newly-constructed value instead of delegating initialization (and evaluating to void).

Swift SVN r29344
2015-06-08 04:11:28 +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
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
2653a6569b Eliminate ModuleExpr; DeclRefExpr is good enough for anyone.
Swift SVN r28285
2015-05-07 21:10:53 +00:00
John McCall
36c605f7dc Remove ScalarToTupleExpr in favor of a flag on TupleShuffleExpr.
Also, implement in-place initialization through tuple shuffles.

Swift SVN r28227
2015-05-06 23:44:26 +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
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 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
John McCall
79cc258f65 Lower 'throws' to an error result.
Swift SVN r27108
2015-04-08 00:09:29 +00:00
Doug Gregor
441fb9856c Handle lvalue OpaqueValueExprs in SILGen.
Tests coming once Sema starts creating such entities.

Swift SVN r27066
2015-04-07 06:01:16 +00:00
Devin Coughlin
a3c4a8cd50 Add '*' wildcard to #os()
On platforms that are not explicitly mentioned in the #os() guard, this new '*'
availability check generates a version comparison against the minimum deployment target.

This construct, based on feedback from API review, is designed to ease porting
to new platforms. Because new platforms typically branch from
existing platforms, the wildcard allows an API availability check to do the "right"
thing (executing the guarded branch accessing newer APIs) on the new platform without
requiring a modification to every availability guard in the program.

So, if the programmer writes:

  if #os(OSX >= 10.10, *) {
  . . .
  }

and then ports the code to iOS, the body will execute.

We still do compile-time availability checking with '*', so the compiler will
emit errors for references to potentially unavailable symbols in the body when compiled
for iOS.

We require a '*' clause on all #os() guards to force developers to
"future proof" their availability checks against the introduction of new a platform.

Swift SVN r26988
2015-04-04 21:03:20 +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