Commit Graph

1030 Commits

Author SHA1 Message Date
Chris Lattner
a87028e57c Reject uses of noescape parameters that would cause them to escape. Namely, we only
allow the parameter to be caller, or captured by another no-escape closure.


Swift SVN r24121
2014-12-23 21:12:29 +00:00
Chris Lattner
1486238412 Reapply:
propagate the no-escape bit from a parameter into a closure-expr argument.  When a 
ClosureExpr is thus inferred to be non-escape, disable the "self." requirement.

.. with fixes.  Thanks again to Dmitri for reverting + adding testcase.



Swift SVN r24115
2014-12-23 18:21:14 +00:00
Dmitri Hrybenko
7ef8a95f8c Revert "propagate the no-capture bit from a parameter into a
closure-expr argument.  When a "

This reverts commit r24085.  It causes crashes in the validation
testsuite even with r24094.  Testcase:

    var x = { f: Int {} }

Swift SVN r24102
2014-12-23 04:06:15 +00:00
Dmitri Hrybenko
e6a7e49081 Revert "fix a problem in my previous patch, which would cause it to
crash on ClosureExpr's that"

This reverts commit r24094.  It depends on r24085, which I'm reverting.

Swift SVN r24101
2014-12-23 04:06:14 +00:00
Chris Lattner
0eaeda9136 rework & cleanup diagModuleOrMetatypeValue, renaming it to diagSyntacticUseRestrictions
in preparation to extend it.  NFC except for a cleanup of the dynamicType diagnostic.


