Commit Graph

114 Commits

Author SHA1 Message Date
David Farler
3f635d04c7 Reinstante var bindings in refutable patterns, except function parameters.
This reverts commits: b96e06da44,
                      8f2fbdc93a,
                      93b6962478,
                      64024118f4,
                      a759ca9141,
                      3434f9642b,
                      9f33429891,
                      47c043e8a6.

This commit leaves 'var' on function parameters as a warning to be
merged into Swift 2.2. For Swift 3, this will be an error, to be
converted in a follow-up.
2016-01-29 15:27:08 -08:00
Dave Abrahams
d72932e931 Replace Unmanaged with UnsafeReference 2015-12-18 16:22:24 -08:00
Doug Gregor
f245f18a09 Merge remote-tracking branch 'origin/swift-3-api-guidelines' into swift-3-omit-needless-words 2015-12-17 11:35:58 -08:00
Dmitri Gribenko
339c7a99dc Remove no-argument initializers from unsafe pointer types
The preferred way to create a nil pointer is to use the 'nil' literal.

Affected types:
AutoreleasingUnsafeMutablePointer
OpaquePointer
UnsafeMutablePointer
UnsafePointer
2015-12-16 14:59:50 -08:00
Doug Gregor
06c5e9cd5b Enable "omit needless words" by default.
Most of this is in updating the standard library, SDK overlays, and
piles of test cases to use the new names. No surprises here, although
this shows us some potential heuristic tweaks.

There is one substantive compiler change that needs to be factored out
involving synthesizing calls to copyWithZone()/copy(zone:). Aside from
that, there are four failing tests:

    Swift :: ClangModules/objc_parse.swift
    Swift :: Interpreter/SDK/Foundation_test.swift
    Swift :: Interpreter/SDK/archiving_generic_swift_class.swift
    Swift :: Interpreter/SDK/objc_currying.swift

due to two independent remaining compiler bugs:
  * We're not getting partial ordering between NSCoder's
  encode(AnyObject, forKey: String) and NSKeyedArchiver's version of
  that method, and
  * Dynamic lookup (into AnyObject) doesn't know how to find the new
  names. We need the Swift name lookup tables enabled to address this.
2015-12-11 14:46:50 -08:00
Maxim Moiseev
7372e9e045 COpaquePointer => OpaquePointer 2015-12-07 16:52:45 -08:00
Kevin Ballard
66369468aa Use new-style _Nullable keywords in obj-c header
Use the keywords `_Nullable`, `_Nonnull`, and `_Null_unspecified`
instead of the older compatibility forms `__nullable`, `__nonnull`, and
`__null_unspecified`.

Part of rdar://problem/23614638
2015-12-05 19:54:27 -08:00
David Farler
8f2fbdc93a Make function parameters and refutable patterns always immutable
All refutable patterns and function parameters marked with 'var'
is now an error.

- Using explicit 'let' keyword on function parameters causes a warning.
- Don't suggest making function parameters mutable
- Remove uses in the standard library
- Update tests

rdar://problem/23378003
2015-11-09 16:56:13 -08:00
Jordan Rose
239b84395a [PrintAsObjC] Use 'struct _NSZone' rather than redeclaring the typedef.
Part of rdar://problem/22702104

