Commit Graph

199 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
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
Dmitri Hrybenko
2e51d23875 Un-ifdef object literals
Swift SVN r32880
2015-10-25 07:50:53 +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
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
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
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 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
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 Willmore
4330f2a8a9 Instead of replacing ObjectLiteralExpr in CSApply, set its semantic expression (a la InterpolatedStringLiteralExpr).
Swift SVN r27488
2015-04-20 19:41: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
08d3460a19 Implement throw expressions. Untested.
Tests tomorrow for this and 'catch', I promise. :)

Swift SVN r26432
2015-03-23 08:10:15 +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
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
90920ec02f rename the IsaExpr AST node to IsExpr to follow the syntax of the language, NFC.
Swift SVN r25933
2015-03-10 17:11:37 +00:00
Chris Willmore
03a6190a1f <rdar://problem/19031957> Change failable casts from "as" to "as!"
Previously the "as" keyword could either represent coercion or or forced
downcasting. This change separates the two notions. "as" now only means
type conversion, while the new "as!" operator is used to perform forced
downcasting. If a program uses "as" where "as!" is called for, we emit a
diagnostic and fixit.

Internally, this change removes the UnresolvedCheckedCastExpr class, in
favor of directly instantiating CoerceExpr when parsing the "as"
operator, and ForcedCheckedCastExpr when parsing the "as!" operator.

Swift SVN r24253
2015-01-08 00:33:59 +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
Joe Groff
32e6db3f2d Parse signs onto float literals the same way we handle integer literals.
Provides consistency in behavior, particularly in enum raw values, where we reject non-literals. Factor out a common NumberLiteralExpr base for integer and float literals that handles the common sign and representation stuff. Fixes rdar://problem/16504472.

Swift SVN r23390
2014-11-18 00:55:02 +00:00
Devin Coughlin
b727b6d932 Treat potentially unavailable global variable references as optional.
This patch adds the ability (-enable-experimental-unavailable-as-optional) to
treat potentially unavailable declarations as if they had optional types. For
the moment, this is only implemented for global variables.

The high-level approach is to (1) record the potential unavailability of a
declaration reference in the overload choice during constraint generation; (2)
treat the declaration as if it had an optional type during overload resolution
(this is similar to how optional protocol members are treated); and (3) add an
implicit conversion (UnavailableToOptionalExpr) during constraint application
to represent the run-time availability check and optional injection.

This patch does not implement SILGen for UnavailableToOptionalExpr.


Swift SVN r22245
2014-09-24 00:07:46 +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
Doug Gregor
17716524c5 Handle CF <-> Objective-C toll-free-bridged conversions in the type checker.
Introduce an attribute that describes when a given CF type is
toll-free-bridged to an Objective-C class, and which class that
is. Use that information in the type checker to provide the CF <->
Objective-C toll-free-bridged conversions directly, rather than using
the user-defined conversion machinery.

Swift SVN r21376
2014-08-21 21:36:05 +00:00
Doug Gregor
2f3f6acf21 Make "true" and "false" Boolean literal constants for the BooleanLiteralConvertible protocol.
Introduce the new BooleanLiteralConvertible protocol for Boolean
literals. Take "true" and "false" as real keywords (which is most of the
reason for the testsuite churn). Make Bool BooleanLiteralConvertible
and the default Boolean literal type, and ObjCBool
BooleanLiteralConvertible. Fixes <rdar://problem/17405310> and the
recent regression that made ObjCBool not work with true/false.


Swift SVN r19728
2014-07-09 16:57:35 +00:00
Joe Groff
151ed6143d Add a StringToPointerExpr node.
To represent string-to-pointer argument conversions.

Swift SVN r19314
2014-06-28 00:36:43 +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
Joe Groff
08a48565fb Sema: Introduce intrinsic pointer argument conversions.
Add primitive type-checker rules for pointer arguments. An UnsafePointer argument accepts:

- an UnsafePointer value of matching element type, or of any type if the argument is UnsafePointer<Void>,
- an inout parameter of matching element type, or of any type if the argument is UnsafePointer<Void>, or
- an inout Array parameter of matching element type, or of any type if the argument is UnsafePointer<Void>.

A ConstUnsafePointer argument accepts:

- an UnsafePointer, ConstUnsafePointer, or AutoreleasingUnsafePointer value of matching element type, or of any type if the argument is ConstUnsafePointer<Void>,
- an inout parameter of matching element type, or of any type if the argument is ConstUnsafePointer<Void>, or
- an inout or non-inout Array parameter of matching element type, or of any type if the argument is ConstUnsafePointer<Void>.