Swift SVN r24095
2014-12-23 01:14:41 +00:00
Chris Lattner
94f5449e43 fix a problem in my previous patch, which would cause it to crash on ClosureExpr's that
have ErrorType.  This caused regressions in the testsuite :(


Swift SVN r24094
2014-12-23 00:54:40 +00:00
Chris Lattner
410c3ef431 propagate the no-capture bit from a parameter into a closure-expr argument. When a
ClosureExpr is thus inferred to be non-captured, disable the "self." requirement.


Swift SVN r24085
2014-12-22 23:58:39 +00:00
Chris Lattner
cb38806083 fix rdar://19179412, a regression introduced by my capture list rework patch.
This code is trying to avoid emitting multiple diagnostics on the same line:
before it was using a vector to keep track of exprs already emitted, I changed
it to clear the isImplicit() bit.  Clearing isImplicit introduces problems 
because various things (in this case, SourceRange validation) are keyed off 
whether an expression is implicit or not.

Instead of solving it either of those ways, fix our walk to just not recursively
descend into the 'self' argument of a self.foo expression when doing the walk.

While we're here, make it so that ChrisW's example doesn't even produce the 
diagnostic in question: the DRE is in a closure, but only because the entire
class is defined in the closure.  Stop the walker from descending recursively
into decls at all.


Swift SVN r23793
2014-12-08 23:43:12 +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
Chris Lattner
026b88fce8 fix <rdar://problem/18877391> "self." shouldn't be required in the initializer expression in a capture list
My testing for this exposed a more basic bug with capture lists (19146761), which I will look at shortly.


Swift SVN r23690
2014-12-04 20:07:38 +00:00
John McCall
6923101341 Rename "AccessKind" to "AccessSemantics". NFC.
There are a lot of different ways to interpret the
"kind" of an access.  This enum specifically dictates
the semantic rules for an access:  direct-to-storage
and direct-to-accessor accesses may be semantically
different from ordinary accesses, e.g. if there are
observers or overrides.

Swift SVN r22290
2014-09-25 23:12:39 +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
John McCall
8cae5ba1d0 Generalize 'isDirectPropertyAccess' to allow for
direct (i.e. non-polymorphic) access to accessor
functions, and use this in materializeForSet for
computed properties.

Swift SVN r22059
2014-09-18 05:51:32 +00:00
John McCall
75050f8166 Generate an implicit 'materializeForSet' accessor
along with getters and setters.

Just generate it for now.

Swift SVN r22011
2014-09-17 08:08:03 +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
cd32734b24 Add missing case.
Swift SVN r21378
2014-08-21 21:59:48 +00:00
Doug Gregor
63304b57b4 Introduce AvailabilityAttr::prettyPlatformName() to improve diagnostics.
Swift SVN r20958
2014-08-02 21:06:30 +00:00
Doug Gregor
f52c6789db Track the minimum deployment target and use it for 'unavailable' computations.
Swift SVN r20955
2014-08-02 18:05:45 +00:00
Jordan Rose
9f64db085a Fill out the implementation of AvailabilityAttr.
This includes proper printing support as well as proper platform checking
when seeing if a decl is unavailable. A few other places in the code will
now use AvailabilityAttr::isUnavailable instead of just checking the
is-unavailable-always flag (and not always checking the platform).

No new tests yet because this doesn't include /parsing/ the other fields
of AvailabilityAttr. That will come next, at which point we'll test each
of the cases that has been switched over to use
AvailabilityAttr::isUnavailable.

Part of <rdar://problem/17024498>

Swift SVN r20844
2014-07-31 18:58:17 +00:00
Jordan Rose
5c1e9d7d36 [Accessibility] Store setter accessibility explicitly.
Previously, we were just storing setter accessibility via the accessibility
level on the setter function. However, some Stored properties never actually
have a setter synthesized, which led to the compiler dropping the setter
accessibility at serialization time. Rather than try to hack up something
clever, just store the setter accessibility explicitly in every
AbstractStorageDecl. (We still only serialize it for VarDecls, because
settable SubscriptDecls always have setter functions.)

<rdar://problem/17816530>

Swift SVN r20598
2014-07-26 22:43:54 +00:00
Chris Lattner
6d0934d33d Introduce a new 'renamed' modifier on unavailable attributes. This allows Xcode
to emit fixit's when we rename something, e.g.:

t.swift:6:9: error: 'float' has been renamed to Float
var y : float
        ^~~~~
        Float

Adopt this in the stdlib.



Swift SVN r20549
2014-07-25 18:00:37 +00:00
Jordan Rose
8f520414b7 [Accessibility] A private class cannot contain public methods.
There's no meaningful way in which these methods are public, since they
can't be accessed through any value of the type

<rdar://problem/17647878>

Swift SVN r20224
2014-07-20 17:26:24 +00:00
Jordan Rose
6752d856ca [Accessibility] Private members cannot override public members.
...unless they are in a private class.

Consider this scenario:

  class Base {
    func foo() -> Base { ... }
  }
  class Sub : Base {
    private override func foo() -> Sub { ... }
  }
  class Grandchild : Sub {
    override func foo() -> Base { ... }
  }

Because Grandchild can't see Sub, its override of foo() looks perfectly
reasonable...but now Sub's expectations for foo() have been broken.

Swift SVN r19769
2014-07-10 01:20:10 +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
Jordan Rose
faa0fc4e41 [Accessibility] Setter requirements must be public for public conformances.
That is, if a protocol specifies that a property or subscript is settable,
check the accessibility of the conforming type's setter.

Swift SVN r19714
2014-07-09 00:07:45 +00:00
Jordan Rose
3f59d6b9ee Drop the '@' from access control modifiers.
Test and stdlib changes to follow.

Swift SVN r19671
2014-07-08 02:16:59 +00:00
Jordan Rose
d545ac1623 [Accessibility] @required initializers must be as accessible as the type.
Swift SVN r19383
2014-06-30 23:38:36 +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
Ted Kremenek
c91ffb63a5 Tweak "is unavailable" diagnostic to include full declaration name.
This makes many of the diagnostics far more useful for diagnosing
what is really unavailable.

Swift SVN r19201
2014-06-26 00:50:41 +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
Chris Lattner
183b7e3790 fix <rdar://problem/16955318> Observed variable in a closure triggers an assertion
Swift SVN r18419
2014-05-19 14:37:38 +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
Doug Gregor
d360ecd4f7 Extend availability checking to other expressions that have declarations.
We weren't diagnosing initializer delegation/chaining, subscripts, or
(the one that got me concerned) members accessed through AnyObject.

Swift SVN r18271
2014-05-17 20:51:01 +00:00
Chris Lattner
1b3f588d95 fix <rdar://problem/16941124> Overriding property observers warn about using the property value "within its own getter"
This is a regression introduced in r18184 which cased warnings on loads from
a property in its willSet/didSet.


Swift SVN r18210
2014-05-16 20:42:50 +00:00
Chris Lattner
cf55f7edd5 fix:
<rdar://problem/16264989> property not mutable in closure inside of its willSet
and:
<rdar://problem/16826319> willSet immutability behavior is incorrect

by changing how we handle immutability of an observing property within its willSet.
Instead of trying to model it as an rvalue, just model it as an lvalue (which it is)
and diagnose the problem with a warning in MiscDiagnostics.



Swift SVN r18184
2014-05-16 06:32:33 +00:00
Joe Pamer
1e5b9116d4 More array casting work:
- Continue adding support for checked downcasts of array types (rdar://problem/16535104)
- Fix non-bridged array conversions post-r17868
- Fix rdar://problem/16773693
- Add tests for NSArray coercions to and from Array<T>

Swift SVN r17957
2014-05-12 20:49:42 +00:00
Joe Pamer
2eedc06d66 Begin adding plumbing for the type checker to accept "forward" bridged array conversions. (rdar://problem/16540403)
Swift SVN r17640
2014-05-07 19:45:37 +00:00
Joe Pamer
86b79d6bd3 Some code cleanup for array upcast conversions. (Part 2 of the fix for rdar://problem/16540403)
Swift SVN r16837
2014-04-25 19:52:06 +00:00
Joe Pamer
066f5e6da5 Allow for simple upcast conversions between array types. (Part 1 of the fix for rdar://problem/16540403)
Swift SVN r16836
2014-04-25 19:52:05 +00:00