Commit Graph

213 Commits

Author SHA1 Message Date
Jordan Rose
f0aca936c7 Allow '@objc(RuntimeName)' on classes with generic ancestry.
This is accomplished by recognizing this specific situation and
replacing the 'objc' attribute with a hidden '_objcRuntimeName'
attribute. This /only/ applies to classes that are themselves
non-generic (including any enclosing generic context) but that have
generic ancestry, and thus cannot be exposed directly to Objective-C.

This commit also eliminates '@NSKeyedArchiverClassName'. It was
decided that the distinction between '@NSKeyedArchiverClassName' and
'@objc' was too subtle to be worth explaining to developers, and that
any case where you'd use '@NSKeyedArchiverClassName' was already a
place where the ObjC name wasn't visible at compile time.

This commit does not update diagnostics to reflect this change; we're
going to change them anyway.

rdar://problem/32414557
2017-06-05 17:32:25 -07:00
Erik Eckstein
b1d5c77cec Runtime support for the NSArchiver class attributes.
Register class names for NSKeyedArchiver and NSKeyedUnarchiver based on the @NSKeyedArchiveLegacy and @_staticInitializeObjCMetadata class attributes.

@NSKeyedArchiveLegacy registers a class name translation.
@_staticInitializeObjCMetadata just makes sure that the metadata of a class is instantiated.

This registration code is executed as a static initializer, like a C++ global constructor.
2017-05-08 14:00:03 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Philippe Hausler
2ffc3d52f2 [Foundation] Extract NSURL extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
b9da412ddd [Foundation] Extract NSDate extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
da84c29707 [Foundation] Extract NSCoder/NSKeyed(Un)Archiver extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
d1ebf836c9 [Foundation] Extract NSUndoManager extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
1050bc4f1d [Foundation] Extract NSExpression extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
16dce5a76f [Foundation] Extract NSPredicate extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
ae45b2daac [Foundation] Extract NSError extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
c3f87ce097 [Foundation] Extract geometry extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
8017c7abc0 [Foundation] Extract NSRange extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
91f3bb4f55 [Foundation] Extract NSIndexSet extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
cb5b894ac0 [Foundation] Extract NSEnumerator/NSFastEnumeration extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
3522fa8f6e [Foundation] Extract NSSet extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
574f1d068c [Foundation] Extract NSTextCheckingResult extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
c3bcd0dc18 [Foundation] Extract NSDictionary extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
5d28920d8e [Foundation] Extract NSArray extensions into a seperate file
Non functional change; purely organization/gardening
2016-10-03 12:37:25 -07:00
Philippe Hausler
4ce31cc7c0 [Foundation] Extract NSNumber extensions into a seperate file
Non functional change; purely organization/gardening (this also extracts the gyb requirement from Foundation.swift)
2016-10-03 12:37:25 -07:00
Joe Groff
9b1f238e5b SE-0139: Bridge all standard number types to NSNumber.
Extend NSNumber bridging to cover not only `Int`, `UInt`, `Double`, and `Bool`, but all of the standard types as well. Extend the `TypePreservingNSNumber` subclass to accommodate all of these types, so that we preserve type identity for `AnyHashable` and dynamic casting of Swift-bridged NSNumbers. If a pure Cocoa NSNumber is cast, just trust that the user knows what they're doing.

