Commit Graph

950 Commits

Author SHA1 Message Date
Chris Lattner
3e3f568179 By far, the most common use of Lexer::getLocForEndOfToken is in
conjunction with .fixItInsert().  As such, introduce a helper named
.fixItInsertAfter() that does what we all want.  Adopt this in various
places around the compiler.  NFC.



Swift SVN r26147
2015-03-15 05:30:04 +00:00
Devin Coughlin
749f8500d6 Sema: Emit Fix-Its for potential unavailability
We now suggest up to three Fix-Its for each reference to a potentially
unavailable symbol: one to wrap the reference in an if #os(...) { ... }
guard (if possible), one to add an @availability attribute to an enclosing
property or method (if possible), and one to add an @availability attribute
to an enclosing class/struct/extension, etc. or global function.

The goal here is not to infer the "best" Fix-It but rather to ensure
discoverability of #os() and @availability attributes. We want the user, when
faced with an availability diagnostic, to be aware of the tools in her toolbox
to deal with it.

This is still missing QoI improvements, including Fix-Its to update
existing @availability attributes and more precise wording in diagnostics
(e.g, "initializer" instead of function, "class" instead of "type"). These
improvements will come in later commits.

Swift SVN r26073
2015-03-12 23:51:11 +00:00
Ted Kremenek
9e7471d68b Revert "Revert "Rework processing of @noescape closures a bit to fix rdar://19981118:""
Turns out llvm::DataLayoutPass is used in other places, so the bots are still unhappy.
Re-applying the original change so we can fix the problem holistically.

Swift SVN r25761
2015-03-04 20:15:45 +00:00
Ted Kremenek
6781ac7bec Revert "Rework processing of @noescape closures a bit to fix rdar://19981118:"
This is breaking the testing bot because DataLayoutPass was just removed from LLVM trunk.
Chris is the best one to fix this change, but we need to get the bots green.

Swift SVN r25760
2015-03-04 20:03:33 +00:00
Chris Lattner
ab43e444d6 Rework processing of @noescape closures a bit to fix rdar://19981118:
- Have Sema, not SILGen decide if a vardecl can be captured by address
  instead of by-box.  This is a non-local property that is best computed
  during capture set formation.  Sema captures this as a bit on the new
  CapturedValue entry.
- Rework some diagnostic emission to centralize a class of noescape 
  diagnostics in capture set calculation.  Previously, funcdecl closures
  produced their diagnostics there, but ClosureExprs produced them in
  MiscDiagnostics (NFC for this part).

This fixes <rdar://problem/19981118> Swift 1.2 beta 2: Closures nested in @noescape closures copy, rather than reference, captured vars.



Swift SVN r25759
2015-03-04 19:30:36 +00:00
Chris Lattner
3489840b8d rework our representation of capture lists to compute the "isDirect" bit up front
when computing the list.  This simplifies getLocalCaptures to *just* filter out
global captures, and paves the way for other enhancements.  NFC.


Swift SVN r25739
2015-03-04 01:56:48 +00:00
Devin Coughlin
1e5daf7557 [Sema] Suppress deprecation warnings inside implicit functions
This commit suppresses deprecation warnings for references to deprecated symbols
by climbing the DeclContext hierarchy to determine if the warning location is
inside an implicit function.

This is a quick fix to get rid of spurious warnings for deprecated enums whose
nil literal conformance is synthesized by the importer. These warnings would
occur even when user code made no apparent reference to the enum in question and
instead only referred to an imported class that itself referred to the enum in a
method signature. This quick fix intentionally drops some valid warnings
(for example, for a synthesized call to a deprecated initializer in a super
class). rdar://problem/20024980 tracks adding these special purpose warnings
back.

rdar://problem/20007266

Swift SVN r25720
2015-03-03 21:16:01 +00:00
Jordan Rose
746d835ab9 Don't require "self." in local functions.
(unless the local functions are themselves within closures not inferred
@noescape)

Swift SVN r25513
2015-02-24 21:51:13 +00:00
Chris Lattner
eba7aade70 fix <rdar://problem/19763732> False positive in @noescape analysis triggered by default arguments
This was a bug in miscdiagnostics not handling parenexprs inside of scalartotuple expr.