Swift SVN r32231
2015-09-25 17:53:46 +00:00
Jordan Rose
59176785fa [ClangImporter] Typedefs of CFTypeRef should not be imported as AnyObject.
...or rather, typealiases of AnyObject. They should be typealiases of
CFTypeRef. (The problem is that everywhere else CFFooRef becomes a typealias
for CFFoo, but we don't do the same with 'CFType'.)

Fixes a PrintAsObjC problem where we'd try to mark such typealiases as
'strong' if they show up in the generated ObjC header.

rdar://problem/22827172

Swift SVN r32230
2015-09-25 17:53:45 +00:00
Jordan Rose
2b229aa9c7 [PrintAsObjC] Fix infinite loop on typedefs of CFTypeRef.
Swift SVN r31427
2015-08-24 17:48:29 +00:00
Jordan Rose
6c9a4032aa [PrintAsObjC] A nested array of Swift closures is not @objc-compatible.
rdar://problem/22293877

Swift SVN r31308
2015-08-18 21:14:40 +00:00
Jordan Rose
5430b8063a [test] There are no more non-generic Objective-Cs.
Swift SVN r31231
2015-08-13 22:15:00 +00:00
Dmitri Hrybenko
15b0520f4a Remove support for Clang without Objective-C generics
Swift SVN r29074
2015-05-27 20:47:11 +00:00
Dmitri Hrybenko
f46f16ae82 stdlib: implement new print() API
rdar://20775683

Swift SVN r28309
2015-05-08 01:37:59 +00:00
Slava Pestov
58f0b46335 Implement @nonobjc attribute
The following declaration kinds can be marked with this attribute:
- method
- property
- property accessor
- subscript
- constructor

Use cases include resolving circularity for bridging methods in an @objc
class, and allowing overloading methods and constructors in an @objc class
by signature by marking some of them @nonobjc.

It is an error to override an @objc method with a @nonobjc method. The
converse, where we override a @nonobjc method with a @objc method, is
explicitly supported.

It is also an error to put a @nonobjc attribute on a method which is
inferred as @objc due to being part of an @objc protocol conformance.

Fixes <rdar://problem/16763754>.

Swift SVN r28126
2015-05-04 19:26:23 +00:00
Doug Gregor
9271a24a92 Introduce a protocol conformance registry for nominal types.
(Note that this registry isn't fully enabled yet; it's built so that
we can test it, but has not yet taken over the primary task of
managing conformances from the existing system).

The conformance registry tracks all of the protocols to which a
particular nominal type conforms, including those for which
conformance was explicitly specified, implied by other explicit
conformances, inherited from a superclass, or synthesized by the
implementation.

The conformance registry is a lazily-built data structure designed for
multi-file support (which has been a problematic area for protocol
conformances). It allows one to query for the conformances of a type
to a particular protocol, enumerate all protocols to which a type
conforms, and enumerate all of the conformances that are associated
with a particular declaration context (important to eliminate
duplicated witness tables).

The conformance registry diagnoses conflicts and ambiguities among
different conformances of the same type to the same protocol. There
are three common cases where we'll see a diagnostic:

1) Redundant explicit conformance of a type to a protocol:

    protocol P { }
    struct X : P {  }
    extension X : P { } // error: redundant explicit conformance

2) Explicit conformance to a protocol that collides with an inherited
  conformance:

    protocol P { }
    class Super : P { }
    class Sub : Super, P { } // error: redundant explicit conformance

3) Ambiguous placement of an implied conformance:

    protocol P1 { }
    protocol P2 : P1 { }
    protocol P3 : P1 { }

    struct Y { }
    extension Y : P2 { }
    extension Y : P3 { } // error: ambiguous implied conformance to 'P1'

  This happens when two different explicit conformances (here, P2 and
  P3) placed on different declarations (e.g., two extensions, or the
  original definition and other extension) both imply the same
  conformance (P1), and neither of the explicit conformances imply
  each other. We require the user to explicitly specify the ambiguous
  conformance to break the ambiguity and associate the witness table
  with a specific context.

Swift SVN r26067
2015-03-12 21:11:23 +00:00
Dmitri Hrybenko
f43843f25c tests: use the new substitution for the mock SDK
This is required to correctly use the mock SDK when the SDK overlay is
built and tested separately.  (Otherwise, the mock SDK might not get
used, because the overlay SDK options would expand from the
%-substitution, appear first on the command line, and shadow the mock
SDK in the search path).

Swift SVN r25185
2015-02-11 18:57:29 +00:00
David Farler
1e81ef4d32 Narrow trivial accessor creation to @objc VarDecls
Only create trivial accessors if the actual VarDecl is @objc,
explicitly or implicitly, not the class.

Also, replicate the PrintAsObjC test into classes_objc_generics since
"classes" isn't run on compilers that support Objective-C generics, and
fix the expectations.

Swift SVN r25162
2015-02-11 04:08:49 +00:00
David Farler
a079cbc49a Generate trivial accessors for static stored properties in objc classes
Expose static stored properties in @objc classes as trivial class
methods.

static let i: T => +(T)i
static var i: T => +(T)i and +(void)setI:
static var k T { get set } => No change.

Fixes rdar://problem/19784053

