Commit Graph

1015 Commits

Author SHA1 Message Date
Doug Gregor
4e0e32197f Extend 'availability' attribute with an unconditional 'deprecated' option.
Allow an unversioned 'deprecated' attribute to specify unconditional
deprecation of an API, e.g.,

  @availability(*, deprecated, message="sorry")
  func foo() { }

Also support platform-specific deprecation, e.g.,

  @availability(iOS, deprecated, message="don't use this on iOS")
  func bar() { }

Addresses rdar://problem/20562871.

Swift SVN r27355
2015-04-16 06:36:45 +00:00
Doug Gregor
921855ee0d Revert "Extend 'availability' attribute with an unconditional 'deprecated' option."
This reverts r27339; it broke an iOS test.

Swift SVN r27343
2015-04-16 03:36:40 +00:00
Doug Gregor
b4b5dbb5d8 Extend 'availability' attribute with an unconditional 'deprecated' option.
Allow an unversioned 'deprecated' attribute to specify unconditional
deprecation of an API, e.g.,

  @availability(*, deprecated, message="sorry")
  func foo() { }

Also support platform-specific deprecation, e.g.,

  @availability(iOS, deprecated, message="don't use this on iOS")
  func bar() { }

Addresses rdar://problem/20562871.

Swift SVN r27339
2015-04-15 23:59:20 +00:00
Devin Coughlin
d08b98b1ca Sema: Turn on availability checking by default
Enable checking for uses of potentially unavailable APIs. There is
a frontend option to disable it: -disable-availability-checking.

This commit updates the SDK overlays with @availability() annotations for the
declarations where the overlay refers to potentially unavailable APIs. It also changes
several tests that refer to potentially unavailable APIs to use either #available()
or @availability annotations.

Swift SVN r27272
2015-04-14 06:44:01 +00:00
Devin Coughlin
53fd9fb59c Sema: Finish staging back in availability checking in synthesized functions
Remove the suppression of deprecation and potential unavailability diagnostics in
synthesized functions. We still suppress some explicit unavailability diagnostics -- those
in synthesized functions in synthesized functions that are lexically contained in
declarations that are themselves annotated as unavailable. For these cases, the right
solution <rdar://problem/20491640> is to not synthesize the bodies of these functions in
the first place.

rdar://problem/20024980

Swift SVN r27203
2015-04-10 05:19:04 +00:00
Devin Coughlin
cd79e0ba4d Sema: Suppress explicit unavailability diagnostics in unavailable synthesized functions.
Suppress diagnostics about references to unavailable declarations when all
of the following conditions are met:

(1) the reference is in synthesized code;
(2) the reference is in a synthesized method; and
(3) the reference is inside a declaration marked as unavailable.

This, combined with prior work to infer availability annotations for synthesized
methods should eliminate the spurious diagnostics we have seen (e.g.,
rdar://problem/20154926) for references to unavailable types without the hammer
of suppressing all references to unavailable declarations in synthesized
functions. The right thing to do here is to not synthesize the bodies of these
functions in the first place. I've filed <rdar://problem/20491640> to track
this.

We will continue to emit an error for references to unavailable declarations
in non-implicit code, even if the reference is inside a declaration marked
unavailable.

Swift SVN r27197
2015-04-10 02:07:24 +00:00
Devin Coughlin
8c50f67120 Sema: Factor out common logic for finding enclosing declaration availability
A common operation for availability checking is determining whether some
lexically enclosing declaration matches a condition. This commit factors
out that logic. NFC.

Swift SVN r27181
2015-04-09 21:56:22 +00:00
Doug Gregor
762d1d9474 Opened existential metatypes always involve members.
Swift SVN r27172
2015-04-09 18:09:04 +00:00
Jordan Rose
182ef27f95 [ClangImporter] Handle __attribute__((availability(swift, unavailable))).
This is the new and improved version of
__attribute__((annotate("swift1_unavailable"))), with the "improved" being
specifically that the 'availability' attribute supports a message.

This requires a corresponding Clang commit.

Swift side of rdar://problem/18768673.

Swift SVN r27053
2015-04-07 02:40:22 +00:00
Devin Coughlin
3422577752 Sema: Do not emit deprecation warnings for references inside deprecated declarations
We now disregard deprecation warnings if the reference to a deprecated symbol is lexically
contained in a declaration that is itself deprecated on all deployment targets.

Swift SVN r26693
2015-03-29 06:54:26 +00:00
Devin Coughlin
bdc7475d6b Sema: Add temporary flag to stage in availability checking in implicit functions
This flag enables checking of availability (deprecation, explicit unavailability,
and potential unavailability) in synthesized functions. The flag will go away once this
checking is fully staged in.

Swift SVN r26624
2015-03-27 06:48:50 +00:00
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00
Devin Coughlin
02f542c2d0 [Sema]Suppress availability diagnostics inside synthesized functions.
This commit suppresses errors for references to unavailable symbols inside
implicit functions.

This is a quick hack to fix a hit-listed radar <rdar://problem/20007266> where
the compiler was emitting spurious errors for enums explicitly marked
unavailable in Objective-C and whose nil literal conformance is synthesized by
the importer. These errors could occur 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.

We will need to do something systematic about availability and deprecation
diagnostics in synthesized code.  In particular, we should make sure that:
(1) we never emit code that references explicitly unavailable symbols;
(2) that the user never gets an error about symbol that they did not explicitly type; and
(3) that errors can dealt with via the appropriate availability check or annotation. I'm
tracking this with radar rdar://problem/20024980.

rdar://problem/20007266

Swift SVN r26251
2015-03-18 05:51:01 +00:00
Doug Gregor
7677a454ea Move "non-self-conforming protocol type" check out of type validation.
Having semantic checking in type validation introduces the potential for more recursion, triggering crashes. By moving this semantic restriction out to a later stage, we make it more robust. Fixes 6 compiler crashers, although it regressed one compiler crasher that hits a different known issue (assertions in addGenericParameters when we have multiple parameters at the same depth).

Swift SVN r26226
2015-03-17 16:34:28 +00:00
Chris Lattner
01f3e81aa5 Work on VarDecl:
- Rename getParentPattern() -> getParentPatternBinding(), since
   it returns the pattern binding, not the pattern.
 - Introduce new getParentPattern()/getParentInitializer() methods,
   covering the most common uses of getParentPatternBinding().

NFC.



Swift SVN r26175
2015-03-16 01:54:20 +00:00
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