Commit Graph

62 Commits

Author SHA1 Message Date
Jordan Rose
08b6c5f0c9 [ClangImporter] Add support for 'SwiftImportAsNonGeneric' in API notes (#6962)
Generic Objective-C classes with this annotation will be imported as
non-generic in Swift. The Swift 3 behavior hardcoded a certain set of
class /hierarchies/ as permanently non-generic, and this is preserved
in Swift 3 mode.

Actually using this API note in a versioned way (as opposed to just
marking the class non-generic in all language versions) will cause
horrible source compatibility problems in the mix-and-match cases,
where Swift 3 code presents a non-generic type that Swift 4 expects to
be generic or vice versa.  Fixes for this will come later; right now
it's more important to add support for the feature at all.

To avoid unwanted changes in Swift 4, this commit also adds API notes
to make any existing classes in the previously-hardcoded set continue
to import as non-generic even in Swift 4. The difference is that
/subclasses/ of these classes may come in as generic. (If we want to
make a change here, that can be a separate commit.)

rdar://problem/31226414 (Swift side of rdar://problem/28455962)
2017-04-03 15:39:19 -07:00
Jordan Rose
a3eb1a7ac0 [APINotes] Match the SwiftName for NSXMLDTDKind to the headers. (#6901)
In the SDK shipped with Swift 3, NSXMLNodeKind's enumerator
NSXMLDTDKind was mistakenly annotated with `NS_SWIFT_NAME(DTDKind)`
instead of `NS_SWIFT_NAME(dtd)`. We'd like to fix that in a later
version of the SDK, but we need to maintain Swift 3 compatibility on
the off-chance someone is using the bad name. If we /do/ decide to
change this, we can undo this change (going back to an API note
SwiftName of 'dtd') and add a Swift-3-versioned SwiftName of 'DTDKind'
instead.
2017-01-24 15:11:14 -08:00
Jordan Rose
99cdfa84f8 [APINotes] Source compatibility for nullability on array parameters. (#5800)
While the second argument to NSFastEnumeration's
countByEnumerating(with:objects:count:) really shouldn't be nil, it's
possible someone got away with it in Swift 3.

Follow-up for rdar://problem/25846421.
2016-11-15 14:18:09 -08:00
Tony Parker
8f8f6fd5f3 Fix AffineTransform initializer 2016-11-07 14:02:08 -08:00
Kevin Perry
eba89a61a6 Switched from Availability: nonswift to SwiftPrivate: true 2016-10-27 12:50:40 -07:00
Kevin Perry
6f83a82d14 Ensure directory URL enumerator error handler block is invoked with non-nil URL 2016-10-26 16:18:51 -07:00
Jordan Rose
6163679538 [APINotes] Replace old FactoryAsInit annotation with equivalent SwiftNames.
'processInfo' was removed entirely because it's now considered a class property,
and we don't ever import those as initializers.
2016-10-14 09:07:43 -07:00
Jordan Rose
b5aca663bc [ClangImporter] Remove importer-based NS stripping. (#3880)
* [ClangImporter] Remove importer-based NS stripping.

As Tony puts it, in the end we wound up with more Foundation
declarations imported as members or keeping "NS" than those that
dropped it, and any further decisions will be made on a case-by-case
basis. Move all of the existing cases of prefix-stripping into
Foundation's API notes and drop the logic from the compiler.

Tested by dumping the generated interface for Foundation and its
submodules for both macOS and the iOS simulator, and comparing the
results. A few cases did slip through here because of the interaction
between "SwiftName" and "Availability: nonswift".

The next commit will re-add "NS" to some stragglers that we missed.

rdar://problem/26880017

* APINotes: Add "NS" back to a few types.

NSKeyedUnarchiverDelegate
NSKeyedArchiverDelegate
NSTextCheckingTypes
NSBinarySearchingOptions
NSEnumerationOptions
NSSortOptions

More rdar://problem/26880017

* Remove now-redundant SwiftNames from API notes.

No change observed in the generated interface of Foundation and its
submodules.

Finishes rdar://problem/26880017.
2016-08-01 20:54:26 -07:00
Tony Parker
3331dc4399 Merge pull request #3610 from phausler/ByteCountFormatter_naming_updates
[Foundation] Update ByteCountFormatter to have a uniform apinotes ann…
2016-07-26 11:02:11 -07:00
Tony Parker
a0470750bb Merge pull request #3609 from phausler/CharacterSet_naming_changes
[Foundation] Update CharacterSet and NSCharacterSet punctuationCharac…
2016-07-26 09:41:47 -07:00
swift-ci
c41edb8c94 Merge pull request #3670 from parkera/rename_task_to_process 2016-07-25 20:50:20 -07:00
swift-ci
00934a74eb Merge pull request #3667 from parkera/rename_nsoutputstream 2016-07-24 13:59:07 -07:00
Tony Parker
be316f5035 Rename NSTask to Process 2016-07-21 15:23:12 -07:00
Tony Parker
cecc463bd0 Rename NSOutputStream to OutputStream 2016-07-21 14:06:15 -07:00
Tony Parker
6d9515daeb <rdar://problem/27425997> NSCoder encodeInt:forKey cannot be overridden in Swift, throws runtime exception 2016-07-21 11:29:31 -07:00
Philippe Hausler
83e7dbbafc [Foundation] Update ByteCountFormatter to have a uniform apinotes annotation for stringFromByteCount:
rdar://problem/26481720 NSByteCountFormatter naming inconsistency
2016-07-19 11:11:11 -07:00
Philippe Hausler
e9cae7be79 [Foundation] Update CharacterSet and NSCharacterSet punctuationCharacters to more consistent naming
Addresses rdar://problem/26628434 Swift3: "whitespaces"?
2016-07-19 11:09:35 -07:00
Tony Parker
8e814ac875 New value types for Calendar, TimeZone, and Locale
As part of the extensive work on value types in Foundation this year, we
decided to also add value types for these three key classes. In addition
to adding value semantics, the API was extensively audited to improve
Swift interop (especially Calendar).

rdar://26628184
2016-07-17 09:42:37 -07:00
Andrew Trick
888ff1ae99 Revert "New value types for Calendar, TimeZone, and Locale"
This reverts commit 46a9f57329.

This broke Swift CI, OSS incremental RA:

./swift/stdlib/public/SDK/Foundation/TimeZone.swift:228:45: error: 'NSTimeZone' is not implicitly convertible to 'TimeZone'; did you mean to use 'as' to explicitly convert?
        return lhs._wrapped.isEqual(to: rhs._wrapped)
2016-07-16 18:34:32 -07:00
Tony Parker
46a9f57329 New value types for Calendar, TimeZone, and Locale
As part of the extensive work on value types in Foundation this year, we
decided to also add value types for these three key classes. In addition
to adding value semantics, the API was extensively audited to improve
Swift interop (especially Calendar).

rdar://26628184
2016-07-16 17:58:27 -07:00
Andrew Trick
7b5723b9a5 Revert "New value types for Calendar, TimeZone, and Locale"
This reverts commit 9c1f21bdf0.

This breaks swift-ci for everyone:

stdlib/public/SDK/Foundation/Calendar.swift:426:74: error: 'DateInterval' is only available on iOS 10.0 or newer
    public func dateInterval(of component: Component, for date: Date) -> DateInterval? {
2016-07-16 17:08:06 -07:00
Tony Parker
9c1f21bdf0 New value types for Calendar, TimeZone, and Locale
As part of the extensive work on value types in Foundation this year, we
decided to also add value types for these three key classes. In addition
to adding value semantics, the API was extensively audited to improve
Swift interop (especially Calendar).

rdar://26628184
2016-07-16 15:48:08 -07:00
Philippe Hausler
e0ca8fbd80 [Foundation] Keep NS Updates due to changes in SE-0086
Second pass at updates for SE-0086 feedback

<rdar://problem/26892977> Make sure NSOrderedSet keeps its NS
<rdar://problem/26880016> NSBundleResourceRequest should keep its NS
<rdar://problem/26892958> Make sure NSAttributedString keeps its NS
<rdar://problem/26653694> NSCoder.decodeTopLevelObjectForKey does not follow naming guidelines
<rdar://problem/27355801> Foundation should have a structural type for TextCheckingResult
<rdar://problem/26770611> NSExpression naming is a bit awkward in swift
<rdar://problem/26653451> NSCoder encodeDataObject is misleading
<rdar://problem/26653653> NSCoder decodeObjectOfClass is redundant
2016-07-15 09:56:21 -07:00
Tony Parker
35dd2462f4 Naming updates and hoists for SE-0086
XMLNodeOptions -> XMLNode.Options
NSTextCheckingTypes -> hoisted into NSTextCheckingResult
URLSessionTaskMetricsResourceFetchType ->
URLSessionTaskMetrics.ResourceFetchType

27235689
26995110
2016-07-12 18:08:39 -07:00
Tony Parker
d39ad943d4 Some class methods became properties, which invalidated their apinotes fixes.
This change makes them regain their fixed names.

<rdar://problem/27301651> Renaming changes resulted in notANumber becoming notA
2016-07-12 17:22:18 -07:00
Doug Gregor
823c24b355 [SE-0112] Rename ErrorProtocol to Error.
This is bullet (5) of the proposed solution in SE-0112, and the last
major piece to be implemented.
2016-07-12 10:53:52 -07:00
Doug Gregor
ca4a32b5a9 [SE-0112] Bridge NSError to ErrorProtocol.
Introduce bridging of NSError to ErrorProtocol, so an Objective-C API
expressed via an "NSError *" will be imported using ErrorProtocol in
the Swift. For example, the Objective-C method:

  - (void)handleError:(NSError *)error userInteractionPermitted:(BOOL)userInteractionPermitted;

will now be imported as:

  func handleError(_ error: ErrorProtocol, userInteractionPermitted: Bool)

This is bullet (3) under the proposed solution of SE-0112. Note that
we made one semantic change here: instead of removing the conformance
of NSError to ErrorProtocol, which caused numerous problems both
theoretical and actual because the model expects that an NSError
conforms to ErrorProtocol without requiring wrapping, we instead limit
the ErrorProtocol -> NSError conversion that would be implied by
bridging. This is defensible in the short term because it also
eliminates the implicit conversion, and aligns with SE-0072, which
eliminates implicit bridging conversions altogether.
2016-07-12 10:53:52 -07:00
Mishal Shah
23b646eed2 Update master to build with Xcode 8 beta 2, OS X 10.12, iOS 10, tvOS 10, and watchOS 3 SDKs 2016-07-06 10:48:45 -07:00
Philippe Hausler
5947b75d17 [Foundation] The hoisted type for EnumerationOptions should be rooted in NSAttributedString not AttributedString 2016-07-05 13:14:30 -07:00
Philippe Hausler
24ff368d4f [Foundation] Swift3 API naming feedback
Addresses the following issues:

rdar://problem/25992816 -[NSUserDefaults registerDefaults] is being imported as NSUserDefaults.register(), which is confusing
rdar://problem/26291437 UserDefaults has 'setURL(forKey:)' instead of 'set(_:forKey:)'
rdar://problem/26375229 FileManager overlay has old naming
rdar://problem/26090891 NSBundle methods that are overridden in the apinotes incorrectly handle the first argument pattern
rdar://problem/26271340 struct URL initializer for fileURLWithFileSystemRepresentation is incorrectly named'
rdar://problem/26443640 XMLDTDNode.Kind conflicts with XMLNode.Kind and should be renamed to XMLDTDNode.DTDKind
rdar://problem/26500390 registerUndoWithTarget in overlay not updated for new API names
rdar://problem/26653451 NSCoder encodeDataObject is misleading
rdar://problem/26653653 NSCoder decodeObjectOfClass is redundant
rdar://problem/26653694 NSCoder.decodeTopLevelObjectForKey does not follow naming guidelines
rdar://problem/26656299 SocketNativeHandle should be a hoisted type to SocketPort
https://bugs.swift.org/browse/SR-1903
2016-07-05 11:19:12 -07:00
Jordan Rose
e8c1ad3959 [APINotes] NSPointerFunctionsOptions 0-valued members shouldn't be [].
.strongMemory and .objectPersonality happen to be the default settings
in their respective subgroups, but that doesn't mean they should be
omitted from the option set.
2016-06-30 15:01:16 -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
Chris Willmore
73d5077bae Add API notes for Foundation following internal Swift 3 naming audit. 2016-04-07 20:35:18 -07:00
Doug Gregor
0e40128d1a [Clang importer] Use Clang swift_bridge attribute for bridging.
When an Objective-C class type is annotated with the swift_bridge
value type, bridge it to the named type. Use API notes on Foundation
rather than special cases.

For Objective-C classes where bridging was baked into the Clang
importer (NSString, NSArray, NSDictionary, NSSet), add API notes to
put the appropriate swift_bridge attribute on these Objective-C
classes.

Note: requires Clang update.
2016-03-10 23:10:28 -08:00
Doug Gregor
c1cc39accc [Clang importer] Rely on Clang's mapping of API notes to attributes directly.
Rather than managing API notes directly in the Clang importer, tell
Clang where to find the API notes files and let it map them directly
to attributes. Then, use the existing attribute-mapping
mechanisms---with minor extensions for cases where Clang previously
didn't map some Swift-specific API notes---to get at that information.

There is a minor regression where we can no longer apply API notes to
declarations that don't have a specific Clang declaration. The
specific example (NSError's inherited init()) comes from
rdar://problem/21042412; we've regressed here, but the correct fix is
(and has always been) on the Objective-C side
(rdar://problem/19977891).

Finishes rdar://problem/24447420.
2016-02-18 16:48:02 -08:00
Jordan Rose
ff7b6b74fe Foundation overlay: Add a generic NSCoder.decodeObjectOfClass(_:forKey:).
Like decodeTopLevelObjectOfClass(_:forKey:), this API works very nicely
as a generic method in Swift, and this one is actually the one we expect
to be commonly used. One thing to note here is that these methods are
stricter than their ObjC counterparts: they will do a forced checked cast
even when the unarchiver does not use "secure" coding.

This depends on the previous commit; without it, we do not actually
enforce type safety for these methods.

The API notes change is to make the non-generic version of this method
unavailable so that it does not participate in overload resolution.
Without this we prefer the non-generic method unless there's a contextual
type for the result. I've filed rdar://problem/22243198 to track taking
this out once Foundation has updated their headers.

rdar://problem/17060110 (again)

Swift SVN r31154
2015-08-12 01:36:08 +00:00
Jordan Rose
5619b5dd44 [apinotes] Remove information that has been migrated into the SDKs.
I'll be filing Radars for the rest of these. (Some of them already have them.)

rdar://problem/19003559&19756368&20276854

Swift SVN r29324
2015-06-05 23:02:17 +00:00
Jordan Rose
fa5bd4c6c8 [ClangImporter] Allow apinotes to affect inherited initializers.
Then use that to ban NSError.init(), because it doesn't create a valid
NSError. In the long run Foundation will hopefully add this to their
headers, but they can't yet (rdar://problem/19977891).

rdar://problem/21042412

Swift SVN r28881
2015-05-21 18:11:17 +00:00
Argyrios Kyrtzidis
dfe9a2de57 [apinotes] Change to nullable parameter for NSZoneName.
Documentation for NSZoneName says:
"If zone is nil, the default zone is used".

Swift SVN r24731
2015-01-26 19:44:04 +00:00
Anna Zaks
7af94af837 [API Notes] Fix inconsistency between NSURLCredential's init and the factory method.
Swift SVN r24632
2015-01-22 03:48:46 +00:00
Anna Zaks
c2a7613612 [API Notes] Address outstanding nullability issues + new audited pieces
<rdar://problem/17902944> UIView's motionEffects property should never return 'nil'
<rdar://problem/17971360> [factor-init] SKPhysicsJointPin's factory method is not converted to a Swift API initializer
<rdar://problem/18553910> #IUO UICollectionViewUpdateItem properties
<rdar://problem/18875692> NSEntityDescription subentities/subentitiesByName should be marked optional
<rdar://problem/18919879> Swift: NSTableView's preparedCellAtColumn(_:row:) should return an optional
<rdar://problem/18940072> NSPredicate's init(format:) should not be optional
<rdar://problem/18987481> NSURLRequest without NSURL crashes Swift
<rdar://problem/19034448> UIPrintInfo’s -init is banned, should use +printInfo
<rdar://problem/19147412> NSUserInterfaceItemIdentification declares identifier as a non-optional String and it should be optional or IUO
<rdar://problem/19347931> Declaration of a parameter in Cocoa API in Swift is wrong (NSDateFormatter)
+ additions to the WatchKit audit

+ additions to HealthKit and HomeKit.

Swift SVN r24630
2015-01-22 03:29:07 +00:00
Anna Zaks
9064df226a [apinotes] Add fresh API audit drop.
Here, we mark the null_resettable properties as explicit "U".
Fixed UIColor and NSColor's initWithCGColor as returning an optional (radar://18420272)
Fixed fontDescriptorWithSymbolicTraits (rdar://problem/18812268)
Contains audit for NSXMLParserDelegate (rdar://problem/18227344)
+ a few other newly audited APIs

Swift SVN r23698
2014-12-05 00:16:08 +00:00
Anna Zaks
e7e455a74a [API Notes] Fix several mis-audits.
See radar://18903832

Swift SVN r23155
2014-11-07 02:53:00 +00:00
Anna Zaks
27116c7aad API Notes: Correct audit errors
- Mark more initializers as non-optional.
    <rdar://problem/18559511> Audit the list of UIKit symbols that marked as returning optional
    <rdar://problem/18559660> Audit the list of AppKit symbols that marked as returning optional
    <rdar://problem/18559676> Audit the list of Foundation symbols that marked as returning optional
    <rdar://problem/18559730> Audit the list of Scenekit symbols that marked as returning optional
 - NSMenu.popUpMenuPositioningItem (radar://18505688)
 - Remove NSXMLParserDelegate audit since it leads to crashes (radar://18227344)
 - UICollectionViewController collectionView should not be optional (radar://18508177)

Swift SVN r22570
2014-10-07 21:24:16 +00:00
Anna Zaks
505257ae9b API Notes: This contains audit for most of AppKit!
Plus, smaller enhancements on the other frameworks.
Removes the need for _PrintableNSObjectType hack (rdar://problem/16883288)

Swift SVN r22185
2014-09-22 21:47:22 +00:00
Anna Zaks
c61280cf35 API Notes: Mark several APIs as unavailable.
- Make NSZone functions unavailable radar://16688847
 - Distributed Objects subsystem should not be imported into Swift radar://16689104
 - NSCalendarDate is available in Swift, but deprecated radar://16689207
 - Do not import NSMethodSignature class and related methods radar://16689329
 - NSInvocationOperation should be unavailble in Swift radar://17921785

Swift SVN r22090
2014-09-18 18:51:51 +00:00
Anna Zaks
61df57ea77 API Notes: Corrections to Foundation and UIKit
Swift SVN r21795
2014-09-09 01:47:04 +00:00
Doug Gregor
37db85ae8f -[NSData initWithBase64EncodedString:options:] can return nil
Swift SVN r21727
2014-09-04 23:06:57 +00:00
Doug Gregor
eaefb5e2b0 String's NSString API: Replace factory methods with failable initializers.
Addresses rdar://problem/18225788.


Swift SVN r21710
2014-09-04 17:21:33 +00:00
Doug Gregor
cc31f9bae0 Temporarily fix nullability of -[NSData initWithBase64EncodedString:options].
This keeps our own test cases running; the actual fix is tracked by
rdar://problem/18230185.


Swift SVN r21708
2014-09-04 16:10:41 +00:00