This XFAILs a couple of serialization tests that attempt to build the Foundation overlay, but which don't properly handle `gyb` files.
2016-09-23 10:34:22 -07:00
airspeedswift
ed5231b47c Numbered all FIXME(ABI) entries for tracking purposes. (#4868) 2016-09-19 16:41:41 -07:00
practicalswift
fa7fbdb8b0 [gardening] Remove redundant nil-initialization of optional variable
From the Swift documentation:

"If you define an optional variable without providing a default value,
 the variable is automatically set to nil for you."
2016-09-18 07:40:07 +02:00
Dmitri Gribenko
30c1695aeb Foundation: add a custom AnyHashable representation for NSSet 2016-09-15 13:27:36 -07:00
Joe Groff
8232d3355b Foundation overlay: Remove unnecessary precondition that array elements be ObjectiveCBridgeable.
This caused a crash when arrays were bridged from ObjC with `Any` or other non-bridged value type elements. Fixes rdar://problem/27905230.
2016-09-07 10:39:05 -07:00
Doug Gregor
57f1090a11 Revert "[Set/Dictionary] Eliminate "bridging" collection entrypoints."
This reverts commit dc0ae675bc. The
change here (presumably the change to Foundation) caused a regression
in several of the bridging-related benchmarks, e.g.,
ObjectiveCBridgeFromNSSetAnyObjectToString, DictionaryBridge,
ObjectiveCBridgeFromNSDictionaryAnyObjectToString.
2016-08-24 13:20:03 -07:00
Doug Gregor
dc0ae675bc [Set/Dictionary] Eliminate "bridging" collection entrypoints.
Remove the functions
_(set|dictionary)Bridge(From|To)ObjectiveC(Conditional) from the
standard library. These entrypoints are no longer used by the compiler
(thanks to generalized collection up/downcasting), so stop using them
in Foundation and in tests.
2016-08-22 15:14:09 -07:00
Jordan Rose
ba3de9ee3b NSNumber already preserves whether a value was originally boolean. (#4366)
Use that instead of rolling it up in _SwiftTypePreservingNSNumber so that we
get the right behavior when we go to write plists.

https://bugs.swift.org/browse/SR-2381
2016-08-18 15:45:30 -07:00
Doug Gregor
27515b623e Revert "NSNumber bridging: use BOOL rather than _Bool when bridging Bools." 2016-08-18 10:36:43 -07:00
Doug Gregor
d68e59371a NSNumber bridging: use BOOL rather than _Bool when bridging Bools.
The Objective-C type encoding of Boolean values in NSNumber is that of
BOOL, which is either signed char or _Bool depending on the
platform. _SwiftTypePreservingNSNumber was using _Bool, which led to
inconsistencies when bridging vs. creating an NSNumber directly. Use
BOOL consistently.

Fixes rdar://problem/27894308.
2016-08-17 16:49:30 -07:00
Joe Groff
e8346935ea Foundation overlay: Fix optionality mismatch in NSMutableDictionary subscript.
`setObject:forKey:` takes a nonnull object, causing us to accidentally pass in a boxed Optional-in-an-Any from the Swift subscript's optional newValue. Fixes rdar://problem/27875914.
2016-08-16 18:05:09 -07:00
Dmitri Gribenko
609ba7321e stdlib: add SPI for bridging for Foundation 2016-08-07 14:20:36 -07:00
Joe Groff
8ef5f40eae Merge pull request #3974 from jckarter/cvararg-post-0072
Make bridged String and collection types conform to CVarArg.
2016-08-05 09:44:25 -07:00
swift-ci
47fe3bd82c Merge pull request #3945 from jckarter/foundation-overlay-post-0072 2016-08-04 09:50:05 -07:00
Joe Groff
62afa03eb9 Improve Foundation overlay to handle bridging subscripts and dictionary literals.
SE-0072 took implicit bridging conversions away, which regressed the ability to express NSDictionaries as dictionary literals and index them using literal keys. Address this by changing the signature of init(dictionaryLiteral:) to use Hashable and Any, and by replacing the subscript from Objective-C with one using _Hashable that does the bridging on the user's behalf. This largely restores the QoI of working with NS collections.
2016-08-04 08:42:36 -07:00
Joe Groff
7535acc86b Make bridged String and collection types conform to CVarArg.
This allows String, Array, Dictionary, and Set to be passed as variadic arguments to Cocoa APIs like NSLog, NSPredicate, stringWithFormat:, etc. rdar://problem/27651717
2016-08-04 07:14:55 -07:00
Erik Eckstein
ae22fe7f6b stdlib/Foundation: optimize the NSDictionary and NSSet copy-constructors
rdar://problem/27678985
2016-08-03 17:20:46 -07:00
Jordan Rose
f42158b12e Revert "[Sema] ban multi-arguments to tuple coercion" (#3922)
It breaks cases where there really is a single unlabeled argument of tuple type, like this:

  let pairs = [(1, "A"), (2, "B")]
  print(pairs.map { $0.0 })
2016-08-01 19:22:19 -07:00
Daniel Duan
c9b73dacc2 [Sema] ban multi-arguments to tuple coercion
Implements part of SE-0110. Single argument in closures will not be accepted if
there exists explicit type with a number of arguments that's not 1.

```swift
let f: (Int, Int) -> Void = { x in } // this is now an error
```

Note there's a second part of SE-0110 which could be considered additive,
which says one must add an extra pair of parens to specify a single arugment
type that is a tuple:

```swift
let g ((Int, Int)) -> Void = { y in } // y should have type (Int, Int)
```

This patch does not implement that part.
2016-07-31 16:22:57 -07:00
Michael Ilseman
ccda8f33d1 [noescape by default] Proliferate @escaping
Adds an explicit @escaping throughout the standard library, validation
test suite, and tests. This will be necessary as soon as noescape is
the default for closure parameters.
2016-07-29 13:48:07 -07:00
Joe Groff
4b9e49827d Make all _toAnyHashable() implements @nonobjc. 2016-07-27 09:25:30 -07:00
Dmitri Gribenko
c0b183a208 Merge pull request #3781 from apple/stdlib-AnyHashable-for-Foundation.NSDecimalNumber
Add AnyHashable support for Foundation.Decimal
2016-07-27 09:22:48 -07:00
Dmitri Gribenko
168b563315 Foundation: stop exporting certain overlay methods to Objective-C 2016-07-27 01:14:56 -07:00
Dmitri Gribenko
ea693dd8d1 Add AnyHashable support for Foundation.Decimal
Add a custom AnyHashable representation to Foundation.Decimal, so that
it behaves like all other bridged types.
2016-07-27 01:14:16 -07:00
Joe Groff
5b3f2af297 Merge pull request #3756 from jckarter/turn-on-anyhashable
Turn on AnyHashable
2016-07-26 15:45:13 -07:00
Andrew Trick
a18d490d6a Migrate from UnsafePointer<Void> to UnsafeRawPointer. (#3773)
* Migrate from `UnsafePointer<Void>` to `UnsafeRawPointer`.

As proposed in SE-0107: UnsafeRawPointer.

`void*` imports as `UnsafeMutableRawPointer`.
`const void*` imports as `UnsafeRawPointer`.

Occurrences of `UnsafePointer<Void>` are replaced with UnsafeRawPointer.

* Migrate overlays from UnsafePointer<Void> to UnsafeRawPointer.

This requires explicit memory binding in several places,
particularly in NSData and CoreAudio.

* Fix a bunch of test cases for Void->Raw migration.

* qsort takes IUO values

* Bridge `Unsafe[Mutable]RawPointer as `void [const] *`.

* Parse #dsohandle as UnsafeMutableRawPointer

* Update a bunch of test cases for Void->Raw migration.

* Trivial fix for the SceneKit test case.

* Add an UnsafeRawPointer self initializer.

This is unfortunately necessary for assignment between types imported from C.

* Tiny simplification of the initializer.
2016-07-26 14:21:15 -07:00
Tony Parker
19998457d3 Merge pull request #3607 from phausler/UndoManager_registerUndo_naming_update
[Foundation] Update UndoManager registerUndo to adopt new naming rules
2016-07-26 14:15:02 -07:00
Joe Groff
1e8dd0e34b ClangImporter: Import unbounded NSSets and NSDictionaries using AnyHashable. 2016-07-26 13:36:05 -07:00
Joe Groff
e884ab737d Foundation: Make AnyHashable bridge to NSObject. 2016-07-26 13:36:05 -07:00
Dmitri Gribenko
a3254b7990 Foundation: add custom AnyHashable representations to NSNumber and NSString
We want NSNumbers bridged from Swift types to bridge back to the same
Swift type.
2016-07-26 03:10:52 -07:00