Commit Graph

96 Commits

Author SHA1 Message Date
Robert Widmann
39494b2ba2 Rearrange test code for exhaustiveness 2017-04-28 02:06:39 -04:00
Doug Gregor
7dd1c87dd3 [SE-0160] Warn about uses of @objc declarations that used deprecated @objc inference.
When in Swift 3 compatibility mode without
`-warn-swift3-objc-inference`, warn on the *uses* of declarations that
depend on the Objective-C runtime that became `@objc` due to the
deprecated inference rule. This far more directly captures important
uses of the deprecated Objective-C entrypoints. We diagnose:

* `#selector` expressions that refer to one of these `@objc` members
* `#keyPath` expressions that refer to one of these `@objc` members
* Dynamic lookup (i.e., member access via `AnyObject`) that refers to
  one of these `@objc` members.
2017-03-31 21:22:15 -07:00
Paweł Szot
e935700c25 [SR-4087] fix "add @available attribute" location (#7864) 2017-03-03 10:51:02 -08:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Jordan Rose
38e6b2808e Do even less availability checking under -disable-availability-checking. (#4214)
...and make sure we're in that mode for SIL inputs and for sil-opt and
sil-extract, even when working with AST types and declarations rather
than SIL types.

Without this, we get zillions of deprecation warnings coming out of
the validation tests SIL/parse_stdlib_*.sil, which dump the standard
library and then attempt to re-parse it. This has been causing the
"long" tests to take, well, too long.
2016-08-11 10:19:46 -07:00
Dmitri Gribenko
d175b3b66d Migrate FileCheck to %FileCheck in tests 2016-08-10 23:52:02 -07:00
David Farler
7bfaeb57f1 [SE-0081] Warn on deprecated where clause inside angle brackets
and provide a fix-it to move it to the new location as referenced
in SE-0081.

Fix up a few stray places in the standard library that is still using
the old syntax.

Update any ./test files that aren't expecting the new warning/fix-it
in -verify mode.

While investigating what I thought was a new crash due to this new
diagnostic, I discovered two sources of quite a few compiler crashers
related to unterminated generic parameter lists, where the right
angle bracket source location was getting unconditionally set to
the current token, even though it wasn't actually a '>'.
2016-07-26 01:41:10 -07:00
Slava Pestov
ddc51c5917 AST: Implement SE-0102, introducing new semantics for Never alongside @noreturn
No migrator support yet, and the code for @noreturn is still in
place.
2016-07-22 14:56:39 -07:00
Devin Coughlin
c553de4478 [Sema] Remove 'deployment target ensures guard will always be true'
Remove the diagnostic that warns when an availability check is unnecessary
because the minimum deployment target ensures it will always be true. This
diagnostic is valuable (it tells users that they have dead fallback code) but
can also be super annoying when a source file is shared between projects with
different deployment targets. There is not currently a good mechanism to
suppress these warnings (for example, by expressing a "compatibility version" in
the source or as a build setting) and so it is better to turn the diagnostic
off.

rdar://problem/22337402
2016-07-10 19:00:47 -04:00
Chris Lattner
3549ec5404 [QoI] make several improvements to the unused expression diagnostics, to go
along with recent policy changes:

- For expression types that are not specifically handled, make sure to
  produce a general "unused value" warning, catching a bunch of unused
  values in the testsuite.

- For unused operator results, diagnose them as uses of the operator
  instead of "calls".

- For calls, mutter the type of the result for greater specificity.

- For initializers, mutter the type of the initialized value.

- Look through OpenExistentialExpr's so we can handle protocol member
  references propertly.

- Look through several other expressions so we handle @discardableResult
  better.
2016-05-16 23:26:07 -07:00
Trent Nadeau
0cc851568a Updated tests to use @discardableResult and _ = . 2016-05-11 22:53:38 -04:00
Chris Lattner
8746676616 Move @noescape and @autoclosure to their new places in various tests, NFC. 2016-04-15 16:05:35 -07:00
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Daniel Duan
7cabf3555b [Parser] update test for SE-0040 changes 2016-03-11 16:01:37 -08:00
Ben Langmuir
ceb1069199 Prefer original spelling of 'static' vs. 'class'
Try to match the original spelling of static/class in diagnostics and
when printing the AST. Also fixes cases with
PrintOptions.PrintImplicitAttrs = false, where we would just print
'class', which was not valid code.
2016-03-03 13:48:30 -08:00
Chris Lattner
dfaaebc0a0 Merge pull request #1333 from dduan/SE-0031
[SE-0031] Adjusting 'inout' Declarations for Type Decoration
2016-02-26 10:41:58 -08:00
Daniel Duan
780b58a9a5 [Parser] update tests for 'inout' syntax adjustment 2016-02-26 01:33:22 -08:00
practicalswift
ce6afbbc2d [gardening] Fix recently introduced typo: "createable" → "creatable" 2016-02-24 07:35:42 +01:00
Doug Gregor
38c1de69e4 Reinstate "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit ce7b2bcf09, tweaking
a few validation tests appropriately (1 crasher fixed, two -verify
tests that needed updating).
2016-01-14 00:21:48 -08:00
Erik Eckstein
ce7b2bcf09 Revert "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit 2b2e9dc80e.

It broke some compiler crasher tests
2016-01-13 20:42:58 -08:00
Slava Pestov
79b24fa7d1 Update availability tests to be independent of the actual deployment target
Use fictional version numbers in the 10.50..10.99 range.
2016-01-13 19:27:26 -08:00
gregomni
2b2e9dc80e [SR-511][Parse] Add 'associatedtype' keyword and fixit
Adds an associatedtype keyword to the parser tokens, and accepts either
typealias or associatedtype to create an AssociatedTypeDecl, warning
that the former is deprecated. The ASTPrinter now emits associatedtype
for AssociatedTypeDecls.

Separated AssociatedType from TypeAlias as two different kinds of
CodeCompletionDeclKinds. This part probably doesn’t turn out to be
absolutely necessary currently, but it is nice cleanup from formerly
specifically glomming the two together.

And then many, many changes to tests. The actual new tests for the fixits
is at the end of Generics/associated_types.swift.
2016-01-13 17:54:31 -08:00
Ge Sen
7ac02d54ba Erase redundant whitespaces. 2015-12-10 13:35:06 +08:00
Joe Groff
fbd2e4d872 Rename @asmname to @_silgen_name.
This reflects the fact that the attribute's only for compiler-internal use, and isn't really equivalent to C's asm attribute, since it doesn't change the calling convention to be C-compatible.
2015-11-17 14:13:48 -08:00
Devin Coughlin
1165aca545 [Sema] Suppress deprecation/availability diagnostics in branches with empty availability
We currently emit diagnostics for references to deprecated and potentially
unavailable APIs in branches that are dead for the current platform and
minimum deployment target. These dead branches can arise when sharing swift
source between targets or in playgrounds intended to be run on multiple OS
versions.

So for example, suppose the developer has the following code targeting
OSX 10.9+ and iOS 8.0+:

if #available(OSX 10.10, *) {
  // Use replacement API introduced in OSX 10.10/iOS 8.0
} else {
  // Use old API deprecated in OSX 10.10/iOS 8.0
}

Compiling the above for iOS and with a miniminum deployment of 8.0 will
result in a deprecation diagnostic for the use of the API in the else branch
even though that branch will never execute. (Note that the branch is not dead on
the OSX target because the minimum deployment target is 10.9. For OSX we also
won't emit a deprecation warning because the API wasn't deprecated until 10.10.

This commit updates availability checking to create refinement contexts with
empty OS version ranges for #available() else branches when those branches
will definitely not execute. It suppresses deprecation and potential
availability diagnostics within those contexts. It does not suppress diagnostics
for references to APIs annotated as unconditionally unavailable (i.e., with
@available(OSX, unavailable, ...) and friends).

rdar://problem/22307360

Swift SVN r31631
2015-09-02 18:18:30 +00:00
Chris Lattner
649e5f937d generalize the existing ? and + constraints on expected diagnostics to
a simpler and more general * constraint.  This paves the way for other improvements.



Swift SVN r30622
2015-07-25 05:23:30 +00:00
Devin Coughlin
3944a1620d Sema: Update diagnostic text for when @available cannot be applied to a variable.
This changes the diagnostic text when a variable cannot be marked potentially unavailable
so that it does not explicitly use the long-style form of @available:

It changes:
  "stored properties cannot be marked potentially unavailable with 'introduced='"
to:
  "stored properties cannot be marked potentially unavailable with '@available'"

Swift SVN r30446
2015-07-21 16:33:51 +00:00
Devin Coughlin
be17941059 Sema: Build type refinement contexts for functions without bodies.
We were skipping building refinement contexts for function declarations without bodies
(such as protocol requirements and @asmname functions). These contexts are needed to
determine whether parameter and return types are available in those declaration.

Swift SVN r30380
2015-07-19 02:09:17 +00:00
Devin Coughlin
78c1961195 Sema: Add Fix-It suggesting @available() to lazy properties
It is safe to add an @available attribute to lazy properties, so suggest a
Fix-It to do so if the property references a potentially unavailable symbol.

rdar://problem/20968204

Swift SVN r30321
2015-07-17 19:01:14 +00:00
Devin Coughlin
538df11695 Sema: Update availability diagnostic for accessor override to mention accessor kind
Update the diagnostic emitted when an accessor override is less available than the
declaration it overrides to mention the accessor kind and the name of the property rather
than just the accessor declaration name, which is '_'.

rdar://problem/20427938

Swift SVN r30319
2015-07-17 17:17:00 +00:00
Devin Coughlin
217d17d6e6 Sema: Consider availability of protocol declaration when diagnosing protocol witness availability.
Now that we allow types to conform to protocols that are less available than the
type itself, we should consider the availability of the protocol when
determining whether a witness is sufficiently available to satisfy the protocol
requirement.

In particular, we should allow the following:

@available(iOS 9.0, *)
class UIRefrigerator { }

@available(iOS 9.0, *)
protocol UIRefrigeratorDelegate {
  func refrigeratorDidCool(refrigerator: UIRefrigerator)
}

@available(iOS 7.0, *)
class MyViewController : UIViewController, UIRefrigeratorDelegate {
  @available(iOS 9.0, *)
  func refrigeratorDidCool(refrigerator: UIRefrigerator) {
    ...
  }
}

This is safe because MyViewController's refrigeratorDidCool() witness is
available everywhere the protocol is available. To check this, we now
additionally intersect the availability of the protocol with the availabilities
of the witness and the requirement before checking containment.

Swift SVN r29996
2015-07-08 22:43:27 +00:00
Devin Coughlin
f93515fa8d Sema: Allow types to conform to protocols that are less available than the type itself.
The previous rules for availability checking prevented types from conforming to protocols
that were less available than the type itself. This was too restrictive, because we want
to allow developers to add additional behavior to their existing classes to
conform to new protocols while still employing older functionality from those classes on
older OSes:

@available(iOS 9.0, *)
protocol UIRefrigeratorDelegate { }

@available(iOS 8.0, *)
class MyViewController : UIViewController, UIRefrigeratorDelegate { }

We now support this idiom (and adding conformnces via protocol extensions) by allowing
references to potentially unavailable protocols inside inheritance clauses.

It is still an availability error to refer to potentially unavailable protocols in other
settings -- so, for example, attempting to cast to an unavailable protocol will cause
a compile-time error.

rdar://problem/21718497

Swift SVN r29958
2015-07-08 04:22:14 +00:00
Devin Coughlin
550b9feb05 [Sema] Improve clarity of fix-it hint to add #available.
As suggested by Jordan, change "add if #available version check" to
"add 'if #available' version check" to make it easier to read.

Swift SVN r29650
2015-06-25 01:03:50 +00:00
Devin Coughlin
5a71aaef6c [Sema] Update availability fix-it to be consistent.
Change the fix-it suggesting adding #available to be consistent with the fix-it
adding @available.

This changes "guard with version check" to "add if #available version check".

rdar://problem/21275857

Swift SVN r29648
2015-06-25 00:23:02 +00:00
Devin Coughlin
8e071b1148 Revert "[Sema] Suppress warning about useless availability checks in playgrounds and script mode."
As Jordan notes, this uses the wrong check: isScriptMode() is also true for
main.swift in an app or command-line tool.

This reverts commit 8a72f4357bc04a386cf82acd1de06896515ab5a8.

Swift SVN r29583
2015-06-23 23:39:44 +00:00
Devin Coughlin
200b55be70 [Sema] Suppress warning about useless availability checks in playgrounds and script mode.
We normally report a warning when a #available() check will always be true
because of the minimum deployment target. These warnings are potentially
annoying when the developer either cannot change the minimum deployment target
from the default (as in playgrounds) or when doing so is burdensome (as for
command-line scripts, which would require passing a target triple) -- so
suppress them.

rdar://problem/21324005

Swift SVN r29582
2015-06-23 23:31:12 +00:00
Slava Pestov
67a1f24d59 Sema: 'dynamic' attribute now diagnoses if Foundation is not imported
This prevents us from seeing a less useful error message from SILGen
further down the line.

Also fix a bug where @objc without importing Foundation was not diagnosed
after the first top-level form. Some tests were relying on this behavior,
so fix those tests, either by splitting off the objc parts of the test, or
just by passing the -disable-objc-attr-requires-foundation-module flag.

Fixes <rdar://problem/20660270>.

Swift SVN r29359
2015-06-10 01:18:27 +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
Devin Coughlin
7e6a40de7d QoI: Improve diagnostic when protocol witness is less available than protocol requires.
Instead of the rather inscrutable "'foo()' is less available than protocol requires" be
more helpful: "protocol 'HasFoo' requires 'foo()' to be available on OS X 10.9 and newer".

Also add a note indicating where the conformance was introduced, as this may be in a
separate location from both the witness and requirement.

rdar://problem/20610411

Swift SVN r29028
2015-05-26 07:48:45 +00:00
Devin Coughlin
4e9cc49a2b [Sema] Handle multiple guard #available() statements in same block.
The type refinement context builder now handles the case where multiple refinement
contexts have scopes ending after the same statement. This fixes a crash when we had
two guard #available()s in the same block.

rdar://problem/21012706

Swift SVN r28763
2015-05-19 07:19:06 +00:00
Devin Coughlin
c9952640bb Support short-form @available attributes.
Allow availability attributes of the form:

  @available(iOS 8.0, OSX 10.10, *)
  func foo() { }

This form is intended for use by third-party developers when annotating their
own declarations and uses the same syntax as #available(). This annotation
says that on iOS foo() is available on version 8.0 and newer; on OSX it is
available on 10.10; and on any other un-mentioned platform it considered
available on the minimum deployment target and greater. Just like with

For now, we support this form during parsing by synthesizing multiple implicit
long-form @available attributes. So, for example, the above annotation will
synthesize two implicit attributes:

  @available(iOS, introduced=8.0)
  @available(OSX, introduced=10.10)
  func foo() { }

Synthesizing attributes in this way is not ideal -- it makes for a poor Fix-It
experience, among other things -- but it exposes the short-form syntax with
minimal invasiveness.

rdar://problem/20938565

Swift SVN r28647
2015-05-15 23:36:11 +00:00
Devin Coughlin
9f4233bdc1 Move validation of #available() from Sema to Parse
In anticipation of adding short-form @available() annotations, move validation
of #available() platform/version lists out of Sema and into the parser. This
also enables slightly more graceful recovery from errors.

Swift SVN r28637
2015-05-15 20:08:25 +00:00
Devin Coughlin
32935bdaec Sema: Build refinement context for bodies of while loops
This allows #available() to be used in the guard condition of a while loop:

while i > 10, #available(iOS 8.0, *) {
  // Use APIs available on iOS 8.0 and above.
}

rdar://problem/20936160

Swift SVN r28623
2015-05-15 14:33:37 +00:00
Devin Coughlin
424b442db2 Sema: Don't suggest Fix-It to mark stored property as potentially unavailable
Stop suggesting Fix-Its to add @available() to stored properties. We don't allow this
yet, so the "fixed" code would still emit an error when compiled.

rdar://problem/20939804

Swift SVN r28604
2015-05-15 03:03:20 +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
Ted Kremenek
62feb5c949 Change @availability to @available.
This came out of today's language review meeting.
The intent is to match #available with the attribute
that describes availability.

This is a divergence from Objective-C.

Swift SVN r28484
2015-05-12 20:06:13 +00:00
Chris Lattner
4366da9250 more testcase updates for upcoming diagnostics change.
Swift SVN r28409
2015-05-11 06:05:00 +00:00
Dmitri Hrybenko
f46f16ae82 stdlib: implement new print() API
rdar://20775683

Swift SVN r28309
2015-05-08 01:37:59 +00:00
Chris Lattner
37f5452d15 require -> guard.
Swift SVN r28223
2015-05-06 22:53:38 +00:00
Devin Coughlin
8a28d46be2 Sema: Teach availability checking about require/else.
We now introduce a TypeRefinementContext for the fallthrough branch of a require/else
statement that continues until the end of the BraceStmt that contains the RequireStmt. The
body of  the else is checked in the context that contains the RequireStmt.

This enables availability checking with early return:

require #available(iOS 8.0, *) else { return }

Swift SVN r28113
2015-05-04 05:44:06 +00:00