Commit Graph

137 Commits

Author SHA1 Message Date
Jordan Rose
a679aca7c5 [PrintAsObjC] Fix class properties with generic parameters.
public static var myDictionary: [String: AnyObject]

becomes

    SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, copy)
      NSDictionary<NSString *, id> * _Nonnull myDictionary;)

and the commas in the ObjC generic break the macro, just like they do with
C++ templates. Fix this by making the macro variadic.

rdar://problem/26879147
2016-06-20 15:12:45 -07:00
Jordan Rose
e7fe0abeed Don't treat Swift methods named "init" as ObjC ARC init methods. (#2989)
Under ARC, methods in the "init" family are considered to have
NS_REPLACES_RECEIVER semantics ("consumes" self and returning a
value at +1). This is correct for Objective-C "init methods",
which are equivalent for Swift's initializers, but almost never
correct for any other methods that happen to start with the word
"init".

Note that Swift still follows all the other ARC conventions, so
if you name a method or property, say, "newItemController", the
value will be returned at +1. For methods this is probably
desirable, but for properties maybe not. We could do something
similar for property accessors to make sure they always have
the default "no method family" semantics in Objective-C.

rdar://problem/25759260
2016-06-20 14:09:53 -07:00
Mishal Shah
87b7bcfd3e Update master to build with Xcode 8 beta 1, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs. 2016-06-14 14:53:55 -07:00
Jordan Rose
8643de9842 [PrintAsObjC] Respect private(set) on class properties.
rdar://problem/24564858
2016-06-09 18:25:15 -07:00
Jordan Rose
135e9b99f1 [PrintAsObjC] Emit Xcode-7-compatible class properties.
There's not yet a released version of Apple Clang that supports
Objective-C class properties, so make sure the generated header
guards any uses of them with a __has_feature check, and provides
declarations of the accessor methods as well.

https://bugs.swift.org/browse/SR-1442
2016-05-09 14:13:57 -07:00
Chris Lattner
8c1c0bed8c update the last of the testsuite to have parens around function type parameters. 2016-05-06 21:07:08 -07:00
Joe Groff
c49a992598 Turn on import of ObjC generics. 2016-04-25 11:56:13 -07:00
Joe Groff
f4765f676c Sema: Allow ObjC generic extensions to perform @objc operations involving generics.
Though the generic type information isn't present, it isn't necessary if we're just invoking other operations from Objective-C. This should allow an extension to use the generic class's own API to some degree, as it would if defined on the nongeneric form.
2016-04-16 08:27:32 -07:00
Jordan Rose
a79a893f9a [test] Add new tests for pointers with explicit nullability. 2016-04-11 20:06:40 -07:00
Jordan Rose
bc83940301 Make pointer nullability explicit using Optional.
Implements SE-0055: https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md

- Add NULL as an extra inhabitant of Builtin.RawPointer (currently
  hardcoded to 0 rather than being target-dependent).
- Import non-object pointers as Optional/IUO when nullable/null_unspecified
  (like everything else).
- Change the type checker's *-to-pointer conversions to handle a layer of
  optional.
- Use 'AutoreleasingUnsafeMutablePointer<NSError?>?' as the type of error
  parameters exported to Objective-C.
- Drop NilLiteralConvertible conformance for all pointer types.
- Update the standard library and then all the tests.

I've decided to leave this commit only updating existing tests; any new
tests will come in the following commits. (That may mean some additional
implementation work to follow.)

The other major piece that's missing here is migration. I'm hoping we get
a lot of that with Swift 1.1's work for optional object references, but
I still need to investigate.
2016-04-11 20:06:38 -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
Saleem Abdulrasool
89d37bc694 test: ignore unused options in some tests
These tests explicitly disable the use of modules.  However, the lit
configuration is such that the module cache path will be passed unconditionally
to the clang invocation.  Squelch the unused option warning (error).
2016-04-05 10:00:37 -07:00
Jordan Rose
50e3b33739 [ClangImporter] Implement importing of ObjC class properties.
For the most part this was just "check isInstanceProperty"; the one feature not yet implemented
is the emission of ObjC metadata for class properties.

rdar://problem/16830785
2016-03-31 14:27:56 -07:00
Joe Groff
4c47c22cae update tests for split objc_generics 2016-03-28 09:50:30 -07:00
Joe Groff
ecc943736f Optionals of ObjC generic class type are representable in ObjC. 2016-03-28 09:50:30 -07:00
Joe Groff
874dbd8de4 PrintAsObjC: Handle imported generic classes. 2016-03-28 09:50:30 -07:00
Doug Gregor
593932741c Remove historical flags -enable-omit-needless-words/-enable-infer-default-arguments/-enable-swift-name-lookup-tables.
NFC; all of these options are always-on now and we no longer have a
way to turn them off.
2016-03-22 17:04:19 -07:00
Max Moiseev
bb3eaaf308 Merging in latest master 2016-02-24 15:10:25 -08:00
Max Moiseev
0b759a409c Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-23 14:26:14 -08:00
Max Moiseev
a558d13a3b Revert "Replace Unmanaged with UnsafeReference"
This reverts commit d72932e931.
2016-02-15 17:13:40 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Max Moiseev
55fde4c923 making tests pass 2016-02-10 16:08:40 -08:00
David Farler
8a5ed405bf Make var parameters an error for Swift 3
This finishes up revisions to SE-0003 - only var function parameters
are disallowed for Swift 3.
2016-01-30 12:39:17 -08:00
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