An AutoreleasingUnsafePointer argument accepts:

- an AutoreleasingUnsafePointer value of matching element type, or
- an inout parameter of matching element type.

This disrupts some error messages in unrelated tests, which is tracked by <rdar://problem/17380520>.

Swift SVN r19008
2014-06-19 18:03:10 +00:00
Doug Gregor
4eeee3580f Remove *CollectionDowncastExpr; wen're not using them any more.
This simplifies constraint application quite a bit, and eliminates
some code duplication.


Swift SVN r18980
2014-06-18 13:10:22 +00:00
Doug Gregor
4019d28ba8 Start using the forced collection downcast entry points.
This means that we'll get deferred checking of array and dictionary
downcasts when writing "arr as Derived[]", 
"(dict as? Dictionary<DerivedKey, DerivedValue>)!", etc, when the
collection can do so.

This is both a general optimization and also staging for
<rdar://problem/17319154>.


Swift SVN r18975
2014-06-18 05:22:41 +00:00
Doug Gregor
f0186ea490 Rename CollectionDowncastExpr to ConditionalCollectionDowncastExpr.
Swift SVN r18974
2014-06-18 04:25:07 +00:00
Chris Lattner
60fc0e6cd2 Implement <rdar://problem/16951729> nil should be a literal type
This is all goodness, and eliminates a major source of implicit conversions.
One thing this regresses on though, is that we now reject "x == nil" where
x is an option type and the element of the optional is not Equtatable.  If
this is important, there are ways to enable this, but directly testing it as
a logic value is more straight-forward.

This does not include support for pattern matching against nil, that will be
a follow on patch.



Swift SVN r18918
2014-06-15 22:59:03 +00:00
Doug Gregor
c5e3dc4e20 Rename ArrayDowncastExpr to CollectionDowncastExpr. NFC
Swift SVN r18898
2014-06-14 17:08:33 +00:00
Doug Gregor
1789c4ccbc Collapse CollectionBridgedConversionExpr into CollectionUpcastConversionExpr.
Semantically, these expressions handle the same thing: an upcast of a
collection when the underlying element types of the source are
subtypes of or can be bridged to subtypes of the destination. This
reduces some branching in the type checker and eliminates duplication
in SILGen.

Swift SVN r18865
2014-06-13 16:32:47 +00:00
Doug Gregor
5ca3882b06 Rename array upcast/bridge expressions to "collection".
This is staging for dictionary bridging upcasts.


Swift SVN r18840
2014-06-12 21:41:55 +00:00
Joe Groff
cf9e0d2624 Sema: Introduce metatype-to-object conversions.
Allow class metatypes (including class-constrained existential metatypes) to be treated as subtypes of AnyObject, and single-@objc protocol metatypes to be treated as subtypes of the Protocol class from objc. No codegen support yet, so this is hidden behind a frontend flag for now.

Swift SVN r18810
2014-06-11 23:06:23 +00:00
Doug Gregor
67ca1c9ea1 Implement the new casting syntaxes "as" and "as?".
There's a bit of a reshuffle of the ExplicitCastExpr subclasses:
  - The existing ConditionalCheckedCastExpr expression node now represents
"as?". 
  - A new ForcedCheckedCastExpr node represents "as" when it is a
  downcast.
  - CoerceExpr represents "as" when it is a coercion.
  - A new UnresolvedCheckedCastExpr node describes "as" before it has
  been type-checked down to ForcedCheckedCastExpr or CoerceExpr. This
  wasn't a strictly necessary change, but it helps us detangle what's
  going on.

There are a few new diagnostics to help users avoid getting bitten by
as/as? mistakes:
  - Custom errors when a forced downcast (as) is used as the operand
  of postfix '!' or '?', with Fix-Its to remove the '!' or make the
  downcast conditional (with as?), respectively.
  - A warning when a forced downcast is injected into an optional,
  with a suggestion to use a conditional downcast.
  - A new error when the postfix '!' is used for a contextual
  downcast, with a Fix-It to replace it with "as T" with the
  contextual type T.

Lots of test updates, none of which felt like regressions. The new
tests are in test/expr/cast/optionals.swift. 

Addresses <rdar://problem/17000058>


Swift SVN r18556
2014-05-22 06:15:29 +00:00
Doug Gregor
f477f061fe Replace ArrayDowncastConversionExpr with ArrayDowncastExpr.
Array downcast is an explicit cast written "x as U[]", not an implicit
conversion, so make it a subclass of ExplicitCastExpr. The only
effective change here is that we retain the location of the "as" and
the type as written in the AST. No semantic change.



Swift SVN r18391
2014-05-19 04:41:42 +00:00