Swift SVN r25152
2015-02-11 00:44:59 +00:00
Jordan Rose
d397a323a3 [PrintAsObjC] Output nullability for CF types and non-retainable pointers.
For pointer types that Swift doesn't currently import using Optional
(see rdar://problem/15189170 and its dups), use __null_unspecified.

rdar://problem/19775335

Swift SVN r25144
2015-02-10 23:52:48 +00:00
Graham Batty
83b4384fac Update test flags for linux failures and support.
Also removed the sdk 'feature' in favour of the more specific
objc_interop.

Swift SVN r24856
2015-01-30 21:31:48 +00:00
Doug Gregor
b18352463e Fix expected output for non-ObjC-generics build.
Swift SVN r24653
2015-01-22 21:22:33 +00:00
Doug Gregor
fe5fe16c46 PrintAsObjC: Start printing __null_unspecified where needed.
Fixes rdar://problem/19499467.

Swift SVN r24643
2015-01-22 19:26:21 +00:00
Jordan Rose
0c182d73a3 [PrintAsObjC] Prefer the Clang name of imported typedefs.
Previously, when dealing with CF typedefs of other CF types, we would strip
off the "Ref" suffix...and then leave it off when it came time to print the
Objective-C header.

rdar://problem/19446942

Swift SVN r24562
2015-01-20 20:42:01 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Doug Gregor
83d4c3783d Teach the Objective-C printer to print specialized array/dictionary/set types.
Swift SVN r24197
2015-01-06 00:16:42 +00:00
Chris Willmore
43e112cdb0 Add Set->NSSet bridging to PrintAsObjC.
Swift SVN r23757
2014-12-06 04:44:10 +00:00
Dmitri Hrybenko
1eea220932 Use one module cache directory for all the lit tests to speed them up
Doing so is safe even though we have mock SDK.  The include paths for
modules with the same name in the real and mock SDKs are different, and
the module files will be distinct (because they will have a different
hash).

This reduces test runtime on OS X by 30% and brings it under a minute on
a 16-core machine.

This also uncovered some problems with some tests -- even when run for
iOS configurations, some tests would still run with macosx triple.  I
fixed the tests where I noticed this issue.

rdar://problem/19125022

Swift SVN r23683
2014-12-04 11:21:48 +00:00
Graham Batty
83f27a8af7 Revert "Mark tests that don't pass on linux as XFAIL."
This reverts commit 2711ca86de7bf6a7885ccea24219a48a590b1e95.

Swift SVN r23577
2014-11-24 17:42:13 +00:00
Graham Batty
198402dcfe Mark tests that don't pass on linux as XFAIL.
Swift SVN r23573
2014-11-24 17:40:37 +00:00
Doug Gregor
267f0ff756 Wrap context-sensitive nullability keywords in SWIFT_NULLABILITY.
Swift SVN r23533
2014-11-21 21:28:17 +00:00
Doug Gregor
96bdf90fcc Stop printing __null_unspecified per rdar://problem/18383574.
Swift SVN r23510
2014-11-21 05:06:53 +00:00
Doug Gregor
07740515c2 Emit nullability context-sensitive keywords for instancetype.
Swift SVN r23486
2014-11-20 21:16:00 +00:00
Joe Groff
944860adb0 PrintAsObjC: Handle forward declarations of @objc enums.
If enums are used as parameters or returns of @objc methods, we may need to forward declare those enums when printing the class @interface.

Swift SVN r23445
2014-11-19 22:27:48 +00:00
Doug Gregor
96a9751372 PrintAsObjC: Print nullability type specifiers to capture optionality.
Part of rdar://problem/19005653. There is still some work to do to
produce pretty output here, but the current output is correct.

Swift SVN r23444
2014-11-19 21:08:23 +00:00
Jordan Rose
b3dc2280a2 [PrintAsObjC] Only print inner classes if they are explicitly marked @objc.
This reduces the chances of conflict among inner class names. It's too easy
for a class to be implicitly marked @objc in Swift.

To make this work, correctly preserve the implicitness of @objc through
serialization. (We were probably intending to do this all along, since we
were serializing the flag but not doing anything with it at the other end.)

Swift SVN r21678
2014-09-03 18:19:00 +00:00
Jordan Rose
1c7b8f2972 [PrintAsObjC] Don't print nested classes as nested in Objective-C.
There are still problems with nested classes:
- They're much more likely to have colliding compile-time names
  (since the outer class's name is dropped).
- They're only picked up if the outer class is also @objc.

But at least now we won't generate invalid Objective-C. Unless the inner
classes have the same name.

rdar://problem/18187877

Swift SVN r21677
2014-09-03 18:18:59 +00:00
Doug Gregor
28866251b0 Clang importer SDK: separate out CoreFoundation.h so we can build it up.
Swift SVN r21375
2014-08-21 21:36:02 +00:00
Dave Abrahams
1438d617cd [stdlib] Rename ConstUnsafePointer=>UnsafePointer
Swift SVN r20318
2014-07-22 17:10:54 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Jordan Rose
a419138a7a [PrintAsObjC] Print 'struct Foo' or 'enum Foo' instead of 'Foo' when necessary.
To do this, we keep track of decls with superfluous typedefs (rather than
just the typedefs), and check for that. Tag decls without typedefs are
printed with the tag.

<rdar://problem/17569385>

Swift SVN r20221
2014-07-20 17:26:20 +00:00
Jordan Rose
52f7cd48b0 [PrintAsObjC] Print ownership qualifiers on properties.
weak => 'weak', unless the type is a CF type. I'm not sure weak references to
        CF types work anyway, but until we have that cleared up this works.

unowned => 'assign'. In Objective-C, use of 'assign' for object properties is
           largely deprecated in favor of 'unsafe_unretained', but unowned
           properties behave more like a 'safe_unretained'. Since they don't
           auto-update like 'weak', though, this should hint to clients to
           be careful about lifetimes.

unowned(unsafe) => 'unsafe_unretained'

As before, Arrays, Dictionaries, and Strings are considered 'copy' properties;
blocks are now considered 'copy' properties as well.

All other types get their (implied)  default: 'strong' for objects, 'assign'
for primitives.

<rdar://problem/17346846>

Swift SVN r20112
2014-07-17 20:59:53 +00:00
Doug Gregor
b29192fe54 Diagnose non-optional @IBOutlets <rdar://problem/17654693>.
A while back we decided to require @IBOutlets to be optional (via ! or
?); we got as far as ripping out the implicit !'ification of
@IBOutlets, but never added the diagnostic. Diagnose this restriction
with Fix-Its.

Swift SVN r19981
2014-07-15 19:52:01 +00:00
Jordan Rose
f35e50e017 [PrintAsObjC] Include IBOutlet/IBAction/IBOutletCollection in the header.
Also, fix a bug where value properties weren't getting marked as "copy"
if wrapped in IUOs, and replace some identifier-based comparisons with
pointer comparisons against ASTContext-cached decls.

<rdar://problem/17007235>

Swift SVN r19874
2014-07-12 01:52:01 +00:00
Chris Lattner
5b49d59c57 Remove the @ from @final and @lazy, the last major piece of
rdar://17168115.

Also, reinstate the ARM driver change and testcase that I removed
in my last patch.


Swift SVN r19790
2014-07-10 06:23:27 +00:00
Jordan Rose
c90cd11aff [PrintAsObjC] Only include internal decls if we have a bridging header.
The upshot of this is that internal decls in an app target will be in the
generated header but internal decls in a framework target will not. This
is important since the generated header is part of a framework's public
interface. Users always have the option to add members via category to an
internal framework type they need to use from Objective-C, or to write the
@interface themselves if the entire type is missing. Only internal protocols
are left out by this.

The presence of the bridging header isn't a /perfect/ way to decide this,
but it's close enough. In an app target without a bridging header, it's
unlikely that there will be ObjC sources depending on the generated header.

Swift SVN r19763
2014-07-09 23:58:57 +00:00
Jordan Rose
9e970f313e [PrintAsObjC] Handle dictionary sugar syntax.
<rdar://problem/17594798>

Swift SVN r19734
2014-07-09 18:44:47 +00:00
Jordan Rose
cf53b747d0 Don't infer @objc on private members.
You can still mark them @objc explicitly (or @IBOutlet, or anything else that
would require ObjC interop).

Also, don't print private decls in the generated header, whether @objc or not.
not.

Swift SVN r19733
2014-07-09 18:44:46 +00:00
Doug Gregor
3f4a07ffde Remove accidental commit: we don't need to annotate this as @objc
Swift SVN r19709
2014-07-08 23:02:46 +00:00