Swift SVN r25455
2015-02-21 01:38:06 +00:00
Devin Coughlin
503e824e12 Warn on uses of deprecated APIs
Emit a warning when the developer uses an API that has been marked deprecated with an
availability attribute. Following the Clang behavior, we will only warn if the API is
deprecated on all deployment targets. For example, if an API is deprecated as of
OS X 10.11 but the minimum deployment target is 10.10 then no warning will be emitted.

rdar://problem/17406050

Swift SVN r25288
2015-02-13 23:44:28 +00:00
Dmitri Hrybenko
61286f0260 Fix warnings produced by a newer version of Clang
Swift SVN r25257
2015-02-12 23:50:47 +00:00
Doug Gregor
954b4e4d83 Implement @autoclosure(escaping).
Addresses rdar://problem/19499207.

Swift SVN r25249
2015-02-12 21:09:47 +00:00
Jordan Rose
6f87cff84e Be more consistent about requiring "self." in closures.
"self." is required whenever it causes a potentially escaping closure to
capture 'self'. This happens not just in plain ClosureExprs, but in local
functions as well. In addition, even no-escape ClosureExprs can require
self to be captured in a /parent/ closure, which may be potentially-escaping.

Swift SVN r25173
2015-02-11 07:20:29 +00:00
Devin Coughlin
a960c00456 Sema: Check getter and setter availability.
This commit adds checking for accesses of potentially unavailable getters and setters.
When walking an expression to check availability, AvailabilityWalker now keeps track of
the context for when it encounters a MemberRefExpr. This context be either
(1) the next encountered member reference could cause  the member's getter to be called
(e.g., the member ref is for a read of the property); (2) the member's setter could be
called (e.g., the member ref is the left-hand-side of an assignment);  or (3) the member
ref generates the lvalue for for an InOutExpr (&) -- in which case we have to assume both
the getter and the setter could be called. These diagnostics are protected by the
-enable-experimental-availability-checking flag.

This commit does not import separate getter and setter availability from Objective-C; that
is coming in a future commit.

Swift SVN r24870
2015-01-31 00:47:12 +00:00
Devin Coughlin
00ccdbc6c1 Sema: Move potential unavailability diagnostics into MiscDiagnostics.
This commit moves potential unavailability diagnostics (when not treating unavailable
symbols as optional) out of CSApply.cpp and into MiscDiagnostics.cpp, alongside the
deprecation-based and explicitly unavailable checks. This move is a precursor to adding
support for separate availability information on getters and setters. No intended
functional change.

Swift SVN r24836
2015-01-30 00:25:27 +00:00
Jordan Rose
a3a6c2695b Put the current target into LangOptions.
This has been long in coming. We always had it in IRGenOpts (in string form).
We had the version number in LangOpts for availability purposes. We had to
pass IRGenOpts to the ClangImporter to actually create the right target.
Some of our semantic checks tested the current OS by looking at the "os"
target configuration! And we're about to need to serialize the target for
debugging purposes.

Swift SVN r24468
2015-01-16 02:48:54 +00:00
Chris Lattner
696749d819 Three things:
- Make @autoclosure imply @__noescape everywhere, not just in the stdlib.
 - Change various noescape diagnostics to refer to "parameters", not "arguments" of the function.
 - Teach the noescape diagnostics to notice if the noescape problem is due to an
   @autoclosure argument that is implicitly noescape.  In this case, produce a helpful note
   that indicates that the invalid use of the noescape is due to the autoclosure implying it.



Swift SVN r24222
2015-01-06 22:40:24 +00:00
Chris Lattner
fcdb304bc4 Implicit conversions of noescape pointers are ok when they add qualifiers.
XCTest needs this.



Swift SVN r24139
2014-12-24 00:57:07 +00:00
Chris Lattner
58e0efc345 Enhance getDeclCaptureKind() to take the closure that is capturing the
given decl, and plumb the information down to it.  NFC since the argument
is currently dead.



Swift SVN r24132
2014-12-23 23:08:38 +00:00
Chris Lattner
3578c7fde0 Teach the type checker about subtype relationships of noescape, and use this
to allow passing off a no-escape formal parameter to the argument of a 
noescape parameter call.



Swift SVN r24126
2014-12-23 22:18:09 +00:00
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